Search in sources :

Example 11 with Allocator

use of androidx.media3.exoplayer.upstream.Allocator in project media by androidx.

the class SsMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher = createEventDispatcher(id);
    DrmSessionEventListener.EventDispatcher drmEventDispatcher = createDrmEventDispatcher(id);
    SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, mediaTransferListener, compositeSequenceableLoaderFactory, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, mediaSourceEventDispatcher, manifestLoaderErrorThrower, allocator);
    mediaPeriods.add(period);
    return period;
}
Also used : EventDispatcher(androidx.media3.exoplayer.source.MediaSourceEventListener.EventDispatcher) MediaSourceEventListener(androidx.media3.exoplayer.source.MediaSourceEventListener) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener)

Example 12 with Allocator

use of androidx.media3.exoplayer.upstream.Allocator in project media by androidx.

the class MediaSourceList method createPeriod.

/**
 * Returns a new {@link MediaPeriod} identified by {@code periodId}.
 *
 * @param id The identifier of the period.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param startPositionUs The expected start position, in microseconds.
 * @return A new {@link MediaPeriod}.
 */
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs) {
    Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
    MediaSource.MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
    MediaSourceHolder holder = Assertions.checkNotNull(mediaSourceByUid.get(mediaSourceHolderUid));
    enableMediaSource(holder);
    holder.activeMediaPeriodIds.add(childMediaPeriodId);
    MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
    mediaSourceByMediaPeriod.put(mediaPeriod, holder);
    disableUnusedMediaSources();
    return mediaPeriod;
}
Also used : MaskingMediaSource(androidx.media3.exoplayer.source.MaskingMediaSource) MediaSource(androidx.media3.exoplayer.source.MediaSource) MaskingMediaPeriod(androidx.media3.exoplayer.source.MaskingMediaPeriod) MediaPeriod(androidx.media3.exoplayer.source.MediaPeriod)

Example 13 with Allocator

use of androidx.media3.exoplayer.upstream.Allocator in project media by androidx.

the class ExoPlayerTest method seekDiscontinuityWithAdjustment.

@Test
public void seekDiscontinuityWithAdjustment() throws Exception {
    FakeTimeline timeline = new FakeTimeline(1);
    FakeMediaSource mediaSource = new FakeMediaSource(timeline, ExoPlayerTestRunner.VIDEO_FORMAT) {

        @Override
        protected MediaPeriod createMediaPeriod(MediaPeriodId id, TrackGroupArray trackGroupArray, Allocator allocator, MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher, DrmSessionManager drmSessionManager, DrmSessionEventListener.EventDispatcher drmEventDispatcher, @Nullable TransferListener transferListener) {
            FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray, allocator, TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            false);
            mediaPeriod.setSeekToUsOffset(10);
            return mediaPeriod;
        }
    };
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).seek(10).play().build();
    ExoPlayerTestRunner testRunner = new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setActionSchedule(actionSchedule).build().start().blockUntilEnded(TIMEOUT_MS);
    testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_SEEK, Player.DISCONTINUITY_REASON_SEEK_ADJUSTMENT);
}
Also used : TransferListener(androidx.media3.datasource.TransferListener) Allocator(androidx.media3.exoplayer.upstream.Allocator) FakeMediaSource(androidx.media3.test.utils.FakeMediaSource) ActionSchedule(androidx.media3.test.utils.ActionSchedule) DrmSessionManager(androidx.media3.exoplayer.drm.DrmSessionManager) TrackGroupArray(androidx.media3.common.TrackGroupArray) FakeMediaPeriod(androidx.media3.test.utils.FakeMediaPeriod) FakeTimeline(androidx.media3.test.utils.FakeTimeline) MediaPeriodId(androidx.media3.exoplayer.source.MediaSource.MediaPeriodId) ExoPlayerTestRunner(androidx.media3.test.utils.ExoPlayerTestRunner) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 14 with Allocator

use of androidx.media3.exoplayer.upstream.Allocator 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 15 with Allocator

use of androidx.media3.exoplayer.upstream.Allocator 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)

Aggregations

FakeMediaSource (androidx.media3.test.utils.FakeMediaSource)19 FakeTimeline (androidx.media3.test.utils.FakeTimeline)18 MediaPeriodId (androidx.media3.exoplayer.source.MediaSource.MediaPeriodId)17 Test (org.junit.Test)17 Nullable (androidx.annotation.Nullable)15 Allocator (androidx.media3.exoplayer.upstream.Allocator)15 TransferListener (androidx.media3.datasource.TransferListener)13 FakeMediaPeriod (androidx.media3.test.utils.FakeMediaPeriod)13 TrackGroupArray (androidx.media3.common.TrackGroupArray)12 DrmSessionManager (androidx.media3.exoplayer.drm.DrmSessionManager)12 Timeline (androidx.media3.common.Timeline)11 TestExoPlayerBuilder (androidx.media3.test.utils.TestExoPlayerBuilder)11 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)9 ExoPlayerTestRunner (androidx.media3.test.utils.ExoPlayerTestRunner)8 AdPlaybackState (androidx.media3.common.AdPlaybackState)7 MediaPeriod (androidx.media3.exoplayer.source.MediaPeriod)7 MediaSourceEventListener (androidx.media3.exoplayer.source.MediaSourceEventListener)7 SinglePeriodTimeline (androidx.media3.exoplayer.source.SinglePeriodTimeline)7 ActionSchedule (androidx.media3.test.utils.ActionSchedule)7 TimelineWindowDefinition (androidx.media3.test.utils.FakeTimeline.TimelineWindowDefinition)7