# SynchronousMediaCodecAdapter

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

*** ** * ** ***


```
@UnstableApi
class SynchronousMediaCodecAdapter : MediaCodecAdapter
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter` that operates the underlying `https://developer.android.com/reference/android/media/MediaCodec.html` in synchronous mode.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter.Factory : https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.Factory` A factory for `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter` instances. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#dequeueInputBufferIndex()()` Returns the next available input buffer index from the underlying `https://developer.android.com/reference/android/media/MediaCodec.html` or `https://developer.android.com/reference/android/media/MediaCodec.html#INFO_TRY_AGAIN_LATER` if no such buffer exists. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)(bufferInfo: https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html!)` Returns the next available output buffer index from the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 35) https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#detachOutputSurface()()` Detaches the current output surface. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#flush()()` Flushes the adapter and the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getInputBuffer(int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns a writable ByteBuffer object for a dequeued input buffer index. |
| `https://developer.android.com/reference/android/os/PersistableBundle.html!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getMetrics()()` Returns metrics data about the current codec instance. |
| `https://developer.android.com/reference/java/nio/ByteBuffer.html?` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getOutputBuffer(int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns a read-only ByteBuffer for a dequeued output buffer index. |
| `https://developer.android.com/reference/android/media/MediaFormat.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getOutputFormat()()` Gets the `https://developer.android.com/reference/android/media/MediaFormat.html` that was output from the `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#needsReconfiguration()()` Whether the adapter needs to be reconfigured before it is used. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#queueInputBuffer(int,int,int,long,int)( index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Submit an input buffer for decoding. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#queueSecureInputBuffer(int,int,androidx.media3.decoder.CryptoInfo,long,int)( index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, info: https://developer.android.com/reference/kotlin/androidx/media3/decoder/CryptoInfo!, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, flags: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Submit an input buffer that is potentially encrypted for decoding. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#release()()` Releases the adapter and the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#releaseOutputBuffer(int,boolean)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, render: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Returns the buffer to the `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#releaseOutputBuffer(int,long)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, renderTimeStampNs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Updates the output buffer's surface timestamp and sends it to the `https://developer.android.com/reference/android/media/MediaCodec.html` to render it on the output surface. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setOnFrameRenderedListener(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.OnFrameRenderedListener,android.os.Handler)( listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.OnFrameRenderedListener!, handler: https://developer.android.com/reference/android/os/Handler.html! )` Registers a callback to be invoked when an output frame is rendered on the output surface. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setOutputSurface(android.view.Surface)(surface: https://developer.android.com/reference/android/view/Surface.html!)` Dynamically sets the output surface of a `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setParameters(android.os.Bundle)(params: https://developer.android.com/reference/android/os/Bundle.html!)` Communicate additional parameter changes to the `https://developer.android.com/reference/android/media/MediaCodec.html` instance. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setVideoScalingMode(int)(@https://developer.android.com/reference/kotlin/androidx/media3/common/C.VideoScalingMode scalingMode: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Specifies the scaling mode to use, if a surface was specified when the codec was created. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#subscribeToVendorParameters(java.util.List<java.lang.String>)(names: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` Subscribe to vendor parameters, so that these parameters will be present in `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters generate output format change event. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#unsubscribeFromVendorParameters(java.util.List<java.lang.String>)(names: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` Unsubscribe from vendor parameters, so that these parameters will not be present in `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters no longer generate output format change event. |

### Inherited functions

From [androidx.media3.exoplayer.mediacodec.MediaCodecAdapter](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#registerOnBufferAvailableListener(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.OnBufferAvailableListener)(
listener: https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.OnBufferAvailableListener!
)`

Registers a listener that will be called when an input or output buffer becomes available.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `<E : https://developer.android.com/reference/java/lang/Exception.html?> https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#useBuffer(androidx.media3.common.util.ThrowingRunnable<E>)(runnable: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ThrowingRunnable<E!>!)`

Uses an acquired input or output buffer (e.g. to read from or write data to it).

## Public functions

### dequeueInputBufferIndex

```
fun dequeueInputBufferIndex(): Int
```

Returns the next available input buffer index from the underlying `https://developer.android.com/reference/android/media/MediaCodec.html` or `https://developer.android.com/reference/android/media/MediaCodec.html#INFO_TRY_AGAIN_LATER` if no such buffer exists.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the underlying `https://developer.android.com/reference/android/media/MediaCodec.html` raised an error. |

### dequeueOutputBufferIndex

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

Returns the next available output buffer index from the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. If the next available output is a MediaFormat change, it will return `https://developer.android.com/reference/android/media/MediaCodec.html#INFO_OUTPUT_FORMAT_CHANGED` and you should call `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` to get the format. If there is no available output, this method will return `https://developer.android.com/reference/android/media/MediaCodec.html#INFO_TRY_AGAIN_LATER`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If the underlying `https://developer.android.com/reference/android/media/MediaCodec.html` raised an error. |

### detachOutputSurface

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

Detaches the current output surface.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#detachOutputSurface()` |   |

### flush

```
fun flush(): Unit
```

Flushes the adapter and the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`.

### getInputBuffer

```
fun getInputBuffer(index: Int): ByteBuffer?
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#getInputBuffer(int)` |   |

### getMetrics

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

Returns metrics data about the current codec instance.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#getMetrics()` |   |

### getOutputBuffer

```
fun getOutputBuffer(index: Int): ByteBuffer?
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#getOutputBuffer(int)` |   |

### getOutputFormat

```
fun getOutputFormat(): MediaFormat!
```

Gets the `https://developer.android.com/reference/android/media/MediaFormat.html` that was output from the `https://developer.android.com/reference/android/media/MediaCodec.html`.

Call this method if a previous call to `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)` returned `https://developer.android.com/reference/android/media/MediaCodec.html#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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#dequeueInputBufferIndex()`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#queueInputBuffer(int, int, int, long, int)` |   |

### 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 `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#dequeueInputBufferIndex()`.

This method behaves like `https://developer.android.com/reference/android/media/MediaCodec.html#queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)`, with the difference that `info` is of type `https://developer.android.com/reference/kotlin/androidx/media3/decoder/CryptoInfo` and not `https://developer.android.com/reference/android/media/MediaCodec.CryptoInfo.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)` |   |

### release

```
fun release(): Unit
```

Releases the adapter and the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`.

### releaseOutputBuffer

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

Returns the buffer to the `https://developer.android.com/reference/android/media/MediaCodec.html`. If the `https://developer.android.com/reference/android/media/MediaCodec.html` 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.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#releaseOutputBuffer(int, boolean)` |   |

### releaseOutputBuffer

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

Updates the output buffer's surface timestamp and sends it to the `https://developer.android.com/reference/android/media/MediaCodec.html` to render it on the output surface. If the `https://developer.android.com/reference/android/media/MediaCodec.html` is not configured with an output surface, this call will simply return the buffer to the `https://developer.android.com/reference/android/media/MediaCodec.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#releaseOutputBuffer(int, long)` |   |

### setOnFrameRenderedListener

```
fun setOnFrameRenderedListener(
    listener: MediaCodecAdapter.OnFrameRenderedListener!,
    handler: Handler!
): Unit
```

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#setOnFrameRenderedListener(android.media.MediaCodec.OnFrameRenderedListener, android.os.Handler)` |   |

### setOutputSurface

```
fun setOutputSurface(surface: Surface!): Unit
```

Dynamically sets the output surface of a `https://developer.android.com/reference/android/media/MediaCodec.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#setOutputSurface(android.view.Surface)` |   |

### setParameters

```
fun setParameters(params: Bundle!): Unit
```

Communicate additional parameter changes to the `https://developer.android.com/reference/android/media/MediaCodec.html` instance.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#setParameters(android.os.Bundle)` |   |

### setVideoScalingMode

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

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

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#setVideoScalingMode(int)` |   |

### subscribeToVendorParameters

```
@RequiresApi(value = 31)
fun subscribeToVendorParameters(names: (Mutable)List<String!>!): Unit
```

Subscribe to vendor parameters, so that these parameters will be present in `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters generate output format change event.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#subscribeToVendorParameters(java.util.List&lt;java.lang.String&gt;)` |   |

### unsubscribeFromVendorParameters

```
@RequiresApi(value = 31)
fun unsubscribeFromVendorParameters(names: (Mutable)List<String!>!): Unit
```

Unsubscribe from vendor parameters, so that these parameters will not be present in `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters no longer generate output format change event.

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.html#unsubscribeFromVendorParameters(java.util.List&lt;java.lang.String&gt;)` |   |