Skip to content

Commit

Permalink
Fix merging of selected streams.
Browse files Browse the repository at this point in the history
Playback would fail if a renderer is toggled from consuming from
one child to another in a single step.

Issue: #1900

-------------
Created by MOE: https:/google/moe
MOE_MIGRATED_REVID=135270356
  • Loading branch information
ojw28 committed Oct 5, 2016
1 parent 053dc27 commit d334dfd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

* Fixes for MergingMediaSource and sideloaded subtitles.
([#1882](https:/google/ExoPlayer/issues/1882),
[#1854](https:/google/ExoPlayer/issues/1854)).
[#1854](https:/google/ExoPlayer/issues/1854),
[#1900](https:/google/ExoPlayer/issues/1900)).
* Reduced effect of application code leaking player references
([#1855](https:/google/ExoPlayer/issues/1855)).
* Initial support for fragmented MP4 in HLS.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamF
}
}
streamPeriodIndices.clear();
// Select tracks for each child, copying the resulting streams back into the streams array.
// Select tracks for each child, copying the resulting streams back into a new streams array.
SampleStream[] newStreams = new SampleStream[selections.length];
SampleStream[] childStreams = new SampleStream[selections.length];
TrackSelection[] childSelections = new TrackSelection[selections.length];
ArrayList<MediaPeriod> enabledPeriodsList = new ArrayList<>(periods.length);
Expand All @@ -106,22 +107,20 @@ public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamF
if (selectionChildIndices[j] == i) {
// Assert that the child provided a stream for the selection.
Assertions.checkState(childStreams[j] != null);
streams[j] = childStreams[j];
newStreams[j] = childStreams[j];
periodEnabled = true;
streamPeriodIndices.put(childStreams[j], i);
} else if (streamChildIndices[j] == i) {
// Assert that the child cleared any previous stream.
Assertions.checkState(childStreams[j] == null);
if (selectionChildIndices[j] == C.INDEX_UNSET) {
// No other child will be setting the stream at index j, so clear it.
streams[j] = null;
}
}
}
if (periodEnabled) {
enabledPeriodsList.add(periods[i]);
}
}
// Copy the new streams back into the streams array.
System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
// Update the local state.
enabledPeriods = new MediaPeriod[enabledPeriodsList.size()];
enabledPeriodsList.toArray(enabledPeriods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.ParsingLoadable;
import com.google.android.exoplayer2.util.Assertions;
import java.io.IOException;
import java.util.ArrayList;
import java.util.IdentityHashMap;
Expand Down Expand Up @@ -154,7 +155,8 @@ public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamF
}
boolean selectedNewTracks = false;
streamWrapperIndices.clear();
// Select tracks for each child, copying the resulting streams back into the streams array.
// Select tracks for each child, copying the resulting streams back into a new streams array.
SampleStream[] newStreams = new SampleStream[selections.length];
SampleStream[] childStreams = new SampleStream[selections.length];
TrackSelection[] childSelections = new TrackSelection[selections.length];
ArrayList<HlsSampleStreamWrapper> enabledSampleStreamWrapperList = new ArrayList<>(
Expand All @@ -168,19 +170,23 @@ public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamF
mayRetainStreamFlags, childStreams, streamResetFlags, !seenFirstTrackSelection);
boolean wrapperEnabled = false;
for (int j = 0; j < selections.length; j++) {
if (selectionChildIndices[j] == i
|| (selectionChildIndices[j] == C.INDEX_UNSET && streamChildIndices[j] == i)) {
streams[j] = childStreams[j];
if (childStreams[j] != null) {
wrapperEnabled = true;
streamWrapperIndices.put(childStreams[j], i);
}
if (selectionChildIndices[j] == i) {
// Assert that the child provided a stream for the selection.
Assertions.checkState(childStreams[j] != null);
newStreams[j] = childStreams[j];
wrapperEnabled = true;
streamWrapperIndices.put(childStreams[j], i);
} else if (streamChildIndices[j] == i) {
// Assert that the child cleared any previous stream.
Assertions.checkState(childStreams[j] == null);
}
}
if (wrapperEnabled) {
enabledSampleStreamWrapperList.add(sampleStreamWrappers[i]);
}
}
// Copy the new streams back into the streams array.
System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
// Update the local state.
enabledSampleStreamWrappers = new HlsSampleStreamWrapper[enabledSampleStreamWrapperList.size()];
enabledSampleStreamWrapperList.toArray(enabledSampleStreamWrappers);
Expand Down

0 comments on commit d334dfd

Please sign in to comment.