Search in sources :

Example 1 with SampleStream

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

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

use of androidx.media3.exoplayer.source.SampleStream in project media by androidx.

the class EventSampleStreamTest method readDataOutOfBoundReturnEndOfStreamAfterFormatForNonDynamicEventSampleStream.

/**
 * Tests that a non-dynamic {@link EventSampleStream} will return a buffer with {@link
 * C#BUFFER_FLAG_END_OF_STREAM} when trying to read sample out-of-bound.
 */
@Test
public void readDataOutOfBoundReturnEndOfStreamAfterFormatForNonDynamicEventSampleStream() {
    EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[0], new EventMessage[0]);
    EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
    // first read - read format
    readData(sampleStream);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.isEndOfStream()).isTrue();
}
Also used : EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Example 4 with SampleStream

use of androidx.media3.exoplayer.source.SampleStream in project media by androidx.

the class EventSampleStreamTest method seekToUsThenUpdateStreamContinueToReadFromSeekPosition.

/**
 * Tests that {@link EventSampleStream#updateEventStream(EventStream, boolean)} will update the
 * underlying event stream, but keep the timestamp the stream has seek to, so the next {@link
 * EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call will return sample data
 * from the seek position.
 */
@Test
public void seekToUsThenUpdateStreamContinueToReadFromSeekPosition() {
    long presentationTimeUs1 = 1000000;
    long presentationTimeUs2 = 2000000;
    long presentationTimeUs3 = 3000000;
    EventMessage eventMessage1 = newEventMessageWithId(1);
    EventMessage eventMessage2 = newEventMessageWithId(2);
    EventMessage eventMessage3 = newEventMessageWithId(3);
    EventStream eventStream1 = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2 }, new EventMessage[] { eventMessage1, eventMessage2 });
    EventStream eventStream2 = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs1, presentationTimeUs2, presentationTimeUs3 }, new EventMessage[] { eventMessage1, eventMessage2, eventMessage3 });
    EventSampleStream sampleStream = new EventSampleStream(eventStream1, FORMAT, true);
    // first read - read format
    readData(sampleStream);
    sampleStream.seekToUs(presentationTimeUs2);
    sampleStream.updateEventStream(eventStream2, true);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage2));
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Example 5 with SampleStream

use of androidx.media3.exoplayer.source.SampleStream in project media by androidx.

the class EventSampleStreamTest method readDataReturnDataAfterFormat.

/**
 * Tests that {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} will
 * return sample data after the first call.
 */
@Test
public void readDataReturnDataAfterFormat() {
    long presentationTimeUs = 1000000;
    EventMessage eventMessage = newEventMessageWithId(1);
    EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[] { presentationTimeUs }, new EventMessage[] { eventMessage });
    EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, false);
    // first read - read format
    readData(sampleStream);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Aggregations

EventStream (androidx.media3.exoplayer.dash.manifest.EventStream)15 Test (org.junit.Test)15 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)10 EventMessage (androidx.media3.extractor.metadata.emsg.EventMessage)10 TrackGroup (androidx.media3.common.TrackGroup)6 SampleStream (androidx.media3.exoplayer.source.SampleStream)5 Format (androidx.media3.common.Format)3 FormatHolder (androidx.media3.exoplayer.FormatHolder)3 MetadataRenderer (androidx.media3.exoplayer.metadata.MetadataRenderer)3 ChunkSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream)3 TextRenderer (androidx.media3.exoplayer.text.TextRenderer)3 ArrayList (java.util.ArrayList)3 DecoderInputBuffer (androidx.media3.decoder.DecoderInputBuffer)2 CompositeSequenceableLoader (androidx.media3.exoplayer.source.CompositeSequenceableLoader)2 EmptySampleStream (androidx.media3.exoplayer.source.EmptySampleStream)2 SampleQueue (androidx.media3.exoplayer.source.SampleQueue)2 FixedTrackSelection (androidx.media3.exoplayer.trackselection.FixedTrackSelection)2 TrackSelectorResult (androidx.media3.exoplayer.trackselection.TrackSelectorResult)2 NullableType (org.checkerframework.checker.nullness.compatqual.NullableType)2 Uri (android.net.Uri)1