CapturingRenderersFactory.CapturingMediaCodecVideoRenderer


protected class CapturingRenderersFactory.CapturingMediaCodecVideoRenderer : MediaCodecVideoRenderer


A MediaCodecVideoRenderer that will not skip or drop buffers due to slow processing.

Summary

Protected constructors

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

Protected functions

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

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

Inherited Constants

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

Indicates no codec operating rate should be set.

From androidx.media3.exoplayer.Renderer
const Long

Default minimum duration that the playback clock must advance before render can make progress.

const Long

Default duration to progress reported if the renderer does not need calls to render to progress, if it's in STATE_ENABLED and already ready or ended.

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 message that can be passed to a renderer to set its priority.

const Int

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

const Int

The type of message that can be passed to a renderer to direct it to enable or disable scrubbing mode.

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 type of message that can be passed to a renderer to direct it to transfer relevant resources to another renderer.

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

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

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
Unit

Enables the renderer to invoke onProcessedStreamChange on the first stream.

Boolean

Flushes the codec.

Long
getDurationToProgressUs(positionUs: Long, elapsedRealtimeUs: Long)

Returns minimum amount of playback clock time that must pass in order for the render call to make progress.

Long
getDurationToProgressUs(
    positionUs: Long,
    elapsedRealtimeUs: Long,
    isOnBufferAvailableListenerRegistered: Boolean
)

Returns minimum time playback must advance in order for the render call to make progress.

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 the renderer has skipped flushing the codec and is waiting to process an earlier frame.

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
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 the input buffer should be skipped before the decoder.

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.

abstract Int

Returns the Capabilities for the 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.video.MediaCodecVideoRenderer
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.

Unit
changeVideoSinkInputStream(
    videoSink: VideoSink!,
    @VideoSink.InputType inputType: Int,
    format: Format!,
    @VideoSink.FirstFrameReleaseInstruction firstFrameReleaseInstruction: Int
)

Called when ready to change the input stream.

Boolean

Returns whether the codec is known to implement setOutputSurface incorrectly.

MediaCodecDecoderException!
PlaybackVideoGraphWrapper!
createPlaybackVideoGraphWrapper(
    context: Context!,
    videoFrameReleaseControl: VideoFrameReleaseControl!
)

Creates a PlaybackVideoGraphWrapper instance.

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

Drops the output buffer with the specified index.

Unit

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

Unit

Experimental setter to ignore the checks for advancing timestamps before checking whether a late frame needs to be force released.

Long

Returns the timestamp that is added to the buffer presentation time (the player decoding position) to get the frame presentation time, in microseconds.

Int

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

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

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

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.

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!
getMediaCodecConfiguration(
    codecInfo: MediaCodecInfo!,
    format: Format!,
    crypto: MediaCrypto?,
    codecOperatingRate: Float
)

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

MediaFormat!
getMediaFormat(
    format: Format!,
    codecMimeType: String!,
    codecMaxValues: MediaCodecVideoRenderer.CodecMaxValues!,
    codecOperatingRate: Float,
    deviceNeedsNoPostProcessWorkaround: Boolean,
    tunnelingAudioSessionId: Int
)

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

String!

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

Surface?

Returns the output surface.

Unit

Handles supplemental data associated with an input buffer.

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.

Boolean
maybeDropBuffersToKeyframe(
    positionUs: Long,
    treatDroppedBuffersAsSkipped: Boolean
)

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

Boolean

Initializes the processing pipeline, if needed by the implementation.

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

Unit

Called when the renderer is reset.

Unit

Called when the renderer is started.

Unit

Called when the renderer is stopped.

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

Called when the renderer's stream has changed.

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

Incrementally renders the SampleStream.

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

This function is deprecated.

Override renderOutputBufferV21 instead.

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

Renders the output buffer with the specified index.

Unit

Incrementally renders any remaining output.

Unit

Resets the renderer internal state after a codec flush.

Unit
@RequiresApi(value = 23)
setOutputSurfaceV23(codec: MediaCodecAdapter!, surface: Surface!)
Unit
setPlaybackSpeed(currentPlaybackSpeed: Float, targetPlaybackSpeed: Float)

Indicates the playback speed to this renderer.

Unit

Sets the video effects to apply.

Boolean

Returns whether the input buffer should be discarded before decoding.

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

Returns whether the frame should be dropped.

Boolean

Returns whether the codec should be flushed in cases such that the codec was not released.

Boolean
shouldForceReleaseFrame(earlyUs: Long, elapsedSinceLastReleaseUs: Long)

Whether a frame should be forced for release.

Boolean
shouldForceRenderOutputBuffer(
    earlyUs: Long,
    elapsedSinceLastRenderUs: Long
)

Returns whether to force rendering an output buffer.

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

Returns whether this frame should be ignored.

Boolean
Boolean

Returns whether the codec should be released rather than flushed.

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

Skips the output buffer with the specified index.

Int

Returns the Capabilities for the given Format.

java-static Int
@RendererCapabilities.Capabilities
supportsFormat(
    context: Context!,
    mediaCodecSelector: MediaCodecSelector!,
    format: Format!
)

Returns the Capabilities of MediaCodecVideoRenderer for a 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.

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.

java-static Boolean
isFormatSupported(
    @RendererCapabilities.Capabilities supportFlags: Int,
    allowExceedsCapabilities: Boolean
)

Returns whether the C.FormatSupport from the combined Capabilities indicates the format is supported.

Unit

Sets the Listener.

From androidx.media3.exoplayer.video.VideoFrameReleaseControl.FrameTimingEvaluator
abstract Boolean
shouldIgnoreFrame(
    earlyUs: Long,
    positionUs: Long,
    elapsedRealtimeUs: Long,
    isLastFrame: Boolean,
    treatDroppedBuffersAsSkipped: Boolean
)

Returns whether this frame should be ignored.

Protected constructors

CapturingMediaCodecVideoRenderer

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

Protected functions

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.

shouldSkipBuffersWithIdenticalReleaseTime

protected fun shouldSkipBuffersWithIdenticalReleaseTime(): Boolean

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