Adjust FakeSampleStream to take varargs of FakeSampleStreamItem.

This is instead of taking a list.

PiperOrigin-RevId: 292354720
This commit is contained in:
samrobinson 2020-01-30 16:35:15 +00:00 committed by Oliver Woodman
parent 3e6efe7eaf
commit 52fb5f38a7
3 changed files with 23 additions and 24 deletions

View File

@ -32,7 +32,6 @@ import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
@ -146,8 +145,9 @@ public class MetadataRendererTest {
new FakeSampleStream(
EMSG_FORMAT,
/* eventDispatcher= */ null,
Arrays.asList(new FakeSampleStreamItem(input), FakeSampleStreamItem.END_OF_STREAM_ITEM),
0),
/* timeUsIncrement= */ 0,
new FakeSampleStreamItem(input),
FakeSampleStreamItem.END_OF_STREAM_ITEM),
/* offsetUs= */ 0L);
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the format
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the data

View File

@ -250,8 +250,8 @@ public class FakeMediaPeriod implements MediaPeriod {
return new FakeSampleStream(
selection.getSelectedFormat(),
eventDispatcher,
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM,
/* timeUsIncrement= */ 0);
/* timeUsIncrement= */ 0,
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
}
/**
@ -266,7 +266,7 @@ public class FakeMediaPeriod implements MediaPeriod {
// When seeking back to 0, queue our single sample at time 0 again.
((FakeSampleStream) sampleStream)
.resetSampleStreamItems(
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM, /* timeUs= */ 0);
/* timeUs= */ 0, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
}
}

View File

@ -25,8 +25,6 @@ import com.google.android.exoplayer2.source.SampleStream;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Fake {@link SampleStream} that outputs a given {@link Format}, any amount of {@link
@ -81,10 +79,11 @@ public final class FakeSampleStream implements SampleStream {
}
}
/** List for use when a single sample is to be output, followed by the end of stream. */
public static final List<FakeSampleStreamItem> SINGLE_SAMPLE_THEN_END_OF_STREAM =
Arrays.asList(
new FakeSampleStreamItem(new byte[] {0}), FakeSampleStreamItem.END_OF_STREAM_ITEM);
/** Constant array for use when a single sample is to be output, followed by the end of stream. */
public static final FakeSampleStreamItem[] SINGLE_SAMPLE_THEN_END_OF_STREAM =
new FakeSampleStreamItem[] {
new FakeSampleStreamItem(new byte[] {0}), FakeSampleStreamItem.END_OF_STREAM_ITEM
};
private final ArrayDeque<FakeSampleStreamItem> fakeSampleStreamItems;
private final int timeUsIncrement;
@ -109,10 +108,10 @@ public final class FakeSampleStream implements SampleStream {
this(
format,
eventDispatcher,
/* timeUsIncrement= */ 0,
shouldOutputSample
? SINGLE_SAMPLE_THEN_END_OF_STREAM
: Collections.singletonList(FakeSampleStreamItem.END_OF_STREAM_ITEM),
/* timeUsIncrement= */ 0);
: new FakeSampleStreamItem[] {FakeSampleStreamItem.END_OF_STREAM_ITEM});
}
/**
@ -121,31 +120,31 @@ public final class FakeSampleStream implements SampleStream {
*
* @param format The {@link Format} to output.
* @param eventDispatcher An {@link EventDispatcher} to notify of read events.
* @param fakeSampleStreamItems The list of {@link FakeSampleStreamItem items} to customize the
* return values of {@link #readData(FormatHolder, DecoderInputBuffer, boolean)}. Note that
* once an EOS buffer has been read, that will return every time readData is called.
* @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
* EOS buffer has been read, that will return every time readData is called.
*/
public FakeSampleStream(
Format format,
@Nullable EventDispatcher eventDispatcher,
List<FakeSampleStreamItem> fakeSampleStreamItems,
int timeUsIncrement) {
int timeUsIncrement,
FakeSampleStreamItem... fakeSampleStreamItems) {
this.format = format;
this.eventDispatcher = eventDispatcher;
this.fakeSampleStreamItems = new ArrayDeque<>(fakeSampleStreamItems);
this.fakeSampleStreamItems = new ArrayDeque<>(Arrays.asList(fakeSampleStreamItems));
this.timeUsIncrement = timeUsIncrement;
}
/**
* Resets the samples provided by this sample stream to the provided list.
* Clears and assigns new samples provided by this sample stream.
*
* @param fakeSampleStreamItems The list of {@link FakeSampleStreamItem items} to provide.
* @param timeUs The time at which samples will start being output, in microseconds.
* @param fakeSampleStreamItems The {@link FakeSampleStreamItem items} to provide.
*/
public void resetSampleStreamItems(List<FakeSampleStreamItem> fakeSampleStreamItems, int timeUs) {
public void resetSampleStreamItems(int timeUs, FakeSampleStreamItem... fakeSampleStreamItems) {
this.fakeSampleStreamItems.clear();
this.fakeSampleStreamItems.addAll(fakeSampleStreamItems);
this.fakeSampleStreamItems.addAll(Arrays.asList(fakeSampleStreamItems));
this.timeUs = timeUs;
readEOSBuffer = false;
}