Search in sources :

Example 1 with InitializationChunk

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

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(com.google.android.exoplayer2.source.SampleQueue) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) Nullable(androidx.annotation.Nullable)

Example 2 with InitializationChunk

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

the class DashUtil method loadInitializationData.

private static void loadInitializationData(DataSource dataSource, Representation representation, int baseUrlIndex, ChunkExtractor chunkExtractor, RangedUri requestUri) throws IOException {
    DataSpec dataSpec = DashUtil.buildDataSpec(representation, representation.baseUrls.get(baseUrlIndex).url, requestUri, /* flags= */
    0);
    InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
    chunkExtractor);
    initializationChunk.load();
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 3 with InitializationChunk

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

the class DefaultDashChunkSource method newInitializationChunk.

protected Chunk newInitializationChunk(RepresentationHolder representationHolder, DataSource dataSource, Format trackFormat, @C.SelectionReason int trackSelectionReason, @Nullable Object trackSelectionData, @Nullable RangedUri initializationUri, @Nullable RangedUri indexUri) {
    Representation representation = representationHolder.representation;
    @Nullable RangedUri requestUri;
    if (initializationUri != null) {
        // It's common for initialization and index data to be stored adjacently. Attempt to merge
        // the two requests together to request both at once.
        requestUri = initializationUri.attemptMerge(indexUri, representationHolder.selectedBaseUrl.url);
        if (requestUri == null) {
            requestUri = initializationUri;
        }
    } else {
        requestUri = indexUri;
    }
    DataSpec dataSpec = DashUtil.buildDataSpec(representation, representationHolder.selectedBaseUrl.url, requestUri, /* flags= */
    0);
    return new InitializationChunk(dataSource, dataSpec, trackFormat, trackSelectionReason, trackSelectionData, representationHolder.chunkExtractor);
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) RangedUri(com.google.android.exoplayer2.source.dash.manifest.RangedUri) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Representation(com.google.android.exoplayer2.source.dash.manifest.Representation) Nullable(androidx.annotation.Nullable)

Example 4 with InitializationChunk

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

the class DashUtil method loadInitializationData.

private static void loadInitializationData(DataSource dataSource, Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri) throws IOException, InterruptedException {
    DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl), requestUri.start, requestUri.length, representation.getCacheKey());
    InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec, representation.format, C.SELECTION_REASON_UNKNOWN, null, /* trackSelectionData */
    extractorWrapper);
    initializationChunk.load();
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 5 with InitializationChunk

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

the class DefaultDashChunkSource method onChunkLoadCompleted.

@Override
public void onChunkLoadCompleted(Chunk chunk) {
    if (chunk instanceof InitializationChunk) {
        InitializationChunk initializationChunk = (InitializationChunk) chunk;
        int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
        RepresentationHolder representationHolder = representationHolders[trackIndex];
        // where it does we should ignore it.
        if (representationHolder.segmentIndex == null) {
            @Nullable ChunkIndex chunkIndex = representationHolder.chunkExtractor.getChunkIndex();
            if (chunkIndex != null) {
                representationHolders[trackIndex] = representationHolder.copyWithNewSegmentIndex(new DashWrappingSegmentIndex(chunkIndex, representationHolder.representation.presentationTimeOffsetUs));
            }
        }
    }
    if (playerTrackEmsgHandler != null) {
        playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
    }
}
Also used : InitializationChunk(com.google.android.exoplayer2.source.chunk.InitializationChunk) Nullable(androidx.annotation.Nullable) ChunkIndex(com.google.android.exoplayer2.extractor.ChunkIndex)

Aggregations

InitializationChunk (com.google.android.exoplayer2.source.chunk.InitializationChunk)4 Nullable (androidx.annotation.Nullable)3 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)3 ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)1 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)1 SampleQueue (com.google.android.exoplayer2.source.SampleQueue)1 RangedUri (com.google.android.exoplayer2.source.dash.manifest.RangedUri)1 Representation (com.google.android.exoplayer2.source.dash.manifest.Representation)1