mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Adjust FakeSampleStream
to take varargs of FakeSampleStreamItem
.
This is instead of taking a list. PiperOrigin-RevId: 292354720
This commit is contained in:
parent
3e6efe7eaf
commit
52fb5f38a7
@ -32,7 +32,6 @@ import com.google.android.exoplayer2.testutil.TestUtil;
|
|||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -146,8 +145,9 @@ public class MetadataRendererTest {
|
|||||||
new FakeSampleStream(
|
new FakeSampleStream(
|
||||||
EMSG_FORMAT,
|
EMSG_FORMAT,
|
||||||
/* eventDispatcher= */ null,
|
/* eventDispatcher= */ null,
|
||||||
Arrays.asList(new FakeSampleStreamItem(input), FakeSampleStreamItem.END_OF_STREAM_ITEM),
|
/* timeUsIncrement= */ 0,
|
||||||
0),
|
new FakeSampleStreamItem(input),
|
||||||
|
FakeSampleStreamItem.END_OF_STREAM_ITEM),
|
||||||
/* offsetUs= */ 0L);
|
/* offsetUs= */ 0L);
|
||||||
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the format
|
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the format
|
||||||
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the data
|
renderer.render(/* positionUs= */ 0, /* elapsedRealtimeUs= */ 0); // Read the data
|
||||||
|
@ -250,8 +250,8 @@ public class FakeMediaPeriod implements MediaPeriod {
|
|||||||
return new FakeSampleStream(
|
return new FakeSampleStream(
|
||||||
selection.getSelectedFormat(),
|
selection.getSelectedFormat(),
|
||||||
eventDispatcher,
|
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.
|
// When seeking back to 0, queue our single sample at time 0 again.
|
||||||
((FakeSampleStream) sampleStream)
|
((FakeSampleStream) sampleStream)
|
||||||
.resetSampleStreamItems(
|
.resetSampleStreamItems(
|
||||||
FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM, /* timeUs= */ 0);
|
/* timeUs= */ 0, FakeSampleStream.SINGLE_SAMPLE_THEN_END_OF_STREAM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ import com.google.android.exoplayer2.source.SampleStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Arrays;
|
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
|
* 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. */
|
/** Constant array 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 =
|
public static final FakeSampleStreamItem[] SINGLE_SAMPLE_THEN_END_OF_STREAM =
|
||||||
Arrays.asList(
|
new FakeSampleStreamItem[] {
|
||||||
new FakeSampleStreamItem(new byte[] {0}), FakeSampleStreamItem.END_OF_STREAM_ITEM);
|
new FakeSampleStreamItem(new byte[] {0}), FakeSampleStreamItem.END_OF_STREAM_ITEM
|
||||||
|
};
|
||||||
|
|
||||||
private final ArrayDeque<FakeSampleStreamItem> fakeSampleStreamItems;
|
private final ArrayDeque<FakeSampleStreamItem> fakeSampleStreamItems;
|
||||||
private final int timeUsIncrement;
|
private final int timeUsIncrement;
|
||||||
@ -109,10 +108,10 @@ public final class FakeSampleStream implements SampleStream {
|
|||||||
this(
|
this(
|
||||||
format,
|
format,
|
||||||
eventDispatcher,
|
eventDispatcher,
|
||||||
|
/* timeUsIncrement= */ 0,
|
||||||
shouldOutputSample
|
shouldOutputSample
|
||||||
? SINGLE_SAMPLE_THEN_END_OF_STREAM
|
? SINGLE_SAMPLE_THEN_END_OF_STREAM
|
||||||
: Collections.singletonList(FakeSampleStreamItem.END_OF_STREAM_ITEM),
|
: new FakeSampleStreamItem[] {FakeSampleStreamItem.END_OF_STREAM_ITEM});
|
||||||
/* timeUsIncrement= */ 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,31 +120,31 @@ 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 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 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(
|
public FakeSampleStream(
|
||||||
Format format,
|
Format format,
|
||||||
@Nullable EventDispatcher eventDispatcher,
|
@Nullable EventDispatcher eventDispatcher,
|
||||||
List<FakeSampleStreamItem> fakeSampleStreamItems,
|
int timeUsIncrement,
|
||||||
int timeUsIncrement) {
|
FakeSampleStreamItem... fakeSampleStreamItems) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.eventDispatcher = eventDispatcher;
|
this.eventDispatcher = eventDispatcher;
|
||||||
this.fakeSampleStreamItems = new ArrayDeque<>(fakeSampleStreamItems);
|
this.fakeSampleStreamItems = new ArrayDeque<>(Arrays.asList(fakeSampleStreamItems));
|
||||||
this.timeUsIncrement = timeUsIncrement;
|
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 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.clear();
|
||||||
this.fakeSampleStreamItems.addAll(fakeSampleStreamItems);
|
this.fakeSampleStreamItems.addAll(Arrays.asList(fakeSampleStreamItems));
|
||||||
this.timeUs = timeUs;
|
this.timeUs = timeUs;
|
||||||
readEOSBuffer = false;
|
readEOSBuffer = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user