MediaCodecRenderer


@UnstableApi
abstract class MediaCodecRenderer : BaseRenderer

Known direct subclasses
MediaCodecAudioRenderer

Decodes and renders audio using MediaCodec and an AudioSink.

MediaCodecVideoRenderer

Decodes and renders video using MediaCodec.


An abstract renderer that uses MediaCodec to decode samples for rendering.

Summary

Nested types

Thrown when a failure occurs instantiating a decoder.

Constants

const Float

Indicates no codec operating rate should be set.

Public constructors

MediaCodecRenderer(
    @C.TrackType trackType: Int,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    assumedMinimumCodecOperatingRate: Float
)

Public functions

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
render(positionUs: Long, elapsedRealtimeUs: Long)

Incrementally renders the SampleStream.

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.

Int

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

Int

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

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.

MediaCodecDecoderException!
Boolean

Flushes the codec.

Boolean

Flushes the codec.

Int

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

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.

abstract (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.

abstract 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.

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.

Unit

Handles supplemental data associated with an input buffer.

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
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
onPositionReset(positionUs: Long, joining: Boolean)

Called when the position is reset.

Unit
@CallSuper
onProcessedOutputBuffer(presentationTimeUs: Long)

Called when an output buffer is successfully processed.

Unit

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

Unit

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

Unit

Called when ready to initialize the MediaCodecAdapter.

Unit

Called when the renderer is reset.

Unit

Called when the renderer is started.

Unit

Called when the renderer is stopped.

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

Called when the renderer's stream has changed.

abstract 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
Unit

Incrementally renders any remaining output.

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.

Boolean
Boolean

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

Boolean

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

abstract Int

Returns the Capabilities for the given Format.

java-static Boolean

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

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.

Inherited Constants

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.

MediaClock?

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

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

Handles a message delivered to the target.

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 is released.

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.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 String!

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

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.

Constants

CODEC_OPERATING_RATE_UNSET

protected const val CODEC_OPERATING_RATE_UNSET = -1.0f: Float

Indicates no codec operating rate should be set.

Public constructors

MediaCodecRenderer

MediaCodecRenderer(
    @C.TrackType trackType: Int,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    enableDecoderFallback: Boolean,
    assumedMinimumCodecOperatingRate: Float
)
Parameters
@C.TrackType trackType: Int

The track type that the renderer handles.

codecAdapterFactory: MediaCodecAdapter.Factory!

A factory for MediaCodecAdapter 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 less efficient or slower than the primary decoder.

assumedMinimumCodecOperatingRate: Float

A codec operating rate that all codecs instantiated by this renderer are assumed to meet implicitly (i.e. without the operating rate being set explicitly using KEY_OPERATING_RATE).

Public functions

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.

render

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

Incrementally renders the SampleStream.

If the renderer is in the STATE_ENABLED state then each call to this method will do work toward being ready to render the SampleStream when the renderer is started. If the renderer is in the STATE_STARTED state then calls to this method will render the SampleStream in sync with the specified media positions.

The renderer may also render the very start of the media at the current position (e.g. the first frame of a video stream) while still in the STATE_ENABLED state, unless it's the initial start of the media after calling enable with mayRenderStartOfStream set to false.

This method should return quickly, and should not block if the renderer is unable to make useful progress.

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

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.

setPlaybackSpeed

fun setPlaybackSpeed(currentPlaybackSpeed: Float, targetPlaybackSpeed: Float): Unit

Indicates the playback speed to this renderer.

The default implementation is a no-op.

Parameters
currentPlaybackSpeed: Float

The factor by which playback is currently sped up.

targetPlaybackSpeed: Float

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

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs handling the playback speed.

setRenderTimeLimitMs

fun setRenderTimeLimitMs(renderTimeLimitMs: Long): Unit

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

This method should be called right after creating an instance of this class.

Parameters
renderTimeLimitMs: Long

The render time limit in milliseconds, or TIME_UNSET for no limit.

supportsFormat

@RendererCapabilities.Capabilities
fun supportsFormat(format: Format!): Int

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

Parameters
format: Format!

The format.

Returns
Int

The Capabilities for this format.

supportsMixedMimeTypeAdaptation

@RendererCapabilities.AdaptiveSupport
fun supportsMixedMimeTypeAdaptation(): Int

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

Returns
Int

The AdaptiveSupport for adapting between supported formats that have different MIME types.

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.

createDecoderException

protected fun createDecoderException(cause: Throwable!, codecInfo: MediaCodecInfo?): MediaCodecDecoderException!

flushOrReinitializeCodec

protected fun flushOrReinitializeCodec(): Boolean

Flushes the codec. If flushing is not possible, the codec will be released and re-instantiated. This method is a no-op if the codec is null.

The implementation of this method calls flushOrReleaseCodec, and maybeInitCodecOrBypass if the codec needs to be re-instantiated.

Returns
Boolean

Whether the codec was released and reinitialized, rather than being flushed.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs re-instantiating the codec.

flushOrReleaseCodec

protected fun flushOrReleaseCodec(): Boolean

Flushes the codec. If flushing is not possible, the codec will be released. This method is a no-op if the codec is null.

Returns
Boolean

Whether the codec was released.

getCodecBufferFlags

protected fun getCodecBufferFlags(buffer: DecoderInputBuffer!): Int

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

Parameters
buffer: DecoderInputBuffer!

The input buffer.

Returns
Int

The flags to set on queueInputBuffer or queueSecureInputBuffer.

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 abstract 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 abstract 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.

getOutputStreamOffsetUs

protected fun getOutputStreamOffsetUs(): Long

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

getOutputStreamStartPositionUs

protected fun getOutputStreamStartPositionUs(): Long

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

getPlaybackSpeed

protected fun getPlaybackSpeed(): Float

Returns the current playback speed, as set by setPlaybackSpeed.

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.

isBypassEnabled

protected fun isBypassEnabled(): Boolean

Returns whether bypass is enabled by the renderer.

isBypassPossible

protected fun isBypassPossible(format: Format!): Boolean

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

This method returns the possibility of bypass mode with checking both the renderer capabilities and DRM protection.

Parameters
format: Format!

The input Format.

Returns
Boolean

Whether playback bypassing MediaCodec is possible.

maybeInitCodecOrBypass

protected fun maybeInitCodecOrBypass(): Unit

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

@CallSuper
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.

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.

onProcessedOutputBuffer

@CallSuper
protected fun onProcessedOutputBuffer(presentationTimeUs: Long): Unit

Called when an output buffer is successfully processed.

Parameters
presentationTimeUs: Long

The timestamp associated with the output buffer.

onProcessedStreamChange

protected fun onProcessedStreamChange(): Unit

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

onQueueInputBuffer

protected fun onQueueInputBuffer(buffer: DecoderInputBuffer!): Unit

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

The default implementation is a no-op.

Parameters
buffer: DecoderInputBuffer!

The buffer to be queued.

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs handling the input buffer.

onReadyToInitializeCodec

protected fun onReadyToInitializeCodec(format: Format!): Unit

Called when ready to initialize the MediaCodecAdapter.

This method is called just before the renderer obtains the configuration for the MediaCodecAdapter and creates the adapter via the passed in MediaCodecAdapter.Factory.

The default implementation is a no-op.

Parameters
format: Format!

The Format for which the codec is being configured.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs preparing for initializing the codec.

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.

onStreamChanged

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

Called when the renderer's stream has changed. This occurs when the renderer is enabled after onEnabled has been called, and also when the stream has been replaced whilst the renderer is enabled or started.

The default implementation is a no-op.

Parameters
formats: Array<Format!>!

The enabled formats.

startPositionUs: Long

The start position of the new stream in renderer time (microseconds).

offsetUs: Long

The offset that will be added to the timestamps of buffers read via readSource so that decoder input buffers have monotonically increasing timestamps.

mediaPeriodId: MediaSource.MediaPeriodId!

The MediaSource.MediaPeriodId of the MediaPeriod that produces the stream.

processOutputBuffer

protected abstract 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.

releaseCodec

protected fun releaseCodec(): Unit

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.

resetCodecStateForFlush

@CallSuper
protected fun resetCodecStateForFlush(): Unit

Resets the renderer internal state after a codec flush.

resetCodecStateForRelease

@CallSuper
protected fun resetCodecStateForRelease(): Unit

Resets the renderer internal state after a codec release.

Note that this only needs to reset state variables that are changed in addition to those already changed in resetCodecStateForFlush.

setPendingOutputEndOfStream

protected fun setPendingOutputEndOfStream(): Unit

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

setPendingPlaybackException

protected fun setPendingPlaybackException(exception: ExoPlaybackException!): Unit

Sets an exception to be re-thrown by render.

Parameters
exception: ExoPlaybackException!

The exception.

shouldInitCodec

protected fun shouldInitCodec(codecInfo: MediaCodecInfo!): Boolean

shouldReinitCodec

protected fun shouldReinitCodec(): Boolean

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

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 abstract 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.

supportsFormatDrm

protected java-static fun supportsFormatDrm(format: Format!): Boolean

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

updateCodecOperatingRate

protected fun updateCodecOperatingRate(): Boolean

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

Returns
Boolean

False if codec release and re-initialization was triggered. True in all other cases.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs releasing or initializing a codec.

updateOutputFormatForTime

protected fun updateOutputFormatForTime(presentationTimeUs: Long): Unit

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

Subclasses should only call this method if operating in a mode where buffers are not dequeued from the decoder, for example when using video tunneling).

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs as a result of the output format change.

Protected properties

codec

protected val codecMediaCodecAdapter?

codecInfo

protected val codecInfoMediaCodecInfo?

codecNeedsEosPropagation

protected val codecNeedsEosPropagationBoolean

codecOperatingRate

protected val codecOperatingRateFloat

codecOutputMediaFormat

protected val codecOutputMediaFormatMediaFormat?

decoderCounters

protected val decoderCountersDecoderCounters!