MediaCodecVideoRenderer


@UnstableApi
class MediaCodecVideoRenderer : MediaCodecRenderer, VideoFrameReleaseControl.FrameTimingEvaluator


Decodes and renders video using MediaCodec.

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

Summary

Nested types

Public constructors

MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!
)
MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long
)
MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int,
    assumedMinimumCodecOperatingRate: Float
)

Creates a new instance.

MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int,
    assumedMinimumCodecOperatingRate: Float,
    videoSinkProvider: VideoSinkProvider?
)

Creates a new instance.

Public functions

Unit

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

java-static Int
getCodecMaxInputSize(codecInfo: MediaCodecInfo!, format: Format!)

Returns a maximum input size for a given codec and format.

String!

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

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

Handles a message delivered to the target.

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

Incrementally renders the SampleStream.

Unit
setPlaybackSpeed(currentPlaybackSpeed: Float, targetPlaybackSpeed: Float)

Indicates the playback speed to this renderer.

Unit

Sets the video effects to apply.

Boolean
shouldDropFrame(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastFrame: Boolean
)

Returns whether the frame should be dropped.

Boolean
shouldForceReleaseFrame(earlyUs: Long, elapsedSinceLastReleaseUs: Long)

Whether a frame should be forced for release.

Boolean
shouldIgnoreFrame(
    earlyUs: Long,
    positionUs: Long,
    elapsedRealtimeUs: Long,
    isLastFrame: Boolean,
    treatDroppedBuffersAsSkipped: Boolean
)

Returns whether this frame should be ignored.

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.

Boolean

Returns whether the codec is known to implement setOutputSurface incorrectly.

MediaCodecDecoderException!
Unit
dropOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
)

Drops the output buffer with the specified index.

Int

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

MediaCodecVideoRenderer.CodecMaxValues!
getCodecMaxValues(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    streamFormats: Array<Format!>!
)

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

Boolean

Returns whether the codec needs the renderer to propagate the end-of-stream signal directly, rather than by using an end-of-stream buffer queued to the codec.

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.

java-static Int
getMaxInputSize(codecInfo: MediaCodecInfo!, format: Format!)

Returns a maximum input buffer size for a given MediaCodec and Format.

MediaCodecAdapter.Configuration!
@TargetApi(value = 17)
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!
@TargetApi(value = 21)
getMediaFormat(
    format: Format!,
    codecMimeType: String!,
    codecMaxValues: MediaCodecVideoRenderer.CodecMaxValues!,
    codecOperatingRate: Float,
    deviceNeedsNoPostProcessWorkaround: Boolean,
    tunnelingAudioSessionId: Int
)

Returns the framework MediaFormat that should be used to configure the decoder.

Surface?

Returns the output surface.

Unit

Handles supplemental data associated with an input buffer.

Boolean
maybeDropBuffersToKeyframe(
    positionUs: Long,
    treatDroppedBuffersAsSkipped: Boolean
)

Drops frames from the current output buffer to the next keyframe at or before the playback position.

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.

Unit

Called when the renderer is initialized.

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
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
onProcessedTunneledBuffer(presentationTimeUs: Long)

Called when a buffer was processed in tunneling mode.

Unit

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

Unit

Called when ready to initialize the MediaCodecAdapter.

Unit

Called when ready to register an input stream when video effects are enabled.

Unit

Called when the renderer is released.

Unit
@TargetApi(value = 17)
onReset()

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
renderOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
)

Renders the output buffer with the specified index.

Unit
@RequiresApi(value = 21)
renderOutputBufferV21(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long,
    releaseTimeNs: Long
)

Renders the output buffer with the specified index.

Unit

Resets the renderer internal state after a codec flush.

Unit
@RequiresApi(value = 23)
setOutputSurfaceV23(codec: MediaCodecAdapter!, surface: Surface!)
Boolean
shouldDropBuffersToKeyframe(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastBuffer: Boolean
)

Returns whether to drop all buffers from the buffer being processed to the keyframe at or after the current playback position, if possible.

Boolean
shouldDropOutputBuffer(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastBuffer: Boolean
)

Returns whether the buffer being processed should be dropped.

Boolean
shouldForceRenderOutputBuffer(
    earlyUs: Long,
    elapsedSinceLastRenderUs: Long
)

Returns whether to force rendering an output buffer.

Boolean
Boolean

Returns whether to skip buffers that have an identical release time as the previous released buffer.

Unit
skipOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
)

Skips the output buffer with the specified index.

Int

Returns the Capabilities for the given Format.

Unit
updateDroppedBufferCounters(
    droppedInputBufferCount: Int,
    droppedDecoderBufferCount: Int
)

Updates local counters and decoderCounters to reflect that buffers were dropped.

Unit

Updates local counters and DecoderCounters with a new video frame processing offset.

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.

MediaClock?

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

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 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
Boolean

Flushes the codec.

Boolean

Flushes the codec.

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
onOutputStreamOffsetUsChanged(outputStreamOffsetUs: Long)

Called after the output stream offset changes.

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

Called when the renderer's stream has changed.

Unit
Unit

Incrementally renders any remaining output.

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
setRenderTimeLimitMs(renderTimeLimitMs: Long)

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

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.

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.

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

MediaCodecVideoRenderer

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

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

eventHandler: Handler?

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

eventListener: VideoRendererEventListener?

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

maxDroppedFramesToNotify: Int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
Parameters
context: Context!

A context.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

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: VideoRendererEventListener?

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

maxDroppedFramesToNotify: Int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int
)
Parameters
context: Context!

A context.

codecAdapterFactory: MediaCodecAdapter.Factory!

The MediaCodecAdapter.Factory used to create instances.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

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: VideoRendererEventListener?

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

maxDroppedFramesToNotify: Int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int,
    assumedMinimumCodecOperatingRate: Float
)

Creates a new instance.

Parameters
context: Context!

A context.

codecAdapterFactory: MediaCodecAdapter.Factory!

The MediaCodecAdapter.Factory used to create instances.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

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: VideoRendererEventListener?

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

maxDroppedFramesToNotify: Int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

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

MediaCodecVideoRenderer

MediaCodecVideoRenderer(
    context: Context!,
    codecAdapterFactory: MediaCodecAdapter.Factory!,
    mediaCodecSelector: MediaCodecSelector!,
    allowedJoiningTimeMs: Long,
    enableDecoderFallback: Boolean,
    eventHandler: Handler?,
    eventListener: VideoRendererEventListener?,
    maxDroppedFramesToNotify: Int,
    assumedMinimumCodecOperatingRate: Float,
    videoSinkProvider: VideoSinkProvider?
)

Creates a new instance.

Parameters
context: Context!

A context.

codecAdapterFactory: MediaCodecAdapter.Factory!

The MediaCodecAdapter.Factory used to create instances.

mediaCodecSelector: MediaCodecSelector!

A decoder selector.

allowedJoiningTimeMs: Long

The maximum duration in milliseconds for which this video renderer can attempt to seamlessly join an ongoing playback.

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: VideoRendererEventListener?

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

maxDroppedFramesToNotify: Int

The maximum number of frames that can be dropped between invocations of onDroppedFrames.

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

videoSinkProvider: VideoSinkProvider?

The VideoSinkProvider that will used be used for applying video effects also providing the VideoFrameReleaseControl for releasing video frames. If null, the CompositingVideoSinkProvider with its default configuration will be used, and the renderer will drive releasing of video frames by itself.

Public functions

enableMayRenderStartOfStream

fun enableMayRenderStartOfStream(): Unit

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

This is used to update the value of mayRenderStartOfStream passed to enable.

getCodecMaxInputSize

java-static fun getCodecMaxInputSize(codecInfo: MediaCodecInfo!, format: Format!): Int

Returns a maximum input size for a given codec and format.

Parameters
codecInfo: MediaCodecInfo!

Information about the MediaCodec being configured.

format: Format!

The format.

Returns
Int

A maximum input size in bytes, or NO_VALUE if a maximum could not be determined.

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.

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.

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

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

setVideoEffects

fun setVideoEffects(effects: (Mutable)List<Effect!>!): Unit

Sets the video effects to apply.

shouldDropFrame

fun shouldDropFrame(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastFrame: Boolean
): Boolean

Returns whether the frame should be dropped.

Parameters
earlyUs: Long

The time until the buffer should be presented in microseconds. A negative value indicates that the buffer is late.

elapsedRealtimeUs: Long

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

isLastFrame: Boolean

Whether the buffer is the last buffer in the current stream.

shouldForceReleaseFrame

fun shouldForceReleaseFrame(earlyUs: Long, elapsedSinceLastReleaseUs: Long): Boolean

Whether a frame should be forced for release.

Parameters
earlyUs: Long

The time until the buffer should be presented in microseconds. A negative value indicates that the buffer is late.

elapsedSinceLastReleaseUs: Long

The elapsed time since the last frame was released, in microseconds.

Returns
Boolean

Whether the video frame should be force released.

shouldIgnoreFrame

fun shouldIgnoreFrame(
    earlyUs: Long,
    positionUs: Long,
    elapsedRealtimeUs: Long,
    isLastFrame: Boolean,
    treatDroppedBuffersAsSkipped: Boolean
): Boolean

Returns whether this frame should be ignored.

Parameters
earlyUs: Long

The time until the buffer should be presented in microseconds. A negative value indicates that the buffer is late.

positionUs: Long

The playback position, in microseconds.

elapsedRealtimeUs: Long

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

isLastFrame: Boolean

Whether the buffer is the last buffer in the current stream.

treatDroppedBuffersAsSkipped: Boolean

Whether dropped buffers should be treated as intentionally skipped.

Returns
Boolean

Whether this frame should be ignored.

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.

codecNeedsSetOutputSurfaceWorkaround

protected fun codecNeedsSetOutputSurfaceWorkaround(name: String!): Boolean

Returns whether the codec is known to implement setOutputSurface incorrectly.

If true is returned then we fall back to releasing and re-instantiating the codec instead.

Parameters
name: String!

The name of the codec.

Returns
Boolean

True if the device is known to implement setOutputSurface incorrectly.

createDecoderException

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

dropOutputBuffer

protected fun dropOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
): Unit

Drops the output buffer with the specified index.

Parameters
codec: MediaCodecAdapter!

The codec that owns the output buffer.

index: Int

The index of the output buffer to drop.

presentationTimeUs: Long

The presentation time of the output buffer, in microseconds.

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.

getCodecMaxValues

protected fun getCodecMaxValues(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    streamFormats: Array<Format!>!
): MediaCodecVideoRenderer.CodecMaxValues!

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

Parameters
codecInfo: MediaCodecInfo!

Information about the MediaCodec being configured.

format: Format!

The Format for which the codec is being configured.

streamFormats: Array<Format!>!

The possible stream formats.

getCodecNeedsEosPropagation

protected fun getCodecNeedsEosPropagation(): Boolean

Returns whether the codec needs the renderer to propagate the end-of-stream signal directly, rather than by using an end-of-stream buffer queued to the codec.

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.

getMaxInputSize

protected java-static fun getMaxInputSize(codecInfo: MediaCodecInfo!, format: Format!): Int

Returns a maximum input buffer size for a given MediaCodec and Format.

Parameters
codecInfo: MediaCodecInfo!

Information about the MediaCodec being configured.

format: Format!

The format.

Returns
Int

A maximum input buffer size in bytes, or NO_VALUE if a maximum could not be determined.

getMediaCodecConfiguration

@TargetApi(value = 17)
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

@TargetApi(value = 21)
protected fun getMediaFormat(
    format: Format!,
    codecMimeType: String!,
    codecMaxValues: MediaCodecVideoRenderer.CodecMaxValues!,
    codecOperatingRate: Float,
    deviceNeedsNoPostProcessWorkaround: Boolean,
    tunnelingAudioSessionId: Int
): MediaFormat!

Returns the framework MediaFormat that should be used to configure the decoder.

Parameters
format: Format!

The Format of media.

codecMimeType: String!

The MIME type handled by the codec.

codecMaxValues: MediaCodecVideoRenderer.CodecMaxValues!

Codec max values that should be used when configuring the decoder.

codecOperatingRate: Float

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

deviceNeedsNoPostProcessWorkaround: Boolean

Whether the device is known to do post processing by default that isn't compatible with ExoPlayer.

tunnelingAudioSessionId: Int

The audio session id to use for tunneling, or AUDIO_SESSION_ID_UNSET if tunneling should not be enabled.

Returns
MediaFormat!

The framework MediaFormat that should be used to configure the decoder.

getSurface

protected fun getSurface(): Surface?

Returns the output surface.

handleInputBufferSupplementalData

@TargetApi(value = 29)
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.

maybeDropBuffersToKeyframe

protected fun maybeDropBuffersToKeyframe(
    positionUs: Long,
    treatDroppedBuffersAsSkipped: Boolean
): Boolean

Drops frames from the current output buffer to the next keyframe at or before the playback position. If no such keyframe exists, as the playback position is inside the same group of pictures as the buffer being processed, returns false. Returns true otherwise.

Parameters
positionUs: Long

The current playback position, in microseconds.

treatDroppedBuffersAsSkipped: Boolean

Whether dropped buffers should be treated as intentionally skipped.

Returns
Boolean

Whether any buffers were dropped.

Throws
androidx.media3.exoplayer.ExoPlaybackException

If an error occurs flushing the codec.

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.

onInit

protected fun onInit(): Unit

Called when the renderer is initialized.

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.

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.

onProcessedTunneledBuffer

protected fun onProcessedTunneledBuffer(presentationTimeUs: Long): Unit

Called when a buffer was processed in tunneling mode.

onQueueInputBuffer

@CallSuper
protected fun onQueueInputBuffer(buffer: DecoderInputBuffer!): Unit

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

In tunneling mode for pre Marshmallow, the buffer is treated as if immediately output.

Parameters
buffer: DecoderInputBuffer!

The buffer to be queued.

Throws
androidx.media3.exoplayer.ExoPlaybackException

Thrown if an error occurs handling the input buffer.

onReadyToInitializeCodec

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

onReadyToRegisterVideoSinkInputStream

protected fun onReadyToRegisterVideoSinkInputStream(): Unit

Called when ready to register an input stream when video effects are enabled.

The default implementation is a no-op.

onRelease

protected fun onRelease(): Unit

Called when the renderer is released.

The default implementation is a no-op.

onReset

@TargetApi(value = 17)
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.

renderOutputBuffer

protected fun renderOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
): Unit

Renders the output buffer with the specified index. This method is only called if the platform API version of the device is less than 21.

Parameters
codec: MediaCodecAdapter!

The codec that owns the output buffer.

index: Int

The index of the output buffer to drop.

presentationTimeUs: Long

The presentation time of the output buffer, in microseconds.

renderOutputBufferV21

@RequiresApi(value = 21)
protected fun renderOutputBufferV21(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long,
    releaseTimeNs: Long
): Unit

Renders the output buffer with the specified index. This method is only called if the platform API version of the device is 21 or later.

Parameters
codec: MediaCodecAdapter!

The codec that owns the output buffer.

index: Int

The index of the output buffer to drop.

presentationTimeUs: Long

The presentation time of the output buffer, in microseconds.

releaseTimeNs: Long

The wallclock time at which the frame should be displayed, in nanoseconds.

resetCodecStateForFlush

@CallSuper
protected fun resetCodecStateForFlush(): Unit

Resets the renderer internal state after a codec flush.

setOutputSurfaceV23

@RequiresApi(value = 23)
protected fun setOutputSurfaceV23(codec: MediaCodecAdapter!, surface: Surface!): Unit

shouldDropBuffersToKeyframe

protected fun shouldDropBuffersToKeyframe(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastBuffer: Boolean
): Boolean

Returns whether to drop all buffers from the buffer being processed to the keyframe at or after the current playback position, if possible.

Parameters
earlyUs: Long

The time until the current buffer should be presented in microseconds. A negative value indicates that the buffer is late.

elapsedRealtimeUs: Long

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

isLastBuffer: Boolean

Whether the buffer is the last buffer in the current stream.

shouldDropOutputBuffer

protected fun shouldDropOutputBuffer(
    earlyUs: Long,
    elapsedRealtimeUs: Long,
    isLastBuffer: Boolean
): Boolean

Returns whether the buffer being processed should be dropped.

Parameters
earlyUs: Long

The time until the buffer should be presented in microseconds. A negative value indicates that the buffer is late.

elapsedRealtimeUs: Long

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

isLastBuffer: Boolean

Whether the buffer is the last buffer in the current stream.

shouldForceRenderOutputBuffer

protected fun shouldForceRenderOutputBuffer(
    earlyUs: Long,
    elapsedSinceLastRenderUs: Long
): Boolean

Returns whether to force rendering an output buffer.

Parameters
earlyUs: Long

The time until the current buffer should be presented in microseconds. A negative value indicates that the buffer is late.

elapsedSinceLastRenderUs: Long

The elapsed time since the last output buffer was rendered, in microseconds.

Returns
Boolean

Returns whether to force rendering an output buffer.

shouldInitCodec

protected fun shouldInitCodec(codecInfo: MediaCodecInfo!): Boolean

shouldSkipBuffersWithIdenticalReleaseTime

protected fun shouldSkipBuffersWithIdenticalReleaseTime(): Boolean

Returns whether to skip buffers that have an identical release time as the previous released buffer.

skipOutputBuffer

protected fun skipOutputBuffer(
    codec: MediaCodecAdapter!,
    index: Int,
    presentationTimeUs: Long
): Unit

Skips the output buffer with the specified index.

Parameters
codec: MediaCodecAdapter!

The codec that owns the output buffer.

index: Int

The index of the output buffer to skip.

presentationTimeUs: Long

The presentation time of the output buffer, in microseconds.

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.

updateDroppedBufferCounters

protected fun updateDroppedBufferCounters(
    droppedInputBufferCount: Int,
    droppedDecoderBufferCount: Int
): Unit

Updates local counters and decoderCounters to reflect that buffers were dropped.

Parameters
droppedInputBufferCount: Int

The number of buffers dropped from the source before being passed to the decoder.

droppedDecoderBufferCount: Int

The number of buffers dropped after being passed to the decoder.

updateVideoFrameProcessingOffsetCounters

protected fun updateVideoFrameProcessingOffsetCounters(processingOffsetUs: Long): Unit

Updates local counters and DecoderCounters with a new video frame processing offset.

Parameters
processingOffsetUs: Long

The video frame processing offset.