diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java index 70174b8105..80c378a666 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsChunkSource.java @@ -103,6 +103,7 @@ import java.util.Locale; private final HlsPlaylistTracker playlistTracker; private final TrackGroup trackGroup; + private boolean isTimestampMaster; private byte[] scratchSpace; private IOException fatalError; @@ -176,6 +177,16 @@ import java.util.Locale; fatalError = null; } + /** + * Sets whether this chunk source is responsible for initializing timestamp adjusters. + * + * @param isTimestampMaster True if this chunk source is responsible for initializing timestamp + * adjusters. + */ + public void setIsTimestampMaster(boolean isTimestampMaster) { + this.isTimestampMaster = isTimestampMaster; + } + /** * Returns the next chunk to load. *
@@ -280,7 +291,6 @@ import java.util.Locale;
|| previous.discontinuitySequenceNumber != segment.discontinuitySequenceNumber
|| format != previous.trackFormat;
boolean extractorNeedsInit = true;
- boolean isTimestampMaster = false;
TimestampAdjuster timestampAdjuster = null;
String lastPathSegment = chunkUri.getLastPathSegment();
if (lastPathSegment.endsWith(AAC_FILE_EXTENSION)) {
@@ -299,7 +309,6 @@ import java.util.Locale;
startTimeUs);
extractor = new WebvttExtractor(format.language, timestampAdjuster);
} else if (lastPathSegment.endsWith(MP4_FILE_EXTENSION)) {
- isTimestampMaster = true;
if (needNewExtractor) {
timestampAdjuster = timestampAdjusterProvider.getAdjuster(
segment.discontinuitySequenceNumber, startTimeUs);
@@ -310,7 +319,6 @@ import java.util.Locale;
}
} else if (needNewExtractor) {
// MPEG-2 TS segments, but we need a new extractor.
- isTimestampMaster = true;
timestampAdjuster = timestampAdjusterProvider.getAdjuster(
segment.discontinuitySequenceNumber, startTimeUs);
// This flag ensures the change of pid between streams does not affect the sample queues.
diff --git a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java
index 3951b30a78..be07b3410e 100644
--- a/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java
+++ b/library/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java
@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.source.SampleStream;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist;
+import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl;
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistTracker;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;
@@ -166,6 +167,18 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
// Update the local state.
enabledSampleStreamWrappers = new HlsSampleStreamWrapper[enabledSampleStreamWrapperList.size()];
enabledSampleStreamWrapperList.toArray(enabledSampleStreamWrappers);
+
+ // The first enabled sample stream wrapper is responsible for intializing the timestamp
+ // adjuster. This way, if present, variants are responsible. Otherwise, audio renditions are.
+ // If only subtitles are present, then text renditions are used for timestamp adjustment
+ // initialization.
+ if (enabledSampleStreamWrappers.length > 0) {
+ enabledSampleStreamWrappers[0].setIsTimestampMaster(true);
+ for (int i = 1; i < enabledSampleStreamWrappers.length; i++) {
+ enabledSampleStreamWrappers[i].setIsTimestampMaster(false);
+ }
+ }
+
sequenceableLoader = new CompositeSequenceableLoader(enabledSampleStreamWrappers);
if (seenFirstTrackSelection && selectedNewTracks) {
seekToUs(positionUs);
@@ -241,7 +254,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
}
@Override
- public void onPlaylistRefreshRequired(HlsMasterPlaylist.HlsUrl url) {
+ public void onPlaylistRefreshRequired(HlsUrl url) {
playlistTracker.refreshPlaylist(url, this);
}
@@ -269,7 +282,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
}
@Override
- public void onPlaylistLoadError(HlsMasterPlaylist.HlsUrl url, IOException error) {
+ public void onPlaylistLoadError(HlsUrl url, IOException error) {
for (HlsSampleStreamWrapper sampleStreamWrapper : enabledSampleStreamWrappers) {
sampleStreamWrapper.onPlaylistLoadError(url, error);
}
@@ -281,11 +294,11 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
private void buildAndPrepareSampleStreamWrappers() {
HlsMasterPlaylist masterPlaylist = playlistTracker.getMasterPlaylist();
// Build the default stream wrapper.
- List