MediaCodecInfo
@UnstableApi
public final class MediaCodecInfo
Information about a MediaCodec for a given MIME type.
Summary
Constants |
|
|---|---|
static final int |
The value returned by |
static final String |
TAG = "MediaCodecInfo" |
Public fields |
|
|---|---|
final boolean |
Whether the decoder supports seamless resolution switches. |
final @Nullable MediaCodecInfo.CodecCapabilities |
The capabilities of the decoder, like the profiles/levels it supports, or |
final String |
The MIME type that the codec uses for media of type |
final boolean |
Whether the codec supports "detached" surface mode where it is able to decode without an attached surface. |
final boolean |
Whether the codec is hardware accelerated. |
final String |
The MIME type handled by the codec. |
final String |
The name of the decoder. |
final boolean |
Whether the decoder is secure. |
final boolean |
Whether the codec is software only. |
final boolean |
Whether the decoder supports tunneling. |
final boolean |
Whether the codec is from the vendor. |
Public methods |
|
|---|---|
@Nullable Point |
alignVideoSizeV21(int width, int height)Returns the smallest video size greater than or equal to a specified size that also satisfies the |
DecoderReuseEvaluation |
canReuseCodec(Format oldFormat, Format newFormat)Evaluates whether it's possible to reuse an instance of this decoder that's currently decoding |
float |
getMaxSupportedFrameRate(int width, int height)Returns the max video frame rate that this codec can support at the provided resolution, or |
int |
Returns an upper bound on the maximum number of supported instances, or |
MediaCodecInfo.CodecProfileLevel[] |
The profile levels supported by the decoder. |
boolean |
isAudioChannelCountSupportedV21(int channelCount)Whether the decoder supports audio with a given channel count. |
boolean |
isAudioSampleRateSupportedV21(int sampleRate)Whether the decoder supports audio with a given sample rate. |
boolean |
isFormatFunctionallySupported(Format format)Returns whether the decoder may functionally support decoding the given |
boolean |
isFormatSupported(Format format)Returns whether the decoder may support decoding the given |
boolean |
Whether the codec handles HDR10+ out-of-band metadata. |
boolean |
isSeamlessAdaptationSupported(Format format)Returns whether it may be possible to adapt an instance of this decoder to playing a different format when the codec is configured to play media in the specified |
boolean |
isVideoSizeAndRateSupportedV21(int width, int height, double frameRate)Whether the decoder supports video with a given width, height and frame rate. |
static MediaCodecInfo |
newInstance(Creates an instance. |
String |
toString() |
Constants
MAX_SUPPORTED_INSTANCES_UNKNOWN
public static final int MAX_SUPPORTED_INSTANCES_UNKNOWN = -1
The value returned by getMaxSupportedInstances if the upper bound on the maximum number of supported instances is unknown.
Public fields
capabilities
public final @Nullable MediaCodecInfo.CodecCapabilities capabilities
The capabilities of the decoder, like the profiles/levels it supports, or null if not known.
codecMimeType
public final String codecMimeType
The MIME type that the codec uses for media of type mimeType. Equal to mimeType unless the codec is known to use a non-standard MIME type alias.
detachedSurfaceSupported
public final boolean detachedSurfaceSupported
Whether the codec supports "detached" surface mode where it is able to decode without an attached surface. Only relevant for video codecs.
| See also | |
|---|---|
FEATURE_DetachedSurface |
hardwareAccelerated
public final boolean hardwareAccelerated
Whether the codec is hardware accelerated.
This could be an approximation as the exact information is only provided in API levels 29+.
| See also | |
|---|---|
isHardwareAccelerated |
name
public final String name
The name of the decoder.
May be passed to createByCodecName to create an instance of the decoder.
secure
public final boolean secure
Whether the decoder is secure.
| See also | |
|---|---|
isFeatureSupported |
|
FEATURE_SecurePlayback |
softwareOnly
public final boolean softwareOnly
Whether the codec is software only.
This could be an approximation as the exact information is only provided in API levels 29+.
| See also | |
|---|---|
isSoftwareOnly |
Public methods
alignVideoSizeV21
public @Nullable Point alignVideoSizeV21(int width, int height)
Returns the smallest video size greater than or equal to a specified size that also satisfies the MediaCodec's width and height alignment requirements.
| Parameters | |
|---|---|
int width |
Width in pixels. |
int height |
Height in pixels. |
| Returns | |
|---|---|
@Nullable Point |
The smallest video size greater than or equal to the specified size that also satisfies the |
canReuseCodec
public DecoderReuseEvaluation canReuseCodec(Format oldFormat, Format newFormat)
Evaluates whether it's possible to reuse an instance of this decoder that's currently decoding oldFormat to decode newFormat instead.
For adaptation to succeed, the codec must also be configured with maximum values that are compatible with the new format.
| Returns | |
|---|---|
DecoderReuseEvaluation |
The result of the evaluation. |
getMaxSupportedFrameRate
public float getMaxSupportedFrameRate(int width, int height)
Returns the max video frame rate that this codec can support at the provided resolution, or RATE_UNSET if this is not a video codec.
getMaxSupportedInstances
public int getMaxSupportedInstances()
Returns an upper bound on the maximum number of supported instances, or MAX_SUPPORTED_INSTANCES_UNKNOWN if unknown. Applications should not expect to operate more instances than the returned maximum.
| See also | |
|---|---|
getMaxSupportedInstances |
getProfileLevels
public MediaCodecInfo.CodecProfileLevel[] getProfileLevels()
The profile levels supported by the decoder.
| Returns | |
|---|---|
MediaCodecInfo.CodecProfileLevel[] |
The profile levels supported by the decoder. |
isAudioChannelCountSupportedV21
public boolean isAudioChannelCountSupportedV21(int channelCount)
Whether the decoder supports audio with a given channel count.
| Parameters | |
|---|---|
int channelCount |
The channel count. |
| Returns | |
|---|---|
boolean |
Whether the decoder supports audio with the given channel count. |
isAudioSampleRateSupportedV21
public boolean isAudioSampleRateSupportedV21(int sampleRate)
Whether the decoder supports audio with a given sample rate.
| Parameters | |
|---|---|
int sampleRate |
The sample rate in Hz. |
| Returns | |
|---|---|
boolean |
Whether the decoder supports audio with the given sample rate. |
isFormatFunctionallySupported
public boolean isFormatFunctionallySupported(Format format)
Returns whether the decoder may functionally support decoding the given format.
| Parameters | |
|---|---|
Format format |
The input media format. |
| Returns | |
|---|---|
boolean |
Whether the decoder may functionally support decoding the given |
isFormatSupported
public boolean isFormatSupported(Format format)
Returns whether the decoder may support decoding the given format both functionally and performantly.
| Parameters | |
|---|---|
Format format |
The input media format. |
| Returns | |
|---|---|
boolean |
Whether the decoder may support decoding the given |
| Throws | |
|---|---|
androidx.media3.exoplayer.mediacodec.MediaCodecUtil.DecoderQueryException |
Thrown if an error occurs while querying decoders. |
isHdr10PlusOutOfBandMetadataSupported
public boolean isHdr10PlusOutOfBandMetadataSupported()
Whether the codec handles HDR10+ out-of-band metadata.
isSeamlessAdaptationSupported
public boolean isSeamlessAdaptationSupported(Format format)
Returns whether it may be possible to adapt an instance of this decoder to playing a different format when the codec is configured to play media in the specified format.
For adaptation to succeed, the codec must also be configured with appropriate maximum values and canReuseCodec must return true for the old/new formats.
| Parameters | |
|---|---|
Format format |
The format of media for which the decoder will be configured. |
| Returns | |
|---|---|
boolean |
Whether adaptation may be possible |
isVideoSizeAndRateSupportedV21
public boolean isVideoSizeAndRateSupportedV21(int width, int height, double frameRate)
Whether the decoder supports video with a given width, height and frame rate.
| Parameters | |
|---|---|
int width |
Width in pixels. |
int height |
Height in pixels. |
double frameRate |
Optional frame rate in frames per second. Ignored if set to |
| Returns | |
|---|---|
boolean |
Whether the decoder supports video with the given width, height and frame rate. |
newInstance
public static MediaCodecInfo newInstance(
String name,
String mimeType,
String codecMimeType,
@Nullable MediaCodecInfo.CodecCapabilities capabilities,
boolean hardwareAccelerated,
boolean softwareOnly,
boolean vendor,
boolean forceDisableAdaptive,
boolean forceSecure
)
Creates an instance.
| Parameters | |
|---|---|
String name |
The name of the |
String mimeType |
A MIME type supported by the |
String codecMimeType |
The MIME type that the codec uses for media of type |
@Nullable MediaCodecInfo.CodecCapabilities capabilities |
The capabilities of the |
boolean hardwareAccelerated |
Whether the |
boolean softwareOnly |
Whether the |
boolean vendor |
Whether the |
boolean forceDisableAdaptive |
Whether |
boolean forceSecure |
Whether |
| Returns | |
|---|---|
MediaCodecInfo |
The created instance. |