Skip to content

Commit

Permalink
Match MergingMediaPeriod track selection by period index in id
Browse files Browse the repository at this point in the history
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 542a1ef)
  • Loading branch information
microkatz authored and christosts committed Feb 2, 2023
1 parent 5e6f79a commit c37442b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,13 @@ public long selectTracks(
for (int i = 0; i < selections.length; i++) {
Integer streamChildIndex = streams[i] == null ? null : streamPeriodIndices.get(streams[i]);
streamChildIndices[i] = streamChildIndex == null ? C.INDEX_UNSET : streamChildIndex;
selectionChildIndices[i] = C.INDEX_UNSET;
if (selections[i] != null) {
TrackGroup mergedTrackGroup = selections[i].getTrackGroup();
TrackGroup childTrackGroup =
checkNotNull(childTrackGroupByMergedTrackGroup.get(mergedTrackGroup));
for (int j = 0; j < periods.length; j++) {
if (periods[j].getTrackGroups().indexOf(childTrackGroup) != C.INDEX_UNSET) {
selectionChildIndices[i] = j;
break;
}
}
// mergedTrackGroup.id is 'periods array index' + ":" + childTrackGroup.id
selectionChildIndices[i] =
Integer.parseInt(mergedTrackGroup.id.substring(0, mergedTrackGroup.id.indexOf(":")));
} else {
selectionChildIndices[i] = C.INDEX_UNSET;
}
}
streamPeriodIndices.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,39 @@ public void selectTracks_withSameArguments_forwardsEqualSelectionsToChildSources
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)
throws Exception {
MediaPeriod[] mediaPeriods = new MediaPeriod[definitions.length];
Expand Down

0 comments on commit c37442b

Please sign in to comment.