Class MediaCodecUtil


  • public final class MediaCodecUtil
    extends Object
    A utility class for querying the available codecs.
    • 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()
        Clears the codec cache.

        This method should only be called in tests.

      • 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.
      • 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 format support are listed first. The returned list is modifiable for convenience.
      • 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.