SynchronousMediaCodecAdapter


@UnstableApi
class SynchronousMediaCodecAdapter : MediaCodecAdapter


A MediaCodecAdapter that operates the underlying MediaCodec in synchronous mode.

Summary

Public functions

Int

Returns the next available input buffer index from the underlying MediaCodec or INFO_TRY_AGAIN_LATER if no such buffer exists.

Int

Returns the next available output buffer index from the underlying MediaCodec.

Unit

Detaches the current output surface.

Unit

Flushes the adapter and the underlying MediaCodec.

ByteBuffer?

Returns a writable ByteBuffer object for a dequeued input buffer index.

PersistableBundle!
@RequiresApi(value = 26)
getMetrics()

Returns metrics data about the current codec instance.

ByteBuffer?

Returns a read-only ByteBuffer for a dequeued output buffer index.

MediaFormat!

Gets the MediaFormat that was output from the MediaCodec.

Boolean

Whether the adapter needs to be reconfigured before it is used.

Unit
queueInputBuffer(
    index: Int,
    offset: Int,
    size: Int,
    presentationTimeUs: Long,
    flags: Int
)

Submit an input buffer for decoding.

Unit
queueSecureInputBuffer(
    index: Int,
    offset: Int,
    info: CryptoInfo!,
    presentationTimeUs: Long,
    flags: Int
)

Submit an input buffer that is potentially encrypted for decoding.

Unit

Releases the adapter and the underlying MediaCodec.

Unit
releaseOutputBuffer(index: Int, render: Boolean)

Returns the buffer to the MediaCodec.

Unit
releaseOutputBuffer(index: Int, renderTimeStampNs: Long)

Updates the output buffer's surface timestamp and sends it to the MediaCodec to render it on the output surface.

Unit
@RequiresApi(value = 23)
setOnFrameRenderedListener(
    listener: MediaCodecAdapter.OnFrameRenderedListener!,
    handler: Handler!
)

Registers a callback to be invoked when an output frame is rendered on the output surface.

Unit
@RequiresApi(value = 23)
setOutputSurface(surface: Surface!)

Dynamically sets the output surface of a MediaCodec.

Unit

Communicate additional parameter changes to the MediaCodec instance.

Unit

Specifies the scaling mode to use, if a surface was specified when the codec was created.

Inherited functions

From androidx.media3.exoplayer.mediacodec.MediaCodecAdapter
Boolean

Registers a listener that will be called when an input or output buffer becomes available.

Public functions

dequeueInputBufferIndex

fun dequeueInputBufferIndex(): Int

Returns the next available input buffer index from the underlying MediaCodec or INFO_TRY_AGAIN_LATER if no such buffer exists.

Throws
java.lang.IllegalStateException

If the underlying MediaCodec raised an error.

dequeueOutputBufferIndex

fun dequeueOutputBufferIndex(bufferInfo: MediaCodec.BufferInfo!): Int

Returns the next available output buffer index from the underlying MediaCodec. If the next available output is a MediaFormat change, it will return INFO_OUTPUT_FORMAT_CHANGED and you should call getOutputFormat to get the format. If there is no available output, this method will return INFO_TRY_AGAIN_LATER.

Throws
java.lang.IllegalStateException

If the underlying MediaCodec raised an error.

detachOutputSurface

@RequiresApi(value = 35)
fun detachOutputSurface(): Unit

Detaches the current output surface.

See also
MediaCodec

flush

fun flush(): Unit

Flushes the adapter and the underlying MediaCodec.

getInputBuffer

fun getInputBuffer(index: Int): ByteBuffer?

Returns a writable ByteBuffer object for a dequeued input buffer index.

See also
getInputBuffer

getMetrics

@RequiresApi(value = 26)
fun getMetrics(): PersistableBundle!

Returns metrics data about the current codec instance.

See also
getMetrics

getOutputBuffer

fun getOutputBuffer(index: Int): ByteBuffer?

Returns a read-only ByteBuffer for a dequeued output buffer index.

See also
getOutputBuffer

getOutputFormat

fun getOutputFormat(): MediaFormat!

Gets the MediaFormat that was output from the MediaCodec.

Call this method if a previous call to dequeueOutputBufferIndex returned INFO_OUTPUT_FORMAT_CHANGED.

needsReconfiguration

fun needsReconfiguration(): Boolean

Whether the adapter needs to be reconfigured before it is used.

queueInputBuffer

fun queueInputBuffer(
    index: Int,
    offset: Int,
    size: Int,
    presentationTimeUs: Long,
    flags: Int
): Unit

Submit an input buffer for decoding.

The index must be an input buffer index that has been obtained from a previous call to dequeueInputBufferIndex.

See also
queueInputBuffer

queueSecureInputBuffer

fun queueSecureInputBuffer(
    index: Int,
    offset: Int,
    info: CryptoInfo!,
    presentationTimeUs: Long,
    flags: Int
): Unit

Submit an input buffer that is potentially encrypted for decoding.

The index must be an input buffer index that has been obtained from a previous call to dequeueInputBufferIndex.

This method behaves like queueSecureInputBuffer, with the difference that info is of type CryptoInfo and not android.media.MediaCodec.CryptoInfo.

release

fun release(): Unit

Releases the adapter and the underlying MediaCodec.

releaseOutputBuffer

fun releaseOutputBuffer(index: Int, render: Boolean): Unit

Returns the buffer to the MediaCodec. If the MediaCodec was configured with an output surface, setting render to true will first send the buffer to the output surface. The surface will release the buffer back to the codec once it is no longer used/displayed.

releaseOutputBuffer

fun releaseOutputBuffer(index: Int, renderTimeStampNs: Long): Unit

Updates the output buffer's surface timestamp and sends it to the MediaCodec to render it on the output surface. If the MediaCodec is not configured with an output surface, this call will simply return the buffer to the MediaCodec.

setOnFrameRenderedListener

@RequiresApi(value = 23)
fun setOnFrameRenderedListener(
    listener: MediaCodecAdapter.OnFrameRenderedListener!,
    handler: Handler!
): Unit

Registers a callback to be invoked when an output frame is rendered on the output surface.

setOutputSurface

@RequiresApi(value = 23)
fun setOutputSurface(surface: Surface!): Unit

Dynamically sets the output surface of a MediaCodec.

See also
setOutputSurface

setParameters

fun setParameters(params: Bundle!): Unit

Communicate additional parameter changes to the MediaCodec instance.

See also
setParameters

setVideoScalingMode

fun setVideoScalingMode(@C.VideoScalingMode scalingMode: Int): Unit

Specifies the scaling mode to use, if a surface was specified when the codec was created.