# ForwardingMediaCodecAdapter

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/ForwardingMediaCodecAdapter.java+class:androidx.media3.exoplayer.mediacodec.ForwardingMediaCodecAdapter)

*** ** * ** ***


```
@UnstableApi
public class ForwardingMediaCodecAdapter implements MediaCodecAdapter
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter` instance that forwards all calls to its delegate.

Subclasses can override methods as part of the [decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern).

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#ForwardingMediaCodecAdapter(androidx.media3.exoplayer.mediacodec.MediaCodecAdapter)(https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter delegate)` |

| ### Public methods |
|---|---|
| `int` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#detachOutputSurface()()` Detaches the current output surface. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#needsReconfiguration()()` Whether the adapter needs to be reconfigured before it is used. |
| `void` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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` | `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#setVideoScalingMode(int)(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/ForwardingMediaCodecAdapter#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/ForwardingMediaCodecAdapter#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. |
| `void` | `<E extends https://developer.android.com/reference/java/lang/Exception.html> https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#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 constructors

### ForwardingMediaCodecAdapter

```
public ForwardingMediaCodecAdapter(MediaCodecAdapter delegate)
```

## 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)` |   |

### registerOnBufferAvailableListener

```
public boolean registerOnBufferAvailableListener(
    MediaCodecAdapter.OnBufferAvailableListener listener
)
```

Registers a listener that will be called when an input or output buffer becomes available.

Returns false if listener was not successfully registered for callbacks.

| Returns |
|---|---|
| `boolean` | Whether listener was successfully registered. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/media/MediaCodec.Callback.html#onInputBufferAvailable(android.media.MediaCodec, int)` |   |
| `https://developer.android.com/reference/android/media/MediaCodec.Callback.html#onOutputBufferAvailable(android.media.MediaCodec, int, android.media.MediaCodec.BufferInfo)` |   |

### 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(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;)` |   |

### useBuffer

```
public void <E extends Exception> useBuffer(ThrowingRunnable<E> runnable)
```

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

This can be used for error handling, e.g. to guarantee no operation can invalidate the buffer while it's being used by the application or downstream components.

| Parameters |
|---|---|
| `<E extends https://developer.android.com/reference/java/lang/Exception.html>` | The type of exception thrown by `runnable`. |
| `https://developer.android.com/reference/androidx/media3/common/util/ThrowingRunnable<E> runnable` | The `https://developer.android.com/reference/androidx/media3/common/util/ThrowingRunnable` utilizing an acquired buffer. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/MediaCodecAdapter#useBuffer(androidx.media3.common.util.ThrowingRunnable<E>)` | If `runnable` throws an exception. |
| `https://developer.android.com/reference/androidx/media3/exoplayer/mediacodec/ForwardingMediaCodecAdapter#useBuffer(androidx.media3.common.util.ThrowingRunnable<E>)` |   |