@UnstableApi
class DefaultCodec : Codec


A default Codec implementation that uses MediaCodec.

Summary

Constants

const Int

Public constructors

DefaultCodec(
    context: Context!,
    configurationFormat: Format!,
    configurationMediaFormat: MediaFormat!,
    mediaCodecName: String!,
    isDecoder: Boolean,
    outputSurface: Surface?
)

Creates a DefaultCodec.

Public functions

String!

Returns the name of the underlying codec.

Boolean

Returns whether the Codec's output stream has ended, and no more data can be dequeued.

Boolean
@EnsuresNonNullIf(expression = "#1.data", result = true)
maybeDequeueInputBuffer(inputBuffer: DecoderInputBuffer!)

Dequeues a writable input buffer, if available.

Unit

Queues an input buffer to the Codec.

Unit

Releases the Codec.

Unit

Releases the current output buffer.

Unit
releaseOutputBuffer(renderPresentationTimeUs: Long)

Renders and releases the current output buffer.

Unit

Signals end-of-stream on input to a video encoder.

Protected functions

Unit
@VisibleForTesting
releaseOutputBuffer(render: Boolean, renderPresentationTimeUs: Long)

Releases the output buffer at renderPresentationTimeUs if render is true, otherwise release the buffer without rendering.

Constants

DEFAULT_PCM_ENCODING

const val DEFAULT_PCM_ENCODING = 2: Int

Public constructors

DefaultCodec

DefaultCodec(
    context: Context!,
    configurationFormat: Format!,
    configurationMediaFormat: MediaFormat!,
    mediaCodecName: String!,
    isDecoder: Boolean,
    outputSurface: Surface?
)

Creates a DefaultCodec.

Parameters
context: Context!

The Context.

configurationFormat: Format!

The Format to configure the DefaultCodec. See getConfigurationFormat. The sampleMimeType must not be null.

configurationMediaFormat: MediaFormat!

The MediaFormat to configure the underlying .

mediaCodecName: String!

The name of a specific MediaCodec to instantiate.

isDecoder: Boolean

Whether the DefaultCodec is intended as a decoder.

outputSurface: Surface?

The output Surface if the MediaCodec outputs to a surface.

Public functions

getName

fun getName(): String!

Returns the name of the underlying codec.

This name is of the actual codec, which may not be the same as the mediaCodecName passed to DefaultCodec.

See also
getCanonicalName

isEnded

fun isEnded(): Boolean

Returns whether the Codec's output stream has ended, and no more data can be dequeued.

maybeDequeueInputBuffer

@EnsuresNonNullIf(expression = "#1.data", result = true)
fun maybeDequeueInputBuffer(inputBuffer: DecoderInputBuffer!): Boolean

Dequeues a writable input buffer, if available.

This method must not be called from video encoders because they must use a Surface to receive input.

Parameters
inputBuffer: DecoderInputBuffer!

The buffer where the dequeued buffer data is stored, at inputBuffer.data.

Returns
Boolean

Whether an input buffer is ready to be used.

Throws
androidx.media3.transformer.ExportException

If the underlying decoder or encoder encounters a problem.

queueInputBuffer

fun queueInputBuffer(inputBuffer: DecoderInputBuffer!): Unit

Queues an input buffer to the Codec. No buffers may be queued after end of stream buffer has been queued.

This method must not be called from video encoders because they must use a Surface to receive input.

Parameters
inputBuffer: DecoderInputBuffer!

The input buffer.

Throws
androidx.media3.transformer.ExportException

If the underlying decoder or encoder encounters a problem.

release

fun release(): Unit

Releases the Codec.

releaseOutputBuffer

fun releaseOutputBuffer(render: Boolean): Unit

Releases the current output buffer.

Only set render to true when the Codec is a video decoder. Setting render to true will first render the buffer to the output surface. In this case, the surface will release the buffer back to the Codec once it is no longer used/displayed.

This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.

Calling this method with render set to true is equivalent to calling releaseOutputBuffer with the presentation timestamp of the output buffer info.

Parameters
render: Boolean

Whether the buffer needs to be rendered to the output Surface.

Throws
androidx.media3.transformer.ExportException

If the underlying decoder or encoder encounters a problem.

releaseOutputBuffer

fun releaseOutputBuffer(renderPresentationTimeUs: Long): Unit

Renders and releases the current output buffer.

This method must only be called on video decoders.

This method will first render the buffer to the output surface. The surface will then release the buffer back to the Codec once it is no longer used/displayed.

This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.

Parameters
renderPresentationTimeUs: Long

The presentation timestamp to associate with this buffer, in microseconds.

Throws
androidx.media3.transformer.ExportException

If the underlying decoder or encoder encounters a problem.

signalEndOfInputStream

fun signalEndOfInputStream(): Unit

Signals end-of-stream on input to a video encoder.

This method must only be called on video encoders because they must use a Surface as input. For audio/video decoders or audio encoders, the BUFFER_FLAG_END_OF_STREAM flag should be set on the last input buffer queued.

Throws
androidx.media3.transformer.ExportException

If the underlying video encoder encounters a problem.

Protected functions

releaseOutputBuffer

@VisibleForTesting
protected fun releaseOutputBuffer(render: Boolean, renderPresentationTimeUs: Long): Unit

Releases the output buffer at renderPresentationTimeUs if render is true, otherwise release the buffer without rendering.

Public properties

configurationFormat

val configurationFormatFormat!

inputSurface

val inputSurfaceSurface?

maxPendingFrameCount

val maxPendingFrameCountInt

outputBuffer

val outputBufferByteBuffer?

outputBufferInfo

val outputBufferInfoMediaCodec.BufferInfo!