Search in sources :

Example 96 with MediaSource

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();
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 97 with MediaSource

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);
}
Also used : MediaSourceTestRunner(androidx.media3.test.utils.MediaSourceTestRunner) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) DefaultShuffleOrder(androidx.media3.exoplayer.source.ShuffleOrder.DefaultShuffleOrder) Test(org.junit.Test)

Example 98 with MediaSource

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);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) AdPlaybackState(androidx.media3.common.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(androidx.media3.exoplayer.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(androidx.media3.test.utils.FakeTimeline) AtomicReference(java.util.concurrent.atomic.AtomicReference) Pair(android.util.Pair) Test(org.junit.Test)

Example 99 with MediaSource

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.
    }
}
Also used : FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) Test(org.junit.Test)

Example 100 with MediaSource

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);
}
Also used : FakeTimeline(androidx.media3.test.utils.FakeTimeline) Timeline(androidx.media3.common.Timeline) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)182 FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)117 MediaSource (androidx.media3.exoplayer.source.MediaSource)95 MediaItem (androidx.media3.common.MediaItem)82 Timeline (androidx.media3.common.Timeline)77 FakeTimeline (androidx.media3.test.utils.FakeTimeline)74 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)70 ConcatenatingMediaSource (androidx.media3.exoplayer.source.ConcatenatingMediaSource)66 ActionSchedule (androidx.media3.test.utils.ActionSchedule)60 CompositeMediaSource (androidx.media3.exoplayer.source.CompositeMediaSource)51 MaskingMediaSource (androidx.media3.exoplayer.source.MaskingMediaSource)51 ClippingMediaSource (androidx.media3.exoplayer.source.ClippingMediaSource)50 ServerSideAdInsertionMediaSource (androidx.media3.exoplayer.source.ads.ServerSideAdInsertionMediaSource)50 FakeAdaptiveMediaSource (androidx.media3.test.utils.FakeAdaptiveMediaSource)50 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)45 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)39 NoUidTimeline (androidx.media3.test.utils.NoUidTimeline)39 PlayerRunnable (androidx.media3.test.utils.ActionSchedule.PlayerRunnable)34 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)28 TransferListener (androidx.media3.datasource.TransferListener)25