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:
parent
c9245c61de
commit
486f401736
@ -609,6 +609,7 @@ public final class AnalyticsCollectorTest {
|
||||
concatenatedMediaSource.moveMediaSource(
|
||||
/* currentIndex= */ 0, /* newIndex= */ 1))
|
||||
.waitForTimelineChanged()
|
||||
.waitForPlaybackState(Player.STATE_READY)
|
||||
.play()
|
||||
.build();
|
||||
TestAnalyticsListener listener = runAnalyticsTest(concatenatedMediaSource, actionSchedule);
|
||||
@ -624,6 +625,7 @@ public final class AnalyticsCollectorTest {
|
||||
window0Period1Seq0 /* setPlayWhenReady=false */,
|
||||
period1Seq0 /* setPlayWhenReady=true */,
|
||||
period1Seq0 /* BUFFERING */,
|
||||
period1Seq0 /* READY */,
|
||||
period1Seq0 /* ENDED */);
|
||||
assertThat(listener.getEvents(EVENT_TIMELINE_CHANGED))
|
||||
.containsExactly(
|
||||
@ -659,8 +661,10 @@ public final class AnalyticsCollectorTest {
|
||||
.containsExactly(window0Period1Seq0, window1Period0Seq1);
|
||||
assertThat(listener.getEvents(EVENT_DECODER_DISABLED)).containsExactly(window0Period1Seq0);
|
||||
assertThat(listener.getEvents(EVENT_DROPPED_VIDEO_FRAMES)).containsExactly(window0Period1Seq0);
|
||||
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED)).containsExactly(window0Period1Seq0);
|
||||
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME)).containsExactly(window0Period1Seq0);
|
||||
assertThat(listener.getEvents(EVENT_VIDEO_SIZE_CHANGED))
|
||||
.containsExactly(window0Period1Seq0, period1Seq0);
|
||||
assertThat(listener.getEvents(EVENT_RENDERED_FIRST_FRAME))
|
||||
.containsExactly(window0Period1Seq0, period1Seq0);
|
||||
listener.assertNoMoreEvents();
|
||||
}
|
||||
|
||||
|
@ -145,6 +145,7 @@ public class MetadataRendererTest {
|
||||
new FakeSampleStream(
|
||||
EMSG_FORMAT,
|
||||
/* eventDispatcher= */ null,
|
||||
/* firstSampleTimeUs= */ 0,
|
||||
/* timeUsIncrement= */ 0,
|
||||
new FakeSampleStreamItem(input),
|
||||
FakeSampleStreamItem.END_OF_STREAM_ITEM),
|
||||
|
@ -142,7 +142,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||
|
||||
@Override
|
||||
protected SampleStream createSampleStream(
|
||||
TrackSelection trackSelection, EventDispatcher eventDispatcher) {
|
||||
long positionUs, TrackSelection trackSelection, EventDispatcher eventDispatcher) {
|
||||
FakeChunkSource chunkSource =
|
||||
chunkSourceFactory.createChunkSource(trackSelection, durationUs, transferListener);
|
||||
return new ChunkSampleStream<>(
|
||||
@ -152,7 +152,7 @@ public class FakeAdaptiveMediaPeriod extends FakeMediaPeriod
|
||||
chunkSource,
|
||||
/* callback= */ this,
|
||||
allocator,
|
||||
/* positionUs= */ 0,
|
||||
positionUs,
|
||||
/* drmSessionManager= */ DrmSessionManager.getDummyDrmSessionManager(),
|
||||
new DefaultLoadErrorHandlingPolicy(/* minimumLoadableRetryCount= */ 3),
|
||||
eventDispatcher);
|
||||
|
@ -171,7 +171,7 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
|
||||
assertThat(indexInTrackGroup).isAtLeast(0);
|
||||
assertThat(indexInTrackGroup).isLessThan(trackGroup.length);
|
||||
streams[i] = createSampleStream(selection, eventDispatcher);
|
||||
streams[i] = createSampleStream(positionUs, selection, eventDispatcher);
|
||||
sampleStreams.add(streams[i]);
|
||||
streamResetFlags[i] = true;
|
||||
}
|
||||
@ -241,15 +241,17 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||
/**
|
||||
* 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 eventDispatcher A dispatcher for events that should be used by the sample stream.
|
||||
* @return A {@link SampleStream} for this selection.
|
||||
*/
|
||||
protected SampleStream createSampleStream(
|
||||
TrackSelection selection, EventDispatcher eventDispatcher) {
|
||||
long positionUs, TrackSelection selection, EventDispatcher eventDispatcher) {
|
||||
return new FakeSampleStream(
|
||||
selection.getSelectedFormat(),
|
||||
eventDispatcher,
|
||||
positionUs,
|
||||
/* timeUsIncrement= */ 0,
|
||||
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
|
||||
}
|
||||
@ -258,16 +260,13 @@ public class FakeMediaPeriod implements MediaPeriod {
|
||||
* Seeks inside the given sample stream.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
protected void seekSampleStream(SampleStream sampleStream, long positionUs) {
|
||||
if (positionUs == 0) {
|
||||
// When seeking back to 0, queue our single sample at time 0 again.
|
||||
// Queue a single sample from the seek position again.
|
||||
((FakeSampleStream) sampleStream)
|
||||
.resetSampleStreamItems(
|
||||
/* timeUs= */ 0, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
|
||||
}
|
||||
.resetSampleStreamItems(positionUs, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
|
||||
}
|
||||
|
||||
private void finishPreparation() {
|
||||
|
@ -91,7 +91,7 @@ public final class FakeSampleStream implements SampleStream {
|
||||
@Nullable private final EventDispatcher eventDispatcher;
|
||||
|
||||
private Format format;
|
||||
private int timeUs;
|
||||
private long timeUs;
|
||||
private boolean readFormat;
|
||||
private boolean readEOSBuffer;
|
||||
|
||||
@ -108,6 +108,7 @@ public final class FakeSampleStream implements SampleStream {
|
||||
this(
|
||||
format,
|
||||
eventDispatcher,
|
||||
/* firstSampleTimeUs= */ 0,
|
||||
/* timeUsIncrement= */ 0,
|
||||
shouldOutputSample
|
||||
? SINGLE_SAMPLE_THEN_END_OF_STREAM
|
||||
@ -120,6 +121,7 @@ public final class FakeSampleStream implements SampleStream {
|
||||
*
|
||||
* @param format The {@link Format} to output.
|
||||
* @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 fakeSampleStreamItems The {@link FakeSampleStreamItem items} to customize the return
|
||||
* values of {@link #readData(FormatHolder, DecoderInputBuffer, boolean)}. Note that once an
|
||||
@ -128,11 +130,13 @@ public final class FakeSampleStream implements SampleStream {
|
||||
public FakeSampleStream(
|
||||
Format format,
|
||||
@Nullable EventDispatcher eventDispatcher,
|
||||
long firstSampleTimeUs,
|
||||
int timeUsIncrement,
|
||||
FakeSampleStreamItem... fakeSampleStreamItems) {
|
||||
this.format = format;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.fakeSampleStreamItems = new ArrayDeque<>(Arrays.asList(fakeSampleStreamItems));
|
||||
this.timeUs = firstSampleTimeUs;
|
||||
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 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.addAll(Arrays.asList(fakeSampleStreamItems));
|
||||
this.timeUs = timeUs;
|
||||
|
Loading…
x
Reference in New Issue
Block a user