Search in sources :

Example 1 with Allocator

use of com.google.android.exoplayer2.upstream.Allocator in project ExoPlayer by google.

the class ConcatenatingMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
    MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
    @Nullable MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
    if (holder == null) {
        // Stale event. The media source has already been removed.
        holder = new MediaSourceHolder(new FakeMediaSource(), useLazyPreparation);
        holder.isRemoved = true;
        prepareChildSource(holder, holder.mediaSource);
    }
    enableMediaSource(holder);
    holder.activeMediaPeriodIds.add(childMediaPeriodId);
    MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
    mediaSourceByMediaPeriod.put(mediaPeriod, holder);
    disableUnusedMediaSources();
    return mediaPeriod;
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder) Nullable(androidx.annotation.Nullable)

Example 2 with Allocator

use of com.google.android.exoplayer2.upstream.Allocator in project ExoPlayer by google.

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 : MediaSource(com.google.android.exoplayer2.source.MediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) MaskingMediaPeriod(com.google.android.exoplayer2.source.MaskingMediaPeriod)

Example 3 with Allocator

use of com.google.android.exoplayer2.upstream.Allocator in project ExoPlayer by google.

the class ConcatenatingMediaSourceTest method childSourceIsNotPreparedWithLazyPreparation.

@Test
public void childSourceIsNotPreparedWithLazyPreparation() 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();
    assertThat(childSources[0].isPrepared()).isFalse();
    assertThat(childSources[1].isPrepared()).isFalse();
}
Also used : MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) Test(org.junit.Test)

Example 4 with Allocator

use of com.google.android.exoplayer2.upstream.Allocator 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);
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Example 5 with Allocator

use of com.google.android.exoplayer2.upstream.Allocator 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();
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) MediaSourceTestRunner(com.google.android.exoplayer2.testutil.MediaSourceTestRunner) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Test(org.junit.Test)

Aggregations

FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)19 FakeTimeline (com.google.android.exoplayer2.testutil.FakeTimeline)18 MediaPeriodId (com.google.android.exoplayer2.source.MediaSource.MediaPeriodId)17 Test (org.junit.Test)17 Allocator (com.google.android.exoplayer2.upstream.Allocator)15 Nullable (androidx.annotation.Nullable)14 FakeMediaPeriod (com.google.android.exoplayer2.testutil.FakeMediaPeriod)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 DrmSessionManager (com.google.android.exoplayer2.drm.DrmSessionManager)12 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)12 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)11 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)9 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)8 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)7 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)7 MediaSource (com.google.android.exoplayer2.source.MediaSource)7 SinglePeriodTimeline (com.google.android.exoplayer2.source.SinglePeriodTimeline)7 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)7 TimelineWindowDefinition (com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition)7 NoUidTimeline (com.google.android.exoplayer2.testutil.NoUidTimeline)7