Search in sources :

Example 16 with Allocator

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

the class ExoPlayerTest method shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck.

@Test
public void shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck() throws Exception {
    AdPlaybackState adPlaybackState = FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */
    2, /* adGroupTimesUs...= */
    0);
    long shortAdDurationMs = 1_000;
    adPlaybackState = adPlaybackState.withAdDurationsUs(new long[][] { { shortAdDurationMs, shortAdDurationMs } });
    Timeline timeline = new FakeTimeline(new TimelineWindowDefinition(/* periodCount= */
    1, /* id= */
    0, /* isSeekable= */
    true, /* isDynamic= */
    false, /* durationUs= */
    Util.msToUs(10000), adPlaybackState));
    // Simulate the second ad not being prepared.
    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) {
            return new FakeMediaPeriod(trackGroupArray, allocator, FakeMediaPeriod.TrackDataFactory.singleSampleWithTimeUs(0), mediaSourceEventDispatcher, drmSessionManager, drmEventDispatcher, /* deferOnPrepared= */
            id.adIndexInAdGroup == 1);
        }
    };
    ExoPlayer player = new TestExoPlayerBuilder(context).build();
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    // The player is not stuck in the buffering state.
    TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_READY);
}
Also used : TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Allocator(com.google.android.exoplayer2.upstream.Allocator) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) FakeMediaPeriod(com.google.android.exoplayer2.testutil.FakeMediaPeriod) NoUidTimeline(com.google.android.exoplayer2.testutil.NoUidTimeline) SinglePeriodTimeline(com.google.android.exoplayer2.source.SinglePeriodTimeline) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) AdPlaybackState(com.google.android.exoplayer2.source.ads.AdPlaybackState) ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) TimelineWindowDefinition(com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) TestExoPlayerBuilder(com.google.android.exoplayer2.testutil.TestExoPlayerBuilder) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Example 17 with Allocator

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

the class FakeAdaptiveMediaPeriod method selectTracks.

// Casting sample streams created by this class.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    assertThat(prepared).isTrue();
    int rendererCount = selections.length;
    for (int i = 0; i < rendererCount; i++) {
        if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
            ((ChunkSampleStream<FakeChunkSource>) streams[i]).release();
            sampleStreams.remove(streams[i]);
            streams[i] = null;
        }
        if (streams[i] == null && selections[i] != null) {
            ExoTrackSelection selection = selections[i];
            assertThat(selection.length()).isAtLeast(1);
            TrackGroup trackGroup = selection.getTrackGroup();
            assertThat(trackGroupArray.indexOf(trackGroup)).isNotEqualTo(C.INDEX_UNSET);
            int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
            assertThat(indexInTrackGroup).isAtLeast(0);
            assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
            FakeChunkSource chunkSource = chunkSourceFactory.createChunkSource(selection, durationUs, transferListener);
            ChunkSampleStream<FakeChunkSource> sampleStream = new ChunkSampleStream<>(MimeTypes.getTrackType(selection.getSelectedFormat().sampleMimeType), /* embeddedTrackTypes= */
            null, /* embeddedTrackFormats= */
            null, chunkSource, /* callback= */
            this, allocator, positionUs, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */
            3), mediaSourceEventDispatcher);
            streams[i] = sampleStream;
            sampleStreams.add(sampleStream);
            streamResetFlags[i] = true;
        }
    }
    sequenceableLoader = new CompositeSequenceableLoader(sampleStreams.toArray(new ChunkSampleStream[0]));
    return seekToUs(positionUs);
}
Also used : ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection) DefaultLoadErrorHandlingPolicy(com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy) TrackGroup(com.google.android.exoplayer2.source.TrackGroup) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) CompositeSequenceableLoader(com.google.android.exoplayer2.source.CompositeSequenceableLoader)

Example 18 with Allocator

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

the class HlsSampleStreamWrapper method track.

// ExtractorOutput implementation. Called by the loading thread.
@Override
public DefaultTrackOutput track(int id, int type) {
    if (sampleQueues.indexOfKey(id) >= 0) {
        return sampleQueues.get(id);
    }
    DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator);
    trackOutput.setUpstreamFormatChangeListener(this);
    trackOutput.sourceId(upstreamChunkUid);
    sampleQueues.put(id, trackOutput);
    return trackOutput;
}
Also used : DefaultTrackOutput(com.google.android.exoplayer2.extractor.DefaultTrackOutput)

Example 19 with Allocator

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

the class DashMediaPeriod method buildSampleStream.

private ChunkSampleStream<DashChunkSource> buildSampleStream(int adaptationSetIndex, TrackSelection selection, long positionUs) {
    AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
    int embeddedTrackCount = 0;
    int[] embeddedTrackTypes = new int[2];
    boolean enableEventMessageTrack = hasEventMessageTrack(adaptationSet);
    if (enableEventMessageTrack) {
        embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_METADATA;
    }
    boolean enableCea608Track = hasCea608Track(adaptationSet);
    if (enableCea608Track) {
        embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_TEXT;
    }
    if (embeddedTrackCount < embeddedTrackTypes.length) {
        embeddedTrackTypes = Arrays.copyOf(embeddedTrackTypes, embeddedTrackCount);
    }
    DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(manifestLoaderErrorThrower, manifest, periodIndex, adaptationSetIndex, selection, elapsedRealtimeOffset, enableEventMessageTrack, enableCea608Track);
    ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(adaptationSet.type, embeddedTrackTypes, chunkSource, this, allocator, positionUs, minLoadableRetryCount, eventDispatcher);
    return stream;
}
Also used : ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)

Example 20 with Allocator

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

the class DashMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(int periodIndex, Allocator allocator, long positionUs) {
    EventDispatcher periodEventDispatcher = eventDispatcher.copyWithMediaTimeOffsetMs(manifest.getPeriod(periodIndex).startMs);
    DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest, periodIndex, chunkSourceFactory, minLoadableRetryCount, periodEventDispatcher, elapsedRealtimeOffsetMs, loaderErrorThrower, allocator);
    periodsById.put(mediaPeriod.id, mediaPeriod);
    return mediaPeriod;
}
Also used : EventDispatcher(com.google.android.exoplayer2.source.AdaptiveMediaSourceEventListener.EventDispatcher)

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