FakeSampleStream
@UnstableApi
public class FakeSampleStream implements SampleStream
Fake SampleStream that outputs a given Format and any amount of items.
Summary
Nested types |
|---|
public final class FakeSampleStream.FakeSampleStreamItemItem to customize a return value of |
Public constructors |
|---|
FakeSampleStream(Creates a fake sample stream which outputs the given |
Public methods |
|
|---|---|
void |
Appends |
void |
discardTo(long positionUs, boolean toKeyframe)Discards data from the queue. |
long |
Returns the timestamp of the largest queued sample in the queue, or |
boolean |
Returns whether data has been written to the sample queue until the end of stream signal. |
boolean |
isReady()Returns whether data is available to be read. |
void |
Throws an error that's preventing data from being read. |
int |
readData(Attempts to read from the stream. |
void |
release()Release the stream and its underlying sample queue. |
void |
reset()Resets the sample queue. |
boolean |
seekToUs(long positionUs, boolean allowTimeBeyondBuffer)Seeks the stream to a new position using already available data in the queue. |
int |
skipData(long positionUs)Attempts to skip to the keyframe before the specified position, or to the end of the stream if |
void |
writeData(long startPositionUs)Writes all not yet written |
Inherited Constants |
||||||
|---|---|---|---|---|---|---|
|
Public constructors
FakeSampleStream
public FakeSampleStream(
Allocator allocator,
@Nullable MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher,
DrmSessionManager drmSessionManager,
DrmSessionEventListener.EventDispatcher drmEventDispatcher,
Format initialFormat,
List<FakeSampleStream.FakeSampleStreamItem> fakeSampleStreamItems
)
Creates a fake sample stream which outputs the given Format followed by the provided items.
| Parameters | |
|---|---|
Allocator allocator |
An |
@Nullable MediaSourceEventListener.EventDispatcher mediaSourceEventDispatcher |
A |
DrmSessionManager drmSessionManager |
A |
DrmSessionEventListener.EventDispatcher drmEventDispatcher |
A |
Format initialFormat |
The first |
List<FakeSampleStream.FakeSampleStreamItem> fakeSampleStreamItems |
The |
Public methods
append
public void append(List<FakeSampleStream.FakeSampleStreamItem> items)
Appends FakeSampleStreamItems to the list of items that should be written to the queue.
Note that this data is only written to the queue once writeData is called.
| Parameters | |
|---|---|
List<FakeSampleStream.FakeSampleStreamItem> items |
The items to append. |
discardTo
public void discardTo(long positionUs, boolean toKeyframe)
Discards data from the queue.
| Parameters | |
|---|---|
long positionUs |
The position to discard to, in microseconds. |
boolean toKeyframe |
Whether to discard to keyframes only. |
getLargestQueuedTimestampUs
public long getLargestQueuedTimestampUs()
Returns the timestamp of the largest queued sample in the queue, or MIN_VALUE if no samples are queued.
isLoadingFinished
public boolean isLoadingFinished()
Returns whether data has been written to the sample queue until the end of stream signal.
isReady
public boolean isReady()
Returns whether data is available to be read.
Note: If the stream has ended then a buffer with the end of stream flag can always be read from readData. Hence an ended stream is always ready.
| Returns | |
|---|---|
boolean |
Whether data is available to be read. |
maybeThrowError
public void maybeThrowError()
Throws an error that's preventing data from being read. Does nothing if no such error exists.
| Throws | |
|---|---|
java.io.IOException |
The underlying error. |
readData
public int readData(
FormatHolder formatHolder,
DecoderInputBuffer buffer,
@SampleStream.ReadFlags int readFlags
)
Attempts to read from the stream.
If the stream has ended then BUFFER_FLAG_END_OF_STREAM flag is set on
buffer and RESULT_BUFFER_READ is returned. Else if no data is available then RESULT_NOTHING_READ is returned. Else if the format of the media is changing or if
formatRequired is set then formatHolder is populated and RESULT_FORMAT_READ is returned. Else buffer is populated and RESULT_BUFFER_READ is returned.
| Parameters | |
|---|---|
FormatHolder formatHolder |
A |
DecoderInputBuffer buffer |
A |
@SampleStream.ReadFlags int readFlags |
Flags controlling the behavior of this read operation. |
| Returns | |
|---|---|
int |
The |
| Throws | |
|---|---|
androidx.media3.decoder.DecoderInputBuffer.InsufficientCapacityException |
If the |
reset
public void reset()
Resets the sample queue.
A new call to writeData is required to fill the queue again.
seekToUs
public boolean seekToUs(long positionUs, boolean allowTimeBeyondBuffer)
Seeks the stream to a new position using already available data in the queue.
| Parameters | |
|---|---|
long positionUs |
The new position, in microseconds. |
boolean allowTimeBeyondBuffer |
Whether the operation can succeed if timeUs is beyond the end of the queue, by seeking to the last sample (or keyframe). |
| Returns | |
|---|---|
boolean |
Whether seeking inside the available data was possible. |
skipData
public int skipData(long positionUs)
Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.
| Parameters | |
|---|---|
long positionUs |
The specified time. |
| Returns | |
|---|---|
int |
The number of samples that were skipped. |
writeData
public void writeData(long startPositionUs)
Writes all not yet written sample stream items to the sample queue starting at the given position.
| Parameters | |
|---|---|
long startPositionUs |
The start position, in microseconds. |