Commit ace97fac by michaelkatz Committed by christosts

Match MergingMediaPeriod track selection by period index in id

MergingMediaPeriod creates its track groups with ids concatenating position in its periods array and the underlying child track group id. The ids can be used in selectTracks for matching to periods list.

Issue: google/ExoPlayer#10930
PiperOrigin-RevId: 505074653
(cherry picked from commit ee055ef0)
parent b9bb3235
...@@ -117,17 +117,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -117,17 +117,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
for (int i = 0; i < selections.length; i++) { for (int i = 0; i < selections.length; i++) {
Integer streamChildIndex = streams[i] == null ? null : streamPeriodIndices.get(streams[i]); Integer streamChildIndex = streams[i] == null ? null : streamPeriodIndices.get(streams[i]);
streamChildIndices[i] = streamChildIndex == null ? C.INDEX_UNSET : streamChildIndex; streamChildIndices[i] = streamChildIndex == null ? C.INDEX_UNSET : streamChildIndex;
selectionChildIndices[i] = C.INDEX_UNSET;
if (selections[i] != null) { if (selections[i] != null) {
TrackGroup mergedTrackGroup = selections[i].getTrackGroup(); TrackGroup mergedTrackGroup = selections[i].getTrackGroup();
TrackGroup childTrackGroup = // mergedTrackGroup.id is 'periods array index' + ":" + childTrackGroup.id
checkNotNull(childTrackGroupByMergedTrackGroup.get(mergedTrackGroup)); selectionChildIndices[i] =
for (int j = 0; j < periods.length; j++) { Integer.parseInt(mergedTrackGroup.id.substring(0, mergedTrackGroup.id.indexOf(":")));
if (periods[j].getTrackGroups().indexOf(childTrackGroup) != C.INDEX_UNSET) { } else {
selectionChildIndices[i] = j; selectionChildIndices[i] = C.INDEX_UNSET;
break;
}
}
} }
} }
streamPeriodIndices.clear(); streamPeriodIndices.clear();
......
...@@ -197,6 +197,39 @@ public final class MergingMediaPeriodTest { ...@@ -197,6 +197,39 @@ public final class MergingMediaPeriodTest {
assertThat(firstSelectionChild2).isEqualTo(secondSelectionChild2); assertThat(firstSelectionChild2).isEqualTo(secondSelectionChild2);
} }
// https://github.com/google/ExoPlayer/issues/10930
@Test
public void selectTracks_withIdenticalFormats_selectsMatchingPeriod() throws Exception {
MergingMediaPeriod mergingMediaPeriod =
prepareMergingPeriod(
new MergingPeriodDefinition(
/* timeOffsetUs= */ 0, /* singleSampleTimeUs= */ 123_000, childFormat11),
new MergingPeriodDefinition(
/* timeOffsetUs= */ -3000, /* singleSampleTimeUs= */ 456_000, childFormat11));
ExoTrackSelection[] selectionArray = {
new FixedTrackSelection(mergingMediaPeriod.getTrackGroups().get(1), /* track= */ 0)
};
SampleStream[] streams = new SampleStream[1];
mergingMediaPeriod.selectTracks(
selectionArray,
/* mayRetainStreamFlags= */ new boolean[2],
streams,
/* streamResetFlags= */ new boolean[2],
/* positionUs= */ 0);
mergingMediaPeriod.continueLoading(/* positionUs= */ 0);
FormatHolder formatHolder = new FormatHolder();
DecoderInputBuffer inputBuffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
streams[0].readData(formatHolder, inputBuffer, FLAG_REQUIRE_FORMAT);
assertThat(streams[0].readData(formatHolder, inputBuffer, /* readFlags= */ 0))
.isEqualTo(C.RESULT_BUFFER_READ);
assertThat(inputBuffer.timeUs).isEqualTo(456_000 - 3000);
}
private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions) private MergingMediaPeriod prepareMergingPeriod(MergingPeriodDefinition... definitions)
throws Exception { throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length]; MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
......
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