Skip to content

Commit

Permalink
Proposed fix for issue 6256 (stale TrackSelection reference)
Browse files Browse the repository at this point in the history
Move the update of the HlsChunkSource's TrackSelection reference to be seperate from the loop that recreates HlsSampleStreams.  This way the reference is update even if the input HlsSampleStream reference was not nulled out (retain the stream when a new TrackSelection is created that is essentially a copy of the previous one.
  • Loading branch information
stevemayhew committed Aug 2, 2019
1 parent 1275217 commit ddfaa97
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,32 @@ public boolean selectTracks(TrackSelection[] selections, boolean[] mayRetainStre
SampleStream[] streams, boolean[] streamResetFlags, long positionUs, boolean forceReset) {
Assertions.checkState(prepared);
int oldEnabledTrackGroupCount = enabledTrackGroupCount;
// Deselect old tracks.

// 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;

for (int i = 0; i < selections.length; i++) {
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
TrackSelection selection = selections[i];

// Deselect old tracks, discarding the sample stream unless mayRetainStream is set
if (streams[i] != null && (selection == null || !mayRetainStreamFlags[i])) {
enabledTrackGroupCount--;
((HlsSampleStream) streams[i]).unbindSampleQueue();
streams[i] = null;
}

// update the possibly changed reference to the track selection for the primary track group
if (selection != null) {
int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
if (trackGroupIndex == primaryTrackGroupIndex) {
primaryTrackSelection = selection;
chunkSource.selectTracks(selection);
}
}
}

// We'll always need to seek if we're being forced to reset, or if this is a first selection to
// a position other than the one we started preparing with, or if we're making a selection
// having previously disabled all tracks.
Expand All @@ -286,20 +304,12 @@ public boolean selectTracks(TrackSelection[] selections, boolean[] mayRetainStre
|| (seenFirstTrackSelection
? oldEnabledTrackGroupCount == 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.
for (int i = 0; i < selections.length; i++) {
if (streams[i] == null && selections[i] != null) {
enabledTrackGroupCount++;
TrackSelection selection = selections[i];
int trackGroupIndex = trackGroups.indexOf(selection.getTrackGroup());
if (trackGroupIndex == primaryTrackGroupIndex) {
primaryTrackSelection = selection;
chunkSource.selectTracks(selection);
}
int trackGroupIndex = trackGroups.indexOf(selections[i].getTrackGroup());
streams[i] = new HlsSampleStream(this, trackGroupIndex);
streamResetFlags[i] = true;
if (trackGroupToSampleQueueIndex != null) {
Expand Down

0 comments on commit ddfaa97

Please sign in to comment.