@UnstableApi
class MediaCodecUtil


A utility class for querying the available codecs.

Summary

Nested types

Thrown when an error occurs querying the device for its underlying media capabilities.

Public functions

synchronized java-static Unit
java-static String?

Returns an alternative codec MIME type (besides the default sampleMimeType) that can be used to decode samples of the provided Format.

java-static (Mutable)List<MediaCodecInfo!>!
getAlternativeDecoderInfos(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean,
    requiresTunnelingDecoder: Boolean
)

Returns a list of decoders for alternative MIME types that can decode samples of the provided Format, in the priority order specified by the MediaCodecSelector.

java-static Pair<Int!, Int!>?
@InlineMe(replacement = "CodecSpecificDataUtil.getCodecProfileAndLevel(format)", imports = [""androidx.media3.common.util.CodecSpecificDataUtil""])
getCodecProfileAndLevel(format: Format!)

This function is deprecated.

Use getCodecProfileAndLevel.

java-static MediaCodecInfo?
getDecoderInfo(mimeType: String!, secure: Boolean, tunneling: Boolean)

Returns information about the preferred decoder for a given MIME type.

synchronized java-static (Mutable)List<MediaCodecInfo!>!
getDecoderInfos(mimeType: String!, secure: Boolean, tunneling: Boolean)

Returns all MediaCodecInfos for the given MIME type, in the order given by .

java-static (Mutable)List<MediaCodecInfo!>!
@RequiresNonNull(value = "#2.sampleMimeType")
getDecoderInfosSoftMatch(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean,
    requiresTunnelingDecoder: Boolean
)

Returns a list of decoders that can decode media in the specified format, in the priority order specified by the MediaCodecSelector.

java-static (Mutable)List<MediaCodecInfo!>!
getDecoderInfosSortedByFormatSupport(
    decoderInfos: (Mutable)List<MediaCodecInfo!>!,
    format: Format!
)

Returns a copy of the provided decoder list sorted such that decoders with functional format support are listed first.

java-static MediaCodecInfo?

Returns information about a decoder that will only decrypt data, without decoding it.

java-static Pair<Int!, Int!>?

Returns profile and level (as defined by CodecProfileLevel) corresponding to the base layer (for the case of falling back to single-layer HEVC from L-HEVC).

java-static Int

Returns the maximum frame size supported by the default H264 decoder.

java-static Unit
warmDecoderInfoCache(mimeType: String!, secure: Boolean, tunneling: Boolean)

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

Public functions

clearDecoderInfoCache

@VisibleForTesting
synchronized java-static fun clearDecoderInfoCache(): Unit

getAlternativeCodecMimeType

java-static fun getAlternativeCodecMimeType(format: Format!): String?

Returns an alternative codec MIME type (besides the default sampleMimeType) that can be used to decode samples of the provided Format.

Parameters
format: Format!

The media format.

Returns
String?

An alternative MIME type of a codec that be used decode samples of the provided Format (besides the default sampleMimeType), or null if no such alternative exists.

getAlternativeDecoderInfos

java-static fun getAlternativeDecoderInfos(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean,
    requiresTunnelingDecoder: Boolean
): (Mutable)List<MediaCodecInfo!>!

Returns a list of decoders for alternative MIME types that can decode samples of the provided Format, in the priority order specified by the MediaCodecSelector.

Since the MediaCodecSelector only has access to sampleMimeType, the list is not ordered to account for whether each decoder supports the details of the format (e.g., taking into account the format's profile, level, resolution and so on). getDecoderInfosSortedByFormatSupport can be used to further sort the list into an order where decoders that fully support the format come first.

Parameters
mediaCodecSelector: MediaCodecSelector!

The decoder selector.

format: Format!

The Format for which an alternative decoder is required.

requiresSecureDecoder: Boolean

Whether a secure decoder is required.

requiresTunnelingDecoder: Boolean

Whether a tunneling decoder is required.

Returns
(Mutable)List<MediaCodecInfo!>!

A list of MediaCodecInfos corresponding to alternative decoders. May be empty.

Throws
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException

Thrown if there was an error querying decoders.

getCodecProfileAndLevel

@InlineMe(replacement = "CodecSpecificDataUtil.getCodecProfileAndLevel(format)", imports = [""androidx.media3.common.util.CodecSpecificDataUtil""])
java-static fun getCodecProfileAndLevel(format: Format!): Pair<Int!, Int!>?

getDecoderInfo

java-static fun getDecoderInfo(mimeType: String!, secure: Boolean, tunneling: Boolean): MediaCodecInfo?

Returns information about the preferred decoder for a given MIME type.

Parameters
mimeType: String!

The MIME type.

secure: Boolean

Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.

tunneling: Boolean

Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.

Returns
MediaCodecInfo?

A MediaCodecInfo describing the decoder, or null if no suitable decoder exists.

Throws
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException

If there was an error querying the available decoders.

getDecoderInfos

synchronized java-static fun getDecoderInfos(mimeType: String!, secure: Boolean, tunneling: Boolean): (Mutable)List<MediaCodecInfo!>!

Returns all MediaCodecInfos for the given MIME type, in the order given by .

Parameters
mimeType: String!

The MIME type.

secure: Boolean

Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.

tunneling: Boolean

Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.

Returns
(Mutable)List<MediaCodecInfo!>!

An unmodifiable list of all MediaCodecInfos for the given MIME type, in the order given by MediaCodecList.

Throws
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException

If there was an error querying the available decoders.

getDecoderInfosSoftMatch

@RequiresNonNull(value = "#2.sampleMimeType")
java-static fun getDecoderInfosSoftMatch(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean,
    requiresTunnelingDecoder: Boolean
): (Mutable)List<MediaCodecInfo!>!

Returns a list of decoders that can decode media in the specified format, in the priority order specified by the MediaCodecSelector.

Since the MediaCodecSelector only has access to sampleMimeType, the list is not ordered to account for whether each decoder supports the details of the format (e.g., taking into account the format's profile, level, resolution and so on). getDecoderInfosSortedByFormatSupport can be used to further sort the list into an order where decoders that fully support the format come first.

This list is more complete than getDecoderInfos, as it also considers alternative MIME types that are a close match using getAlternativeCodecMimeType.

Parameters
mediaCodecSelector: MediaCodecSelector!

The decoder selector.

format: Format!

The Format for which a decoder is required.

requiresSecureDecoder: Boolean

Whether a secure decoder is required.

requiresTunnelingDecoder: Boolean

Whether a tunneling decoder is required.

Returns
(Mutable)List<MediaCodecInfo!>!

A list of MediaCodecInfos corresponding to decoders. May be empty.

Throws
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException

Thrown if there was an error querying decoders.

getDecoderInfosSortedByFormatSupport

java-static fun getDecoderInfosSortedByFormatSupport(
    decoderInfos: (Mutable)List<MediaCodecInfo!>!,
    format: Format!
): (Mutable)List<MediaCodecInfo!>!

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.

getDecryptOnlyDecoderInfo

java-static fun getDecryptOnlyDecoderInfo(): MediaCodecInfo?

Returns information about a decoder that will only decrypt data, without decoding it.

Returns
MediaCodecInfo?

A MediaCodecInfo describing the decoder, or null if no suitable decoder exists.

Throws
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException

If there was an error querying the available decoders.

getHevcBaseLayerCodecProfileAndLevel

java-static fun getHevcBaseLayerCodecProfileAndLevel(format: Format!): Pair<Int!, Int!>?

Returns profile and level (as defined by CodecProfileLevel) corresponding to the base layer (for the case of falling back to single-layer HEVC from L-HEVC).

Parameters
format: Format!

Media format with codec specific initialization data.

Returns
Pair<Int!, Int!>?

A pair (profile constant, level constant) if the initializationData of the format is well-formed and recognized, or null otherwise.

maxH264DecodableFrameSize

java-static fun maxH264DecodableFrameSize(): Int

Returns the maximum frame size supported by the default H264 decoder.

Returns
Int

The maximum frame size for an H264 stream that can be decoded on the device.

warmDecoderInfoCache

java-static fun warmDecoderInfoCache(mimeType: String!, secure: Boolean, tunneling: Boolean): Unit

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

Calling this method may speed up subsequent calls to getDecoderInfo and getDecoderInfos.

Parameters
mimeType: String!

The MIME type.

secure: Boolean

Whether the decoder is required to support secure decryption. Always pass false unless secure decryption really is required.

tunneling: Boolean

Whether the decoder is required to support tunneling. Always pass false unless tunneling really is required.