Skip to content

Commit

Permalink
Discard preparation chunk if track selection does not include it
Browse files Browse the repository at this point in the history
This avoids breaking the player if the first variant is not
supported by the device.

Issue:#2353

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=148025791
  • Loading branch information
AquilesCanta authored and ojw28 committed Feb 23, 2017
1 parent 55a3fca commit 72e1eae
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ public boolean selectTracks(TrackSelection[] selections, boolean[] mayRetainStre
}
}
// Enable new tracks.
TrackSelection primaryTrackSelection = null;
boolean selectedNewTracks = false;
for (int i = 0; i < selections.length; i++) {
if (streams[i] == null && selections[i] != null) {
TrackSelection selection = selections[i];
int group = trackGroups.indexOf(selection.getTrackGroup());
setTrackGroupEnabledState(group, true);
if (group == primaryTrackGroupIndex) {
primaryTrackSelection = selection;
chunkSource.selectTracks(selection);
}
streams[i] = new HlsSampleStream(this, group);
Expand All @@ -205,6 +207,14 @@ public boolean selectTracks(TrackSelection[] selections, boolean[] mayRetainStre
sampleQueues.valueAt(i).disable();
}
}
if (primaryTrackSelection != null && !mediaChunks.isEmpty()) {
primaryTrackSelection.updateSelectedTrack(0);
int chunkIndex = chunkSource.getTrackGroup().indexOf(mediaChunks.getLast().trackFormat);
if (primaryTrackSelection.getSelectedIndexInTrackGroup() != chunkIndex) {
// The loaded preparation chunk does match the selection. We discard it.
seekTo(lastSeekPositionUs);
}
}
}
// Cancel requests if necessary.
if (enabledTrackCount == 0) {
Expand Down

0 comments on commit 72e1eae

Please sign in to comment.