use of androidx.media3.exoplayer.source.MediaSource in project media by androidx.
the class ConcatenatingMediaSourceTest method childSourceIsPreparedWithLazyPreparationAfterPeriodCreation.
@Test
public void childSourceIsPreparedWithLazyPreparationAfterPeriodCreation() throws IOException {
FakeMediaSource[] childSources = createMediaSources(/* count= */
2);
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, /* useLazyPreparation= */
true, new DefaultShuffleOrder(0), childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */
null);
Timeline timeline = testRunner.prepareSource();
testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
assertThat(childSources[0].isPrepared()).isTrue();
assertThat(childSources[1].isPrepared()).isFalse();
}
use of androidx.media3.exoplayer.source.MediaSource in project media by androidx.
the class ConcatenatingMediaSourceTest method removeUnpreparedChildSourceWithLazyPreparation.
@Test
public void removeUnpreparedChildSourceWithLazyPreparation() throws IOException {
FakeMediaSource[] childSources = createMediaSources(/* count= */
2);
mediaSource = new ConcatenatingMediaSource(/* isAtomic= */
false, /* useLazyPreparation= */
true, new DefaultShuffleOrder(0), childSources);
testRunner = new MediaSourceTestRunner(mediaSource, /* allocator= */
null);
testRunner.prepareSource();
// Check that removal doesn't throw even though the child sources are unprepared.
mediaSource.removeMediaSource(0);
}
use of androidx.media3.exoplayer.source.MediaSource in project media by androidx.
the class ServerSideAdInsertionMediaSourceTest method timeline_containsAdsDefinedInAdPlaybackState.
@Test
public void timeline_containsAdsDefinedInAdPlaybackState() throws Exception {
FakeTimeline wrappedTimeline = new FakeTimeline(new FakeTimeline.TimelineWindowDefinition(/* periodCount= */
1, /* id= */
0, /* isSeekable= */
true, /* isDynamic= */
true, /* isLive= */
true, /* isPlaceholder= */
false, /* durationUs= */
10_000_000, /* defaultPositionUs= */
3_000_000, /* windowOffsetInFirstPeriodUs= */
42_000_000L, AdPlaybackState.NONE));
ServerSideAdInsertionMediaSource mediaSource = new ServerSideAdInsertionMediaSource(new FakeMediaSource(wrappedTimeline), /* adPlaybackStateUpdater= */
null);
// Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adsId= */
new Object(), /* adGroupTimesUs...= */
15_000_000, 41_500_000, 42_200_000).withIsServerSideInserted(/* adGroupIndex= */
0, /* isServerSideInserted= */
true).withIsServerSideInserted(/* adGroupIndex= */
1, /* isServerSideInserted= */
true).withIsServerSideInserted(/* adGroupIndex= */
2, /* isServerSideInserted= */
true).withAdCount(/* adGroupIndex= */
0, /* adCount= */
1).withAdCount(/* adGroupIndex= */
1, /* adCount= */
2).withAdCount(/* adGroupIndex= */
2, /* adCount= */
1).withAdDurationsUs(/* adGroupIndex= */
0, /* adDurationsUs...= */
500_000).withAdDurationsUs(/* adGroupIndex= */
1, /* adDurationsUs...= */
300_000, 100_000).withAdDurationsUs(/* adGroupIndex= */
2, /* adDurationsUs...= */
400_000).withContentResumeOffsetUs(/* adGroupIndex= */
0, /* contentResumeOffsetUs= */
100_000).withContentResumeOffsetUs(/* adGroupIndex= */
1, /* contentResumeOffsetUs= */
400_000).withContentResumeOffsetUs(/* adGroupIndex= */
2, /* contentResumeOffsetUs= */
200_000);
AtomicReference<Timeline> timelineReference = new AtomicReference<>();
mediaSource.setAdPlaybackStates(ImmutableMap.of(new Pair<>(0, 0), adPlaybackState));
mediaSource.prepareSource((source, timeline) -> timelineReference.set(timeline), /* mediaTransferListener= */
null, PlayerId.UNSET);
runMainLooperUntil(() -> timelineReference.get() != null);
Timeline timeline = timelineReference.get();
assertThat(timeline.getPeriodCount()).isEqualTo(1);
Timeline.Period period = timeline.getPeriod(/* periodIndex= */
0, new Timeline.Period());
assertThat(period.getAdGroupCount()).isEqualTo(3);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
0)).isEqualTo(1);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
1)).isEqualTo(2);
assertThat(period.getAdCountInAdGroup(/* adGroupIndex= */
2)).isEqualTo(1);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
0)).isEqualTo(15_000_000);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
1)).isEqualTo(41_500_000);
assertThat(period.getAdGroupTimeUs(/* adGroupIndex= */
2)).isEqualTo(42_200_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0)).isEqualTo(500_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
1, /* adIndexInAdGroup= */
0)).isEqualTo(300_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
1, /* adIndexInAdGroup= */
1)).isEqualTo(100_000);
assertThat(period.getAdDurationUs(/* adGroupIndex= */
2, /* adIndexInAdGroup= */
0)).isEqualTo(400_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
0)).isEqualTo(100_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
1)).isEqualTo(400_000);
assertThat(period.getContentResumeOffsetUs(/* adGroupIndex= */
2)).isEqualTo(200_000);
// windowDurationUs + windowOffsetInFirstPeriodUs - sum(adDurations) + sum(contentResumeOffsets)
assertThat(period.getDurationUs()).isEqualTo(51_400_000);
// positionInWindowUs + sum(adDurationsBeforeWindow) - sum(contentResumeOffsetsBeforeWindow)
assertThat(period.getPositionInWindowUs()).isEqualTo(-41_600_000);
Timeline.Window window = timeline.getWindow(/* windowIndex= */
0, new Timeline.Window());
assertThat(window.positionInFirstPeriodUs).isEqualTo(41_600_000);
// windowDurationUs - sum(adDurationsInWindow) + sum(applicableContentResumeOffsetUs)
assertThat(window.durationUs).isEqualTo(9_800_000);
}
use of androidx.media3.exoplayer.source.MediaSource in project media by androidx.
the class ConcatenatingMediaSourceTest method illegalArguments.
@Test
public void illegalArguments() {
MediaSource validSource = new FakeMediaSource(createFakeTimeline(1));
// Null sources.
try {
mediaSource.addMediaSource(null);
fail("Null mediaSource not allowed.");
} catch (NullPointerException e) {
// Expected.
}
MediaSource[] mediaSources = { validSource, null };
try {
mediaSource.addMediaSources(Arrays.asList(mediaSources));
fail("Null mediaSource not allowed.");
} catch (NullPointerException e) {
// Expected.
}
}
use of androidx.media3.exoplayer.source.MediaSource in project media by androidx.
the class ConcatenatingMediaSourceTest method emptyTimelineMediaSource.
@Test
public void emptyTimelineMediaSource() throws IOException, InterruptedException {
Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertEmpty(timeline);
mediaSource.addMediaSource(new FakeMediaSource(Timeline.EMPTY));
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertEmpty(timeline);
mediaSource.addMediaSources(Arrays.asList(new MediaSource[] { new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY), new FakeMediaSource(Timeline.EMPTY) }));
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertEmpty(timeline);
testRunner.assertCompletedManifestLoads();
// Insert non-empty media source to leave empty sources at the start, the end, and the middle
// (with single and multiple empty sources in a row).
MediaSource[] mediaSources = createMediaSources(3);
mediaSource.addMediaSource(1, mediaSources[0]);
testRunner.assertTimelineChangeBlocking();
mediaSource.addMediaSource(4, mediaSources[1]);
testRunner.assertTimelineChangeBlocking();
mediaSource.addMediaSource(6, mediaSources[2]);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertWindowTags(timeline, 111, 222, 333);
TimelineAsserts.assertPeriodCounts(timeline, 1, 2, 3);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 2, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, false, 1, 2, C.INDEX_UNSET);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, false, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, false, 1, 2, 0);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, 1, 2, C.INDEX_UNSET);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertPreviousWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 1, 2, 0);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_OFF, true, C.INDEX_UNSET, 0, 1);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ONE, true, 0, 1, 2);
TimelineAsserts.assertNextWindowIndices(timeline, Player.REPEAT_MODE_ALL, true, 2, 0, 1);
assertThat(timeline.getFirstWindowIndex(false)).isEqualTo(0);
assertThat(timeline.getLastWindowIndex(false)).isEqualTo(2);
assertThat(timeline.getFirstWindowIndex(true)).isEqualTo(2);
assertThat(timeline.getLastWindowIndex(true)).isEqualTo(0);
testRunner.assertPrepareAndReleaseAllPeriods();
testRunner.assertCompletedManifestLoads(0, 1, 2);
assertCompletedAllMediaPeriodLoads(timeline);
}
Aggregations