# 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
public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter
```

<br />

*** ** * ** ***

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

## Summary

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

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/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. |
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)(https://developer.android.com/reference/android/media/MediaCodec.BufferInfo.html bufferInfo)` Returns the next available output buffer index from the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 35) https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#detachOutputSurface()()` Detaches the current output surface. |
| `void` | `https://developer.android.com/reference/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/androidx/annotation/Nullable https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getInputBuffer(int)(int index)` 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/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getMetrics()()` Returns metrics data about the current codec instance. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#getOutputBuffer(int)(int index)` 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/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`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#needsReconfiguration()()` Whether the adapter needs to be reconfigured before it is used. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#queueInputBuffer(int,int,int,long,int)( int index, int offset, int size, long presentationTimeUs, int flags )` Submit an input buffer for decoding. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#queueSecureInputBuffer(int,int,androidx.media3.decoder.CryptoInfo,long,int)( int index, int offset, https://developer.android.com/reference/androidx/media3/decoder/CryptoInfo info, long presentationTimeUs, int flags )` Submit an input buffer that is potentially encrypted for decoding. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#release()()` Releases the adapter and the underlying `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#releaseOutputBuffer(int,boolean)(int index, boolean render)` Returns the buffer to the `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#releaseOutputBuffer(int,long)(int index, long renderTimeStampNs)` 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. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setOnFrameRenderedListener(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.OnFrameRenderedListener,android.os.Handler)( https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.OnFrameRenderedListener listener, https://developer.android.com/reference/android/os/Handler.html handler )` Registers a callback to be invoked when an output frame is rendered on the output surface. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setOutputSurface(android.view.Surface)(https://developer.android.com/reference/android/view/Surface.html surface)` Dynamically sets the output surface of a `https://developer.android.com/reference/android/media/MediaCodec.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setParameters(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html params)` Communicate additional parameter changes to the `https://developer.android.com/reference/android/media/MediaCodec.html` instance. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#setVideoScalingMode(int)(@https://developer.android.com/reference/androidx/media3/common/C.VideoScalingMode int scalingMode)` Specifies the scaling mode to use, if a surface was specified when the codec was created. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#subscribeToVendorParameters(java.util.List<java.lang.String>)(https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> names)` Subscribe to vendor parameters, so that these parameters will be present in `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters generate output format change event. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/SynchronousMediaCodecAdapter#unsubscribeFromVendorParameters(java.util.List<java.lang.String>)(https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/java/lang/String.html> names)` Unsubscribe from vendor parameters, so that these parameters will not be present in `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#getOutputFormat()` and changes to these parameters no longer generate output format change event. |

### Inherited methods

From [androidx.media3.exoplayer.mediacodec.MediaCodecAdapter](https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter) `boolean` `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#registerOnBufferAvailableListener(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter.OnBufferAvailableListener)(
https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter.OnBufferAvailableListener listener
)`

Registers a listener that will be called when an input or output buffer becomes available.
`void` `<E extends https://developer.android.com/reference/java/lang/Exception.html> https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#useBuffer(androidx.media3.common.util.ThrowingRunnable<E>)(https://developer.android.com/reference/androidx/media3/common/util/ThrowingRunnable<E> runnable)`

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

## Public methods

### dequeueInputBufferIndex

```
public int 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.

| 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

```
public int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
```

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/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)
public void detachOutputSurface()
```

Detaches the current output surface.

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

### flush

```
public void flush()
```

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

### getInputBuffer

```
public @Nullable ByteBuffer getInputBuffer(int index)
```

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)
public PersistableBundle getMetrics()
```

Returns metrics data about the current codec instance.

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

### getOutputBuffer

```
public @Nullable ByteBuffer getOutputBuffer(int index)
```

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

```
public MediaFormat 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`.

Call this method if a previous call to `https://developer.android.com/reference/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

```
public boolean needsReconfiguration()
```

Whether the adapter needs to be reconfigured before it is used.

### queueInputBuffer

```
public void queueInputBuffer(
    int index,
    int offset,
    int size,
    long presentationTimeUs,
    int flags
)
```

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/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#dequeueInputBufferIndex()`.

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

### queueSecureInputBuffer

```
public void queueSecureInputBuffer(
    int index,
    int offset,
    CryptoInfo info,
    long presentationTimeUs,
    int flags
)
```

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/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/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

```
public void release()
```

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

### releaseOutputBuffer

```
public void releaseOutputBuffer(int index, boolean render)
```

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

```
public void releaseOutputBuffer(int index, long renderTimeStampNs)
```

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

```
public void setOnFrameRenderedListener(
    MediaCodecAdapter.OnFrameRenderedListener listener,
    Handler handler
)
```

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

```
public void setOutputSurface(Surface surface)
```

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

```
public void setParameters(Bundle params)
```

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

```
public void setVideoScalingMode(@C.VideoScalingMode int scalingMode)
```

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)
public void subscribeToVendorParameters(List<String> names)
```

Subscribe to vendor parameters, so that these parameters will be present in `https://developer.android.com/reference/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)
public void unsubscribeFromVendorParameters(List<String> names)
```

Unsubscribe from vendor parameters, so that these parameters will not be present in `https://developer.android.com/reference/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;)` |   |