Search in sources :

Example 11 with SampleQueue

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

the class HlsSampleStreamWrapper method continueLoading.

@Override
public boolean continueLoading(long positionUs) {
    if (loadingFinished || loader.isLoading() || loader.hasFatalError()) {
        return false;
    }
    List<HlsMediaChunk> chunkQueue;
    long loadPositionUs;
    if (isPendingReset()) {
        chunkQueue = Collections.emptyList();
        loadPositionUs = pendingResetPositionUs;
        for (SampleQueue sampleQueue : sampleQueues) {
            sampleQueue.setStartTimeUs(pendingResetPositionUs);
        }
    } else {
        chunkQueue = readOnlyMediaChunks;
        HlsMediaChunk lastMediaChunk = getLastMediaChunk();
        loadPositionUs = lastMediaChunk.isLoadCompleted() ? lastMediaChunk.endTimeUs : max(lastSeekPositionUs, lastMediaChunk.startTimeUs);
    }
    nextChunkHolder.clear();
    chunkSource.getNextChunk(positionUs, loadPositionUs, chunkQueue, /* allowEndOfStream= */
    prepared || !chunkQueue.isEmpty(), nextChunkHolder);
    boolean endOfStream = nextChunkHolder.endOfStream;
    @Nullable Chunk loadable = nextChunkHolder.chunk;
    @Nullable Uri playlistUrlToLoad = nextChunkHolder.playlistUrl;
    if (endOfStream) {
        pendingResetPositionUs = C.TIME_UNSET;
        loadingFinished = true;
        return true;
    }
    if (loadable == null) {
        if (playlistUrlToLoad != null) {
            callback.onPlaylistRefreshRequired(playlistUrlToLoad);
        }
        return false;
    }
    if (isMediaChunk(loadable)) {
        initMediaChunkLoad((HlsMediaChunk) loadable);
    }
    loadingChunk = loadable;
    long elapsedRealtimeMs = loader.startLoading(loadable, this, loadErrorHandlingPolicy.getMinimumLoadableRetryCount(loadable.type));
    mediaSourceEventDispatcher.loadStarted(new LoadEventInfo(loadable.loadTaskId, loadable.dataSpec, elapsedRealtimeMs), loadable.type, trackType, loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData, loadable.startTimeUs, loadable.endTimeUs);
    return true;
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) Chunk(com.google.android.exoplayer2.source.chunk.Chunk) Uri(android.net.Uri) Nullable(androidx.annotation.Nullable)

Example 12 with SampleQueue

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

the class HlsSampleStreamWrapper method seekToUs.

/**
 * Attempts to seek to the specified position in microseconds.
 *
 * @param positionUs The seek position in microseconds.
 * @param forceReset If true then a reset is forced (i.e. in-buffer seeking is disabled).
 * @return Whether the wrapper was reset, meaning the wrapped sample queues were reset. If false,
 *     an in-buffer seek was performed.
 */
public boolean seekToUs(long positionUs, boolean forceReset) {
    lastSeekPositionUs = positionUs;
    if (isPendingReset()) {
        // A reset is already pending. We only need to update its position.
        pendingResetPositionUs = positionUs;
        return true;
    }
    // If we're not forced to reset, try and seek within the buffer.
    if (sampleQueuesBuilt && !forceReset && seekInsideBufferUs(positionUs)) {
        return false;
    }
    // We can't seek inside the buffer, and so need to reset.
    pendingResetPositionUs = positionUs;
    loadingFinished = false;
    mediaChunks.clear();
    if (loader.isLoading()) {
        if (sampleQueuesBuilt) {
            // Discard as much as we can synchronously.
            for (SampleQueue sampleQueue : sampleQueues) {
                sampleQueue.discardToEnd();
            }
        }
        loader.cancelLoading();
    } else {
        loader.clearFatalError();
        resetSampleQueues();
    }
    return true;
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue)

Example 13 with SampleQueue

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

the class HlsSampleStreamWrapper method mapSampleQueuesToMatchTrackGroups.

@RequiresNonNull("trackGroups")
@EnsuresNonNull("trackGroupToSampleQueueIndex")
private void mapSampleQueuesToMatchTrackGroups() {
    int trackGroupCount = trackGroups.length;
    trackGroupToSampleQueueIndex = new int[trackGroupCount];
    Arrays.fill(trackGroupToSampleQueueIndex, C.INDEX_UNSET);
    for (int i = 0; i < trackGroupCount; i++) {
        for (int queueIndex = 0; queueIndex < sampleQueues.length; queueIndex++) {
            SampleQueue sampleQueue = sampleQueues[queueIndex];
            Format upstreamFormat = Assertions.checkStateNotNull(sampleQueue.getUpstreamFormat());
            if (formatsMatch(upstreamFormat, trackGroups.get(i).getFormat(0))) {
                trackGroupToSampleQueueIndex[i] = queueIndex;
                break;
            }
        }
    }
    for (HlsSampleStream sampleStream : hlsSampleStreams) {
        sampleStream.bindSampleQueue();
    }
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue) Format(com.google.android.exoplayer2.Format) EnsuresNonNull(org.checkerframework.checker.nullness.qual.EnsuresNonNull) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 14 with SampleQueue

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

the class HlsSampleStreamWrapper method release.

public void release() {
    if (prepared) {
        // sampleQueues may still be being modified by the loading thread.
        for (SampleQueue sampleQueue : sampleQueues) {
            sampleQueue.preRelease();
        }
    }
    loader.release(this);
    handler.removeCallbacksAndMessages(null);
    released = true;
    hlsSampleStreams.clear();
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue)

Example 15 with SampleQueue

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

the class HlsSampleStreamWrapper method skipData.

public int skipData(int sampleQueueIndex, long positionUs) {
    if (isPendingReset()) {
        return 0;
    }
    SampleQueue sampleQueue = sampleQueues[sampleQueueIndex];
    int skipCount = sampleQueue.getSkipCount(positionUs, loadingFinished);
    // Ensure we don't skip into preload chunks until we can be sure they are permanently published.
    @Nullable HlsMediaChunk lastChunk = Iterables.getLast(mediaChunks, /* defaultValue= */
    null);
    if (lastChunk != null && !lastChunk.isPublished()) {
        int readIndex = sampleQueue.getReadIndex();
        int firstSampleIndex = lastChunk.getFirstSampleIndex(sampleQueueIndex);
        skipCount = min(skipCount, firstSampleIndex - readIndex);
    }
    sampleQueue.skip(skipCount);
    return skipCount;
}
Also used : SampleQueue(com.google.android.exoplayer2.source.SampleQueue) Nullable(androidx.annotation.Nullable)

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