@UnstableApi
public interface SampleConsumer


Consumer of encoded media samples, raw audio or raw video frames.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation SampleConsumer.InputResult

Specifies the result of an input operation.

Constants

default static final int

The operation of queueing input successful and end of input has been automatically signalled.

default static final int

The operation of queueing input was successful.

default static final int

The operation of queueing/registering input was unsuccessful.

Public methods

default ColorInfo

Returns the expected input ColorInfo.

default @Nullable DecoderInputBuffer

Returns a DecoderInputBuffer, if available.

default Surface

Returns the input Surface, where the consumer reads input frames from.

default int

Returns the number of input video frames pending in the consumer.

default int
@SampleConsumer.InputResult
queueInputBitmap(
    Bitmap inputBitmap,
    TimestampIterator timestampIterator
)

Attempts to provide an input Bitmap to the consumer.

default boolean

Attempts to queue new input to the consumer.

default int
@SampleConsumer.InputResult
queueInputTexture(int texId, long presentationTimeUs)

Attempts to provide an input texture to the consumer.

default boolean
registerVideoFrame(long presentationTimeUs)

Attempts to register a video frame to the consumer.

default void

Provides a OnInputFrameProcessedListener to the consumer.

default void

Informs the consumer that no further input frames will be rendered.

Constants

INPUT_RESULT_END_OF_STREAM

default static final int INPUT_RESULT_END_OF_STREAM = 3

The operation of queueing input successful and end of input has been automatically signalled.

The caller should not signal end of input as this has already been done internally.

INPUT_RESULT_SUCCESS

default static final int INPUT_RESULT_SUCCESS = 1

The operation of queueing input was successful.

The caller can queue more input or signal signal end of input.

INPUT_RESULT_TRY_AGAIN_LATER

default static final int INPUT_RESULT_TRY_AGAIN_LATER = 2

The operation of queueing/registering input was unsuccessful.

The caller should queue try again later.

Public methods

getExpectedInputColorInfo

default ColorInfo getExpectedInputColorInfo()

Returns the expected input ColorInfo.

Should only be used for raw video data.

getInputBuffer

default @Nullable DecoderInputBuffer getInputBuffer()

Returns a DecoderInputBuffer, if available.

This buffer should be filled with new input data and queued to the consumer.

If this method returns a non-null buffer:

  • The buffer's data is non-null.
  • The same buffer instance is returned if this method is called multiple times before queuing input.

Should only be used for compressed data and raw audio data.

getInputSurface

default Surface getInputSurface()

Returns the input Surface, where the consumer reads input frames from.

Should only be used for raw video data.

getPendingVideoFrameCount

default int getPendingVideoFrameCount()

Returns the number of input video frames pending in the consumer. Pending input frames are frames that have been registered but not processed off the input surface yet.

Should only be used for raw video data.

queueInputBitmap

@SampleConsumer.InputResult
default int queueInputBitmap(
    Bitmap inputBitmap,
    TimestampIterator timestampIterator
)

Attempts to provide an input Bitmap to the consumer.

Should only be used for image data.

Parameters
Bitmap inputBitmap

The Bitmap to queue to the consumer.

TimestampIterator timestampIterator

A TimestampIterator generating the exact timestamps that the bitmap should be shown at.

Returns
int

The InputResult describing the result of the operation.

queueInputBuffer

default boolean queueInputBuffer()

Attempts to queue new input to the consumer.

The input buffer from getInputBuffer should be filled with the new input before calling this method.

An input buffer should not be used anymore after it has been successfully queued.

Should only be used for compressed data and raw audio data.

Returns
boolean

Whether the input was successfully queued. If false, the caller should try again later.

queueInputTexture

@SampleConsumer.InputResult
default int queueInputTexture(int texId, long presentationTimeUs)

Attempts to provide an input texture to the consumer.

Should only be used for raw video data.

Parameters
int texId

The ID of the texture to queue to the consumer.

long presentationTimeUs

The presentation time for the texture, in microseconds.

Returns
int

The InputResult describing the result of the operation.

registerVideoFrame

default boolean registerVideoFrame(long presentationTimeUs)

Attempts to register a video frame to the consumer.

Each frame to consume should be registered using this method. After a frame is successfully registered, it should be rendered to the input surface.

Should only be used for raw video data.

Parameters
long presentationTimeUs

The presentation time of the frame to register, in microseconds.

Returns
boolean

Whether the frame was successfully registered. If false, the caller should try again later.

setOnInputFrameProcessedListener

default void setOnInputFrameProcessedListener(
    OnInputFrameProcessedListener listener
)

Provides a OnInputFrameProcessedListener to the consumer.

Should only be used for raw video data when input is provided by texture ID.

signalEndOfVideoInput

default void signalEndOfVideoInput()

Informs the consumer that no further input frames will be rendered.

Should only be used for raw video data.