public EventSampleStream( EventStream eventStream, Format upstreamFormat, boolean eventStreamAppendable) { this.upstreamFormat = upstreamFormat; this.eventStream = eventStream; eventMessageEncoder = new EventMessageEncoder(); pendingSeekPositionUs = C.TIME_UNSET; eventTimesUs = eventStream.presentationTimesUs; updateEventStream(eventStream, eventStreamAppendable); }
/** * 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; } } } }
/** * Tests that {@link EventSampleStream#updateEventStream(EventStream, boolean)} will update the * underlying event stream, but keep the timestamp the stream has skipped to, so the next * {@link EventSampleStream#readData(FormatHolder, DecoderInputBuffer, boolean)} call * will return sample data from the skipped position. */ @Test public void testSkipDataThenUpdateStreamContinueToReadFromSkippedPosition() { long presentationTimeUs1 = 1000000; long presentationTimeUs2 = 2000000; long presentationTimeUs3 = 3000000; EventMessage eventMessage1 = newEventMessageWithIdAndTime(1, presentationTimeUs1); EventMessage eventMessage2 = newEventMessageWithIdAndTime(2, presentationTimeUs2); EventMessage eventMessage3 = newEventMessageWithIdAndTime(3, presentationTimeUs3); 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.skipData(presentationTimeUs2 + 1); sampleStream.updateEventStream(eventStream2, true); int result = readData(sampleStream); assertThat(result).isEqualTo(C.RESULT_BUFFER_READ); assertThat(inputBuffer.data.array()) .isEqualTo(getEncodedMessage(eventMessage3)); }
/** * 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, boolean)} call * will return sample data from the seek position. */ @Test public void testSeekToUsThenUpdateStreamContinueToReadFromSeekPosition() { long presentationTimeUs1 = 1000000; long presentationTimeUs2 = 2000000; long presentationTimeUs3 = 3000000; EventMessage eventMessage1 = newEventMessageWithIdAndTime(1, presentationTimeUs1); EventMessage eventMessage2 = newEventMessageWithIdAndTime(2, presentationTimeUs2); EventMessage eventMessage3 = newEventMessageWithIdAndTime(3, presentationTimeUs3); 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)); }
/** * 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, boolean)} call * will return sample data from the seek position. */ @Test public void testSeekToThenUpdateStreamContinueToReadFromSeekPositionEvenSeekMoreThanAvailable() { long presentationTimeUs1 = 1000000; long presentationTimeUs2 = 2000000; long presentationTimeUs3 = 3000000; EventMessage eventMessage1 = newEventMessageWithIdAndTime(1, presentationTimeUs1); EventMessage eventMessage2 = newEventMessageWithIdAndTime(2, presentationTimeUs2); EventMessage eventMessage3 = newEventMessageWithIdAndTime(3, presentationTimeUs3); 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)); }
sampleStream.updateEventStream(eventStream2, true); int result = readData(sampleStream); assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);
readData(sampleStream); sampleStream.updateEventStream(eventStream2, true); int result = readData(sampleStream); assertThat(result).isEqualTo(C.RESULT_BUFFER_READ);