MediaCodecAudioRenderer


@UnstableApi
class MediaCodecAudioRenderer : MediaCodecRenderer, MediaClock


Decodes and renders audio using MediaCodec and an AudioSink.

This renderer accepts the following messages sent via createMessage on the playback thread:

Summary

Public constructors

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!
)
MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?
)
MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)
MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)
MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioCapabilities: AudioCapabilities!,
    audioProcessors: Array<AudioProcessor!>!
)

This function is deprecated.

Use a constructor without AudioCapabilities.

MediaCodecAudioRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)

Creates a new instance.

Public functions

MediaClock?

If the renderer advances its own playback position then this method returns a corresponding MediaClock.

String!

Returns the name of this renderer, for logging and debugging purposes.

PlaybackParameters!

Returns the active playback parameters.

Long

Returns the current media position in microseconds.

Unit
handleMessage(@Renderer.MessageType messageType: Int, message: Any?)

Handles a message delivered to the target.

Boolean

Returns whether there is a skipped silence since the last call to this method.

Boolean

Whether the renderer is ready for the ExoPlayer instance to transition to STATE_ENDED.

Boolean

Whether the renderer is able to immediately render media from the current position.

Unit

Attempts to set the playback parameters.

Protected functions

DecoderReuseEvaluation!
canReuseCodec(
    codecInfo: MediaCodecInfo!,
    oldFormat: Format!,
    newFormat: Format!
)

Evaluates whether the existing MediaCodec can be kept for a new Format, and if it can whether it requires reconfiguration.

Int
getCodecMaxInputSize(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    streamFormats: Array<Format!>!
)

Returns a maximum input size suitable for configuring a codec for format in a way that will allow possible adaptation to other compatible formats in streamFormats.

Float
getCodecOperatingRateV23(
    targetPlaybackSpeed: Float,
    format: Format!,
    streamFormats: Array<Format!>!
)

Returns the KEY_OPERATING_RATE value for a given playback speed, current Format and set of possible stream formats.

(Mutable)List<MediaCodecInfo!>!
getDecoderInfos(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean
)

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

MediaCodecAdapter.Configuration!
getMediaCodecConfiguration(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    crypto: MediaCrypto?,
    codecOperatingRate: Float
)

Returns the MediaCodecAdapter.Configuration that will be used to create and configure a MediaCodec to decode the given Format for a playback.

MediaFormat!
getMediaFormat(
    format: Format!,
    codecMimeType: String!,
    codecMaxInputSize: Int,
    codecOperatingRate: Float
)

Returns the framework MediaFormat that can be used to configure a MediaCodec for decoding the given Format for playback.

Unit

Handles supplemental data associated with an input buffer.

Unit
onCodecError(codecError: Exception!)

Called when a codec error has occurred.

Unit
onCodecInitialized(
    name: String!,
    configuration: MediaCodecAdapter.Configuration!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
)

Called when a MediaCodec has been created and configured.

Unit

Called when a MediaCodec has been released.

Unit

Called when the renderer is disabled.

Unit
onEnabled(joining: Boolean, mayRenderStartOfStream: Boolean)

Called when the renderer is enabled.

DecoderReuseEvaluation?

Called when a new Format is read from the upstream MediaPeriod.

Unit
onOutputFormatChanged(format: Format!, mediaFormat: MediaFormat?)

Called when one of the output formats changes.

Unit
onOutputStreamOffsetUsChanged(outputStreamOffsetUs: Long)

Called after the output stream offset changes.

Unit

See onPositionDiscontinuity.

Unit
onPositionReset(positionUs: Long, joining: Boolean)

Called when the position is reset.

Unit

Called after the last output buffer before a stream change has been processed.

Unit

Called when the renderer is released.

Unit

Called when the renderer is reset.

Unit

Called when the renderer is started.

Unit

Called when the renderer is stopped.

Boolean
processOutputBuffer(
    positionUs: Long,
    elapsedRealtimeUs: Long,
    codec: MediaCodecAdapter?,
    buffer: ByteBuffer?,
    bufferIndex: Int,
    bufferFlags: Int,
    sampleCount: Int,
    bufferPresentationTimeUs: Long,
    isDecodeOnlyBuffer: Boolean,
    isLastBuffer: Boolean,
    format: Format!
)

Processes an output media buffer.

Unit

Incrementally renders any remaining output.

Boolean

Returns whether buffers in the input format can be processed without a codec.

Int

Returns the Capabilities for the given Format.

Inherited Constants

From androidx.media3.exoplayer.mediacodec.MediaCodecRenderer
const Float

Indicates no codec operating rate should be set.

From androidx.media3.exoplayer.Renderer
const Int

Applications or extensions may define custom MSG_* constants that can be passed to renderers.

const Int

A type of a message that can be passed to an audio renderer via createMessage.

const Int

The type of a message that can be passed to audio and video renderers via createMessage.

const Int

A type of a message that can be passed to an audio renderer via createMessage.

const Int

The type of a message that can be passed to a camera motion renderer via createMessage.

const Int

The type of a message that can be passed to a video renderer via createMessage.

const Int

The type of message that can be passed to an image renderer to set a desired image output.

const Int

The type of a message that can be passed to audio renderers via createMessage.

const Int

The type of a message that can be passed to a MediaCodec-based video renderer via createMessage.

const Int

The type of a message that can be passed to an audio renderer via createMessage.

const Int

The type of a message that can be passed to a video renderer.

const Int

The type of a message that can be passed to a video renderer via createMessage.

const Int

The type of a message that can be passed to a video renderer via createMessage.

const Int

The type of a message that can be passed to a video renderer to set the desired output resolution.

const Int

A type of a message that can be passed to an audio renderer via createMessage.

const Int

The type of a message that can be passed to a Renderer via createMessage, to inform the renderer that it can schedule waking up another component.

const Int

The renderer is disabled.

const Int

The renderer is enabled but not started.

const Int

The renderer is started.

From androidx.media3.exoplayer.RendererCapabilities
const Int

The Renderer can adapt between formats, but may suffer a brief discontinuity (~50-100ms) when adaptation occurs.

const Int

The Renderer does not support adaptation between formats.

const Int

The Renderer can seamlessly adapt between formats.

const Int

A mask to apply to Capabilities to obtain the AdaptiveSupport only.

const Int

The renderer supports audio offload and gapless transitions with this format.

const Int

Audio offload is not supported with this format.

const Int

The renderer supports audio offload and speed changes with this format.

const Int

The renderer supports audio offload with this format.

const Int

A mask to apply to Capabilities to obtain AudioOffloadSupport only.

const Int

The format exceeds the primary decoder's capabilities but is supported by fallback decoder

const Int

The format's MIME type is unsupported and the renderer may use a decoder for a fallback MIME type.

const Int

A mask to apply to Capabilities to obtain DecoderSupport only.

const Int

The renderer is able to use the primary decoder for the format's MIME type.

const Int

This property is deprecated.

Use FORMAT_EXCEEDS_CAPABILITIES instead.

const Int

This property is deprecated.

Use FORMAT_HANDLED instead.

const Int

A mask to apply to Capabilities to obtain the C.FormatSupport only.

const Int

This property is deprecated.

Use FORMAT_UNSUPPORTED_DRM instead.

const Int

This property is deprecated.

Use FORMAT_UNSUPPORTED_SUBTYPE instead.

const Int

This property is deprecated.

Use FORMAT_UNSUPPORTED_TYPE instead.

const Int

The renderer is not able to use hardware acceleration.

const Int

The renderer is able to use hardware acceleration.

const Int

A mask to apply to Capabilities to obtain HardwareAccelerationSupport only.

const Int

The Renderer does not support tunneled output.

const Int

The Renderer supports tunneled output.

const Int

A mask to apply to Capabilities to obtain TunnelingSupport only.

Inherited functions

From androidx.media3.exoplayer.BaseRenderer
Unit

Clears the Listener.

ExoPlaybackException!
createRendererException(
    cause: Throwable!,
    format: Format?,
    @PlaybackException.ErrorCode errorCode: Int
)

Creates an ExoPlaybackException of type TYPE_RENDERER for this renderer.

ExoPlaybackException!
createRendererException(
    cause: Throwable!,
    format: Format?,
    isRecoverable: Boolean,
    @PlaybackException.ErrorCode errorCode: Int
)

Creates an ExoPlaybackException of type TYPE_RENDERER for this renderer.

Unit

Disable the renderer, transitioning it to the STATE_DISABLED state.

Unit
enable(
    configuration: RendererConfiguration!,
    formats: Array<Format!>!,
    stream: SampleStream!,
    positionUs: Long,
    joining: Boolean,
    mayRenderStartOfStream: Boolean,
    startPositionUs: Long,
    offsetUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Enables the renderer to consume from the specified SampleStream.

RendererCapabilities!

Returns the capabilities of the renderer.

Boolean

Returns whether the renderer has read the current SampleStream to the end.

Unit
init(index: Int, playerId: PlayerId!, clock: Clock!)

Initializes the renderer for playback with a player.

Boolean

Returns whether the current SampleStream will be the final one supplied before the renderer is next disabled or reset.

Boolean

Returns whether the upstream source is ready.

Unit

Throws an error that's preventing the renderer from reading from its SampleStream.

Unit

Called when the renderer is initialized.

Unit

Called when the renderer capabilities are changed.

Unit

Called when a new timeline is set.

Int
@SampleStream.ReadDataResult
readSource(
    formatHolder: FormatHolder!,
    buffer: DecoderInputBuffer!,
    @SampleStream.ReadFlags readFlags: Int
)

Reads from the enabled upstream source.

Unit

Releases the renderer.

Unit
replaceStream(
    formats: Array<Format!>!,
    stream: SampleStream!,
    startPositionUs: Long,
    offsetUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Replaces the SampleStream from which samples will be consumed.

Unit

Forces the renderer to give up any resources (e.g. media decoders) that it may be holding.

Unit
resetPosition(positionUs: Long)

Signals to the renderer that a position discontinuity has occurred.

Unit

Signals to the renderer that the current SampleStream will be the final one supplied before it is next disabled or reset.

Unit

Sets the Listener.

Int
skipSource(positionUs: Long)

Attempts to skip to the keyframe before the specified position, or to the end of the stream if positionUs is beyond it.

Unit

Starts the renderer, meaning that calls to render will cause media to be rendered.

Unit

Stops the renderer, transitioning it to the STATE_ENABLED state.

From androidx.media3.exoplayer.mediacodec.MediaCodecRenderer
MediaCodecDecoderException!
Boolean

Flushes the codec.

Boolean

Flushes the codec.

Int

Returns the flags that should be set on queueInputBuffer or queueSecureInputBuffer for this buffer.

Long

Returns the offset that should be subtracted from bufferPresentationTimeUs in processOutputBuffer to get the playback position with respect to the media.

Long

Returns the start position of the current output stream in microseconds.

Float

Returns the current playback speed, as set by setPlaybackSpeed.

Boolean

Returns whether bypass is enabled by the renderer.

Boolean

Returns whether buffers in the input format can be processed without a codec.

Unit
Unit
@CallSuper
onProcessedOutputBuffer(presentationTimeUs: Long)

Called when an output buffer is successfully processed.

Unit

Called immediately before an input buffer is queued into the codec.

Unit

Called when ready to initialize the MediaCodecAdapter.

Unit
onStreamChanged(
    formats: Array<Format!>!,
    startPositionUs: Long,
    offsetUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Called when the renderer's stream has changed.

Unit
Unit
render(positionUs: Long, elapsedRealtimeUs: Long)

Incrementally renders the SampleStream.

Unit

Resets the renderer internal state after a codec flush.

Unit

Resets the renderer internal state after a codec release.

Unit

Notifies the renderer that output end of stream is pending and should be handled on the next render.

Unit

Sets an exception to be re-thrown by render.

Unit
setPlaybackSpeed(currentPlaybackSpeed: Float, targetPlaybackSpeed: Float)

Indicates the playback speed to this renderer.

Unit
setRenderTimeLimitMs(renderTimeLimitMs: Long)

Sets a limit on the time a single render call can spend draining and filling the decoder.

Boolean
Boolean

Returns whether the renderer needs to re-initialize the codec, possibly as a result of a change in device capabilities.

Int

Returns the extent to which the Renderer supports a given format.

java-static Boolean

Returns whether this renderer supports the given Format's DRM scheme.

Int

Returns the extent to which the Renderer supports adapting between supported formats that have different MIME types.

Boolean

Updates the codec operating rate, or triggers codec release and re-initialization if a previously set operating rate needs to be cleared.

Unit
updateOutputFormatForTime(presentationTimeUs: Long)

Updates the output formats for the specified output buffer timestamp, calling onOutputFormatChanged if a change has occurred.

From androidx.media3.exoplayer.Renderer
abstract Unit
enable(
    configuration: RendererConfiguration!,
    formats: Array<Format!>!,
    stream: SampleStream!,
    positionUs: Long,
    joining: Boolean,
    mayRenderStartOfStream: Boolean,
    startPositionUs: Long,
    offsetUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Enables the renderer to consume from the specified SampleStream.

Unit

Enables this renderer to render the start of the stream even if the state is not STATE_STARTED yet.

abstract Unit
replaceStream(
    formats: Array<Format!>!,
    stream: SampleStream!,
    startPositionUs: Long,
    offsetUs: Long,
    mediaPeriodId: MediaSource.MediaPeriodId!
)

Replaces the SampleStream from which samples will be consumed.

From androidx.media3.exoplayer.RendererCapabilities
java-static Int

Returns Capabilities for the given C.FormatSupport.

java-static Int

Returns Capabilities combining the given C.FormatSupport, and TunnelingSupport.

java-static Int
@RendererCapabilities.Capabilities
create(
    @C.FormatSupport formatSupport: Int,
    @RendererCapabilities.AdaptiveSupport adaptiveSupport: Int,
    @RendererCapabilities.TunnelingSupport tunnelingSupport: Int,
    @RendererCapabilities.AudioOffloadSupport audioOffloadSupport: Int
)

Returns Capabilities combining the given C.FormatSupport, , TunnelingSupport, and AudioOffloadSupport.

java-static Int
@RendererCapabilities.Capabilities
create(
    @C.FormatSupport formatSupport: Int,
    @RendererCapabilities.AdaptiveSupport adaptiveSupport: Int,
    @RendererCapabilities.TunnelingSupport tunnelingSupport: Int,
    @RendererCapabilities.HardwareAccelerationSupport hardwareAccelerationSupport: Int,
    @RendererCapabilities.DecoderSupport decoderSupport: Int
)

Returns Capabilities combining the given C.FormatSupport, , TunnelingSupport, HardwareAccelerationSupport, and .

java-static Int
@RendererCapabilities.Capabilities
create(
    @C.FormatSupport formatSupport: Int,
    @RendererCapabilities.AdaptiveSupport adaptiveSupport: Int,
    @RendererCapabilities.TunnelingSupport tunnelingSupport: Int,
    @RendererCapabilities.HardwareAccelerationSupport hardwareAccelerationSupport: Int,
    @RendererCapabilities.DecoderSupport decoderSupport: Int,
    @RendererCapabilities.AudioOffloadSupport audioOffloadSupport: Int
)

Returns Capabilities combining the given C.FormatSupport, , TunnelingSupport, HardwareAccelerationSupport, and AudioOffloadSupport.

java-static Int

Returns the AdaptiveSupport from the combined Capabilities.

java-static Int

Returns the AudioOffloadSupport from the combined Capabilities.

java-static Int

Returns the DecoderSupport from the combined Capabilities.

java-static Int

Returns the C.FormatSupport from the combined Capabilities.

java-static Int

Returns the HardwareAccelerationSupport from the combined Capabilities.

java-static Int

Returns the TunnelingSupport from the combined Capabilities.

Unit

Sets the Listener.

Public constructors

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

eventHandler: Handler?

A handler to use when delivering events to eventListener. May be null if delivery of events is not required.

eventListener: AudioRendererEventListener?

A listener of events. May be null if delivery of events is not required.

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

eventHandler: Handler?

A handler to use when delivering events to eventListener. May be null if delivery of events is not required.

eventListener: AudioRendererEventListener?

A listener of events. May be null if delivery of events is not required.

audioSink: AudioSink!

The sink to which audio will be output.

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

enableDecoderFallback: Boolean

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

eventHandler: Handler?

A handler to use when delivering events to eventListener. May be null if delivery of events is not required.

eventListener: AudioRendererEventListener?

A listener of events. May be null if delivery of events is not required.

audioSink: AudioSink!

The sink to which audio will be output.

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioCapabilities: AudioCapabilities!,
    audioProcessors: Array<AudioProcessor!>!
)

MediaCodecAudioRenderer

MediaCodecAudioRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: AudioRendererEventListener?,
    audioSink: AudioSink!
)

Creates a new instance.

Parameters
context: Context!

A context.

codecAdapterFactory: MediaCodecAdapter.Factory!

The MediaCodecAdapter.Factory used to create instances.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

enableDecoderFallback: Boolean

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

eventHandler: Handler?

A handler to use when delivering events to eventListener. May be null if delivery of events is not required.

eventListener: AudioRendererEventListener?

A listener of events. May be null if delivery of events is not required.

audioSink: AudioSink!

The sink to which audio will be output.

Public functions

getMediaClock

fun getMediaClock(): MediaClock?

If the renderer advances its own playback position then this method returns a corresponding MediaClock. If provided, the player will use the returned MediaClock as its source of time during playback. A player may have at most one renderer that returns a from this method.

Returns
MediaClock?

The MediaClock tracking the playback position of the renderer, or null.

getName

fun getName(): String!

Returns the name of this renderer, for logging and debugging purposes. Should typically be the renderer's (un-obfuscated) class name.

Returns
String!

The name of this renderer.

getPlaybackParameters

fun getPlaybackParameters(): PlaybackParameters!

Returns the active playback parameters.

getPositionUs

fun getPositionUs(): Long

Returns the current media position in microseconds.

handleMessage

fun handleMessage(@Renderer.MessageType messageType: Int, message: Any?): Unit

Handles a message delivered to the target.

Parameters
@Renderer.MessageType messageType: Int

The message type.

message: Any?

The message payload.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurred whilst handling the message. Should only be thrown by targets that handle messages on the playback thread.

hasSkippedSilenceSinceLastCall

fun hasSkippedSilenceSinceLastCall(): Boolean

Returns whether there is a skipped silence since the last call to this method.

isEnded

fun isEnded(): Boolean

Whether the renderer is ready for the ExoPlayer instance to transition to STATE_ENDED. The player will make this transition as soon as true is returned by all of its renderers.

This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.

Returns
Boolean

Whether the renderer is ready for the player to transition to the ended state.

isReady

fun isReady(): Boolean

Whether the renderer is able to immediately render media from the current position.

If the renderer is in the STATE_STARTED state then returning true indicates that the renderer has everything that it needs to continue playback. Returning false indicates that the player should pause until the renderer is ready.

If the renderer is in the STATE_ENABLED state then returning true indicates that the renderer is ready for playback to be started. Returning false indicates that it is not.

This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.

Returns
Boolean

Whether the renderer is ready to render media.

setPlaybackParameters

fun setPlaybackParameters(playbackParameters: PlaybackParameters!): Unit

Attempts to set the playback parameters. The media clock may override the speed if changing the playback parameters is not supported.

Parameters
playbackParameters: PlaybackParameters!

The playback parameters to attempt to set.

Protected functions

canReuseCodec

protected fun canReuseCodec(
    codecInfo: MediaCodecInfo!,
    oldFormat: Format!,
    newFormat: Format!
): DecoderReuseEvaluation!

Evaluates whether the existing MediaCodec can be kept for a new Format, and if it can whether it requires reconfiguration.

The default implementation does not allow decoder reuse.

Parameters
codecInfo: MediaCodecInfo!

A MediaCodecInfo describing the decoder.

oldFormat: Format!

The Format for which the existing instance is configured.

newFormat: Format!

The new Format.

Returns
DecoderReuseEvaluation!

The result of the evaluation.

getCodecMaxInputSize

protected fun getCodecMaxInputSize(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    streamFormats: Array<Format!>!
): Int

Returns a maximum input size suitable for configuring a codec for format in a way that will allow possible adaptation to other compatible formats in streamFormats.

Parameters
codecInfo: MediaCodecInfo!

A MediaCodecInfo describing the decoder.

format: Format!

The Format for which the codec is being configured.

streamFormats: Array<Format!>!

The possible stream formats.

Returns
Int

A suitable maximum input size.

getCodecOperatingRateV23

protected fun getCodecOperatingRateV23(
    targetPlaybackSpeed: Float,
    format: Format!,
    streamFormats: Array<Format!>!
): Float

Returns the KEY_OPERATING_RATE value for a given playback speed, current Format and set of possible stream formats.

The default implementation returns CODEC_OPERATING_RATE_UNSET.

Parameters
targetPlaybackSpeed: Float

The target factor by which playback should be sped up. This may be different from the current playback speed, for example, if the speed is temporarily adjusted for live playback.

format: Format!

The Format for which the codec is being configured.

streamFormats: Array<Format!>!

The possible stream formats.

Returns
Float

The codec operating rate, or CODEC_OPERATING_RATE_UNSET if no codec operating rate should be set.

getDecoderInfos

protected fun getDecoderInfos(
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!,
    requiresSecureDecoder: Boolean
): (Mutable)List<MediaCodecInfo!>!

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

Parameters
mediaCodecSelector: MediaCodecSelector!

The decoder selector.

format: Format!

The Format for which a decoder is required.

requiresSecureDecoder: Boolean

Whether a secure 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.

getMediaCodecConfiguration

protected fun getMediaCodecConfiguration(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    crypto: MediaCrypto?,
    codecOperatingRate: Float
): MediaCodecAdapter.Configuration!

Returns the MediaCodecAdapter.Configuration that will be used to create and configure a MediaCodec to decode the given Format for a playback.

Parameters
codecInfo: MediaCodecInfo!

Information about the MediaCodec being configured.

format: Format!

The Format for which the codec is being configured.

crypto: MediaCrypto?

For drm protected playbacks, a MediaCrypto to use for decryption.

codecOperatingRate: Float

The codec operating rate, or CODEC_OPERATING_RATE_UNSET if no codec operating rate should be set.

Returns
MediaCodecAdapter.Configuration!

The parameters needed to call configure.

getMediaFormat

protected fun getMediaFormat(
    format: Format!,
    codecMimeType: String!,
    codecMaxInputSize: Int,
    codecOperatingRate: Float
): MediaFormat!

Returns the framework MediaFormat that can be used to configure a MediaCodec for decoding the given Format for playback.

Parameters
format: Format!

The Format of the media.

codecMimeType: String!

The MIME type handled by the codec.

codecMaxInputSize: Int

The maximum input size supported by the codec.

codecOperatingRate: Float

The codec operating rate, or CODEC_OPERATING_RATE_UNSET if no codec operating rate should be set.

Returns
MediaFormat!

The framework MediaFormat.

handleInputBufferSupplementalData

protected fun handleInputBufferSupplementalData(buffer: DecoderInputBuffer!): Unit

Handles supplemental data associated with an input buffer.

The default implementation is a no-op.

Parameters
buffer: DecoderInputBuffer!

The input buffer that is about to be queued.

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs handling supplemental data.

onCodecError

protected fun onCodecError(codecError: Exception!): Unit

Called when a codec error has occurred.

The default implementation is a no-op.

Parameters
codecError: Exception!

The error.

onCodecInitialized

protected fun onCodecInitialized(
    name: String!,
    configuration: MediaCodecAdapter.Configuration!,
    initializedTimestampMs: Long,
    initializationDurationMs: Long
): Unit

Called when a MediaCodec has been created and configured.

The default implementation is a no-op.

Parameters
name: String!

The name of the codec that was initialized.

configuration: MediaCodecAdapter.Configuration!

The MediaCodecAdapter.Configuration used to configure the codec.

initializedTimestampMs: Long

elapsedRealtime when initialization finished.

initializationDurationMs: Long

The time taken to initialize the codec in milliseconds.

onCodecReleased

protected fun onCodecReleased(name: String!): Unit

Called when a MediaCodec has been released.

The default implementation is a no-op.

Parameters
name: String!

The name of the codec that was released.

onDisabled

protected fun onDisabled(): Unit

Called when the renderer is disabled.

The default implementation is a no-op.

onEnabled

protected fun onEnabled(joining: Boolean, mayRenderStartOfStream: Boolean): Unit

Called when the renderer is enabled.

The default implementation is a no-op.

Parameters
joining: Boolean

Whether this renderer is being enabled to join an ongoing playback.

mayRenderStartOfStream: Boolean

Whether this renderer is allowed to render the start of the stream even if the state is not STATE_STARTED yet.

onInputFormatChanged

protected fun onInputFormatChanged(formatHolder: FormatHolder!): DecoderReuseEvaluation?

Called when a new Format is read from the upstream MediaPeriod.

Parameters
formatHolder: FormatHolder!

A FormatHolder that holds the new Format.

Returns
DecoderReuseEvaluation?

The result of the evaluation to determine whether the existing decoder instance can be reused for the new format, or null if the renderer did not have a decoder.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs re-initializing the MediaCodec.

onOutputFormatChanged

protected fun onOutputFormatChanged(format: Format!, mediaFormat: MediaFormat?): Unit

Called when one of the output formats changes.

The default implementation is a no-op.

Parameters
format: Format!

The input Format to which future output now corresponds. If the renderer is in bypass mode, this is also the output format.

mediaFormat: MediaFormat?

The codec output MediaFormat, or null if the renderer is in bypass mode.

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs configuring the output.

onOutputStreamOffsetUsChanged

protected fun onOutputStreamOffsetUsChanged(outputStreamOffsetUs: Long): Unit

Called after the output stream offset changes.

The default implementation is a no-op.

Parameters
outputStreamOffsetUs: Long

The output stream offset in microseconds.

onPositionDiscontinuity

@CallSuper
protected fun onPositionDiscontinuity(): Unit

See onPositionDiscontinuity.

onPositionReset

protected fun onPositionReset(positionUs: Long, joining: Boolean): Unit

Called when the position is reset. This occurs when the renderer is enabled after onStreamChanged has been called, and also when a position discontinuity is encountered.

After a position reset, the renderer's SampleStream is guaranteed to provide samples starting from a key frame.

The default implementation is a no-op.

Parameters
positionUs: Long

The new playback position in microseconds.

joining: Boolean

Whether this renderer is being enabled to join an ongoing playback.

onProcessedStreamChange

protected fun onProcessedStreamChange(): Unit

Called after the last output buffer before a stream change has been processed.

onRelease

protected fun onRelease(): Unit

Called when the renderer is released.

The default implementation is a no-op.

onReset

protected fun onReset(): Unit

Called when the renderer is reset.

The default implementation is a no-op.

onStarted

protected fun onStarted(): Unit

Called when the renderer is started.

The default implementation is a no-op.

onStopped

protected fun onStopped(): Unit

Called when the renderer is stopped.

The default implementation is a no-op.

processOutputBuffer

protected fun processOutputBuffer(
    positionUs: Long,
    elapsedRealtimeUs: Long,
    codec: MediaCodecAdapter?,
    buffer: ByteBuffer?,
    bufferIndex: Int,
    bufferFlags: Int,
    sampleCount: Int,
    bufferPresentationTimeUs: Long,
    isDecodeOnlyBuffer: Boolean,
    isLastBuffer: Boolean,
    format: Format!
): Boolean

Processes an output media buffer.

When a new ByteBuffer is passed to this method its position and limit delineate the data to be processed. The return value indicates whether the buffer was processed in full. If true is returned then the next call to this method will receive a new buffer to be processed. If false is returned then the same buffer will be passed to the next call. An implementation of this method is free to modify the buffer and can assume that the buffer will not be externally modified between successive calls. Hence an implementation can, for example, modify the buffer's position to keep track of how much of the data it has processed.

Note that the first call to this method following a call to onPositionReset will always receive a new ByteBuffer to be processed.

Parameters
positionUs: Long

The current media time in microseconds, measured at the start of the current iteration of the rendering loop.

elapsedRealtimeUs: Long

elapsedRealtime in microseconds, measured at the start of the current iteration of the rendering loop.

codec: MediaCodecAdapter?

The MediaCodecAdapter instance, or null in bypass mode were no codec is used.

buffer: ByteBuffer?

The output buffer to process, or null if the buffer data is not made available to the application layer (see getOutputBuffer). This buffer can only be null for video data. Note that the buffer data can still be rendered in this case by using the bufferIndex.

bufferIndex: Int

The index of the output buffer.

bufferFlags: Int

The flags attached to the output buffer.

sampleCount: Int

The number of samples extracted from the sample queue in the buffer. This allows handling multiple samples as a batch for efficiency.

bufferPresentationTimeUs: Long

The presentation time of the output buffer in microseconds.

isDecodeOnlyBuffer: Boolean

Whether the buffer timestamp is less than the intended playback start position.

isLastBuffer: Boolean

Whether the buffer is known to contain the last sample of the current stream. This flag is set on a best effort basis, and any logic relying on it should degrade gracefully to handle cases where it's not set.

format: Format!

The Format associated with the buffer.

Returns
Boolean

Whether the output buffer was fully processed (for example, rendered or skipped).

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs processing the output buffer.

renderToEndOfStream

protected fun renderToEndOfStream(): Unit

Incrementally renders any remaining output.

The default implementation is a no-op.

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs rendering remaining output.

shouldUseBypass

protected fun shouldUseBypass(format: Format!): Boolean

Returns whether buffers in the input format can be processed without a codec.

This method is only called if the content is not DRM protected, because if the content is DRM protected use of bypass is never possible.

Parameters
format: Format!

The input Format.

Returns
Boolean

Whether playback bypassing MediaCodec is supported.

supportsFormat

@RendererCapabilities.Capabilities
protected fun supportsFormat(mediaCodecSelector: MediaCodecSelector!, format: Format!): Int

Returns the Capabilities for the given Format.

Parameters
mediaCodecSelector: MediaCodecSelector!

The decoder selector.

format: Format!

The Format.

Returns
Int

The Capabilities for this Format.

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

If there was an error querying decoders.