Search in sources :

Example 1 with InitializationChunk

use of androidx.media3.exoplayer.source.chunk.InitializationChunk in project media by androidx.

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(androidx.media3.exoplayer.source.chunk.InitializationChunk) DataSpec(androidx.media3.datasource.DataSpec)

Example 2 with InitializationChunk

use of androidx.media3.exoplayer.source.chunk.InitializationChunk in project media by androidx.

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(androidx.media3.exoplayer.source.chunk.InitializationChunk) Nullable(androidx.annotation.Nullable) ChunkIndex(androidx.media3.extractor.ChunkIndex)

Example 3 with InitializationChunk

use of androidx.media3.exoplayer.source.chunk.InitializationChunk in project media by androidx.

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(androidx.media3.exoplayer.source.chunk.InitializationChunk) RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) DataSpec(androidx.media3.datasource.DataSpec) Representation(androidx.media3.exoplayer.dash.manifest.Representation) Nullable(androidx.annotation.Nullable)

Example 4 with InitializationChunk

use of androidx.media3.exoplayer.source.chunk.InitializationChunk 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

Nullable (androidx.annotation.Nullable)3 InitializationChunk (androidx.media3.exoplayer.source.chunk.InitializationChunk)3 DataSpec (androidx.media3.datasource.DataSpec)2 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)1 Representation (androidx.media3.exoplayer.dash.manifest.Representation)1 LoadEventInfo (androidx.media3.exoplayer.source.LoadEventInfo)1 SampleQueue (androidx.media3.exoplayer.source.SampleQueue)1 ChunkIndex (androidx.media3.extractor.ChunkIndex)1