Codec
@UnstableApi
interface Codec
DefaultCodec |
A default |
Provides a layer of abstraction for interacting with decoders and encoders.
DecoderInputBuffers are used as both decoders' and encoders' input buffers.
Summary
Nested types |
|---|
interface Codec.DecoderFactoryA factory for |
interface Codec.EncoderFactoryA factory for |
Public functions |
|
|---|---|
Format! |
Returns the |
Format! |
Returns the |
Surface! |
Returns the input |
Int |
Returns the maximum number of frames that may be pending in the output |
String! |
getName()Returns the name of the underlying codec. |
ByteBuffer? |
Returns the current output |
MediaCodec.BufferInfo? |
Returns the |
Format? |
Returns the current output format, or |
Boolean |
isEnded()Returns whether the |
Boolean |
maybeDequeueInputBuffer(inputBuffer: DecoderInputBuffer!)Dequeues a writable input buffer, if available. |
Unit |
queueInputBuffer(inputBuffer: DecoderInputBuffer!)Queues an input buffer to the |
Unit |
release()Releases the |
Unit |
releaseOutputBuffer(render: Boolean)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. |
Public functions
getConfigurationFormat
fun getConfigurationFormat(): Format!
Returns the Format used for configuring the Codec.
The configuration Format is the input Format used by the DecoderFactory or output Format used by the EncoderFactory for selecting and configuring the underlying decoder or encoder.
getInputFormat
fun getInputFormat(): Format!
Returns the Format accepted by the codec.
This format may differ from the Format returned by getConfigurationFormat, depending on the underlying codec and configuration format requested.
| Throws | |
|---|---|
androidx.media3.transformer.ExportException |
If the underlying decoder or encoder encounters a problem. |
getInputSurface
fun getInputSurface(): Surface!
Returns the input Surface of an underlying video encoder.
This method must only be called on video encoders because audio/video decoders and audio encoders don't use a Surface as input.
getMaxPendingFrameCount
fun getMaxPendingFrameCount(): Int
Returns the maximum number of frames that may be pending in the output Codec at a time, or 5 as a default value.
getOutputBuffer
fun getOutputBuffer(): ByteBuffer?
Returns the current output ByteBuffer, or null if unavailable.
This method must not be called on video decoders because they must output to a Surface.
| Throws | |
|---|---|
androidx.media3.transformer.ExportException |
If the underlying decoder or encoder encounters a problem. |
getOutputBufferInfo
fun getOutputBufferInfo(): MediaCodec.BufferInfo?
Returns the BufferInfo associated with the current output buffer, or null if there is no output buffer available.
This method returns null if and only if getOutputBuffer returns null.
| Throws | |
|---|---|
androidx.media3.transformer.ExportException |
If the underlying decoder or encoder encounters a problem. |
getOutputFormat
fun getOutputFormat(): Format?
Returns the current output format, or null if unavailable.
| Throws | |
|---|---|
androidx.media3.transformer.ExportException |
If the underlying decoder or encoder encounters a problem. |
isEnded
fun isEnded(): Boolean
Returns whether the Codec's output stream has ended, and no more data can be dequeued.
maybeDequeueInputBuffer
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 |
| 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 |
| Throws | |
|---|---|
androidx.media3.transformer.ExportException |
If the underlying decoder or encoder encounters a problem. |
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.
| 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. |