Package com.google.android.exoplayer2.util

## Class MediaFormatUtil

- java.lang.Object
- - com.google.android.exoplayer2.util.MediaFormatUtil

-     public final class MediaFormatUtil
      extends Object

  Helper class containing utility methods for managing `MediaFormat` instances.

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `KEY_MAX_BIT_RATE` | The `MediaFormat` key for the maximum bitrate in bits per second.
    `static String` | `KEY_PCM_ENCODING_EXTENDED` | Custom `MediaFormat` key associated with an integer representing the PCM encoding.
    `static String` | `KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT` | Custom `MediaFormat` key associated with a float representing the ratio between a pixel's width and height.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static MediaFormat` | `createMediaFormatFromFormat​(Format format)` | Returns a `MediaFormat` representing the given ExoPlayer `Format`.
    `static byte[]` | `getArray​(ByteBuffer byteBuffer)` |
    `static ColorInfo` | `getColorInfo​(MediaFormat mediaFormat)` | Creates and returns a `ColorInfo`, if a valid instance is described in the `MediaFormat`.
    `static void` | `maybeSetByteBuffer​(MediaFormat format, String key, byte[] value)` | Sets a `MediaFormat` `ByteBuffer` value.
    `static void` | `maybeSetColorInfo​(MediaFormat format, ColorInfo colorInfo)` | Sets a `MediaFormat`'s color information.
    `static void` | `maybeSetFloat​(MediaFormat format, String key, float value)` | Sets a `MediaFormat` float value.
    `static void` | `maybeSetInteger​(MediaFormat format, String key, int value)` | Sets a `MediaFormat` integer value.
    `static void` | `maybeSetString​(MediaFormat format, String key, String value)` | Sets a `MediaFormat` `String` value.
    `static void` | `setCsdBuffers​(MediaFormat format, List<byte[]> csdBuffers)` | Sets a `MediaFormat`'s codec specific data buffers.

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

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

- - ### Field Detail

    - #### KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT

          public static final String KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT

      Custom `MediaFormat` key associated with a float representing the ratio between a pixel's width and height.
      See Also:
        Constant Field Values

    - #### KEY_PCM_ENCODING_EXTENDED

          public static final String KEY_PCM_ENCODING_EXTENDED

      Custom `MediaFormat` key associated with an integer representing the PCM encoding.

      Equivalent to `MediaFormat.KEY_PCM_ENCODING`, except it allows additional values defined by `C.PcmEncoding`, including `C.ENCODING_PCM_16BIT_BIG_ENDIAN`, `C.ENCODING_PCM_24BIT`, and `C.ENCODING_PCM_32BIT`.

      See Also:
        Constant Field Values

    - #### KEY_MAX_BIT_RATE

          public static final String KEY_MAX_BIT_RATE

      The `MediaFormat` key for the maximum bitrate in bits per second.

      The associated value is an integer.

      The key string constant is the same as `MediaFormat#KEY_MAX_BITRATE`. Values for it are already returned by the framework MediaExtractor; the key is a hidden field in `MediaFormat` though, which is why it's being replicated here.

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### createMediaFormatFromFormat

          public static MediaFormat createMediaFormatFromFormat​(Format format)

      Returns a `MediaFormat` representing the given ExoPlayer `Format`.

      May include the following custom keys:

      - `KEY_PIXEL_WIDTH_HEIGHT_RATIO_FLOAT`.
      - `KEY_PCM_ENCODING_EXTENDED`.

    - #### maybeSetString

          public static void maybeSetString​(MediaFormat format,
                                            String key,
                                            @Nullable
                                            String value)

      Sets a `MediaFormat` `String` value. Does nothing if `value` is null.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `key` - The key to set.
        `value` - The value to set.

    - #### setCsdBuffers

          public static void setCsdBuffers​(MediaFormat format,
                                           List<byte[]> csdBuffers)

      Sets a `MediaFormat`'s codec specific data buffers.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `csdBuffers` - The csd buffers to set.

    - #### maybeSetInteger

          public static void maybeSetInteger​(MediaFormat format,
                                             String key,
                                             int value)

      Sets a `MediaFormat` integer value. Does nothing if `value` is `Format.NO_VALUE`.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `key` - The key to set.
        `value` - The value to set.

    - #### maybeSetFloat

          public static void maybeSetFloat​(MediaFormat format,
                                           String key,
                                           float value)

      Sets a `MediaFormat` float value. Does nothing if `value` is `Format.NO_VALUE`.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `key` - The key to set.
        `value` - The value to set.

    - #### maybeSetByteBuffer

          public static void maybeSetByteBuffer​(MediaFormat format,
                                                String key,
                                                @Nullable
                                                byte[] value)

      Sets a `MediaFormat` `ByteBuffer` value. Does nothing if `value` is null.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `key` - The key to set.
        `value` - The byte array that will be wrapped to obtain the value.

    - #### maybeSetColorInfo

          public static void maybeSetColorInfo​(MediaFormat format,
                                               @Nullable
                                               ColorInfo colorInfo)

      Sets a `MediaFormat`'s color information. Does nothing if `colorInfo` is null.
      Parameters:
        `format` - The `MediaFormat` being configured.
        `colorInfo` - The color info to set.

    - #### getColorInfo

          @Nullable
          public static ColorInfo getColorInfo​(MediaFormat mediaFormat)

      Creates and returns a `ColorInfo`, if a valid instance is described in the `MediaFormat`.

    - #### getArray

          public static byte[] getArray​(ByteBuffer byteBuffer)