mirror of
https://github.com/androidx/media.git
synced 2025-05-14 02:59:52 +08:00
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 ee055ef004686ddb3844666f9506a95c6e16a59f)
This commit is contained in:
parent
b9bb3235c2
commit
ace97facf2
@ -117,17 +117,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
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();
|
||||
|
@ -197,6 +197,39 @@ public final class MergingMediaPeriodTest {
|
||||
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];
|
||||
|
Loading…
x
Reference in New Issue
Block a user