Package com.google.android.exoplayer2.decoder

## Class SimpleDecoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>

- java.lang.Object
- - com.google.android.exoplayer2.decoder.SimpleDecoder<I,​O,​E>

- All Implemented Interfaces:
    `Decoder<I,​O,​E>`
  Direct Known Subclasses:
    `FlacDecoder`, `Gav1Decoder`, `OpusDecoder`, `SimpleSubtitleDecoder`, `VpxDecoder`

      public abstract class SimpleDecoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>
      extends Object
      implements Decoder<I,​O,​E>

  Base class for `Decoder`s that use their own decode thread and decode each input buffer immediately into a corresponding output buffer.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `SimpleDecoder​(I[] inputBuffers, O[] outputBuffers)` |

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `protected abstract I` | `createInputBuffer()` | Creates a new input buffer.
    `protected abstract O` | `createOutputBuffer()` | Creates a new output buffer.
    `protected abstract E` | `createUnexpectedDecodeException​(Throwable error)` | Creates an exception to propagate for an unexpected decode error.
    `protected abstract E` | `decode​(I inputBuffer, O outputBuffer, boolean reset)` | Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`.
    `I` | `dequeueInputBuffer()` | Dequeues the next input buffer to be filled and queued to the decoder.
    `O` | `dequeueOutputBuffer()` | Dequeues the next output buffer from the decoder.
    `void` | `flush()` | Flushes the decoder.
    `void` | `queueInputBuffer​(I inputBuffer)` | Queues an input buffer to the decoder.
    `void` | `release()` | Releases the decoder.
    `protected void` | `releaseOutputBuffer​(O outputBuffer)` | Releases an output buffer back to the decoder.
    `protected void` | `setInitialInputBufferSize​(int size)` | Sets the initial size of each input buffer.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.google.android.exoplayer2.decoder.Decoder

      `getName`

- - ### Constructor Detail

    - #### SimpleDecoder

          protected SimpleDecoder​(I[] inputBuffers,
                                  O[] outputBuffers)

      Parameters:
        `inputBuffers` - An array of nulls that will be used to store references to input buffers.
        `outputBuffers` - An array of nulls that will be used to store references to output buffers.

  - ### Method Detail

    - #### setInitialInputBufferSize

          protected final void setInitialInputBufferSize​(int size)

      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 `dequeueInputBuffer()`.

      Parameters:
        `size` - The required input buffer size.

    - #### dequeueInputBuffer

          @Nullable
          public final I dequeueInputBuffer()
                                     throws E extends DecoderException

      Description copied from interface: `Decoder`
      Dequeues the next input buffer to be filled and queued to the decoder.
      Specified by:
        `dequeueInputBuffer` in interface `Decoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>`
      Returns:
        The input buffer, which will have been cleared, or null if a buffer isn't available.
      Throws:
        `E` - If a decoder error has occurred.
        `E extends DecoderException`

    - #### queueInputBuffer

          public final void queueInputBuffer​(I inputBuffer)
                                      throws E extends DecoderException

      Description copied from interface: `Decoder`
      Queues an input buffer to the decoder.
      Specified by:
        `queueInputBuffer` in interface `Decoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>`
      Parameters:
        `inputBuffer` - The input buffer.
      Throws:
        `E` - If a decoder error has occurred.
        `E extends DecoderException`

    - #### dequeueOutputBuffer

          @Nullable
          public final O dequeueOutputBuffer()
                                      throws E extends DecoderException

      Description copied from interface: `Decoder`
      Dequeues the next output buffer from the decoder.
      Specified by:
        `dequeueOutputBuffer` in interface `Decoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>`
      Returns:
        The output buffer, or null if an output buffer isn't available.
      Throws:
        `E` - If a decoder error has occurred.
        `E extends DecoderException`

    - #### releaseOutputBuffer

          @CallSuper
          protected void releaseOutputBuffer​(O outputBuffer)

      Releases an output buffer back to the decoder.
      Parameters:
        `outputBuffer` - The output buffer being released.

    - #### flush

          public final void flush()

      Description copied from interface: `Decoder`
      Flushes the decoder. Ownership of dequeued input buffers is returned to the decoder. The caller is still responsible for releasing any dequeued output buffers.
      Specified by:
        `flush` in interface `Decoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>`

    - #### release

          @CallSuper
          public void release()

      Description copied from interface: `Decoder`
      Releases the decoder. Must be called when the decoder is no longer needed.
      Specified by:
        `release` in interface `Decoder<I extends DecoderInputBuffer,​O extends DecoderOutputBuffer,​E extends DecoderException>`

    - #### createInputBuffer

          protected abstract I createInputBuffer()

      Creates a new input buffer.

    - #### createOutputBuffer

          protected abstract O createOutputBuffer()

      Creates a new output buffer.

    - #### createUnexpectedDecodeException

          protected abstract E createUnexpectedDecodeException​(Throwable error)

      Creates an exception to propagate for an unexpected decode error.
      Parameters:
        `error` - The unexpected decode error.
      Returns:
        The exception to propagate.

    - #### decode

          @Nullable
          protected abstract E decode​(I inputBuffer,
                                      O outputBuffer,
                                      boolean reset)

      Decodes the `inputBuffer` and stores any decoded output in `outputBuffer`.
      Parameters:
        `inputBuffer` - The buffer to decode.
        `outputBuffer` - The output buffer to store decoded data. The flag `C.BUFFER_FLAG_DECODE_ONLY` will be set if the same flag is set on `inputBuffer`, but may be set/unset as required. If the flag is set when the call returns then the output buffer will not be made available to dequeue. The output buffer may not have been populated in this case.
        `reset` - Whether the decoder must be reset before decoding.
      Returns:
        A decoder exception if an error occurred, or null if decoding was successful.