Search in sources :

Example 1 with ChunkSampleStream

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

the class SsMediaPeriod method selectTracks.

@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    ArrayList<ChunkSampleStream<SsChunkSource>> sampleStreamsList = new ArrayList<>();
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] != null) {
            @SuppressWarnings("unchecked") ChunkSampleStream<SsChunkSource> stream = (ChunkSampleStream<SsChunkSource>) streams[i];
            if (selections[i] == null || !mayRetainStreamFlags[i]) {
                stream.release();
                streams[i] = null;
            } else {
                sampleStreamsList.add(stream);
            }
        }
        if (streams[i] == null && selections[i] != null) {
            ChunkSampleStream<SsChunkSource> stream = buildSampleStream(selections[i], positionUs);
            sampleStreamsList.add(stream);
            streams[i] = stream;
            streamResetFlags[i] = true;
        }
    }
    sampleStreams = newSampleStreamArray(sampleStreamsList.size());
    sampleStreamsList.toArray(sampleStreams);
    sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
    return positionUs;
}
Also used : ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) ArrayList(java.util.ArrayList) CompositeSequenceableLoader(com.google.android.exoplayer2.source.CompositeSequenceableLoader)

Example 2 with ChunkSampleStream

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

the class DashMediaPeriod method selectTracks.

@Override
public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    int adaptationSetCount = adaptationSets.size();
    HashMap<Integer, ChunkSampleStream<DashChunkSource>> primarySampleStreams = new HashMap<>();
    // First pass for primary tracks.
    for (int i = 0; i < selections.length; i++) {
        if (streams[i] instanceof ChunkSampleStream) {
            @SuppressWarnings("unchecked") ChunkSampleStream<DashChunkSource> stream = (ChunkSampleStream<DashChunkSource>) streams[i];
            if (selections[i] == null || !mayRetainStreamFlags[i]) {
                stream.release();
                streams[i] = null;
            } else {
                int adaptationSetIndex = trackGroups.indexOf(selections[i].getTrackGroup());
                primarySampleStreams.put(adaptationSetIndex, stream);
            }
        }
        if (streams[i] == null && selections[i] != null) {
            int trackGroupIndex = trackGroups.indexOf(selections[i].getTrackGroup());
            if (trackGroupIndex < adaptationSetCount) {
                ChunkSampleStream<DashChunkSource> stream = buildSampleStream(trackGroupIndex, selections[i], positionUs);
                primarySampleStreams.put(trackGroupIndex, stream);
                streams[i] = stream;
                streamResetFlags[i] = true;
            }
        }
    }
    // Second pass for embedded tracks.
    for (int i = 0; i < selections.length; i++) {
        if ((streams[i] instanceof EmbeddedSampleStream || streams[i] instanceof EmptySampleStream) && (selections[i] == null || !mayRetainStreamFlags[i])) {
            // The stream is for an embedded track and is either no longer selected or needs replacing.
            releaseIfEmbeddedSampleStream(streams[i]);
            streams[i] = null;
        }
        // may have been replaced, selected or deselected.
        if (selections[i] != null) {
            int trackGroupIndex = trackGroups.indexOf(selections[i].getTrackGroup());
            if (trackGroupIndex >= adaptationSetCount) {
                int embeddedTrackIndex = trackGroupIndex - adaptationSetCount;
                EmbeddedTrackInfo embeddedTrackInfo = embeddedTrackInfos[embeddedTrackIndex];
                int adaptationSetIndex = embeddedTrackInfo.adaptationSetIndex;
                ChunkSampleStream<?> primaryStream = primarySampleStreams.get(adaptationSetIndex);
                SampleStream stream = streams[i];
                boolean mayRetainStream = primaryStream == null ? stream instanceof EmptySampleStream : (stream instanceof EmbeddedSampleStream && ((EmbeddedSampleStream) stream).parent == primaryStream);
                if (!mayRetainStream) {
                    releaseIfEmbeddedSampleStream(stream);
                    streams[i] = primaryStream == null ? new EmptySampleStream() : primaryStream.selectEmbeddedTrack(positionUs, embeddedTrackInfo.trackType);
                    streamResetFlags[i] = true;
                }
            }
        }
    }
    sampleStreams = newSampleStreamArray(primarySampleStreams.size());
    primarySampleStreams.values().toArray(sampleStreams);
    sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
    return positionUs;
}
Also used : EmptySampleStream(com.google.android.exoplayer2.source.EmptySampleStream) ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) HashMap(java.util.HashMap) EmbeddedSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream.EmbeddedSampleStream) ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) EmptySampleStream(com.google.android.exoplayer2.source.EmptySampleStream) SampleStream(com.google.android.exoplayer2.source.SampleStream) CompositeSequenceableLoader(com.google.android.exoplayer2.source.CompositeSequenceableLoader) EmbeddedSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream.EmbeddedSampleStream)

Example 3 with ChunkSampleStream

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

the class DashMediaPeriod method buildSampleStream.

private ChunkSampleStream<DashChunkSource> buildSampleStream(int adaptationSetIndex, TrackSelection selection, long positionUs) {
    AdaptationSet adaptationSet = adaptationSets.get(adaptationSetIndex);
    int embeddedTrackCount = 0;
    int[] embeddedTrackTypes = new int[2];
    boolean enableEventMessageTrack = hasEventMessageTrack(adaptationSet);
    if (enableEventMessageTrack) {
        embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_METADATA;
    }
    boolean enableCea608Track = hasCea608Track(adaptationSet);
    if (enableCea608Track) {
        embeddedTrackTypes[embeddedTrackCount++] = C.TRACK_TYPE_TEXT;
    }
    if (embeddedTrackCount < embeddedTrackTypes.length) {
        embeddedTrackTypes = Arrays.copyOf(embeddedTrackTypes, embeddedTrackCount);
    }
    DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(manifestLoaderErrorThrower, manifest, periodIndex, adaptationSetIndex, selection, elapsedRealtimeOffset, enableEventMessageTrack, enableCea608Track);
    ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(adaptationSet.type, embeddedTrackTypes, chunkSource, this, allocator, positionUs, minLoadableRetryCount, eventDispatcher);
    return stream;
}
Also used : ChunkSampleStream(com.google.android.exoplayer2.source.chunk.ChunkSampleStream) AdaptationSet(com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)

Aggregations

ChunkSampleStream (com.google.android.exoplayer2.source.chunk.ChunkSampleStream)3 CompositeSequenceableLoader (com.google.android.exoplayer2.source.CompositeSequenceableLoader)2 EmptySampleStream (com.google.android.exoplayer2.source.EmptySampleStream)1 SampleStream (com.google.android.exoplayer2.source.SampleStream)1 EmbeddedSampleStream (com.google.android.exoplayer2.source.chunk.ChunkSampleStream.EmbeddedSampleStream)1 AdaptationSet (com.google.android.exoplayer2.source.dash.manifest.AdaptationSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1