# DefaultCodec

# DefaultCodec

Artifact:[androidx.media3:media3-transformer](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/transformer/DefaultCodec.java+class:androidx.media3.transformer.DefaultCodec)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/transformer/DefaultCodec "View this page in Java")

<br />

```
@UnstableApi
class DefaultCodec : Codec
```

<br />

*** ** * ** ***

A default[Codec](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec)implementation that uses[MediaCodec](https://developer.android.com/reference/android/media/MediaCodec.html).

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [DEFAULT_PCM_ENCODING](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#DEFAULT_PCM_ENCODING())` = 2` |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                            ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DefaultCodec](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#DefaultCodec(android.content.Context,androidx.media3.common.Format,android.media.MediaFormat,java.lang.String,boolean,android.view.Surface))`(` ` context: `[Context](https://developer.android.com/reference/android/content/Context.html)`!,` ` configurationFormat: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!,` ` configurationMediaFormat: `[MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html)`!,` ` mediaCodecName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!,` ` isDecoder: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`,` ` outputSurface: `[Surface](https://developer.android.com/reference/android/view/Surface.html)`?` `)` Creates a`DefaultCodec`. |

|                                   ### Public functions                                    |
|-------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | [getInputFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#getInputFormat())`()` Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)accepted by the codec.                                                                                                                                                                                                                                                                                      |
| [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`      | [getName](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#getName())`()` Returns the name of the underlying codec.                                                                                                                                                                                                                                                                                                                                                                                  |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)       | [isEnded](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#isEnded())`()` Returns whether the`Codec`'s output stream has ended, and no more data can be dequeued.                                                                                                                                                                                                                                                                                                                                    |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)       | `@`[EnsuresNonNullIf](https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/EnsuresNonNullIf.html)`(expression = "#1.data", result = true)` [maybeDequeueInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#maybeDequeueInputBuffer(androidx.media3.decoder.DecoderInputBuffer))`(inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!)` Dequeues a writable input buffer, if available. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)             | [queueInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#queueInputBuffer(androidx.media3.decoder.DecoderInputBuffer))`(inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!)` Queues an input buffer to the`Codec`.                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)             | [release](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#release())`()` Releases the`Codec`.                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)             | [releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#releaseOutputBuffer(boolean))`(render: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Releases the current output buffer.                                                                                                                                                                                                                                                            |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)             | [releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#releaseOutputBuffer(long))`(renderPresentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Renders and releases the current output buffer.                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)             | [signalEndOfInputStream](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#signalEndOfInputStream())`()` Signals end-of-stream on input to a video encoder.                                                                                                                                                                                                                                                                                                                                           |

|                            ### Protected functions                            |
|-------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[VisibleForTesting](https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting) [releaseOutputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#releaseOutputBuffer(boolean,long))`(render: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`, renderPresentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Releases the output buffer at`renderPresentationTimeUs`if`render`is` true`, otherwise release the buffer without rendering. |

|                                                                                                ### Public properties                                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`                                                                                                                            | [configurationFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#configurationFormat())                                                                                                            |
| [Surface](https://developer.android.com/reference/android/view/Surface.html)`?`                                                                                                                                      | [inputSurface](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#inputSurface())                                                                                                                          |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                          | [maxPendingFrameCount](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#maxPendingFrameCount())                                                                                                          |
| [ByteBuffer](https://developer.android.com/reference/java/nio/ByteBuffer.html)`?`                                                                                                                                    | [outputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#outputBuffer())                                                                                                                          |
| [MediaCodec.BufferInfo](https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html)`!`                                                                                                         | [outputBufferInfo](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#outputBufferInfo())                                                                                                                  |
| `@`[MonotonicNonNull](https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/MonotonicNonNull.html)` `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!` | `@`[MonotonicNonNull](https://checkerframework.org/api/org/checkerframework/checker/nullness/qual/MonotonicNonNull.html) [outputFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#outputFormat()) |

## 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](https://developer.android.com/reference/android/content/Context.html)`!`                        | The[Context](https://developer.android.com/reference/android/content/Context.html).                                                                                                                                                                                                                                                                                                                          |
| `configurationFormat: `[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)`!`     | The[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)to configure the`DefaultCodec`. See[getConfigurationFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#getConfigurationFormat()). The[sampleMimeType](https://developer.android.com/reference/kotlin/androidx/media3/common/Format#sampleMimeType())must not be`null`. |
| `configurationMediaFormat: `[MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html)`!` | The[MediaFormat](https://developer.android.com/reference/android/media/MediaFormat.html)to configure the underlying[MediaCodec](https://developer.android.com/reference/android/media/MediaCodec.html).                                                                                                                                                                                                      |
| `mediaCodecName: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`               | The name of a specific[MediaCodec](https://developer.android.com/reference/android/media/MediaCodec.html)to instantiate.                                                                                                                                                                                                                                                                                     |
| `isDecoder: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                     | Whether the`DefaultCodec`is intended as a decoder.                                                                                                                                                                                                                                                                                                                                                           |
| `outputSurface: `[Surface](https://developer.android.com/reference/android/view/Surface.html)`?`                     | The output[Surface](https://developer.android.com/reference/android/view/Surface.html)if the[MediaCodec](https://developer.android.com/reference/android/media/MediaCodec.html)outputs to a surface.                                                                                                                                                                                                         |

## Public functions

### getInputFormat

```
fun getInputFormat(): Format!
```

Returns the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)accepted by the codec.

This format may differ from the[Format](https://developer.android.com/reference/kotlin/androidx/media3/common/Format)returned by[getConfigurationFormat](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getConfigurationFormat()), depending on the underlying codec and configuration format requested.  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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](https://developer.android.com/reference/kotlin/androidx/media3/transformer/DefaultCodec#DefaultCodec(android.content.Context,androidx.media3.common.Format,android.media.MediaFormat,java.lang.String,boolean,android.view.Surface)).  

|                                                   See also                                                   |
|--------------------------------------------------------------------------------------------------------------|---|
| [getCanonicalName](https://developer.android.com/reference/android/media/MediaCodec.html#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](https://developer.android.com/reference/android/view/Surface.html)to receive input.  

|                                                            Parameters                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!` | The buffer where the dequeued buffer data is stored, at[inputBuffer.data](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer#data()). |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether an input buffer is ready to be used. |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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](https://developer.android.com/reference/kotlin/androidx/media3/decoder/Buffer#isEndOfStream())buffer has been queued.

This method must not be called from video encoders because they must use a[Surface](https://developer.android.com/reference/android/view/Surface.html)to receive input.  

|                                                            Parameters                                                             |
|-----------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
| `inputBuffer: `[DecoderInputBuffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer)`!` | The[input buffer](https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderInputBuffer). |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#releaseOutputBuffer(long))with the presentation timestamp of the[output buffer info](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#getOutputBufferInfo()).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| `render: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether the buffer needs to be rendered to the output[Surface](https://developer.android.com/reference/android/view/Surface.html). |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | The presentation timestamp to associate with this buffer, in microseconds. |

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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](https://developer.android.com/reference/android/view/Surface.html)as input. For audio/video decoders or audio encoders, the[BUFFER_FLAG_END_OF_STREAM](https://developer.android.com/reference/kotlin/androidx/media3/common/C#BUFFER_FLAG_END_OF_STREAM())flag should be set on the last input buffer[queued](https://developer.android.com/reference/kotlin/androidx/media3/transformer/Codec#queueInputBuffer(androidx.media3.decoder.DecoderInputBuffer)).  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/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.  

|                                                                  Throws                                                                   |
|-------------------------------------------------------------------------------------------------------------------------------------------|---|
| [androidx.media3.transformer.ExportException](https://developer.android.com/reference/kotlin/androidx/media3/transformer/ExportException) |   |

## Public properties

### configurationFormat

```
val configurationFormat: Format!
```  

### inputSurface

```
val inputSurface: Surface?
```  

### maxPendingFrameCount

```
val maxPendingFrameCount: Int
```  

### outputBuffer

```
val outputBuffer: ByteBuffer?
```  

### outputBufferInfo

```
val outputBufferInfo: MediaCodec.BufferInfo!
```  

### outputFormat

```
@MonotonicNonNull
val outputFormat: @MonotonicNonNull Format!
```