Search in sources :

Example 36 with SampleStream

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

the class DashMediaPeriod method selectTracks.

@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    int[] streamIndexToTrackGroupIndex = getStreamIndexToTrackGroupIndex(selections);
    releaseDisabledStreams(selections, mayRetainStreamFlags, streams);
    releaseOrphanEmbeddedStreams(selections, streams, streamIndexToTrackGroupIndex);
    selectNewStreams(selections, streams, streamResetFlags, positionUs, streamIndexToTrackGroupIndex);
    ArrayList<ChunkSampleStream<DashChunkSource>> sampleStreamList = new ArrayList<>();
    ArrayList<EventSampleStream> eventSampleStreamList = new ArrayList<>();
    for (SampleStream sampleStream : streams) {
        if (sampleStream instanceof ChunkSampleStream) {
            @SuppressWarnings("unchecked") ChunkSampleStream<DashChunkSource> stream = (ChunkSampleStream<DashChunkSource>) sampleStream;
            sampleStreamList.add(stream);
        } else if (sampleStream instanceof EventSampleStream) {
            eventSampleStreamList.add((EventSampleStream) sampleStream);
        }
    }
    sampleStreams = newSampleStreamArray(sampleStreamList.size());
    sampleStreamList.toArray(sampleStreams);
    eventSampleStreams = new EventSampleStream[eventSampleStreamList.size()];
    eventSampleStreamList.toArray(eventSampleStreams);
    compositeSequenceableLoader = compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
    return positionUs;
}
Also used : ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) ArrayList(java.util.ArrayList) EmptySampleStream(com.google.android.exoplayer2.source.EmptySampleStream) EmbeddedSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream.EmbeddedSampleStream) ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) SampleStream(com.google.android.exoplayer2.source.SampleStream)

Example 37 with SampleStream

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

the class MergingMediaPeriod method selectTracks.

@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    // Map each selection and stream onto a child period index.
    int[] streamChildIndices = new int[selections.length];
    int[] selectionChildIndices = new int[selections.length];
    for (int i = 0; i < selections.length; i++) {
        Integer streamChildIndex = streams[i] == null ? null : streamPeriodIndices.get(streams[i]);
        streamChildIndices[i] = streamChildIndex == null ? C.INDEX_UNSET : streamChildIndex;
        selectionChildIndices[i] = C.INDEX_UNSET;
        if (selections[i] != null) {
            TrackGroup mergedTrackGroup = selections[i].getTrackGroup();
            TrackGroup childTrackGroup = checkNotNull(childTrackGroupByMergedTrackGroup.get(mergedTrackGroup));
            for (int j = 0; j < periods.length; j++) {
                if (periods[j].getTrackGroups().indexOf(childTrackGroup) != C.INDEX_UNSET) {
                    selectionChildIndices[i] = j;
                    break;
                }
            }
        }
    }
    streamPeriodIndices.clear();
    // Select tracks for each child, copying the resulting streams back into a new streams array.
    @NullableType SampleStream[] newStreams = new SampleStream[selections.length];
    @NullableType SampleStream[] childStreams = new SampleStream[selections.length];
    @NullableType ExoTrackSelection[] childSelections = new ExoTrackSelection[selections.length];
    ArrayList<MediaPeriod> enabledPeriodsList = new ArrayList<>(periods.length);
    for (int i = 0; i < periods.length; i++) {
        for (int j = 0; j < selections.length; j++) {
            childStreams[j] = streamChildIndices[j] == i ? streams[j] : null;
            if (selectionChildIndices[j] == i) {
                ExoTrackSelection mergedTrackSelection = checkNotNull(selections[j]);
                TrackGroup mergedTrackGroup = mergedTrackSelection.getTrackGroup();
                TrackGroup childTrackGroup = checkNotNull(childTrackGroupByMergedTrackGroup.get(mergedTrackGroup));
                childSelections[j] = new ForwardingTrackSelection(mergedTrackSelection, childTrackGroup);
            } else {
                childSelections[j] = null;
            }
        }
        long selectPositionUs = periods[i].selectTracks(childSelections, mayRetainStreamFlags, childStreams, streamResetFlags, positionUs);
        if (i == 0) {
            positionUs = selectPositionUs;
        } else if (selectPositionUs != positionUs) {
            throw new IllegalStateException("Children enabled at different positions.");
        }
        boolean periodEnabled = false;
        for (int j = 0; j < selections.length; j++) {
            if (selectionChildIndices[j] == i) {
                // Assert that the child provided a stream for the selection.
                SampleStream childStream = Assertions.checkNotNull(childStreams[j]);
                newStreams[j] = childStreams[j];
                periodEnabled = true;
                streamPeriodIndices.put(childStream, i);
            } else if (streamChildIndices[j] == i) {
                // Assert that the child cleared any previous stream.
                Assertions.checkState(childStreams[j] == null);
            }
        }
        if (periodEnabled) {
            enabledPeriodsList.add(periods[i]);
        }
    }
    // Copy the new streams back into the streams array.
    System.arraycopy(newStreams, 0, streams, 0, newStreams.length);
    // Update the local state.
    enabledPeriods = enabledPeriodsList.toArray(new MediaPeriod[0]);
    compositeSequenceableLoader = compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(enabledPeriods);
    return positionUs;
}
Also used : ArrayList(java.util.ArrayList) NullableType(org.checkerframework.checker.nullness.compatqual.NullableType) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection)

Example 38 with SampleStream

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

the class RtspMediaPeriod method selectTracks.

@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    // Input array streams contains the streams selected in the previous track selection.
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
            streams[i] = null;
        }
    }
    // Select new tracks.
    selectedLoadInfos.clear();
    for (int i = 0; i < selections.length; i++) {
        TrackSelection selection = selections[i];
        if (selection == null) {
            continue;
        }
        TrackGroup trackGroup = selection.getTrackGroup();
        int trackGroupIndex = checkNotNull(trackGroups).indexOf(trackGroup);
        selectedLoadInfos.add(checkNotNull(rtspLoaderWrappers.get(trackGroupIndex)).loadInfo);
        // Find the sampleStreamWrapper that contains this track group.
        if (trackGroups.contains(trackGroup)) {
            if (streams[i] == null) {
                streams[i] = new SampleStreamImpl(trackGroupIndex);
                // Update flag for newly created SampleStream.
                streamResetFlags[i] = true;
            }
        }
    }
    // Cancel non-selected loadables.
    for (int i = 0; i < rtspLoaderWrappers.size(); i++) {
        RtspLoaderWrapper loadControl = rtspLoaderWrappers.get(i);
        if (!selectedLoadInfos.contains(loadControl.loadInfo)) {
            loadControl.cancelLoad();
        }
    }
    trackSelected = true;
    maybeSetupTracks();
    return positionUs;
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection) ExoTrackSelection(com.google.android.exoplayer2.trackselection.ExoTrackSelection)

Aggregations

EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)15 Test (org.junit.Test)15 EventMessage (com.google.android.exoplayer2.metadata.emsg.EventMessage)10 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)10 SampleStream (com.google.android.exoplayer2.source.SampleStream)8 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)6 CompositeSequenceableLoader (com.google.android.exoplayer2.source.CompositeSequenceableLoader)5 ChunkSampleStream (com.google.android.exoplayer2.source.chunk.ChunkSampleStream)5 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)5 ArrayList (java.util.ArrayList)5 Format (com.google.android.exoplayer2.Format)3 FormatHolder (com.google.android.exoplayer2.FormatHolder)3 EmptySampleStream (com.google.android.exoplayer2.source.EmptySampleStream)3 TextRenderer (com.google.android.exoplayer2.text.TextRenderer)3 TrackSelectorResult (com.google.android.exoplayer2.trackselection.TrackSelectorResult)3 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 SampleQueue (com.google.android.exoplayer2.source.SampleQueue)2 EmbeddedSampleStream (com.google.android.exoplayer2.source.chunk.ChunkSampleStream.EmbeddedSampleStream)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)2