Search in sources :

Example 1 with SequenceableLoader

use of androidx.media3.exoplayer.source.SequenceableLoader in project media by androidx.

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(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) TrackGroup(androidx.media3.common.TrackGroup) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader)

Example 2 with SequenceableLoader

use of androidx.media3.exoplayer.source.SequenceableLoader in project media by androidx.

the class FakeAdaptiveMediaPeriod method release.

/**
 * Releases the media period.
 */
public void release() {
    prepared = false;
    for (ChunkSampleStream<FakeChunkSource> sampleStream : sampleStreams) {
        sampleStream.release();
    }
    sampleStreams.clear();
    sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
}
Also used : CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader) SequenceableLoader(androidx.media3.exoplayer.source.SequenceableLoader) CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader)

Example 3 with SequenceableLoader

use of androidx.media3.exoplayer.source.SequenceableLoader in project media by androidx.

the class ChunkSampleStream method continueLoading.

// SequenceableLoader implementation
@Override
public boolean continueLoading(long positionUs) {
    if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
        return false;
    }
    boolean pendingReset = isPendingReset();
    List<BaseMediaChunk> chunkQueue;
    long loadPositionUs;
    if (pendingReset) {
        chunkQueue = Collections.emptyList();
        loadPositionUs = pendingResetPositionUs;
    } else {
        chunkQueue = readOnlyMediaChunks;
        loadPositionUs = getLastMediaChunk().endTimeUs;
    }
    chunkSource.getNextChunk(positionUs, loadPositionUs, chunkQueue, nextChunkHolder);
    boolean endOfStream = nextChunkHolder.endOfStream;
    @Nullable Chunk loadable = nextChunkHolder.chunk;
    nextChunkHolder.clear();
    if (endOfStream) {
        pendingResetPositionUs = C.TIME_UNSET;
        loadingFinished = true;
        return true;
    }
    if (loadable == null) {
        return false;
    }
    loadingChunk = loadable;
    if (isMediaChunk(loadable)) {
        BaseMediaChunk mediaChunk = (BaseMediaChunk) loadable;
        if (pendingReset) {
            // even if its timestamp is slightly earlier than the advertised chunk start time.
            if (mediaChunk.startTimeUs != pendingResetPositionUs) {
                primarySampleQueue.setStartTimeUs(pendingResetPositionUs);
                for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
                    embeddedSampleQueue.setStartTimeUs(pendingResetPositionUs);
                }
            }
            pendingResetPositionUs = C.TIME_UNSET;
        }
        mediaChunk.init(chunkOutput);
        mediaChunks.add(mediaChunk);
    } else if (loadable instanceof InitializationChunk) {
        ((InitializationChunk) loadable).init(chunkOutput);
    }
    long elapsedRealtimeMs = loader.startLoading(loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type));
    mediaSourceEventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, elapsedRealtimeMs), loadable.type, primaryTrackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs);
    return true;
}
Also used : SampleQueue(androidx.media3.exoplayer.source.SampleQueue) LoadEventInfo(androidx.media3.exoplayer.source.LoadEventInfo) Nullable(androidx.annotation.Nullable)

Aggregations

CompositeSequenceableLoader (androidx.media3.exoplayer.source.CompositeSequenceableLoader)2 Nullable (androidx.annotation.Nullable)1 TrackGroup (androidx.media3.common.TrackGroup)1 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)1 LoadEventInfo (androidx.media3.exoplayer.source.LoadEventInfo)1 SampleQueue (androidx.media3.exoplayer.source.SampleQueue)1 SequenceableLoader (androidx.media3.exoplayer.source.SequenceableLoader)1 ChunkSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream)1 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)1 DefaultLoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy)1