DefaultCodec
@UnstableApi
class DefaultCodec : Codec
A default Codec implementation that uses MediaCodec.
Summary
Constants |
|
|---|---|
const Int |
Public constructors |
|---|
DefaultCodec(Creates a |
Public functions |
|
|---|---|
Format! |
Returns the |
String! |
getName()Returns the name of the underlying codec. |
Boolean |
isEnded()Returns whether the |
Boolean |
@EnsuresNonNullIf(expression = "#1.data", result = true)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. |
Protected functions |
|
|---|---|
Unit |
@VisibleForTestingReleases the output buffer at |
Public properties |
|
|---|---|
Format! |
|
Surface? |
|
Int |
|
ByteBuffer? |
|
MediaCodec.BufferInfo! |
|
@MonotonicNonNull Format! |
Constants
Public constructors
DefaultCodec
DefaultCodec(
context: Context!,
configurationFormat: Format!,
configurationMediaFormat: MediaFormat!,
mediaCodecName: String!,
isDecoder: Boolean,
outputSurface: Surface?
)
Creates a DefaultCodec.
| Parameters | |
|---|---|
context: Context! |
The |
configurationFormat: Format! |
The |
configurationMediaFormat: MediaFormat! |
The |
mediaCodecName: String! |
The name of a specific |
isDecoder: Boolean |
Whether the |
outputSurface: Surface? |
The output |
Public functions
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. |
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 |
| 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. |
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.