|
| 1 | +package org.schabi.newpipe.player.helper; |
| 2 | + |
| 3 | +import android.net.Uri; |
| 4 | + |
| 5 | +import androidx.annotation.NonNull; |
| 6 | +import androidx.annotation.Nullable; |
| 7 | + |
| 8 | +import com.google.android.exoplayer2.source.dash.manifest.DashManifest; |
| 9 | +import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser; |
| 10 | +import com.google.android.exoplayer2.source.dash.manifest.Period; |
| 11 | +import com.google.android.exoplayer2.source.dash.manifest.ProgramInformation; |
| 12 | +import com.google.android.exoplayer2.source.dash.manifest.ServiceDescriptionElement; |
| 13 | +import com.google.android.exoplayer2.source.dash.manifest.UtcTimingElement; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +/** |
| 18 | + * A {@link DashManifestParser} fixing YouTube DASH manifests to allow starting playback from the |
| 19 | + * newest period available instead of the earliest one in some cases. |
| 20 | + * |
| 21 | + * <p> |
| 22 | + * It changes the {@code availabilityStartTime} passed to a custom value doing the workaround. |
| 23 | + * A better approach to fix the issue should be investigated and used in the future. |
| 24 | + * </p> |
| 25 | + */ |
| 26 | +public class YoutubeDashLiveManifestParser extends DashManifestParser { |
| 27 | + |
| 28 | + // Result of Util.parseXsDateTime("1970-01-01T00:00:00Z") |
| 29 | + private static final long AVAILABILITY_START_TIME_TO_USE = 0; |
| 30 | + |
| 31 | + // There is no computation made with the availabilityStartTime value in the |
| 32 | + // parseMediaPresentationDescription method itself, so we can just override methods called in |
| 33 | + // this method using the workaround value |
| 34 | + // Overriding parsePeriod does not seem to be needed |
| 35 | + |
| 36 | + @SuppressWarnings("checkstyle:ParameterNumber") |
| 37 | + @NonNull |
| 38 | + @Override |
| 39 | + protected DashManifest buildMediaPresentationDescription( |
| 40 | + final long availabilityStartTime, |
| 41 | + final long durationMs, |
| 42 | + final long minBufferTimeMs, |
| 43 | + final boolean dynamic, |
| 44 | + final long minUpdateTimeMs, |
| 45 | + final long timeShiftBufferDepthMs, |
| 46 | + final long suggestedPresentationDelayMs, |
| 47 | + final long publishTimeMs, |
| 48 | + @Nullable final ProgramInformation programInformation, |
| 49 | + @Nullable final UtcTimingElement utcTiming, |
| 50 | + @Nullable final ServiceDescriptionElement serviceDescription, |
| 51 | + @Nullable final Uri location, |
| 52 | + @NonNull final List<Period> periods) { |
| 53 | + return super.buildMediaPresentationDescription( |
| 54 | + AVAILABILITY_START_TIME_TO_USE, |
| 55 | + durationMs, |
| 56 | + minBufferTimeMs, |
| 57 | + dynamic, |
| 58 | + minUpdateTimeMs, |
| 59 | + timeShiftBufferDepthMs, |
| 60 | + suggestedPresentationDelayMs, |
| 61 | + publishTimeMs, |
| 62 | + programInformation, |
| 63 | + utcTiming, |
| 64 | + serviceDescription, |
| 65 | + location, |
| 66 | + periods); |
| 67 | + } |
| 68 | +} |
0 commit comments