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()
Clears the codec cache.static Pair<Integer,Integer>
getCodecProfileAndLevel(Format format)
Returns profile and level (as defined byMediaCodecInfo.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)
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.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.
-
-
-
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)
andgetDecoderInfos(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.
-
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
-
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.
-
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 byMediaCodecInfo.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.
-
-