Search in sources :

Example 21 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class ChunkSampleStream method onLoaderReleased.

@Override
public void onLoaderReleased() {
    primarySampleQueue.release();
    for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
        embeddedSampleQueue.release();
    }
    chunkSource.release();
    if (releaseCallback != null) {
        releaseCallback.onSampleStreamReleased(this);
    }
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue)

Example 22 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class ChunkSampleStream method seekToUs.

/**
 * Seeks to the specified position in microseconds.
 *
 * @param positionUs The seek position in microseconds.
 */
public void seekToUs(long positionUs) {
    lastSeekPositionUs = positionUs;
    if (isPendingReset()) {
        // A reset is already pending. We only need to update its position.
        pendingResetPositionUs = positionUs;
        return;
    }
    // Detect whether the seek is to the start of a chunk that's at least partially buffered.
    @Nullable BaseMediaChunk seekToMediaChunk = null;
    for (int i = 0; i < mediaChunks.size(); i++) {
        BaseMediaChunk mediaChunk = mediaChunks.get(i);
        long mediaChunkStartTimeUs = mediaChunk.startTimeUs;
        if (mediaChunkStartTimeUs == positionUs && mediaChunk.clippedStartTimeUs == C.TIME_UNSET) {
            seekToMediaChunk = mediaChunk;
            break;
        } else if (mediaChunkStartTimeUs > positionUs) {
            // We're not going to find a chunk with a matching start time.
            break;
        }
    }
    // See if we can seek inside the primary sample queue.
    boolean seekInsideBuffer;
    if (seekToMediaChunk != null) {
        // When seeking to the start of a chunk we use the index of the first sample in the chunk
        // rather than the seek position. This ensures we seek to the keyframe at the start of the
        // chunk even if its timestamp is slightly earlier than the advertised chunk start time.
        seekInsideBuffer = primarySampleQueue.seekTo(seekToMediaChunk.getFirstSampleIndex(0));
    } else {
        seekInsideBuffer = primarySampleQueue.seekTo(positionUs, /* allowTimeBeyondBuffer= */
        positionUs < getNextLoadPositionUs());
    }
    if (seekInsideBuffer) {
        // We can seek inside the buffer.
        nextNotifyPrimaryFormatMediaChunkIndex = primarySampleIndexToMediaChunkIndex(primarySampleQueue.getReadIndex(), /* minChunkIndex= */
        0);
        // Seek the embedded sample queues.
        for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
            embeddedSampleQueue.seekTo(positionUs, /* allowTimeBeyondBuffer= */
            true);
        }
    } else {
        // We can't seek inside the buffer, and so need to reset.
        pendingResetPositionUs = positionUs;
        loadingFinished = false;
        mediaChunks.clear();
        nextNotifyPrimaryFormatMediaChunkIndex = 0;
        if (loader.isLoading()) {
            // Discard as much as we can synchronously.
            primarySampleQueue.discardToEnd();
            for (SampleQueue embeddedSampleQueue : embeddedSampleQueues) {
                embeddedSampleQueue.discardToEnd();
            }
            loader.cancelLoading();
        } else {
            loader.clearFatalError();
            resetSampleQueues();
        }
    }
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue) Nullable(androidx.annotation.Nullable)

Example 23 with SampleQueue

use of com.google.android.exoplayer2.source.SampleQueue in project ExoPlayer by google.

the class ProgressiveMediaPeriod method startLoading.

private void startLoading() {
    ExtractingLoadable loadable = new ExtractingLoadable(uri, dataSource, progressiveMediaExtractor, /* extractorOutput= */
    this, loadCondition);
    if (prepared) {
        Assertions.checkState(isPendingReset());
        if (durationUs != C.TIME_UNSET && pendingResetPositionUs > durationUs) {
            loadingFinished = true;
            pendingResetPositionUs = C.TIME_UNSET;
            return;
        }
        loadable.setLoadPosition(Assertions.checkNotNull(seekMap).getSeekPoints(pendingResetPositionUs).first.position, pendingResetPositionUs);
        for (SampleQueue sampleQueue : sampleQueues) {
            sampleQueue.setStartTimeUs(pendingResetPositionUs);
        }
        pendingResetPositionUs = C.TIME_UNSET;
    }
    extractedSamplesCountAtStartOfLoad = getExtractedSamplesCount();
    long elapsedRealtimeMs = loader.startLoading(loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(dataType));
    DataSpec dataSpec = loadable.dataSpec;
    mediaSourceEventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, dataSpec, elapsedRealtimeMs), C.DATA_TYPE_MEDIA, C.TRACK_TYPE_UNKNOWN, /* trackFormat= */
    null, C.SELECTION_REASON_UNKNOWN, /* trackSelectionData= */
    null, /* mediaStartTimeUs= */
    loadable.seekTimeUs, durationUs);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Aggregations

SampleQueue (com.google.android.exoplayer2.source.SampleQueue)14 Nullable (androidx.annotation.Nullable)5 Format (com.google.android.exoplayer2.Format)4 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 ImmutableList (com.google.common.collect.ImmutableList)2 Uri (android.net.Uri)1 FormatHolder (com.google.android.exoplayer2.FormatHolder)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 Metadata (com.google.android.exoplayer2.metadata.Metadata)1 IcyHeaders (com.google.android.exoplayer2.metadata.icy.IcyHeaders)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 Chunk (com.google.android.exoplayer2.source.chunk.Chunk)1 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)1 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)1 DefaultAllocator (com.google.android.exoplayer2.upstream.DefaultAllocator)1 StatsDataSource (com.google.android.exoplayer2.upstream.StatsDataSource)1