Search in sources :

Example 1 with ChunkExtractor

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

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

the class DefaultSsChunkSource method newMediaChunk.

// Private methods.
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs, long chunkSeekTimeUs, @C.SelectionReason int trackSelectionReason, @Nullable Object trackSelectionData, ChunkExtractor chunkExtractor) {
    DataSpec dataSpec = new DataSpec(uri);
    // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
    // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
    long sampleOffsetUs = chunkStartTimeUs;
    return new ContainerMediaChunk(dataSource, dataSpec, format, trackSelectionReason, trackSelectionData, chunkStartTimeUs, chunkEndTimeUs, chunkSeekTimeUs, /* clippedEndTimeUs= */
    C.TIME_UNSET, chunkIndex, /* chunkCount= */
    1, sampleOffsetUs, chunkExtractor);
}
Also used : DataSpec(androidx.media3.datasource.DataSpec) ContainerMediaChunk(androidx.media3.exoplayer.source.chunk.ContainerMediaChunk)

Example 3 with ChunkExtractor

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

the class DefaultSsChunkSource method getNextChunk.

@Override
public final void getNextChunk(long playbackPositionUs, long loadPositionUs, List<? extends MediaChunk> queue, ChunkHolder out) {
    if (fatalError != null) {
        return;
    }
    StreamElement streamElement = manifest.streamElements[streamElementIndex];
    if (streamElement.chunkCount == 0) {
        // There aren't any chunks for us to load.
        out.endOfStream = !manifest.isLive;
        return;
    }
    int chunkIndex;
    if (queue.isEmpty()) {
        chunkIndex = streamElement.getChunkIndex(loadPositionUs);
    } else {
        chunkIndex = (int) (queue.get(queue.size() - 1).getNextChunkIndex() - currentManifestChunkOffset);
        if (chunkIndex < 0) {
            // This is before the first chunk in the current manifest.
            fatalError = new BehindLiveWindowException();
            return;
        }
    }
    if (chunkIndex >= streamElement.chunkCount) {
        // This is beyond the last chunk in the current manifest.
        out.endOfStream = !manifest.isLive;
        return;
    }
    long bufferedDurationUs = loadPositionUs - playbackPositionUs;
    long timeToLiveEdgeUs = resolveTimeToLiveEdgeUs(playbackPositionUs);
    MediaChunkIterator[] chunkIterators = new MediaChunkIterator[trackSelection.length()];
    for (int i = 0; i < chunkIterators.length; i++) {
        int trackIndex = trackSelection.getIndexInTrackGroup(i);
        chunkIterators[i] = new StreamElementIterator(streamElement, trackIndex, chunkIndex);
    }
    trackSelection.updateSelectedTrack(playbackPositionUs, bufferedDurationUs, timeToLiveEdgeUs, queue, chunkIterators);
    long chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
    long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
    long chunkSeekTimeUs = queue.isEmpty() ? loadPositionUs : C.TIME_UNSET;
    int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
    int trackSelectionIndex = trackSelection.getSelectedIndex();
    ChunkExtractor chunkExtractor = chunkExtractors[trackSelectionIndex];
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(trackSelectionIndex);
    Uri uri = streamElement.buildRequestUri(manifestTrackIndex, chunkIndex);
    out.chunk = newMediaChunk(trackSelection.getSelectedFormat(), dataSource, uri, currentAbsoluteChunkIndex, chunkStartTimeUs, chunkEndTimeUs, chunkSeekTimeUs, trackSelection.getSelectionReason(), trackSelection.getSelectionData(), chunkExtractor);
}
Also used : BaseMediaChunkIterator(androidx.media3.exoplayer.source.chunk.BaseMediaChunkIterator) MediaChunkIterator(androidx.media3.exoplayer.source.chunk.MediaChunkIterator) BehindLiveWindowException(androidx.media3.exoplayer.source.BehindLiveWindowException) StreamElement(androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest.StreamElement) ChunkExtractor(androidx.media3.exoplayer.source.chunk.ChunkExtractor) BundledChunkExtractor(androidx.media3.exoplayer.source.chunk.BundledChunkExtractor) Uri(android.net.Uri)

Example 4 with ChunkExtractor

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

the class DashUtil method loadInitializationData.

/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link BundledChunkExtractor} which contains the output.
 *
 * @param chunkExtractor The {@link ChunkExtractor} to use.
 * @param dataSource The source from which the data should be loaded.
 * @param representation The representation which initialization chunk belongs to.
 * @param baseUrlIndex The index of the base URL with which to resolve the request URI.
 * @param loadIndex Whether to load index data too.
 * @throws IOException Thrown when there is an error while loading.
 */
private static void loadInitializationData(ChunkExtractor chunkExtractor, DataSource dataSource, Representation representation, int baseUrlIndex, boolean loadIndex) throws IOException {
    RangedUri initializationUri = Assertions.checkNotNull(representation.getInitializationUri());
    @Nullable RangedUri requestUri;
    if (loadIndex) {
        @Nullable RangedUri indexUri = representation.getIndexUri();
        if (indexUri == null) {
            return;
        }
        // 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, representation.baseUrls.get(baseUrlIndex).url);
        if (requestUri == null) {
            loadInitializationData(dataSource, representation, baseUrlIndex, chunkExtractor, initializationUri);
            requestUri = indexUri;
        }
    } else {
        requestUri = initializationUri;
    }
    loadInitializationData(dataSource, representation, baseUrlIndex, chunkExtractor, requestUri);
}
Also used : RangedUri(androidx.media3.exoplayer.dash.manifest.RangedUri) Nullable(androidx.annotation.Nullable)

Example 5 with ChunkExtractor

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

the class DashUtil method newChunkExtractor.

private static ChunkExtractor newChunkExtractor(int trackType, Format format) {
    String mimeType = format.containerMimeType;
    boolean isWebm = mimeType != null && (mimeType.startsWith(MimeTypes.VIDEO_WEBM) || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
    Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
    return new BundledChunkExtractor(extractor, trackType, format);
}
Also used : FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) ChunkExtractor(androidx.media3.exoplayer.source.chunk.ChunkExtractor) Extractor(androidx.media3.extractor.Extractor) BundledChunkExtractor(androidx.media3.exoplayer.source.chunk.BundledChunkExtractor) MatroskaExtractor(androidx.media3.extractor.mkv.MatroskaExtractor) FragmentedMp4Extractor(androidx.media3.extractor.mp4.FragmentedMp4Extractor) BundledChunkExtractor(androidx.media3.exoplayer.source.chunk.BundledChunkExtractor) MatroskaExtractor(androidx.media3.extractor.mkv.MatroskaExtractor)

Aggregations

DataSpec (androidx.media3.datasource.DataSpec)2 BundledChunkExtractor (androidx.media3.exoplayer.source.chunk.BundledChunkExtractor)2 ChunkExtractor (androidx.media3.exoplayer.source.chunk.ChunkExtractor)2 Uri (android.net.Uri)1 Nullable (androidx.annotation.Nullable)1 RangedUri (androidx.media3.exoplayer.dash.manifest.RangedUri)1 StreamElement (androidx.media3.exoplayer.smoothstreaming.manifest.SsManifest.StreamElement)1 BehindLiveWindowException (androidx.media3.exoplayer.source.BehindLiveWindowException)1 BaseMediaChunkIterator (androidx.media3.exoplayer.source.chunk.BaseMediaChunkIterator)1 ContainerMediaChunk (androidx.media3.exoplayer.source.chunk.ContainerMediaChunk)1 InitializationChunk (androidx.media3.exoplayer.source.chunk.InitializationChunk)1 MediaChunkIterator (androidx.media3.exoplayer.source.chunk.MediaChunkIterator)1 Extractor (androidx.media3.extractor.Extractor)1 MatroskaExtractor (androidx.media3.extractor.mkv.MatroskaExtractor)1 FragmentedMp4Extractor (androidx.media3.extractor.mp4.FragmentedMp4Extractor)1