Pass in initial sample timestamp to FakeSampleStream.

This allows to simulate samples in a stream more accurately
particularly when streams are prepared at a non-zero position and
issuing a sample with position=0 is not expected.

Also makes seek more realistic by also issuing one sample again.

PiperOrigin-RevId: 293344081
This commit is contained in:
tonihei 2020-02-05 12:53:14 +00:00 committed by kim-vde
parent c9245c61de
commit 486f401736
5 changed files with 23 additions and 15 deletions

View File

@ -609,6 +609,7 @@ public final class AnalyticsCollectorTest {
concatenatedMediaSource.moveMediaSource( concatenatedMediaSource.moveMediaSource(
/* currentIndex= */ 0, /* newIndex= */ 1)) /* currentIndex= */ 0, /* newIndex= */ 1))
.waitForTimelineChanged() .waitForTimelineChanged()
.waitForPlaybackState(Player.STATE_READY)
.play() .play()
.build(); .build();
TestAnalyticsListener listener = runAnalyticsTest(concatenatedMediaSource, actionSchedule); TestAnalyticsListener listener = runAnalyticsTest(concatenatedMediaSource, actionSchedule);
@ -624,6 +625,7 @@ public final class AnalyticsCollectorTest {
window0Period1Seq0 /* setPlayWhenReady=false */, window0Period1Seq0 /* setPlayWhenReady=false */,
period1Seq0 /* setPlayWhenReady=true */, period1Seq0 /* setPlayWhenReady=true */,
period1Seq0 /* BUFFERING */, period1Seq0 /* BUFFERING */,
period1Seq0 /* READY */,
period1Seq0 /* ENDED */); period1Seq0 /* ENDED */);
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED)) assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED))
.containsExactly( .containsExactly(
@ -659,8 +661,10 @@ public final class AnalyticsCollectorTest {
.containsExactly(window0Period1Seq0, window1Period0Seq1); .containsExactly(window0Period1Seq0, window1Period0Seq1);
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(window0Period1Seq0); assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(window0Period1Seq0);
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(window0Period1Seq0); assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(window0Period1Seq0);
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(window0Period1Seq0); assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(window0Period1Seq0); .containsExactly(window0Period1Seq0, period1Seq0);
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
.containsExactly(window0Period1Seq0, period1Seq0);
listener.assertNoMoreEvents(); listener.assertNoMoreEvents();
} }

View File

@ -145,6 +145,7 @@ public class MetadataRendererTest {
new FakeSampleStream( new FakeSampleStream(
EMSG_FORMAT, EMSG_FORMAT,
/* eventDispatcher= */ null, /* eventDispatcher= */ null,
/* firstSampleTimeUs= */ 0,
/* timeUsIncrement= */ 0, /* timeUsIncrement= */ 0,
new FakeSampleStreamItem(input), new FakeSampleStreamItem(input),
FakeSampleStreamItem.END_OF_STREAM_ITEM), FakeSampleStreamItem.END_OF_STREAM_ITEM),

View File

@ -142,7 +142,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
@Override @Override
protected SampleStream createSampleStream( protected SampleStream createSampleStream(
TrackSelection trackSelection, EventDispatcher eventDispatcher) { long positionUs, TrackSelection trackSelection, EventDispatcher eventDispatcher) {
FakeChunkSource chunkSource = FakeChunkSource chunkSource =
chunkSourceFactory.createChunkSource(trackSelection, durationUs, transferListener); chunkSourceFactory.createChunkSource(trackSelection, durationUs, transferListener);
return new ChunkSampleStream<>( return new ChunkSampleStream<>(
@ -152,7 +152,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
chunkSource, chunkSource,
/* callback= */ this, /* callback= */ this,
allocator, allocator,
/* positionUs= */ 0, positionUs,
/* drmSessionManager= */ DrmSessionManager.getDummyDrmSessionManager(), /* drmSessionManager= */ DrmSessionManager.getDummyDrmSessionManager(),
new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */ 3), new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */ 3),
eventDispatcher); eventDispatcher);

View File

@ -171,7 +171,7 @@ public class FakeMediaPeriod implements MediaPeriod {
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex()); int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
assertThat(indexInTrackGroup).isAtLeast(0); assertThat(indexInTrackGroup).isAtLeast(0);
assertThat(indexInTrackGroup).isLessThan(trackGroup.length); assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
streams[i] = createSampleStream(selection, eventDispatcher); streams[i] = createSampleStream(positionUs, selection, eventDispatcher);
sampleStreams.add(streams[i]); sampleStreams.add(streams[i]);
streamResetFlags[i] = true; streamResetFlags[i] = true;
} }
@ -241,15 +241,17 @@ public class FakeMediaPeriod implements MediaPeriod {
/** /**
* Creates a sample stream for the provided selection. * Creates a sample stream for the provided selection.
* *
* @param positionUs The position at which the tracks were selected, in microseconds.
* @param selection A selection of tracks. * @param selection A selection of tracks.
* @param eventDispatcher A dispatcher for events that should be used by the sample stream. * @param eventDispatcher A dispatcher for events that should be used by the sample stream.
* @return A {@link SampleStream} for this selection. * @return A {@link SampleStream} for this selection.
*/ */
protected SampleStream createSampleStream( protected SampleStream createSampleStream(
TrackSelection selection, EventDispatcher eventDispatcher) { long positionUs, TrackSelection selection, EventDispatcher eventDispatcher) {
return new FakeSampleStream( return new FakeSampleStream(
selection.getSelectedFormat(), selection.getSelectedFormat(),
eventDispatcher, eventDispatcher,
positionUs,
/* timeUsIncrement= */ 0, /* timeUsIncrement= */ 0,
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM); FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
} }
@ -258,16 +260,13 @@ public class FakeMediaPeriod implements MediaPeriod {
* Seeks inside the given sample stream. * Seeks inside the given sample stream.
* *
* @param sampleStream A sample stream that was created by a call to {@link * @param sampleStream A sample stream that was created by a call to {@link
* #createSampleStream(TrackSelection, EventDispatcher)}. * #createSampleStream(long, TrackSelection, EventDispatcher)}.
* @param positionUs The position to seek to, in microseconds. * @param positionUs The position to seek to, in microseconds.
*/ */
protected void seekSampleStream(SampleStream sampleStream, long positionUs) { protected void seekSampleStream(SampleStream sampleStream, long positionUs) {
if (positionUs == 0) { // Queue a single sample from the seek position again.
// When seeking back to 0, queue our single sample at time 0 again.
((FakeSampleStream) sampleStream) ((FakeSampleStream) sampleStream)
.resetSampleStreamItems( .resetSampleStreamItems(positionUs, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
/* timeUs= */ 0, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
}
} }
private void finishPreparation() { private void finishPreparation() {

View File

@ -91,7 +91,7 @@ public final class FakeSampleStream implements SampleStream {
@Nullable private final EventDispatcher eventDispatcher; @Nullable private final EventDispatcher eventDispatcher;
private Format format; private Format format;
private int timeUs; private long timeUs;
private boolean readFormat; private boolean readFormat;
private boolean readEOSBuffer; private boolean readEOSBuffer;
@ -108,6 +108,7 @@ public final class FakeSampleStream implements SampleStream {
this( this(
format, format,
eventDispatcher, eventDispatcher,
/* firstSampleTimeUs= */ 0,
/* timeUsIncrement= */ 0, /* timeUsIncrement= */ 0,
shouldOutputSample shouldOutputSample
? SINGLE_SAMPLE_THEN_END_OF_STREAM ? SINGLE_SAMPLE_THEN_END_OF_STREAM
@ -120,6 +121,7 @@ public final class FakeSampleStream implements SampleStream {
* *
* @param format The {@link Format} to output. * @param format The {@link Format} to output.
* @param eventDispatcher An {@link EventDispatcher} to notify of read events. * @param eventDispatcher An {@link EventDispatcher} to notify of read events.
* @param firstSampleTimeUs The time at which samples will start being output, in microseconds.
* @param timeUsIncrement The time each sample should increase by, in microseconds. * @param timeUsIncrement The time each sample should increase by, in microseconds.
* @param fakeSampleStreamItems The {@link FakeSampleStreamItem items} to customize the return * @param fakeSampleStreamItems The {@link FakeSampleStreamItem items} to customize the return
* values of {@link #readData(FormatHolder, DecoderInputBuffer, boolean)}. Note that once an * values of {@link #readData(FormatHolder, DecoderInputBuffer, boolean)}. Note that once an
@ -128,11 +130,13 @@ public final class FakeSampleStream implements SampleStream {
public FakeSampleStream( public FakeSampleStream(
Format format, Format format,
@Nullable EventDispatcher eventDispatcher, @Nullable EventDispatcher eventDispatcher,
long firstSampleTimeUs,
int timeUsIncrement, int timeUsIncrement,
FakeSampleStreamItem... fakeSampleStreamItems) { FakeSampleStreamItem... fakeSampleStreamItems) {
this.format = format; this.format = format;
this.eventDispatcher = eventDispatcher; this.eventDispatcher = eventDispatcher;
this.fakeSampleStreamItems = new ArrayDeque<>(Arrays.asList(fakeSampleStreamItems)); this.fakeSampleStreamItems = new ArrayDeque<>(Arrays.asList(fakeSampleStreamItems));
this.timeUs = firstSampleTimeUs;
this.timeUsIncrement = timeUsIncrement; this.timeUsIncrement = timeUsIncrement;
} }
@ -142,7 +146,7 @@ public final class FakeSampleStream implements SampleStream {
* @param timeUs The time at which samples will start being output, in microseconds. * @param timeUs The time at which samples will start being output, in microseconds.
* @param fakeSampleStreamItems The {@link FakeSampleStreamItem items} to provide. * @param fakeSampleStreamItems The {@link FakeSampleStreamItem items} to provide.
*/ */
public void resetSampleStreamItems(int timeUs, FakeSampleStreamItem... fakeSampleStreamItems) { public void resetSampleStreamItems(long timeUs, FakeSampleStreamItem... fakeSampleStreamItems) {
this.fakeSampleStreamItems.clear(); this.fakeSampleStreamItems.clear();
this.fakeSampleStreamItems.addAll(Arrays.asList(fakeSampleStreamItems)); this.fakeSampleStreamItems.addAll(Arrays.asList(fakeSampleStreamItems));
this.timeUs = timeUs; this.timeUs = timeUs;