# Decoder

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

*** ** * ** ***


```
@UnstableApi
public interface Decoder<I, O, E extends DecoderException>
```

<br />

Known direct subclasses [ImageDecoder](https://developer.android.com/reference/androidx/media3/exoplayer/image/ImageDecoder), [SimpleDecoder](https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder), [SubtitleDecoder](https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoder)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/image/ImageDecoder` | A `https://developer.android.com/reference/androidx/media3/decoder/Decoder` implementation for images. |
| `https://developer.android.com/reference/androidx/media3/decoder/SimpleDecoder` | Base class for `https://developer.android.com/reference/androidx/media3/decoder/Decoder`s that use their own decode thread and decode each input buffer immediately into a corresponding output buffer. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoder` | Decodes `https://developer.android.com/reference/androidx/media3/extractor/text/Subtitle`s from `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleInputBuffer`s. |

Known indirect subclasses [BitmapFactoryImageDecoder](https://developer.android.com/reference/androidx/media3/exoplayer/image/BitmapFactoryImageDecoder), [Cea608Decoder](https://developer.android.com/reference/androidx/media3/extractor/text/cea/Cea608Decoder), [Cea708Decoder](https://developer.android.com/reference/androidx/media3/extractor/text/cea/Cea708Decoder), [ExternallyLoadedImageDecoder](https://developer.android.com/reference/androidx/media3/exoplayer/image/ExternallyLoadedImageDecoder), [SimpleSubtitleDecoder](https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder)

|---|---|
| `https://developer.android.com/reference/androidx/media3/exoplayer/image/BitmapFactoryImageDecoder` | An image decoder that uses `https://developer.android.com/reference/android/graphics/BitmapFactory.html` to decode images. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/cea/Cea608Decoder` | A `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoder` for CEA-608 (also known as "line 21 captions" and "EIA-608"). |
| `https://developer.android.com/reference/androidx/media3/extractor/text/cea/Cea708Decoder` | A `https://developer.android.com/reference/androidx/media3/extractor/text/SubtitleDecoder` for CEA-708 (also known as "EIA-708"). |
| `https://developer.android.com/reference/androidx/media3/exoplayer/image/ExternallyLoadedImageDecoder` | An `https://developer.android.com/reference/androidx/media3/exoplayer/image/ImageDecoder` for externally loaded images. |
| `https://developer.android.com/reference/androidx/media3/extractor/text/SimpleSubtitleDecoder` | Base class for subtitle parsers that use their own decode thread. |

*** ** * ** ***

A media decoder.

| Parameters |
|---|---|
| `<I>` | The type of buffer input to the decoder. |
| `<O>` | The type of buffer output from the decoder. |
| `<E extends https://developer.android.com/reference/androidx/media3/decoder/DecoderException>` | The type of exception thrown from the decoder. |

## Summary

| ### Nested types |
|---|
| `public interface https://developer.android.com/reference/androidx/media3/decoder/Decoder.Callback` Callback for asynchronous events. |

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable I` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#dequeueInputBuffer()()` Dequeues the next input buffer to be filled and queued to the decoder. |
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable O` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#dequeueOutputBuffer()()` Dequeues the next output buffer from the decoder. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#flush()()` Flushes the decoder. |
| `abstract https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#getName()()` Returns the name of the decoder. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#queueInputBuffer(I)(I inputBuffer)` Queues an input buffer to the decoder. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#release()()` Releases the decoder. |
| `default void` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#setCallback(androidx.media3.decoder.Decoder.Callback,java.util.concurrent.Executor)(https://developer.android.com/reference/androidx/media3/decoder/Decoder.Callback callback, https://developer.android.com/reference/java/util/concurrent/Executor.html executor)` Sets the callback and executor. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/decoder/Decoder#setOutputStartTimeUs(long)(long outputStartTimeUs)` Sets the timestamp from which output buffers should be produced, in microseconds. |

## Public methods

### dequeueInputBuffer

```
abstract @Nullable I dequeueInputBuffer()
```

Dequeues the next input buffer to be filled and queued to the decoder.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable I` | The input buffer, which will have been cleared, or null if a buffer isn't available. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/Decoder` | If a decoder error has occurred. |

### dequeueOutputBuffer

```
abstract @Nullable O dequeueOutputBuffer()
```

Dequeues the next output buffer from the decoder.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable O` | The output buffer, or null if an output buffer isn't available. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/Decoder` | If a decoder error has occurred. |

### flush

```
abstract void flush()
```

Flushes the decoder. Ownership of dequeued input buffers is returned to the decoder. The caller is still responsible for releasing any dequeued output buffers.

### getName

```
abstract String getName()
```

Returns the name of the decoder.

| Returns |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html` | The name of the decoder. |

### queueInputBuffer

```
abstract void queueInputBuffer(I inputBuffer)
```

Queues an input buffer to the decoder.

| Parameters |
|---|---|
| `I inputBuffer` | The input buffer. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/Decoder` | If a decoder error has occurred. |

### release

```
abstract void release()
```

Releases the decoder. Must be called when the decoder is no longer needed.

### setCallback

```
default void setCallback(Decoder.Callback callback, Executor executor)
```

Sets the callback and executor.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/decoder/Decoder.Callback callback` | The callback to receive events. |
| `https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The executor on which the callback will be invoked. |

### setOutputStartTimeUs

```
abstract void setOutputStartTimeUs(long outputStartTimeUs)
```

Sets the timestamp from which output buffers should be produced, in microseconds.

Any decoded buffer with a timestamp less than `outputStartTimeUs` should be skipped by the implementation and not made available via `https://developer.android.com/reference/androidx/media3/decoder/Decoder#dequeueOutputBuffer()`.

This method must only be called before `https://developer.android.com/reference/androidx/media3/decoder/Decoder#queueInputBuffer(I)` initially or after `https://developer.android.com/reference/androidx/media3/decoder/Decoder#flush()`.

| Parameters |
|---|---|
| `long outputStartTimeUs` | The time from which output buffer should be produced, in microseconds. |