Search in sources :

Example 6 with ChunkIndex

use of com.google.android.exoplayer2.extractor.ChunkIndex in project ExoPlayer by google.

the class DashDownloader method getSegmentIndex.

@Nullable
private DashSegmentIndex getSegmentIndex(DataSource dataSource, int trackType, Representation representation, boolean removing) throws IOException, InterruptedException {
    DashSegmentIndex index = representation.getIndex();
    if (index != null) {
        return index;
    }
    RunnableFutureTask<@NullableType ChunkIndex, IOException> runnable = new RunnableFutureTask<@NullableType ChunkIndex, IOException>() {

        @Override
        @NullableType
        protected ChunkIndex doWork() throws IOException {
            return DashUtil.loadChunkIndex(dataSource, trackType, representation);
        }
    };
    @Nullable ChunkIndex seekMap = execute(runnable, removing);
    return seekMap == null ? null : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
Also used : DashWrappingSegmentIndex(com.google.android.exoplayer2.source.dash.DashWrappingSegmentIndex) RunnableFutureTask(com.google.android.exoplayer2.util.RunnableFutureTask) IOException(java.io.IOException) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) DashSegmentIndex(com.google.android.exoplayer2.source.dash.DashSegmentIndex) ChunkIndex(com.google.android.exoplayer2.extractor.ChunkIndex) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Example 7 with ChunkIndex

use of com.google.android.exoplayer2.extractor.ChunkIndex in project ExoPlayer by google.

the class HlsSampleStreamWrapper method selectTracks.

public boolean selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, boolean isFirstTrackSelection) {
    Assertions.checkState(prepared);
    // Disable old tracks.
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
            int group = ((HlsSampleStream) streams[i]).group;
            setTrackGroupEnabledState(group, false);
            sampleQueues.valueAt(group).disable();
            streams[i] = null;
        }
    }
    // Enable new tracks.
    TrackSelection primaryTrackSelection = null;
    boolean selectedNewTracks = false;
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] == null && selections[i] != null) {
            TrackSelection selection = selections[i];
            int group = trackGroups.indexOf(selection.getTrackGroup());
            setTrackGroupEnabledState(group, true);
            if (group == primaryTrackGroupIndex) {
                primaryTrackSelection = selection;
                chunkSource.selectTracks(selection);
            }
            streams[i] = new HlsSampleStream(this, group);
            streamResetFlags[i] = true;
            selectedNewTracks = true;
        }
    }
    if (isFirstTrackSelection) {
        // At the time of the first track selection all queues will be enabled, so we need to disable
        // any that are no longer required.
        int sampleQueueCount = sampleQueues.size();
        for (int i = 0; i < sampleQueueCount; i++) {
            if (!groupEnabledStates[i]) {
                sampleQueues.valueAt(i).disable();
            }
        }
        if (primaryTrackSelection != null && !mediaChunks.isEmpty()) {
            primaryTrackSelection.updateSelectedTrack(0);
            int chunkIndex = chunkSource.getTrackGroup().indexOf(mediaChunks.getLast().trackFormat);
            if (primaryTrackSelection.getSelectedIndexInTrackGroup() != chunkIndex) {
                // The loaded preparation chunk does match the selection. We discard it.
                seekTo(lastSeekPositionUs);
            }
        }
    }
    // Cancel requests if necessary.
    if (enabledTrackCount == 0) {
        chunkSource.reset();
        downstreamTrackFormat = null;
        mediaChunks.clear();
        if (loader.isLoading()) {
            loader.cancelLoading();
        }
    }
    return selectedNewTracks;
}
Also used : TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection)

Example 8 with ChunkIndex

use of com.google.android.exoplayer2.extractor.ChunkIndex in project ExoPlayer by google.

the class DefaultSsChunkSource method getNextChunk.

@Override
public final void getNextChunk(MediaChunk previous, long playbackPositionUs, ChunkHolder out) {
    if (fatalError != null) {
        return;
    }
    long bufferedDurationUs = previous != null ? (previous.endTimeUs - playbackPositionUs) : 0;
    trackSelection.updateSelectedTrack(bufferedDurationUs);
    StreamElement streamElement = manifest.streamElements[elementIndex];
    if (streamElement.chunkCount == 0) {
        // There aren't any chunks for us to load.
        out.endOfStream = !manifest.isLive;
        return;
    }
    int chunkIndex;
    if (previous == null) {
        chunkIndex = streamElement.getChunkIndex(playbackPositionUs);
    } else {
        chunkIndex = previous.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 chunkStartTimeUs = streamElement.getStartTimeUs(chunkIndex);
    long chunkEndTimeUs = chunkStartTimeUs + streamElement.getChunkDurationUs(chunkIndex);
    int currentAbsoluteChunkIndex = chunkIndex + currentManifestChunkOffset;
    int trackSelectionIndex = trackSelection.getSelectedIndex();
    ChunkExtractorWrapper extractorWrapper = extractorWrappers[trackSelectionIndex];
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(trackSelectionIndex);
    Uri uri = streamElement.buildRequestUri(manifestTrackIndex, chunkIndex);
    out.chunk = newMediaChunk(trackSelection.getSelectedFormat(), dataSource, uri, null, currentAbsoluteChunkIndex, chunkStartTimeUs, chunkEndTimeUs, trackSelection.getSelectionReason(), trackSelection.getSelectionData(), extractorWrapper);
}
Also used : BehindLiveWindowException(com.google.android.exoplayer2.source.BehindLiveWindowException) ChunkExtractorWrapper(com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper) StreamElement(com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement) Uri(android.net.Uri)

Example 9 with ChunkIndex

use of com.google.android.exoplayer2.extractor.ChunkIndex in project ExoPlayer by google.

the class DefaultSsChunkSource method newMediaChunk.

// Private methods.
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri, String cacheKey, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs, int trackSelectionReason, Object trackSelectionData, ChunkExtractorWrapper extractorWrapper) {
    DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
    // 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, chunkIndex, 1, sampleOffsetUs, extractorWrapper);
}
Also used : DataSpec(com.google.android.exoplayer2.upstream.DataSpec) ContainerMediaChunk(com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)

Example 10 with ChunkIndex

use of com.google.android.exoplayer2.extractor.ChunkIndex 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

ChunkIndex (com.google.android.exoplayer2.extractor.ChunkIndex)4 DataSpec (com.google.android.exoplayer2.upstream.DataSpec)4 Uri (android.net.Uri)3 Nullable (androidx.annotation.Nullable)3 BehindLiveWindowException (com.google.android.exoplayer2.source.BehindLiveWindowException)3 MediaChunkIterator (com.google.android.exoplayer2.source.chunk.MediaChunkIterator)3 StreamElement (com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement)3 Format (com.google.android.exoplayer2.Format)2 ContainerMediaChunk (com.google.android.exoplayer2.source.chunk.ContainerMediaChunk)2 SampleQueue (com.google.android.exoplayer2.source.SampleQueue)1 BaseMediaChunkIterator (com.google.android.exoplayer2.source.chunk.BaseMediaChunkIterator)1 BundledChunkExtractor (com.google.android.exoplayer2.source.chunk.BundledChunkExtractor)1 ChunkExtractor (com.google.android.exoplayer2.source.chunk.ChunkExtractor)1 ChunkExtractorWrapper (com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper)1 InitializationChunk (com.google.android.exoplayer2.source.chunk.InitializationChunk)1 SingleSampleMediaChunk (com.google.android.exoplayer2.source.chunk.SingleSampleMediaChunk)1 DashSegmentIndex (com.google.android.exoplayer2.source.dash.DashSegmentIndex)1 DashWrappingSegmentIndex (com.google.android.exoplayer2.source.dash.DashWrappingSegmentIndex)1 HlsUrl (com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist.HlsUrl)1 HlsMediaPlaylist (com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist)1