Search in sources :

Example 1 with ChunkSampleStream

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

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(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) ArrayList(java.util.ArrayList) ChunkSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) EmbeddedSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream.EmbeddedSampleStream) EmptySampleStream(androidx.media3.exoplayer.source.EmptySampleStream) SampleStream(androidx.media3.exoplayer.source.SampleStream)

Example 2 with ChunkSampleStream

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

the class DashMediaPeriod method updateManifest.

/**
 * Updates the {@link DashManifest} and the index of this period in the manifest.
 *
 * @param manifest The updated manifest.
 * @param periodIndex the new index of this period in the updated manifest.
 */
public void updateManifest(DashManifest manifest, int periodIndex) {
    this.manifest = manifest;
    this.periodIndex = periodIndex;
    playerEmsgHandler.updateManifest(manifest);
    if (sampleStreams != null) {
        for (ChunkSampleStream<DashChunkSource> sampleStream : sampleStreams) {
            sampleStream.getChunkSource().updateManifest(manifest, periodIndex);
        }
        callback.onContinueLoadingRequested(this);
    }
    eventStreams = manifest.getPeriod(periodIndex).eventStreams;
    for (EventSampleStream eventSampleStream : eventSampleStreams) {
        for (EventStream eventStream : eventStreams) {
            if (eventStream.id().equals(eventSampleStream.eventStreamId())) {
                int lastPeriodIndex = manifest.getPeriodCount() - 1;
                eventSampleStream.updateEventStream(eventStream, /* eventStreamAppendable= */
                manifest.dynamic && periodIndex == lastPeriodIndex);
                break;
            }
        }
    }
}
Also used : EventStream(androidx.media3.exoplayer.dash.manifest.EventStream)

Example 3 with ChunkSampleStream

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

the class FakeAdaptiveMediaPeriod method selectTracks.

// Casting sample streams created by this class.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public long selectTracks(@NullableType ExoTrackSelection[] selections, boolean[] mayRetainStreamFlags, @NullableType SampleStream[] streams, boolean[] streamResetFlags, long positionUs) {
    assertThat(prepared).isTrue();
    int rendererCount = selections.length;
    for (int i = 0; i < rendererCount; i++) {
        if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
            ((ChunkSampleStream<FakeChunkSource>) streams[i]).release();
            sampleStreams.remove(streams[i]);
            streams[i] = null;
        }
        if (streams[i] == null && selections[i] != null) {
            ExoTrackSelection selection = selections[i];
            assertThat(selection.length()).isAtLeast(1);
            TrackGroup trackGroup = selection.getTrackGroup();
            assertThat(trackGroupArray.indexOf(trackGroup)).isNotEqualTo(C.INDEX_UNSET);
            int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
            assertThat(indexInTrackGroup).isAtLeast(0);
            assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
            FakeChunkSource chunkSource = chunkSourceFactory.createChunkSource(selection, durationUs, transferListener);
            ChunkSampleStream<FakeChunkSource> sampleStream = new ChunkSampleStream<>(MimeTypes.getTrackType(selection.getSelectedFormat().sampleMimeType), /* embeddedTrackTypes= */
            null, /* embeddedTrackFormats= */
            null, chunkSource, /* callback= */
            this, allocator, positionUs, DrmSessionManager.DRM_UNSUPPORTED, new DrmSessionEventListener.EventDispatcher(), new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */
            3), mediaSourceEventDispatcher);
            streams[i] = sampleStream;
            sampleStreams.add(sampleStream);
            streamResetFlags[i] = true;
        }
    }
    sequenceableLoader = new CompositeSequenceableLoader(sampleStreams.toArray(new ChunkSampleStream[0]));
    return seekToUs(positionUs);
}
Also used : ChunkSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) DefaultLoadErrorHandlingPolicy(androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy) TrackGroup(androidx.media3.common.TrackGroup) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader)

Example 4 with ChunkSampleStream

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

the class FakeAdaptiveMediaPeriod method release.

/**
 * Releases the media period.
 */
public void release() {
    prepared = false;
    for (ChunkSampleStream<FakeChunkSource> sampleStream : sampleStreams) {
        sampleStream.release();
    }
    sampleStreams.clear();
    sequenceableLoader = new CompositeSequenceableLoader(new SequenceableLoader[0]);
}
Also used : CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader) SequenceableLoader(androidx.media3.exoplayer.source.SequenceableLoader) CompositeSequenceableLoader(androidx.media3.exoplayer.source.CompositeSequenceableLoader)

Example 5 with ChunkSampleStream

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

the class DashMediaPeriod method buildSampleStream.

private ChunkSampleStream<DashChunkSource> buildSampleStream(TrackGroupInfo trackGroupInfo, ExoTrackSelection selection, long positionUs) {
    int embeddedTrackCount = 0;
    boolean enableEventMessageTrack = trackGroupInfo.embeddedEventMessageTrackGroupIndex != C.INDEX_UNSET;
    TrackGroup embeddedEventMessageTrackGroup = null;
    if (enableEventMessageTrack) {
        embeddedEventMessageTrackGroup = trackGroups.get(trackGroupInfo.embeddedEventMessageTrackGroupIndex);
        embeddedTrackCount++;
    }
    boolean enableClosedCaptionTrack = trackGroupInfo.embeddedClosedCaptionTrackGroupIndex != C.INDEX_UNSET;
    TrackGroup embeddedClosedCaptionTrackGroup = null;
    if (enableClosedCaptionTrack) {
        embeddedClosedCaptionTrackGroup = trackGroups.get(trackGroupInfo.embeddedClosedCaptionTrackGroupIndex);
        embeddedTrackCount += embeddedClosedCaptionTrackGroup.length;
    }
    Format[] embeddedTrackFormats = new Format[embeddedTrackCount];
    int[] embeddedTrackTypes = new int[embeddedTrackCount];
    embeddedTrackCount = 0;
    if (enableEventMessageTrack) {
        embeddedTrackFormats[embeddedTrackCount] = embeddedEventMessageTrackGroup.getFormat(0);
        embeddedTrackTypes[embeddedTrackCount] = C.TRACK_TYPE_METADATA;
        embeddedTrackCount++;
    }
    List<Format> embeddedClosedCaptionTrackFormats = new ArrayList<>();
    if (enableClosedCaptionTrack) {
        for (int i = 0; i < embeddedClosedCaptionTrackGroup.length; i++) {
            embeddedTrackFormats[embeddedTrackCount] = embeddedClosedCaptionTrackGroup.getFormat(i);
            embeddedTrackTypes[embeddedTrackCount] = C.TRACK_TYPE_TEXT;
            embeddedClosedCaptionTrackFormats.add(embeddedTrackFormats[embeddedTrackCount]);
            embeddedTrackCount++;
        }
    }
    PlayerTrackEmsgHandler trackPlayerEmsgHandler = manifest.dynamic && enableEventMessageTrack ? playerEmsgHandler.newPlayerTrackEmsgHandler() : null;
    DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(manifestLoaderErrorThrower, manifest, baseUrlExclusionList, periodIndex, trackGroupInfo.adaptationSetIndices, selection, trackGroupInfo.trackType, elapsedRealtimeOffsetMs, enableEventMessageTrack, embeddedClosedCaptionTrackFormats, trackPlayerEmsgHandler, transferListener, playerId);
    ChunkSampleStream<DashChunkSource> stream = new ChunkSampleStream<>(trackGroupInfo.trackType, embeddedTrackTypes, embeddedTrackFormats, chunkSource, this, allocator, positionUs, drmSessionManager, drmEventDispatcher, loadErrorHandlingPolicy, mediaSourceEventDispatcher);
    synchronized (this) {
        // The map is also accessed on the loading thread so synchronize access.
        trackEmsgHandlerBySampleStream.put(stream, trackPlayerEmsgHandler);
    }
    return stream;
}
Also used : Format(androidx.media3.common.Format) ChunkSampleStream(androidx.media3.exoplayer.source.chunk.ChunkSampleStream) TrackGroup(androidx.media3.common.TrackGroup) ArrayList(java.util.ArrayList) PlayerTrackEmsgHandler(androidx.media3.exoplayer.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler)

Aggregations

ChunkSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream)4 Format (androidx.media3.common.Format)2 TrackGroup (androidx.media3.common.TrackGroup)2 EventStream (androidx.media3.exoplayer.dash.manifest.EventStream)2 CompositeSequenceableLoader (androidx.media3.exoplayer.source.CompositeSequenceableLoader)2 EmptySampleStream (androidx.media3.exoplayer.source.EmptySampleStream)2 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)2 ArrayList (java.util.ArrayList)2 PlayerTrackEmsgHandler (androidx.media3.exoplayer.dash.PlayerEmsgHandler.PlayerTrackEmsgHandler)1 DrmSessionEventListener (androidx.media3.exoplayer.drm.DrmSessionEventListener)1 SampleStream (androidx.media3.exoplayer.source.SampleStream)1 SequenceableLoader (androidx.media3.exoplayer.source.SequenceableLoader)1 EmbeddedSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream.EmbeddedSampleStream)1 DefaultLoadErrorHandlingPolicy (androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy)1