# 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
interface Decoder<I, O, E : DecoderException?>
```

<br />

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

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/image/ImageDecoder` | A `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder` implementation for images. |
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder` | Base class for `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/extractor/text/SubtitleDecoder` | Decodes `https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/Subtitle`s from `https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/SubtitleInputBuffer`s. |

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

|---|---|
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/extractor/text/cea/Cea608Decoder` | A `https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/SubtitleDecoder` for CEA-608 (also known as "line 21 captions" and "EIA-608"). |
| `https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/cea/Cea708Decoder` | A `https://developer.android.com/reference/kotlin/androidx/media3/extractor/text/SubtitleDecoder` for CEA-708 (also known as "EIA-708"). |
| `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/image/ExternallyLoadedImageDecoder` | An `https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/image/ImageDecoder` for externally loaded images. |
| `https://developer.android.com/reference/kotlin/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 : https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderException?>` | The type of exception thrown from the decoder. |

## Summary

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

| ### Public functions |
|---|---|
| `I?` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#dequeueInputBuffer()()` Dequeues the next input buffer to be filled and queued to the decoder. |
| `O?` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#dequeueOutputBuffer()()` Dequeues the next output buffer from the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#flush()()` Flushes the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#getName()()` Returns the name of the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#queueInputBuffer(I)(inputBuffer: I!)` Queues an input buffer to the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#release()()` Releases the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#setCallback(androidx.media3.decoder.Decoder.Callback,java.util.concurrent.Executor)(callback: https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder.Callback!, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!)` Sets the callback and executor. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder#setOutputStartTimeUs(long)(outputStartTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Sets the timestamp from which output buffers should be produced, in microseconds. |

## Public functions

### dequeueInputBuffer

```
fun dequeueInputBuffer(): I?
```

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

| Returns |
|---|---|
| `I?` | The input buffer, which will have been cleared, or null if a buffer isn't available. |

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

### dequeueOutputBuffer

```
fun dequeueOutputBuffer(): O?
```

Dequeues the next output buffer from the decoder.

| Returns |
|---|---|
| `O?` | The output buffer, or null if an output buffer isn't available. |

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

### flush

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

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

```
fun getName(): String!
```

Returns the name of the decoder.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The name of the decoder. |

### queueInputBuffer

```
fun queueInputBuffer(inputBuffer: I!): Unit
```

Queues an input buffer to the decoder.

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

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

### release

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

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

### setCallback

```
fun setCallback(callback: Decoder.Callback!, executor: Executor!): Unit
```

Sets the callback and executor.

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

### setOutputStartTimeUs

```
fun setOutputStartTimeUs(outputStartTimeUs: Long): Unit
```

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/kotlin/androidx/media3/decoder/Decoder#dequeueOutputBuffer()`.

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

| Parameters |
|---|---|
| `outputStartTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The time from which output buffer should be produced, in microseconds. |