Search in sources :

Example 11 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

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(com.google.android.exoplayer2.metadata.emsg.EventMessage) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Example 12 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

the class EventSampleStreamTest method readDataReturnFormatForFirstRead.

/**
 * Tests that {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, int)} will
 * return format for the first call.
 */
@Test
public void readDataReturnFormatForFirstRead() {
    EventStream eventStream = new EventStream(SCHEME_ID, VALUE, TIME_SCALE, new long[0], new EventMessage[0]);
    // Make the event stream appendable so that the format is read. Otherwise, the format will be
    // skipped and the end of input will be read.
    EventSampleStream sampleStream = new EventSampleStream(eventStream, FORMAT, /* eventStreamAppendable= */
    true);
    int result = readData(sampleStream);
    assertThat(result).isEqualTo(C.RESULT_FORMAT_READ);
    assertThat(formatHolder.format).isEqualTo(FORMAT);
}
Also used : EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Example 13 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

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(com.google.android.exoplayer2.metadata.emsg.EventMessage) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Example 14 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

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(com.google.android.exoplayer2.metadata.emsg.EventMessage) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Example 15 with DecoderInputBuffer

use of com.google.android.exoplayer2.decoder.DecoderInputBuffer in project ExoPlayer by google.

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(com.google.android.exoplayer2.metadata.emsg.EventMessage) EventStream(com.google.android.exoplayer2.source.dash.manifest.EventStream) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 EventStream (com.google.android.exoplayer2.source.dash.manifest.EventStream)9 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)8 EventMessage (com.google.android.exoplayer2.metadata.emsg.EventMessage)8 Nullable (androidx.annotation.Nullable)7 Format (com.google.android.exoplayer2.Format)7 ByteBuffer (java.nio.ByteBuffer)6 FormatHolder (com.google.android.exoplayer2.FormatHolder)5 CryptoInfo (com.google.android.exoplayer2.decoder.CryptoInfo)5 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)3 Before (org.junit.Before)3 CryptoException (com.google.android.exoplayer2.decoder.CryptoException)2 DecryptionException (com.google.android.exoplayer2.drm.DecryptionException)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2 SurfaceTexture (android.graphics.SurfaceTexture)1 Handler (android.os.Handler)1 Surface (android.view.Surface)1