FakeSampleStream


@UnstableApi
class FakeSampleStream : SampleStream


Fake SampleStream that outputs a given Format and any amount of items.

Summary

Nested types

Item to customize a return value of readData.

Public constructors

FakeSampleStream(
    allocator: Allocator!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher?,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    initialFormat: Format!,
    fakeSampleStreamItems: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!
)

Creates a fake sample stream which outputs the given Format followed by the provided items.

Public functions

Unit

Appends FakeSampleStreamItems to the list of items that should be written to the queue.

Unit
discardTo(positionUs: Long, toKeyframe: Boolean)

Discards data from the queue.

Long

Returns the timestamp of the largest queued sample in the queue, or MIN_VALUE if no samples are queued.

Boolean

Returns whether data has been written to the sample queue until the end of stream signal.

Boolean

Returns whether data is available to be read.

Unit

Throws an error that's preventing data from being read.

Int
readData(
    formatHolder: FormatHolder!,
    buffer: DecoderInputBuffer!,
    @SampleStream.ReadFlags readFlags: Int
)

Attempts to read from the stream.

Unit

Release the stream and its underlying sample queue.

Unit

Resets the sample queue.

Boolean
seekToUs(positionUs: Long, allowTimeBeyondBuffer: Boolean)

Seeks the stream to a new position using already available data in the queue.

Int
skipData(positionUs: Long)

Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.

Unit
writeData(startPositionUs: Long)

Writes all not yet written sample stream items to the sample queue starting at the given position.

Inherited Constants

From androidx.media3.exoplayer.source.SampleStream
const Int

Specifies that data, supplementalData and cryptoInfo should not be populated when reading a sample buffer.

const Int

Specifies that the read position should not be advanced if a sample buffer is read.

const Int

Specifies that if a sample buffer would normally be read next, the format of the stream should be read instead.

Public constructors

FakeSampleStream

FakeSampleStream(
    allocator: Allocator!,
    mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher?,
    drmSessionManager: DrmSessionManager!,
    drmEventDispatcher: DrmSessionEventListener.EventDispatcher!,
    initialFormat: Format!,
    fakeSampleStreamItems: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!
)

Creates a fake sample stream which outputs the given Format followed by the provided items.

Parameters
allocator: Allocator!

An Allocator.

mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher?

A MediaSourceEventListener.EventDispatcher to notify of media events.

drmSessionManager: DrmSessionManager!

A DrmSessionManager for DRM interactions.

drmEventDispatcher: DrmSessionEventListener.EventDispatcher!

A DrmSessionEventListener.EventDispatcher to notify of DRM events.

initialFormat: Format!

The first Format to output.

fakeSampleStreamItems: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!

The items to output.

Public functions

append

fun append(items: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!): Unit

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
items: (Mutable)List<FakeSampleStream.FakeSampleStreamItem!>!

The items to append.

discardTo

fun discardTo(positionUs: Long, toKeyframe: Boolean): Unit

Discards data from the queue.

Parameters
positionUs: Long

The position to discard to, in microseconds.

toKeyframe: Boolean

Whether to discard to keyframes only.

getLargestQueuedTimestampUs

fun getLargestQueuedTimestampUs(): Long

Returns the timestamp of the largest queued sample in the queue, or MIN_VALUE if no samples are queued.

isLoadingFinished

fun isLoadingFinished(): Boolean

Returns whether data has been written to the sample queue until the end of stream signal.

isReady

fun isReady(): Boolean

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

fun maybeThrowError(): Unit

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

fun readData(
    formatHolder: FormatHolder!,
    buffer: DecoderInputBuffer!,
    @SampleStream.ReadFlags readFlags: Int
): Int

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 FormatHolder to populate in the case of reading a format.

buffer: DecoderInputBuffer!

A DecoderInputBuffer to populate in the case of reading a sample or the end of the stream. If the end of the stream has been reached, the BUFFER_FLAG_END_OF_STREAM flag will be set on the buffer.

@SampleStream.ReadFlags readFlags: Int

Flags controlling the behavior of this read operation.

Returns
Int

The result of the read operation.

Throws
androidx.media3.decoder.DecoderInputBuffer.InsufficientCapacityException

If the buffer has insufficient capacity to hold the data of a sample being read. The buffer timestamp and flags are populated if this exception is thrown, but the read position is not advanced.

release

fun release(): Unit

Release the stream and its underlying sample queue.

reset

fun reset(): Unit

Resets the sample queue.

A new call to writeData is required to fill the queue again.

seekToUs

fun seekToUs(positionUs: Long, allowTimeBeyondBuffer: Boolean): Boolean

Seeks the stream to a new position using already available data in the queue.

Parameters
positionUs: Long

The new position, in microseconds.

allowTimeBeyondBuffer: Boolean

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

fun skipData(positionUs: Long): Int

Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.

Parameters
positionUs: Long

The specified time.

Returns
Int

The number of samples that were skipped.

writeData

fun writeData(startPositionUs: Long): Unit

Writes all not yet written sample stream items to the sample queue starting at the given position.

Parameters
startPositionUs: Long

The start position, in microseconds.