# SimpleDecoder

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/SimpleDecoder.java+class:androidx.media3.decoder.SimpleDecoder)

*** ** * ** ***


```
@UnstableApi
abstract class SimpleDecoder<I : DecoderInputBuffer?, O : DecoderOutputBuffer?, E : DecoderException?> : Decoder<I!, O!, E!>
```

<br />

Known direct subclasses [BitmapFactoryImageDecoder](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/image/BitmapFactoryImageDecoder), [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/SimpleSubtitleDecoder` | Base class for subtitle parsers that use their own decode thread. |

*** ** * ** ***

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.

## Summary

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#SimpleDecoder(I[],O[])(inputBuffers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<I!>!, outputBuffers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<O!>!)` |

| ### Public functions |
|---|---|
| `I?` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#dequeueInputBuffer()()` Dequeues the next input buffer to be filled and queued to the decoder. |
| `O?` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#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/SimpleDecoder#flush()()` Flushes the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#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/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#release()()` Releases the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#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/SimpleDecoder#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. |

| ### Protected functions |
|---|---|
| `abstract I!` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#createInputBuffer()()` Creates a new input buffer. |
| `abstract O!` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#createOutputBuffer()()` Creates a new output buffer. |
| `abstract E!` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#createUnexpectedDecodeException(java.lang.Throwable)(error: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html!)` Creates an exception to propagate for an unexpected decode error. |
| `abstract E?` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#decode(I,O,boolean)(inputBuffer: I!, outputBuffer: O!, reset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#isAtLeastOutputStartTimeUs(long)(timeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns whether a sample time is greater or equal to the `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#setOutputStartTimeUs(long)`, if set. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#releaseOutputBuffer(O)(outputBuffer: O!)` Releases an output buffer back to the decoder. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#setInitialInputBufferSize(int)(size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the initial size of each input buffer. |

### Inherited functions

From [androidx.media3.decoder.Decoder](https://developer.android.com/reference/kotlin/androidx/media3/decoder/Decoder) `abstract 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.

## Protected constructors

### SimpleDecoder

```
protected SimpleDecoder(inputBuffers: Array<I!>!, outputBuffers: Array<O!>!)
```

| Parameters |
|---|---|
| `inputBuffers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<I!>!` | An array of nulls that will be used to store references to input buffers. |
| `outputBuffers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<O!>!` | An array of nulls that will be used to store references to output buffers. |

## 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. |
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder` |   |

### 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. |
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder` |   |

### 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.

### 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. |
| `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder` |   |

### release

```
@CallSuper
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. |

## Protected functions

### createInputBuffer

```
protected abstract fun createInputBuffer(): I!
```

Creates a new input buffer.

### createOutputBuffer

```
protected abstract fun createOutputBuffer(): O!
```

Creates a new output buffer.

### createUnexpectedDecodeException

```
protected abstract fun createUnexpectedDecodeException(error: Throwable!): E!
```

Creates an exception to propagate for an unexpected decode error.

| Parameters |
|---|---|
| `error: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html!` | The unexpected decode error. |

| Returns |
|---|---|
| `E!` | The exception to propagate. |

### decode

```
protected abstract fun decode(inputBuffer: I!, outputBuffer: O!, reset: Boolean): E?
```

Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`.

| Parameters |
|---|---|
| `inputBuffer: I!` | The buffer to decode. |
| `outputBuffer: O!` | The output buffer to store decoded data. The output buffer will not be made available to dequeue if its `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderOutputBuffer#timeUs()` is not `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#isAtLeastOutputStartTimeUs(long)` or when it's marked with `https://developer.android.com/reference/kotlin/androidx/media3/decoder/DecoderOutputBuffer#shouldBeSkipped()`. The output buffer may not have been populated in these cases. |
| `reset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the decoder must be reset before decoding. |

| Returns |
|---|---|
| `E?` | A decoder exception if an error occurred, or null if decoding was successful. |

### isAtLeastOutputStartTimeUs

```
protected fun isAtLeastOutputStartTimeUs(timeUs: Long): Boolean
```

Returns whether a sample time is greater or equal to the `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#setOutputStartTimeUs(long)`, if set.

If this method returns false, the buffer will not be made available as an output buffer.

| Parameters |
|---|---|
| `timeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The buffer time, in microseconds. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the buffer time is greater or equal to the output start time, or `true` if the output start time is not set. |

### releaseOutputBuffer

```
@CallSuper
protected fun releaseOutputBuffer(outputBuffer: O!): Unit
```

Releases an output buffer back to the decoder.

| Parameters |
|---|---|
| `outputBuffer: O!` | The output buffer being released. |

### setInitialInputBufferSize

```
protected fun setInitialInputBufferSize(size: Int): Unit
```

Sets the initial size of each input buffer.

This method should only be called before the decoder is used (i.e. before the first call to `https://developer.android.com/reference/kotlin/androidx/media3/decoder/SimpleDecoder#dequeueInputBuffer()`.

| Parameters |
|---|---|
| `size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The required input buffer size. |