DefaultDecoderFactory


@UnstableApi
public final class DefaultDecoderFactory implements Codec.DecoderFactory


Default implementation of Codec.DecoderFactory that uses MediaCodec for decoding.

Summary

Nested types

Listener for decoder factory events.

Public constructors

Creates a new factory that selects the most preferred decoder for the format.

DefaultDecoderFactory(
    Context context,
    boolean enableDecoderFallback,
    DefaultDecoderFactory.Listener listener
)

Creates a new factory that selects the most preferred decoder, optionally falling back to less preferred decoders if initialization fails.

Public methods

DefaultCodec

Returns a Codec for audio decoding.

DefaultCodec
createForVideoDecoding(
    Format format,
    Surface outputSurface,
    boolean requestSdrToneMapping
)

Returns a Codec for video decoding.

Public constructors

DefaultDecoderFactory

public DefaultDecoderFactory(Context context)

Creates a new factory that selects the most preferred decoder for the format.

DefaultDecoderFactory

public DefaultDecoderFactory(
    Context context,
    boolean enableDecoderFallback,
    DefaultDecoderFactory.Listener listener
)

Creates a new factory that selects the most preferred decoder, optionally falling back to less preferred decoders if initialization fails.

Parameters
Context context

The context.

boolean enableDecoderFallback

Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is less efficient or slower than the primary decoder.

DefaultDecoderFactory.Listener listener

Listener for codec initialization errors.

Public methods

createForAudioDecoding

public DefaultCodec createForAudioDecoding(Format format)

Returns a Codec for audio decoding.

Parameters
Format format

The Format (of the input data) used to determine the underlying decoder and its configuration values.

Returns
DefaultCodec

A Codec for audio decoding.

Throws
androidx.media3.transformer.ExportException

If no suitable Codec can be created.

createForVideoDecoding

public DefaultCodec createForVideoDecoding(
    Format format,
    Surface outputSurface,
    boolean requestSdrToneMapping
)

Returns a Codec for video decoding.

Parameters
Format format

The Format (of the input data) used to determine the underlying decoder and its configuration values.

Surface outputSurface

The Surface to which the decoder output is rendered.

boolean requestSdrToneMapping

Whether to request tone-mapping to SDR.

Returns
DefaultCodec

A Codec for video decoding.

Throws
androidx.media3.transformer.ExportException

If no suitable Codec can be created.