Package com.google.android.exoplayer2.mediacodec

## Class MediaCodecUtil

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

-     public final class MediaCodecUtil
      extends Object

  A utility class for querying the available codecs.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `MediaCodecUtil.DecoderQueryException` | Thrown when an error occurs querying the device for its underlying media capabilities.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static void` | `clearDecoderInfoCache()` |
    `static String` | `getAlternativeCodecMimeType​(Format format)` | Returns an alternative codec MIME type (besides the default `Format.sampleMimeType`) that can be used to decode samples of the provided `Format`.
    `static Pair<Integer,​Integer>` | `getCodecProfileAndLevel​(Format format)` | Returns profile and level (as defined by `MediaCodecInfo.CodecProfileLevel`) corresponding to the codec description string (as defined by RFC 6381) of the given format.
    `static MediaCodecInfo` | `getDecoderInfo​(String mimeType, boolean secure, boolean tunneling)` | Returns information about the preferred decoder for a given mime type.
    `static List<MediaCodecInfo>` | `getDecoderInfos​(String mimeType, boolean secure, boolean tunneling)` | Returns all `MediaCodecInfo`s for the given mime type, in the order given by `MediaCodecList`.
    `static List<MediaCodecInfo>` | `getDecoderInfosSortedByFormatSupport​(List<MediaCodecInfo> decoderInfos, Format format)` | Returns a copy of the provided decoder list sorted such that decoders with functional format support are listed first.
    `static MediaCodecInfo` | `getDecryptOnlyDecoderInfo()` | Returns information about a decoder that will only decrypt data, without decoding it.
    `static int` | `maxH264DecodableFrameSize()` | Returns the maximum frame size supported by the default H264 decoder.
    `static void` | `warmDecoderInfoCache​(String mimeType, boolean secure, boolean tunneling)` | Optional call to warm the codec cache for a given mime type.

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

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

- - ### Method Detail

    - #### warmDecoderInfoCache

          public static void warmDecoderInfoCache​(String mimeType,
                                                  boolean secure,
                                                  boolean tunneling)

      Optional call to warm the codec cache for a given mime type.

      Calling this method may speed up subsequent calls to `getDecoderInfo(String, boolean, boolean)` and `getDecoderInfos(String, boolean, boolean)`.

      Parameters:
        `mimeType` - The mime type.
        `secure` - Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.
        `tunneling` - Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.

    - #### clearDecoderInfoCache

          public static void clearDecoderInfoCache()

    - #### getDecryptOnlyDecoderInfo

          @Nullable
          public static MediaCodecInfo getDecryptOnlyDecoderInfo()
                                                          throws MediaCodecUtil.DecoderQueryException

      Returns information about a decoder that will only decrypt data, without decoding it.
      Returns:
        A `MediaCodecInfo` describing the decoder, or null if no suitable decoder exists.
      Throws:
        `MediaCodecUtil.DecoderQueryException` - If there was an error querying the available decoders.

    - #### getDecoderInfo

          @Nullable
          public static MediaCodecInfo getDecoderInfo​(String mimeType,
                                                      boolean secure,
                                                      boolean tunneling)
                                               throws MediaCodecUtil.DecoderQueryException

      Returns information about the preferred decoder for a given mime type.
      Parameters:
        `mimeType` - The MIME type.
        `secure` - Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.
        `tunneling` - Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.
      Returns:
        A `MediaCodecInfo` describing the decoder, or null if no suitable decoder exists.
      Throws:
        `MediaCodecUtil.DecoderQueryException` - If there was an error querying the available decoders.

    - #### getDecoderInfos

          public static List<MediaCodecInfo> getDecoderInfos​(String mimeType,
                                                             boolean secure,
                                                             boolean tunneling)
                                                      throws MediaCodecUtil.DecoderQueryException

      Returns all `MediaCodecInfo`s for the given mime type, in the order given by `MediaCodecList`.
      Parameters:
        `mimeType` - The MIME type.
        `secure` - Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.
        `tunneling` - Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.
      Returns:
        An unmodifiable list of all `MediaCodecInfo`s for the given mime type, in the order given by `MediaCodecList`.
      Throws:
        `MediaCodecUtil.DecoderQueryException` - If there was an error querying the available decoders.

    - #### getDecoderInfosSortedByFormatSupport

          @CheckResult
          public static List<MediaCodecInfo> getDecoderInfosSortedByFormatSupport​(List<MediaCodecInfo> decoderInfos,
                                                                                  Format format)

      Returns a copy of the provided decoder list sorted such that decoders with functional format support are listed first. The returned list is modifiable for convenience.

    - #### maxH264DecodableFrameSize

          public static int maxH264DecodableFrameSize()
                                               throws MediaCodecUtil.DecoderQueryException

      Returns the maximum frame size supported by the default H264 decoder.
      Returns:
        The maximum frame size for an H264 stream that can be decoded on the device.
      Throws:
        `MediaCodecUtil.DecoderQueryException`

    - #### getCodecProfileAndLevel

          @Nullable
          public static Pair<Integer,​Integer> getCodecProfileAndLevel​(Format format)

      Returns profile and level (as defined by `MediaCodecInfo.CodecProfileLevel`) corresponding to the codec description string (as defined by RFC 6381) of the given format.
      Parameters:
        `format` - Media format with a codec description string, as defined by RFC 6381.
      Returns:
        A pair (profile constant, level constant) if the codec of the `format` is well-formed and recognized, or null otherwise.

    - #### getAlternativeCodecMimeType

          @Nullable
          public static String getAlternativeCodecMimeType​(Format format)

      Returns an alternative codec MIME type (besides the default `Format.sampleMimeType`) that can be used to decode samples of the provided `Format`.
      Parameters:
        `format` - The media format.
      Returns:
        An alternative MIME type of a codec that be used decode samples of the provided `Format` (besides the default `Format.sampleMimeType`), or null if no such alternative exists.