Search in sources :

Example 16 with EventStream

use of androidx.media3.exoplayer.dash.manifest.EventStream in project media by androidx.

the class EventSampleStreamTest method seekToThenUpdateStreamContinueToReadFromSeekPositionEvenSeekMoreThanAvailable.

/**
 * 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 seekToThenUpdateStreamContinueToReadFromSeekPositionEvenSeekMoreThanAvailable() {
    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 }, new EventMessage[] { eventMessage1 });
    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 + 1);
    sampleStream.updateEventStream(eventStream2, true);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage3));
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Example 17 with EventStream

use of androidx.media3.exoplayer.dash.manifest.EventStream in project media by androidx.

the class EventSampleStreamTest method readData_peek_doesNotAdvanceSampleIndex.

@Test
public void readData_peek_doesNotAdvanceSampleIndex() {
    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);
    // read the event with FLAG_PEEK
    int result = readData(sampleStream, SampleStream.FLAG_PEEK);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.isKeyFrame()).isTrue();
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
    // read again gives the same message again (there is only one msg)
    result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.isKeyFrame()).isTrue();
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage));
    // read again gives end of stream
    result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.isEndOfStream()).isTrue();
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Example 18 with EventStream

use of androidx.media3.exoplayer.dash.manifest.EventStream in project media by androidx.

the class EventSampleStreamTest method updateEventStreamContinueToReadAfterLastReadSamplePresentationTime.

/**
 * Tests that {@link EventSampleStream#updateEventStream(EventStream, boolean)} will update the
 * underlying event stream, but keep the read timestamp, so the next {@link
 * EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call will return sample data
 * from after the last read sample timestamp.
 */
@Test
public void updateEventStreamContinueToReadAfterLastReadSamplePresentationTime() {
    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);
    // read first and second sample.
    readData(sampleStream);
    readData(sampleStream);
    sampleStream.updateEventStream(eventStream2, true);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
    assertThat(inputBuffer.data.array()).isEqualTo(getEncodedMessage(eventMessage3));
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) EventStream(androidx.media3.exoplayer.dash.manifest.EventStream) Test(org.junit.Test)

Example 19 with EventStream

use of androidx.media3.exoplayer.dash.manifest.EventStream in project media by androidx.

the class EventSampleStreamTest method skipDataThenUpdateStreamContinueToReadDoNotSkippedMoreThanAvailable.

/**
 * Tests that {@link EventSampleStream#skipData(long)} will only skip to the point right after it
 * last event. A following {@link EventSampleStream#updateEventStream(EventStream, boolean)} will
 * update the underlying event stream and keep the timestamp the stream has skipped to, so the
 * next {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} call will return
 * sample data from the skipped position.
 */
@Test
public void skipDataThenUpdateStreamContinueToReadDoNotSkippedMoreThanAvailable() {
    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 }, new EventMessage[] { eventMessage1 });
    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);
    // even though the skip call is to 2000001, since eventStream1 only contains sample until
    // 1000000, it will only skip to 1000001.
    sampleStream.skipData(presentationTimeUs2 + 1);
    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 20 with EventStream

use of androidx.media3.exoplayer.dash.manifest.EventStream in project media by androidx.

the class DashManifestParserTest method parseMediaPresentationDescription_eventStream.

@Test
public void parseMediaPresentationDescription_eventStream() throws IOException {
    DashManifestParser parser = new DashManifestParser();
    DashManifest manifest = parser.parse(Uri.parse("https://example.com/test.mpd"), TestUtil.getInputStream(ApplicationProvider.getApplicationContext(), SAMPLE_MPD_EVENT_STREAM));
    Period period = manifest.getPeriod(0);
    assertThat(period.eventStreams).hasSize(3);
    // assert text-only event stream
    EventStream eventStream1 = period.eventStreams.get(0);
    assertThat(eventStream1.events.length).isEqualTo(1);
    EventMessage expectedEvent1 = new EventMessage("urn:uuid:XYZY", "call", 10000, 0, "+ 1 800 10101010".getBytes(Charsets.UTF_8));
    assertThat(eventStream1.events[0]).isEqualTo(expectedEvent1);
    assertThat(eventStream1.presentationTimesUs[0]).isEqualTo(0);
    // assert CData-structured event stream
    EventStream eventStream2 = period.eventStreams.get(1);
    assertThat(eventStream2.events.length).isEqualTo(1);
    EventMessage expectedEvent2 = new EventMessage("urn:dvb:iptv:cpm:2014", "", 1500000, 1, Util.getUtf8Bytes("<![CDATA[<BroadcastEvent>\n" + "      <Program crid=\"crid://broadcaster.example.com/ABCDEF\"/>\n" + "      <InstanceDescription>\n" + "      <Title xml:lang=\"en\">The title</Title>\n" + "      <Synopsis xml:lang=\"en\" length=\"medium\">" + "The description</Synopsis>\n" + "      <ParentalGuidance>\n" + "      <mpeg7:ParentalRating href=\"urn:dvb:iptv:rating:2014:15\"/>\n" + "      <mpeg7:Region>GB</mpeg7:Region>\n" + "      </ParentalGuidance>\n" + "      </InstanceDescription>\n" + "      </BroadcastEvent>]]>"));
    assertThat(eventStream2.events[0]).isEqualTo(expectedEvent2);
    assertThat(eventStream2.presentationTimesUs[0]).isEqualTo(300000000);
    // assert xml-structured event stream
    EventStream eventStream3 = period.eventStreams.get(2);
    assertThat(eventStream3.events.length).isEqualTo(1);
    EventMessage expectedEvent3 = new EventMessage("urn:scte:scte35:2014:xml+bin", "", 1000000, 2, Util.getUtf8Bytes("<scte35:Signal>\n" + "         <scte35:Binary>\n" + "         /DAIAAAAAAAAAAAQAAZ/I0VniQAQAgBDVUVJQAAAAH+cAAAAAA==\n" + "         </scte35:Binary>\n" + "       </scte35:Signal>"));
    assertThat(eventStream3.events[0]).isEqualTo(expectedEvent3);
    assertThat(eventStream3.presentationTimesUs[0]).isEqualTo(1000000000);
}
Also used : EventMessage(androidx.media3.extractor.metadata.emsg.EventMessage) Test(org.junit.Test)

Aggregations

EventStream (androidx.media3.exoplayer.dash.manifest.EventStream)16 Test (org.junit.Test)14 EventMessage (androidx.media3.extractor.metadata.emsg.EventMessage)12 Format (androidx.media3.common.Format)3 TrackGroup (androidx.media3.common.TrackGroup)2 ArrayList (java.util.ArrayList)2 Pair (android.util.Pair)1 Nullable (androidx.annotation.Nullable)1 TrackGroupArray (androidx.media3.common.TrackGroupArray)1 SingleSegmentBase (androidx.media3.exoplayer.dash.manifest.SegmentBase.SingleSegmentBase)1 EmptySampleStream (androidx.media3.exoplayer.source.EmptySampleStream)1 ChunkSampleStream (androidx.media3.exoplayer.source.chunk.ChunkSampleStream)1 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1