use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method childSourceWithLazyPreparationOnlyPreparesSourceOnce.
@Test
public void childSourceWithLazyPreparationOnlyPreparesSourceOnce() 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();
// The lazy preparation must only be triggered once, even if we create multiple periods from
// the media source. FakeMediaSource.prepareSource asserts that it's not called twice, so
// creating two periods shouldn't throw.
MediaPeriodId mediaPeriodId = new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0);
testRunner.createPeriod(mediaPeriodId);
testRunner.createPeriod(mediaPeriodId);
}
use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.
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 com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method duplicateNestedMediaSources.
@Test
public void duplicateNestedMediaSources() throws IOException, InterruptedException {
Timeline childTimeline = new FakeTimeline();
FakeMediaSource childSource = new FakeMediaSource(childTimeline);
ConcatenatingMediaSource nestedConcatenation = new ConcatenatingMediaSource();
testRunner.prepareSource();
mediaSource.addMediaSources(Arrays.asList(childSource, nestedConcatenation, nestedConcatenation));
testRunner.assertTimelineChangeBlocking();
nestedConcatenation.addMediaSource(childSource);
testRunner.assertTimelineChangeBlocking();
nestedConcatenation.addMediaSource(childSource);
Timeline timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 1, 1, 1);
testRunner.assertPrepareAndReleaseAllPeriods();
Object childPeriodUid = childTimeline.getUidOfPeriod(/* periodIndex= */
0);
assertThat(childSource.getCreatedMediaPeriods()).containsAtLeast(new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
0), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
1), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
2), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
3), new MediaPeriodId(childPeriodUid, /* windowSequenceNumber= */
4));
// Assert that only one manifest load is needed because the source is reused.
testRunner.assertCompletedManifestLoads(/* windowIndices=... */
0);
assertCompletedAllMediaPeriodLoads(timeline);
testRunner.releaseSource();
childSource.assertReleased();
}
use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method assertCompletedAllMediaPeriodLoads.
private void assertCompletedAllMediaPeriodLoads(Timeline timeline) {
Timeline.Period period = new Timeline.Period();
Timeline.Window window = new Timeline.Window();
ArrayList<MediaPeriodId> expectedMediaPeriodIds = new ArrayList<>();
for (int windowIndex = 0; windowIndex < timeline.getWindowCount(); windowIndex++) {
timeline.getWindow(windowIndex, window);
for (int periodIndex = window.firstPeriodIndex; periodIndex <= window.lastPeriodIndex; periodIndex++) {
timeline.getPeriod(periodIndex, period);
Object periodUid = timeline.getUidOfPeriod(periodIndex);
expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, windowIndex));
for (int adGroupIndex = 0; adGroupIndex < period.getAdGroupCount(); adGroupIndex++) {
for (int adIndex = 0; adIndex < period.getAdCountInAdGroup(adGroupIndex); adIndex++) {
expectedMediaPeriodIds.add(new MediaPeriodId(periodUid, adGroupIndex, adIndex, windowIndex));
}
}
}
}
testRunner.assertCompletedMediaPeriodLoads(expectedMediaPeriodIds.toArray(new MediaPeriodId[0]));
}
use of com.google.android.exoplayer2.source.MediaSource.MediaPeriodId in project ExoPlayer by google.
the class ConcatenatingMediaSourceTest method playlistWithLazyMediaSource.
@Test
public void playlistWithLazyMediaSource() throws IOException, InterruptedException {
// Create some normal (immediately preparing) sources and some lazy sources whose timeline
// updates need to be triggered.
FakeMediaSource[] fastSources = createMediaSources(2);
final FakeMediaSource[] lazySources = new FakeMediaSource[4];
for (int i = 0; i < 4; i++) {
lazySources[i] = new FakeMediaSource(null);
}
// Add lazy sources and normal sources before preparation. Also remove one lazy source again
// before preparation to check it doesn't throw or change the result.
mediaSource.addMediaSource(lazySources[0]);
mediaSource.addMediaSource(0, fastSources[0]);
mediaSource.removeMediaSource(1);
mediaSource.addMediaSource(1, lazySources[1]);
testRunner.assertNoTimelineChange();
// Prepare and assert that the timeline contains all information for normal sources while having
// placeholder information for lazy sources.
Timeline timeline = testRunner.prepareSource();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1);
TimelineAsserts.assertWindowTags(timeline, 111, null);
TimelineAsserts.assertWindowIsDynamic(timeline, false, true);
// Trigger source info refresh for lazy source and check that the timeline now contains all
// information for all windows.
testRunner.runOnPlaybackThread(() -> lazySources[1].setNewSourceInfo(createFakeTimeline(8)));
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 9);
TimelineAsserts.assertWindowTags(timeline, 111, 999);
TimelineAsserts.assertWindowIsDynamic(timeline, false, false);
testRunner.assertPrepareAndReleaseAllPeriods();
testRunner.assertCompletedManifestLoads(0, 1);
assertCompletedAllMediaPeriodLoads(timeline);
// Add further lazy and normal sources after preparation. Also remove one lazy source again to
// check it doesn't throw or change the result.
mediaSource.addMediaSource(1, lazySources[2]);
testRunner.assertTimelineChangeBlocking();
mediaSource.addMediaSource(2, fastSources[1]);
testRunner.assertTimelineChangeBlocking();
mediaSource.addMediaSource(0, lazySources[3]);
testRunner.assertTimelineChangeBlocking();
mediaSource.removeMediaSource(2);
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 1, 1, 2, 9);
TimelineAsserts.assertWindowTags(timeline, null, 111, 222, 999);
TimelineAsserts.assertWindowIsDynamic(timeline, true, false, false, false);
// Create a period from an unprepared lazy media source and assert Callback.onPrepared is not
// called yet.
MediaPeriod lazyPeriod = testRunner.createPeriod(new MediaPeriodId(timeline.getUidOfPeriod(/* periodIndex= */
0), /* windowSequenceNumber= */
0));
CountDownLatch preparedCondition = testRunner.preparePeriod(lazyPeriod, 0);
assertThat(preparedCondition.getCount()).isEqualTo(1);
// Trigger source info refresh for lazy media source. Assert that now all information is
// available again and the previously created period now also finished preparing.
testRunner.runOnPlaybackThread(() -> lazySources[3].setNewSourceInfo(createFakeTimeline(7)));
timeline = testRunner.assertTimelineChangeBlocking();
TimelineAsserts.assertPeriodCounts(timeline, 8, 1, 2, 9);
TimelineAsserts.assertWindowTags(timeline, 888, 111, 222, 999);
TimelineAsserts.assertWindowIsDynamic(timeline, false, false, false, false);
assertThat(preparedCondition.getCount()).isEqualTo(0);
// Release the period and source.
testRunner.releasePeriod(lazyPeriod);
testRunner.releaseSource();
// Assert all sources were fully released.
for (FakeMediaSource fastSource : fastSources) {
fastSource.assertReleased();
}
for (FakeMediaSource lazySource : lazySources) {
lazySource.assertReleased();
}
}
Aggregations