mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +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 542a1ef03f361b29ec731a7334b2922cb54ef4c9)
This commit is contained in:
parent
5e6f79ae63
commit
c37442b24d
@ -118,17 +118,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();
|
||||||
|
@ -198,6 +198,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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user