Package com.google.android.exoplayer2.transformer

## Interface Codec

- All Known Implementing Classes:
    `DefaultCodec`

      public interface Codec

  Provides a layer of abstraction for interacting with decoders and encoders.

  `DecoderInputBuffers` are used as both decoders' and encoders' input buffers.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface | Description
    --- | --- | ---
    `static interface` | `Codec.DecoderFactory` | A factory for decoder instances.
    `static interface` | `Codec.EncoderFactory` | A factory for encoder instances.

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static int` | `UNLIMITED_PENDING_FRAME_COUNT` | Default value for the pending frame count, which represents applying no limit.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Format` | `getConfigurationFormat()` | Returns the `Format` used for configuring the `Codec`.
    `Surface` | `getInputSurface()` | Returns the input `Surface` of an underlying video encoder.
    `default int` | `getMaxPendingFrameCount()` | Returns the maximum number of frames that may be pending in the output `Codec` at a time, or `UNLIMITED_PENDING_FRAME_COUNT` if it's not necessary to enforce a limit.
    `String` | `getName()` | Returns the name of the underlying codec.
    `ByteBuffer` | `getOutputBuffer()` | Returns the current output `ByteBuffer`, or `null` if unavailable.
    `MediaCodec.BufferInfo` | `getOutputBufferInfo()` | Returns the `MediaCodec.BufferInfo` associated with the current output buffer, or `null` if there is no output buffer available.
    `Format` | `getOutputFormat()` | Returns the current output format, or `null` if unavailable.
    `boolean` | `isEnded()` | Returns whether the `Codec`'s output stream has ended, and no more data can be dequeued.
    `boolean` | `maybeDequeueInputBuffer​(DecoderInputBuffer inputBuffer)` | Dequeues a writable input buffer, if available.
    `void` | `queueInputBuffer​(DecoderInputBuffer inputBuffer)` | Queues an input buffer to the `Codec`.
    `void` | `release()` | Releases the `Codec`.
    `void` | `releaseOutputBuffer​(boolean render)` | Releases the current output buffer.
    `void` | `signalEndOfInputStream()` | Signals end-of-stream on input to a video encoder.

- - ### Field Detail

    - #### UNLIMITED_PENDING_FRAME_COUNT

          static final int UNLIMITED_PENDING_FRAME_COUNT

      Default value for the pending frame count, which represents applying no limit.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### getConfigurationFormat

          Format getConfigurationFormat()

      Returns the `Format` used for configuring the `Codec`.

      The configuration `Format` is the input `Format` used by the `Codec.DecoderFactory` or output `Format` used by the `Codec.EncoderFactory` for selecting and configuring the underlying decoder or encoder.

    - #### getName

          String getName()

      Returns the name of the underlying codec.

    - #### getInputSurface

          Surface getInputSurface()

      Returns the input `Surface` of an underlying video encoder.

      This method must only be called on video encoders because audio/video decoders and audio encoders don't use a `Surface` as input.

    - #### getMaxPendingFrameCount

          default int getMaxPendingFrameCount()

      Returns the maximum number of frames that may be pending in the output `Codec` at a time, or `UNLIMITED_PENDING_FRAME_COUNT` if it's not necessary to enforce a limit.

    - #### maybeDequeueInputBuffer

          boolean maybeDequeueInputBuffer​(DecoderInputBuffer inputBuffer)
                                   throws TransformationException

      Dequeues a writable input buffer, if available.

      This method must not be called from video encoders because they must use a `Surface` to receive input.

      Parameters:
        `inputBuffer` - The buffer where the dequeued buffer data is stored, at `inputBuffer.data`.
      Returns:
        Whether an input buffer is ready to be used.
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### queueInputBuffer

          void queueInputBuffer​(DecoderInputBuffer inputBuffer)
                         throws TransformationException

      Queues an input buffer to the `Codec`. No buffers may be queued after end of stream buffer has been queued.

      This method must not be called from video encoders because they must use a `Surface` to receive input.

      Parameters:
        `inputBuffer` - The input buffer.
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### signalEndOfInputStream

          void signalEndOfInputStream()
                               throws TransformationException

      Signals end-of-stream on input to a video encoder.

      This method must only be called on video encoders because they must use a `Surface` as input. For audio/video decoders or audio encoders, the `C.BUFFER_FLAG_END_OF_STREAM` flag should be set on the last input buffer queued.

      Throws:
        `TransformationException` - If the underlying video encoder encounters a problem.

    - #### getOutputFormat

          @Nullable
          Format getOutputFormat()
                          throws TransformationException

      Returns the current output format, or `null` if unavailable.
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### getOutputBuffer

          @Nullable
          ByteBuffer getOutputBuffer()
                              throws TransformationException

      Returns the current output `ByteBuffer`, or `null` if unavailable.

      This method must not be called on video decoders because they must output to a `Surface`.

      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### getOutputBufferInfo

          @Nullable
          MediaCodec.BufferInfo getOutputBufferInfo()
                                             throws TransformationException

      Returns the `MediaCodec.BufferInfo` associated with the current output buffer, or `null` if there is no output buffer available.

      This method returns `null` if and only if `getOutputBuffer()` returns null.

      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### releaseOutputBuffer

          void releaseOutputBuffer​(boolean render)
                            throws TransformationException

      Releases the current output buffer.

      Only set `render` to `true` when the `Codec` is a video decoder. Setting `render` to `true` will first render the buffer to the output surface. In this case, the surface will release the buffer back to the `Codec` once it is no longer used/displayed.

      This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.

      Parameters:
        `render` - Whether the buffer needs to be rendered to the output `Surface`.
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### isEnded

          boolean isEnded()

      Returns whether the `Codec`'s output stream has ended, and no more data can be dequeued.

    - #### release

          void release()

      Releases the `Codec`.