Commit 5e203f48 by olly Committed by Oliver Woodman

Correctly flush HlsSampleStreamWrapper when primary selection changes

Issue: #3079

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162473480
parent 9716b03f
...@@ -166,6 +166,13 @@ import java.util.Locale; ...@@ -166,6 +166,13 @@ import java.util.Locale;
} }
/** /**
* Returns the current track selection.
*/
public TrackSelection getTrackSelection() {
return trackSelection;
}
/**
* Resets the source. * Resets the source.
*/ */
public void reset() { public void reset() {
......
...@@ -38,6 +38,7 @@ import com.google.android.exoplayer2.upstream.Allocator; ...@@ -38,6 +38,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.Loader; import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -204,8 +205,11 @@ import java.util.LinkedList; ...@@ -204,8 +205,11 @@ import java.util.LinkedList;
// having previously disabled all tracks. // having previously disabled all tracks.
boolean seekRequired = forceReset boolean seekRequired = forceReset
|| (seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != lastSeekPositionUs); || (seenFirstTrackSelection ? oldEnabledTrackCount == 0 : positionUs != lastSeekPositionUs);
// Get the old (i.e. current before the loop below executes) primary track selection. The new
// primary selection will equal the old one unless it's changed in the loop.
TrackSelection oldPrimaryTrackSelection = chunkSource.getTrackSelection();
TrackSelection primaryTrackSelection = oldPrimaryTrackSelection;
// Select new tracks. // Select new tracks.
TrackSelection primaryTrackSelection = null;
for (int i = 0; i < selections.length; i++) { for (int i = 0; i < selections.length; i++) {
if (streams[i] == null && selections[i] != null) { if (streams[i] == null && selections[i] != null) {
TrackSelection selection = selections[i]; TrackSelection selection = selections[i];
...@@ -234,7 +238,6 @@ import java.util.LinkedList; ...@@ -234,7 +238,6 @@ import java.util.LinkedList;
if (enabledTrackCount == 0) { if (enabledTrackCount == 0) {
chunkSource.reset(); chunkSource.reset();
downstreamTrackFormat = null; downstreamTrackFormat = null;
pendingResetUpstreamFormats |= !seenFirstTrackSelection;
mediaChunks.clear(); mediaChunks.clear();
if (loader.isLoading()) { if (loader.isLoading()) {
// Discard as much as we can synchronously. // Discard as much as we can synchronously.
...@@ -246,14 +249,24 @@ import java.util.LinkedList; ...@@ -246,14 +249,24 @@ import java.util.LinkedList;
resetSampleQueues(); resetSampleQueues();
} }
} else { } else {
if (!seenFirstTrackSelection && primaryTrackSelection != null && !mediaChunks.isEmpty()) { if (!mediaChunks.isEmpty()
primaryTrackSelection.updateSelectedTrack(0); && !Util.areEqual(primaryTrackSelection, oldPrimaryTrackSelection)) {
int chunkIndex = chunkSource.getTrackGroup().indexOf(mediaChunks.getLast().trackFormat); // The primary track selection has changed and we have buffered media. The buffered media
if (primaryTrackSelection.getSelectedIndexInTrackGroup() != chunkIndex) { // may need to be discarded.
// This is the first selection and the chunk loaded during preparation does not match the boolean primarySampleQueueDirty = false;
// selection. We need to reset to discard it. We also need to ensure that the upstream if (!seenFirstTrackSelection) {
// formats are cleared from the sample queues so that they cannot be read. This is primaryTrackSelection.updateSelectedTrack(0);
// necessary because the consuming renderers may not support these formats. int chunkIndex = chunkSource.getTrackGroup().indexOf(mediaChunks.getLast().trackFormat);
if (primaryTrackSelection.getSelectedIndexInTrackGroup() != chunkIndex) {
// This is the first selection and the chunk loaded during preparation does not match
// the initially selected format.
primarySampleQueueDirty = true;
}
} else {
// The primary sample queue contains media buffered for the old primary track selection.
primarySampleQueueDirty = true;
}
if (primarySampleQueueDirty) {
forceReset = true; forceReset = true;
seekRequired = true; seekRequired = true;
pendingResetUpstreamFormats = true; pendingResetUpstreamFormats = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment