Package com.google.android.exoplayer2.mediacodec

## Class SynchronousMediaCodecAdapter

- java.lang.Object
- - com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter

- All Implemented Interfaces:
    `MediaCodecAdapter`

      public final class SynchronousMediaCodecAdapter
      extends Object
      implements MediaCodecAdapter

  A `MediaCodecAdapter` that operates the underlying `MediaCodec` in synchronous mode.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `SynchronousMediaCodecAdapter.Factory` | A factory for `SynchronousMediaCodecAdapter` instances.

    - ### Nested classes/interfaces inherited from interface com.google.android.exoplayer2.mediacodec.MediaCodecAdapter

      `MediaCodecAdapter.Configuration, MediaCodecAdapter.OnFrameRenderedListener`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `dequeueInputBufferIndex()` | Returns the next available input buffer index from the underlying `MediaCodec` or `MediaCodec.INFO_TRY_AGAIN_LATER` if no such buffer exists.
    `int` | `dequeueOutputBufferIndex​(MediaCodec.BufferInfo bufferInfo)` | Returns the next available output buffer index from the underlying `MediaCodec`.
    `void` | `flush()` | Flushes the adapter and the underlying `MediaCodec`.
    `ByteBuffer` | `getInputBuffer​(int index)` | Returns a writable ByteBuffer object for a dequeued input buffer index.
    `PersistableBundle` | `getMetrics()` | Returns metrics data about the current codec instance.
    `ByteBuffer` | `getOutputBuffer​(int index)` | Returns a read-only ByteBuffer for a dequeued output buffer index.
    `MediaFormat` | `getOutputFormat()` | Gets the `MediaFormat` that was output from the `MediaCodec`.
    `boolean` | `needsReconfiguration()` | Whether the adapter needs to be reconfigured before it is used.
    `void` | `queueInputBuffer​(int index, int offset, int size, long presentationTimeUs, int flags)` | Submit an input buffer for decoding.
    `void` | `queueSecureInputBuffer​(int index, int offset, CryptoInfo info, long presentationTimeUs, int flags)` | Submit an input buffer that is potentially encrypted for decoding.
    `void` | `release()` | Releases the adapter and the underlying `MediaCodec`.
    `void` | `releaseOutputBuffer​(int index, boolean render)` | Returns the buffer to the `MediaCodec`.
    `void` | `releaseOutputBuffer​(int index, long renderTimeStampNs)` | Updates the output buffer's surface timestamp and sends it to the `MediaCodec` to render it on the output surface.
    `void` | `setOnFrameRenderedListener​(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)` | Registers a callback to be invoked when an output frame is rendered on the output surface.
    `void` | `setOutputSurface​(Surface surface)` | Dynamically sets the output surface of a `MediaCodec`.
    `void` | `setParameters​(Bundle params)` | Communicate additional parameter changes to the `MediaCodec` instance.
    `void` | `setVideoScalingMode​(@com.google.android.exoplayer2.C.VideoScalingMode int scalingMode)` | Specifies the scaling mode to use, if a surface was specified when the codec was created.

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

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

- - ### Method Detail

    - #### needsReconfiguration

          public boolean needsReconfiguration()

      Description copied from interface: `MediaCodecAdapter`
      Whether the adapter needs to be reconfigured before it is used.
      Specified by:
        `needsReconfiguration` in interface `MediaCodecAdapter`

    - #### dequeueInputBufferIndex

          public int dequeueInputBufferIndex()

      Description copied from interface: `MediaCodecAdapter`
      Returns the next available input buffer index from the underlying `MediaCodec` or `MediaCodec.INFO_TRY_AGAIN_LATER` if no such buffer exists.
      Specified by:
        `dequeueInputBufferIndex` in interface `MediaCodecAdapter`

    - #### dequeueOutputBufferIndex

          public int dequeueOutputBufferIndex​(MediaCodec.BufferInfo bufferInfo)

      Description copied from interface: `MediaCodecAdapter`
      Returns the next available output buffer index from the underlying `MediaCodec`. If the next available output is a MediaFormat change, it will return `MediaCodec.INFO_OUTPUT_FORMAT_CHANGED` and you should call `MediaCodecAdapter.getOutputFormat()` to get the format. If there is no available output, this method will return `MediaCodec.INFO_TRY_AGAIN_LATER`.
      Specified by:
        `dequeueOutputBufferIndex` in interface `MediaCodecAdapter`

    - #### getOutputFormat

          public MediaFormat getOutputFormat()

      Description copied from interface: `MediaCodecAdapter`
      Gets the `MediaFormat` that was output from the `MediaCodec`.

      Call this method if a previous call to `MediaCodecAdapter.dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)` returned `MediaCodec.INFO_OUTPUT_FORMAT_CHANGED`.

      Specified by:
        `getOutputFormat` in interface `MediaCodecAdapter`

    - #### getInputBuffer

          @Nullable
          public ByteBuffer getInputBuffer​(int index)

      Description copied from interface: `MediaCodecAdapter`
      Returns a writable ByteBuffer object for a dequeued input buffer index.
      Specified by:
        `getInputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.getInputBuffer(int)`

    - #### getOutputBuffer

          @Nullable
          public ByteBuffer getOutputBuffer​(int index)

      Description copied from interface: `MediaCodecAdapter`
      Returns a read-only ByteBuffer for a dequeued output buffer index.
      Specified by:
        `getOutputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.getOutputBuffer(int)`

    - #### queueInputBuffer

          public void queueInputBuffer​(int index,
                                       int offset,
                                       int size,
                                       long presentationTimeUs,
                                       int flags)

      Description copied from interface: `MediaCodecAdapter`
      Submit an input buffer for decoding.

      The `index` must be an input buffer index that has been obtained from a previous call to `MediaCodecAdapter.dequeueInputBufferIndex()`.

      Specified by:
        `queueInputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.queueInputBuffer(int, int, int, long, int)`

    - #### queueSecureInputBuffer

          public void queueSecureInputBuffer​(int index,
                                             int offset,
                                             CryptoInfo info,
                                             long presentationTimeUs,
                                             int flags)

      Description copied from interface: `MediaCodecAdapter`
      Submit an input buffer that is potentially encrypted for decoding.

      The `index` must be an input buffer index that has been obtained from a previous call to `MediaCodecAdapter.dequeueInputBufferIndex()`.

      This method behaves like `MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)`, with the difference that `info` is of type `CryptoInfo` and not `MediaCodec.CryptoInfo`.

      Specified by:
        `queueSecureInputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)`

    - #### releaseOutputBuffer

          public void releaseOutputBuffer​(int index,
                                          boolean render)

      Description copied from interface: `MediaCodecAdapter`
      Returns the buffer to the `MediaCodec`. If the `MediaCodec` was configured with an output surface, setting `render` to `true` will first send the buffer to the output surface. The surface will release the buffer back to the codec once it is no longer used/displayed.
      Specified by:
        `releaseOutputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.releaseOutputBuffer(int, boolean)`

    - #### releaseOutputBuffer

          @RequiresApi(21)
          public void releaseOutputBuffer​(int index,
                                          long renderTimeStampNs)

      Description copied from interface: `MediaCodecAdapter`
      Updates the output buffer's surface timestamp and sends it to the `MediaCodec` to render it on the output surface. If the `MediaCodec` is not configured with an output surface, this call will simply return the buffer to the `MediaCodec`.
      Specified by:
        `releaseOutputBuffer` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.releaseOutputBuffer(int, long)`

    - #### flush

          public void flush()

      Description copied from interface: `MediaCodecAdapter`
      Flushes the adapter and the underlying `MediaCodec`.
      Specified by:
        `flush` in interface `MediaCodecAdapter`

    - #### release

          public void release()

      Description copied from interface: `MediaCodecAdapter`
      Releases the adapter and the underlying `MediaCodec`.
      Specified by:
        `release` in interface `MediaCodecAdapter`

    - #### setOnFrameRenderedListener

          @RequiresApi(23)
          public void setOnFrameRenderedListener​(MediaCodecAdapter.OnFrameRenderedListener listener,
                                                 Handler handler)

      Description copied from interface: `MediaCodecAdapter`
      Registers a callback to be invoked when an output frame is rendered on the output surface.
      Specified by:
        `setOnFrameRenderedListener` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.setOnFrameRenderedListener(android.media.MediaCodec.OnFrameRenderedListener, android.os.Handler)`

    - #### setOutputSurface

          @RequiresApi(23)
          public void setOutputSurface​(Surface surface)

      Description copied from interface: `MediaCodecAdapter`
      Dynamically sets the output surface of a `MediaCodec`.
      Specified by:
        `setOutputSurface` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.setOutputSurface(Surface)`

    - #### setParameters

          @RequiresApi(19)
          public void setParameters​(Bundle params)

      Description copied from interface: `MediaCodecAdapter`
      Communicate additional parameter changes to the `MediaCodec` instance.
      Specified by:
        `setParameters` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.setParameters(Bundle)`

    - #### setVideoScalingMode

          public void setVideoScalingMode​(@VideoScalingMode
                                          @com.google.android.exoplayer2.C.VideoScalingMode int scalingMode)

      Description copied from interface: `MediaCodecAdapter`
      Specifies the scaling mode to use, if a surface was specified when the codec was created.
      Specified by:
        `setVideoScalingMode` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.setVideoScalingMode(int)`

    - #### getMetrics

          @RequiresApi(26)
          public PersistableBundle getMetrics()

      Description copied from interface: `MediaCodecAdapter`
      Returns metrics data about the current codec instance.
      Specified by:
        `getMetrics` in interface `MediaCodecAdapter`
      See Also:
        `MediaCodec.getMetrics()`