Package com.google.android.exoplayer2.transformer

## Class DefaultCodec

- java.lang.Object
- - com.google.android.exoplayer2.transformer.DefaultCodec

- All Implemented Interfaces:
    `Codec`

      public final class DefaultCodec
      extends Object
      implements Codec

  A default `Codec` implementation that uses `MediaCodec`.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.transformer.Codec

      `Codec.DecoderFactory, Codec.EncoderFactory`

  - ### Field Summary

    - ### Fields inherited from interface com.google.android.exoplayer2.transformer.Codec

      `UNLIMITED_PENDING_FRAME_COUNT`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultCodec​(Context context, Format configurationFormat, MediaFormat configurationMediaFormat, String mediaCodecName, boolean isDecoder, Surface outputSurface)` | Creates a `DefaultCodec`.

  - ### Method Summary

    All Methods Instance Methods Concrete 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.
    `int` | `getMaxPendingFrameCount()` | Returns the maximum number of frames that may be pending in the output `Codec` at a time, or `Codec.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.

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

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

- - ### Constructor Detail

    - #### DefaultCodec

          public DefaultCodec​(Context context,
                              Format configurationFormat,
                              MediaFormat configurationMediaFormat,
                              String mediaCodecName,
                              boolean isDecoder,
                              @Nullable
                              Surface outputSurface)
                       throws TransformationException

      Creates a `DefaultCodec`.
      Parameters:
        `context` - The `Context`.
        `configurationFormat` - The `Format` to configure the `DefaultCodec`. See `getConfigurationFormat()`. The `sampleMimeType` must not be `null`.
        `configurationMediaFormat` - The `MediaFormat` to configure the underlying `MediaCodec`.
        `mediaCodecName` - The name of a specific `MediaCodec` to instantiate.
        `isDecoder` - Whether the `DefaultCodec` is intended as a decoder.
        `outputSurface` - The output `Surface` if the `MediaCodec` outputs to a surface.
      Throws:
        `TransformationException`

  - ### Method Detail

    - #### getConfigurationFormat

          public Format getConfigurationFormat()

      Description copied from interface: `Codec`
      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.

      Specified by:
        `getConfigurationFormat` in interface `Codec`

    - #### getInputSurface

          public Surface getInputSurface()

      Description copied from interface: `Codec`
      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.

      Specified by:
        `getInputSurface` in interface `Codec`

    - #### getMaxPendingFrameCount

          public int getMaxPendingFrameCount()

      Description copied from interface: `Codec`
      Returns the maximum number of frames that may be pending in the output `Codec` at a time, or `Codec.UNLIMITED_PENDING_FRAME_COUNT` if it's not necessary to enforce a limit.
      Specified by:
        `getMaxPendingFrameCount` in interface `Codec`

    - #### maybeDequeueInputBuffer

          @EnsuresNonNullIf(expression="#1.data",
                            result=true)
          public boolean maybeDequeueInputBuffer​(DecoderInputBuffer inputBuffer)
                                          throws TransformationException

      Description copied from interface: `Codec`
      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.

      Specified by:
        `maybeDequeueInputBuffer` in interface `Codec`
      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

          public void queueInputBuffer​(DecoderInputBuffer inputBuffer)
                                throws TransformationException

      Description copied from interface: `Codec`
      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.

      Specified by:
        `queueInputBuffer` in interface `Codec`
      Parameters:
        `inputBuffer` - The input buffer.
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### signalEndOfInputStream

          public void signalEndOfInputStream()
                                      throws TransformationException

      Description copied from interface: `Codec`
      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.

      Specified by:
        `signalEndOfInputStream` in interface `Codec`
      Throws:
        `TransformationException` - If the underlying video encoder encounters a problem.

    - #### getOutputFormat

          @Nullable
          public Format getOutputFormat()
                                 throws TransformationException

      Description copied from interface: `Codec`
      Returns the current output format, or `null` if unavailable.
      Specified by:
        `getOutputFormat` in interface `Codec`
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### getOutputBuffer

          @Nullable
          public ByteBuffer getOutputBuffer()
                                     throws TransformationException

      Description copied from interface: `Codec`
      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`.

      Specified by:
        `getOutputBuffer` in interface `Codec`
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### getOutputBufferInfo

          @Nullable
          public MediaCodec.BufferInfo getOutputBufferInfo()
                                                    throws TransformationException

      Description copied from interface: `Codec`
      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 `Codec.getOutputBuffer()` returns null.

      Specified by:
        `getOutputBufferInfo` in interface `Codec`
      Throws:
        `TransformationException` - If the underlying decoder or encoder encounters a problem.

    - #### releaseOutputBuffer

          public void releaseOutputBuffer​(boolean render)
                                   throws TransformationException

      Description copied from interface: `Codec`
      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.

      Specified by:
        `releaseOutputBuffer` in interface `Codec`
      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

          public boolean isEnded()

      Description copied from interface: `Codec`
      Returns whether the `Codec`'s output stream has ended, and no more data can be dequeued.
      Specified by:
        `isEnded` in interface `Codec`

    - #### release

          public void release()

      Description copied from interface: `Codec`
      Releases the `Codec`.
      Specified by:
        `release` in interface `Codec`

    - #### getName

          public String getName()

      Returns the name of the underlying codec.

      This name is of the actual codec, which may not be the same as the `mediaCodecName` passed to `DefaultCodec(Context, Format, MediaFormat, String, boolean, Surface)`.

      Specified by:
        `getName` in interface `Codec`
      See Also:
        `MediaCodec.getCanonicalName()`