PlayerMessage.Target, Renderer, RendererCapabilitiespublic class MediaCodecVideoRenderer extends MediaCodecRenderer
MediaCodec.
This renderer accepts the following messages sent via ExoPlayer.createMessage(Target)
on the playback thread:
Renderer.MSG_SET_SURFACE to set the output surface. The message payload
should be the target Surface, or null.
Renderer.MSG_SET_SCALING_MODE to set the video scaling mode. The message
payload should be one of the integer scaling modes in C.VideoScalingMode. Note that
the scaling mode only applies if the Surface targeted by this renderer is owned by
a SurfaceView.
Renderer.MSG_SET_VIDEO_FRAME_METADATA_LISTENER to set a listener for
metadata associated with frames being rendered. The message payload should be the VideoFrameMetadataListener, or null.
| Modifier and Type | Class | Description |
|---|---|---|
protected static class |
MediaCodecVideoRenderer.CodecMaxValues |
MediaCodecRenderer.DecoderInitializationExceptionRenderer.State, Renderer.VideoScalingMode, Renderer.WakeupListenerRendererCapabilities.AdaptiveSupport, RendererCapabilities.Capabilities, RendererCapabilities.FormatSupport, RendererCapabilities.TunnelingSupportCODEC_OPERATING_RATE_UNSET, decoderCountersMSG_CUSTOM_BASE, MSG_SET_AUDIO_ATTRIBUTES, MSG_SET_AUDIO_SESSION_ID, MSG_SET_AUX_EFFECT_INFO, MSG_SET_CAMERA_MOTION_LISTENER, MSG_SET_SCALING_MODE, MSG_SET_SKIP_SILENCE_ENABLED, MSG_SET_SURFACE, MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER, MSG_SET_VIDEO_FRAME_METADATA_LISTENER, MSG_SET_VOLUME, MSG_SET_WAKEUP_LISTENER, STATE_DISABLED, STATE_ENABLED, STATE_STARTED, VIDEO_SCALING_MODE_DEFAULT, VIDEO_SCALING_MODE_SCALE_TO_FIT, VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPINGADAPTIVE_NOT_SEAMLESS, ADAPTIVE_NOT_SUPPORTED, ADAPTIVE_SEAMLESS, ADAPTIVE_SUPPORT_MASK, FORMAT_EXCEEDS_CAPABILITIES, FORMAT_HANDLED, FORMAT_SUPPORT_MASK, FORMAT_UNSUPPORTED_DRM, FORMAT_UNSUPPORTED_SUBTYPE, FORMAT_UNSUPPORTED_TYPE, TUNNELING_NOT_SUPPORTED, TUNNELING_SUPPORT_MASK, TUNNELING_SUPPORTED| Constructor | Description |
|---|---|
MediaCodecVideoRenderer(Context context,
MediaCodecAdapter.Factory codecAdapterFactory,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs,
boolean enableDecoderFallback,
Handler eventHandler,
VideoRendererEventListener eventListener,
int maxDroppedFramesToNotify) |
Creates a new instance.
|
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector) |
|
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs) |
|
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs,
boolean enableDecoderFallback,
Handler eventHandler,
VideoRendererEventListener eventListener,
int maxDroppedFramesToNotify) |
|
MediaCodecVideoRenderer(Context context,
MediaCodecSelector mediaCodecSelector,
long allowedJoiningTimeMs,
Handler eventHandler,
VideoRendererEventListener eventListener,
int maxDroppedFramesToNotify) |
| Modifier and Type | Method | Description |
|---|---|---|
protected DecoderReuseEvaluation |
canReuseCodec(MediaCodecInfo codecInfo,
Format oldFormat,
Format newFormat) |
Evaluates whether the existing
MediaCodec can be kept for a new Format, and if
it can whether it requires reconfiguration. |
protected boolean |
codecNeedsSetOutputSurfaceWorkaround(String name) |
Returns whether the codec is known to implement
MediaCodec.setOutputSurface(Surface)
incorrectly. |
protected void |
configureCodec(MediaCodecInfo codecInfo,
MediaCodecAdapter codec,
Format format,
MediaCrypto crypto,
float codecOperatingRate) |
Configures a newly created
MediaCodec. |
protected MediaCodecDecoderException |
createDecoderException(Throwable cause,
MediaCodecInfo codecInfo) |
|
protected void |
dropOutputBuffer(MediaCodecAdapter codec,
int index,
long presentationTimeUs) |
Drops the output buffer with the specified index.
|
protected MediaCodecVideoRenderer.CodecMaxValues |
getCodecMaxValues(MediaCodecInfo codecInfo,
Format format,
Format[] streamFormats) |
Returns
MediaCodecVideoRenderer.CodecMaxValues suitable for configuring a codec for format in a way
that will allow possible adaptation to other compatible formats in streamFormats. |
protected boolean |
getCodecNeedsEosPropagation() |
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.
|
protected float |
getCodecOperatingRateV23(float targetPlaybackSpeed,
Format format,
Format[] streamFormats) |
Returns the
MediaFormat.KEY_OPERATING_RATE value for a given playback speed, current
Format and set of possible stream formats. |
protected List<MediaCodecInfo> |
getDecoderInfos(MediaCodecSelector mediaCodecSelector,
Format format,
boolean requiresSecureDecoder) |
Returns a list of decoders that can decode media in the specified format, in priority order.
|
protected static int |
getMaxInputSize(MediaCodecInfo codecInfo,
Format format) |
Returns a maximum input buffer size for a given
MediaCodec and Format. |
protected MediaFormat |
getMediaFormat(Format format,
String codecMimeType,
MediaCodecVideoRenderer.CodecMaxValues codecMaxValues,
float codecOperatingRate,
boolean deviceNeedsNoPostProcessWorkaround,
int tunnelingAudioSessionId) |
Returns the framework
MediaFormat that should be used to configure the decoder. |
String |
getName() |
Returns the name of this renderer, for logging and debugging purposes.
|
protected Surface |
getSurface() |
|
protected void |
handleInputBufferSupplementalData(DecoderInputBuffer buffer) |
Handles supplemental data associated with an input buffer.
|
void |
handleMessage(int messageType,
Object message) |
Handles a message delivered to the target.
|
boolean |
isReady() |
Whether the renderer is able to immediately render media from the current position.
|
protected boolean |
maybeDropBuffersToKeyframe(long positionUs,
boolean treatDroppedBuffersAsSkipped) |
Drops frames from the current output buffer to the next keyframe at or before the playback
position.
|
protected void |
onCodecInitialized(String name,
long initializedTimestampMs,
long initializationDurationMs) |
Called when a
MediaCodec has been created and configured. |
protected void |
onCodecReleased(String name) |
Called when a
MediaCodec has been released. |
protected void |
onDisabled() |
Called when the renderer is disabled.
|
protected void |
onEnabled(boolean joining,
boolean mayRenderStartOfStream) |
Called when the renderer is enabled.
|
protected DecoderReuseEvaluation |
onInputFormatChanged(FormatHolder formatHolder) |
Called when a new
Format is read from the upstream MediaPeriod. |
protected void |
onOutputFormatChanged(Format format,
MediaFormat mediaFormat) |
Called when one of the output formats changes.
|
protected void |
onPositionReset(long positionUs,
boolean joining) |
Called when the position is reset.
|
protected void |
onProcessedOutputBuffer(long presentationTimeUs) |
Called when an output buffer is successfully processed.
|
protected void |
onProcessedStreamChange() |
Called after the last output buffer before a stream change has been processed.
|
protected void |
onProcessedTunneledBuffer(long presentationTimeUs) |
Called when a buffer was processed in tunneling mode.
|
protected void |
onQueueInputBuffer(DecoderInputBuffer buffer) |
Called immediately before an input buffer is queued into the codec.
|
protected void |
onReset() |
Called when the renderer is reset.
|
protected void |
onStarted() |
Called when the renderer is started.
|
protected void |
onStopped() |
Called when the renderer is stopped.
|
protected boolean |
processOutputBuffer(long positionUs,
long elapsedRealtimeUs,
MediaCodecAdapter codec,
ByteBuffer buffer,
int bufferIndex,
int bufferFlags,
int sampleCount,
long bufferPresentationTimeUs,
boolean isDecodeOnlyBuffer,
boolean isLastBuffer,
Format format) |
Processes an output media buffer.
|
protected void |
renderOutputBuffer(MediaCodecAdapter codec,
int index,
long presentationTimeUs) |
Renders the output buffer with the specified index.
|
protected void |
renderOutputBufferV21(MediaCodecAdapter codec,
int index,
long presentationTimeUs,
long releaseTimeNs) |
Renders the output buffer with the specified index.
|
protected void |
resetCodecStateForFlush() |
Resets the renderer internal state after a codec flush.
|
protected void |
setOutputSurfaceV23(MediaCodecAdapter codec,
Surface surface) |
|
void |
setPlaybackSpeed(float currentPlaybackSpeed,
float targetPlaybackSpeed) |
Indicates the playback speed to this renderer.
|
protected boolean |
shouldDropBuffersToKeyframe(long earlyUs,
long elapsedRealtimeUs,
boolean isLastBuffer) |
Returns whether to drop all buffers from the buffer being processed to the keyframe at or after
the current playback position, if possible.
|
protected boolean |
shouldDropOutputBuffer(long earlyUs,
long elapsedRealtimeUs,
boolean isLastBuffer) |
Returns whether the buffer being processed should be dropped.
|
protected boolean |
shouldForceRenderOutputBuffer(long earlyUs,
long elapsedSinceLastRenderUs) |
Returns whether to force rendering an output buffer.
|
protected boolean |
shouldInitCodec(MediaCodecInfo codecInfo) |
|
protected void |
skipOutputBuffer(MediaCodecAdapter codec,
int index,
long presentationTimeUs) |
Skips the output buffer with the specified index.
|
protected int |
supportsFormat(MediaCodecSelector mediaCodecSelector,
Format format) |
Returns the
RendererCapabilities.Capabilities for the given Format. |
protected void |
updateDroppedBufferCounters(int droppedBufferCount) |
Updates local counters and
DecoderCounters to reflect that droppedBufferCount
additional buffers were dropped. |
protected void |
updateVideoFrameProcessingOffsetCounters(long processingOffsetUs) |
Updates local counters and
DecoderCounters with a new video frame processing offset. |
createRendererException, createRendererException, disable, enable, getCapabilities, getConfiguration, getFormatHolder, getIndex, getLastResetPositionUs, getMediaClock, getReadingPositionUs, getState, getStream, getStreamFormats, getTrackType, hasReadStreamToEnd, isCurrentStreamFinal, isSourceReady, maybeThrowStreamError, readSource, replaceStream, reset, resetPosition, setCurrentStreamFinal, setIndex, skipSource, start, stopexperimentalSetAsynchronousBufferQueueingEnabled, experimentalSetForceAsyncQueueingSynchronizationWorkaround, experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled, flushOrReinitializeCodec, flushOrReleaseCodec, getCodec, getCodecInfo, getCodecOperatingRate, getCodecOutputMediaFormat, getOutputStreamOffsetUs, getPlaybackSpeed, isEnded, legacyKeepAvailableCodecInfosWithoutCodec, maybeInitCodecOrBypass, onStreamChanged, releaseCodec, render, renderToEndOfStream, resetCodecStateForRelease, setPendingOutputEndOfStream, setPendingPlaybackException, setRenderTimeLimitMs, shouldUseBypass, supportsFormat, supportsFormatDrm, supportsMixedMimeTypeAdaptation, updateOutputFormatForTimeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitpublic MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector)
context - A context.mediaCodecSelector - A decoder selector.public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long allowedJoiningTimeMs)
context - A context.mediaCodecSelector - A decoder selector.allowedJoiningTimeMs - The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long allowedJoiningTimeMs, @Nullable Handler eventHandler, @Nullable VideoRendererEventListener eventListener, int maxDroppedFramesToNotify)
context - A context.mediaCodecSelector - A decoder selector.allowedJoiningTimeMs - The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.eventHandler - A handler to use when delivering events to eventListener. May be
null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.maxDroppedFramesToNotify - The maximum number of frames that can be dropped between
invocations of VideoRendererEventListener.onDroppedFrames(int, long).public MediaCodecVideoRenderer(Context context, MediaCodecSelector mediaCodecSelector, long allowedJoiningTimeMs, boolean enableDecoderFallback, @Nullable Handler eventHandler, @Nullable VideoRendererEventListener eventListener, int maxDroppedFramesToNotify)
context - A context.mediaCodecSelector - A decoder selector.allowedJoiningTimeMs - The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.enableDecoderFallback - 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 - A handler to use when delivering events to eventListener. May be
null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.maxDroppedFramesToNotify - The maximum number of frames that can be dropped between
invocations of VideoRendererEventListener.onDroppedFrames(int, long).public MediaCodecVideoRenderer(Context context, MediaCodecAdapter.Factory codecAdapterFactory, MediaCodecSelector mediaCodecSelector, long allowedJoiningTimeMs, boolean enableDecoderFallback, @Nullable Handler eventHandler, @Nullable VideoRendererEventListener eventListener, int maxDroppedFramesToNotify)
context - A context.codecAdapterFactory - The MediaCodecAdapter.Factory used to create MediaCodecAdapter instances.mediaCodecSelector - A decoder selector.allowedJoiningTimeMs - The maximum duration in milliseconds for which this video renderer
can attempt to seamlessly join an ongoing playback.enableDecoderFallback - 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 - A handler to use when delivering events to eventListener. May be
null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.maxDroppedFramesToNotify - The maximum number of frames that can be dropped between
invocations of VideoRendererEventListener.onDroppedFrames(int, long).public String getName()
Renderer@Capabilities protected int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format) throws MediaCodecUtil.DecoderQueryException
MediaCodecRendererRendererCapabilities.Capabilities for the given Format.supportsFormat in class MediaCodecRenderermediaCodecSelector - The decoder selector.format - The Format.RendererCapabilities.Capabilities for this Format.MediaCodecUtil.DecoderQueryException - If there was an error querying decoders.protected List<MediaCodecInfo> getDecoderInfos(MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException
MediaCodecRenderergetDecoderInfos in class MediaCodecRenderermediaCodecSelector - The decoder selector.format - The Format for which a decoder is required.requiresSecureDecoder - Whether a secure decoder is required.MediaCodecInfos corresponding to decoders. May be empty.MediaCodecUtil.DecoderQueryException - Thrown if there was an error querying decoders.protected void onEnabled(boolean joining,
boolean mayRenderStartOfStream)
throws ExoPlaybackException
BaseRendererThe default implementation is a no-op.
onEnabled in class MediaCodecRendererjoining - Whether this renderer is being enabled to join an ongoing playback.mayRenderStartOfStream - Whether this renderer is allowed to render the start of the
stream even if the state is not Renderer.STATE_STARTED yet.ExoPlaybackException - If an error occurs.protected void onPositionReset(long positionUs,
boolean joining)
throws ExoPlaybackException
BaseRendererBaseRenderer.onStreamChanged(Format[], long, long) 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.
onPositionReset in class MediaCodecRendererpositionUs - The new playback position in microseconds.joining - Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException - If an error occurs.public boolean isReady()
Renderer
If the renderer is in the Renderer.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 Renderer.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:
Renderer.STATE_ENABLED, Renderer.STATE_STARTED.
isReady in interface RendererisReady in class MediaCodecRendererprotected void onStarted()
BaseRendererThe default implementation is a no-op.
onStarted in class MediaCodecRendererprotected void onStopped()
BaseRendererThe default implementation is a no-op.
onStopped in class MediaCodecRendererprotected void onDisabled()
BaseRendererThe default implementation is a no-op.
onDisabled in class MediaCodecRendererprotected void onReset()
BaseRendererThe default implementation is a no-op.
onReset in class MediaCodecRendererpublic void handleMessage(int messageType,
@Nullable
Object message)
throws ExoPlaybackException
PlayerMessage.TargethandleMessage in interface PlayerMessage.TargethandleMessage in class BaseRenderermessageType - The message type.message - The message payload.ExoPlaybackException - If an error occurred whilst handling the message. Should only be
thrown by targets that handle messages on the playback thread.protected boolean shouldInitCodec(MediaCodecInfo codecInfo)
shouldInitCodec in class MediaCodecRendererprotected boolean getCodecNeedsEosPropagation()
MediaCodecRenderergetCodecNeedsEosPropagation in class MediaCodecRendererprotected void configureCodec(MediaCodecInfo codecInfo, MediaCodecAdapter codec, Format format, @Nullable MediaCrypto crypto, float codecOperatingRate)
MediaCodecRendererMediaCodec.configureCodec in class MediaCodecRenderercodecInfo - Information about the MediaCodec being configured.codec - The MediaCodecAdapter to configure.format - The Format for which the codec is being configured.crypto - For drm protected playbacks, a MediaCrypto to use for decryption.codecOperatingRate - The codec operating rate, or MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET if
no codec operating rate should be set.protected DecoderReuseEvaluation canReuseCodec(MediaCodecInfo codecInfo, Format oldFormat, Format newFormat)
MediaCodecRendererMediaCodec can be kept for a new Format, and if
it can whether it requires reconfiguration.
The default implementation does not allow decoder reuse.
canReuseCodec in class MediaCodecRenderercodecInfo - A MediaCodecInfo describing the decoder.oldFormat - The Format for which the existing instance is configured.newFormat - The new Format.@CallSuper protected void resetCodecStateForFlush()
MediaCodecRendererresetCodecStateForFlush in class MediaCodecRendererpublic void setPlaybackSpeed(float currentPlaybackSpeed,
float targetPlaybackSpeed)
throws ExoPlaybackException
RendererThe default implementation is a no-op.
setPlaybackSpeed in interface RenderersetPlaybackSpeed in class MediaCodecRenderercurrentPlaybackSpeed - The factor by which playback is currently sped up.targetPlaybackSpeed - 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.ExoPlaybackException - If an error occurs handling the playback speed.protected float getCodecOperatingRateV23(float targetPlaybackSpeed,
Format format,
Format[] streamFormats)
MediaCodecRendererMediaFormat.KEY_OPERATING_RATE value for a given playback speed, current
Format and set of possible stream formats.
The default implementation returns MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET.
getCodecOperatingRateV23 in class MediaCodecRenderertargetPlaybackSpeed - 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 - The Format for which the codec is being configured.streamFormats - The possible stream formats.MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET if no codec operating
rate should be set.protected void onCodecInitialized(String name, long initializedTimestampMs, long initializationDurationMs)
MediaCodecRendererMediaCodec has been created and configured.
The default implementation is a no-op.
onCodecInitialized in class MediaCodecRenderername - The name of the codec that was initialized.initializedTimestampMs - SystemClock.elapsedRealtime() when initialization
finished.initializationDurationMs - The time taken to initialize the codec in milliseconds.protected void onCodecReleased(String name)
MediaCodecRendererMediaCodec has been released.
The default implementation is a no-op.
onCodecReleased in class MediaCodecRenderername - The name of the codec that was released.@Nullable protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException
MediaCodecRendererFormat is read from the upstream MediaPeriod.onInputFormatChanged in class MediaCodecRendererformatHolder - A FormatHolder that holds the new Format.null if the renderer did not have a decoder.ExoPlaybackException - If an error occurs re-initializing the MediaCodec.@CallSuper protected void onQueueInputBuffer(DecoderInputBuffer buffer) throws ExoPlaybackException
In tunneling mode for pre Marshmallow, the buffer is treated as if immediately output.
onQueueInputBuffer in class MediaCodecRendererbuffer - The buffer to be queued.ExoPlaybackException - Thrown if an error occurs handling the input buffer.protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat)
MediaCodecRendererThe default implementation is a no-op.
onOutputFormatChanged in class MediaCodecRendererformat - The input Format to which future output now corresponds. If the renderer
is in bypass mode, this is also the output format.mediaFormat - The codec output MediaFormat, or null if the renderer is in
bypass mode.protected void handleInputBufferSupplementalData(DecoderInputBuffer buffer) throws ExoPlaybackException
MediaCodecRendererThe default implementation is a no-op.
handleInputBufferSupplementalData in class MediaCodecRendererbuffer - The input buffer that is about to be queued.ExoPlaybackException - Thrown if an error occurs handling supplemental data.protected boolean processOutputBuffer(long positionUs,
long elapsedRealtimeUs,
@Nullable
MediaCodecAdapter codec,
@Nullable
ByteBuffer buffer,
int bufferIndex,
int bufferFlags,
int sampleCount,
long bufferPresentationTimeUs,
boolean isDecodeOnlyBuffer,
boolean isLastBuffer,
Format format)
throws ExoPlaybackException
MediaCodecRendererWhen 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 MediaCodecRenderer.onPositionReset(long,
boolean) will always receive a new ByteBuffer to be processed.
processOutputBuffer in class MediaCodecRendererpositionUs - The current media time in microseconds, measured at the start of the current
iteration of the rendering loop.elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds, measured at the
start of the current iteration of the rendering loop.codec - The MediaCodecAdapter instance, or null in bypass mode were no codec is
used.buffer - The output buffer to process, or null if the buffer data is not made available to
the application layer (see MediaCodec.getOutputBuffer(int)). 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 - The index of the output buffer.bufferFlags - The flags attached to the output buffer.sampleCount - The number of samples extracted from the sample queue in the buffer. This
allows handling multiple samples as a batch for efficiency.bufferPresentationTimeUs - The presentation time of the output buffer in microseconds.isDecodeOnlyBuffer - Whether the buffer was marked with C.BUFFER_FLAG_DECODE_ONLY
by the source.isLastBuffer - Whether the buffer is the last sample of the current stream.format - The Format associated with the buffer.ExoPlaybackException - If an error occurs processing the output buffer.protected void onProcessedTunneledBuffer(long presentationTimeUs)
throws ExoPlaybackException
ExoPlaybackException@CallSuper protected void onProcessedOutputBuffer(long presentationTimeUs)
MediaCodecRendereronProcessedOutputBuffer in class MediaCodecRendererpresentationTimeUs - The timestamp associated with the output buffer.protected void onProcessedStreamChange()
MediaCodecRendereronProcessedStreamChange in class MediaCodecRendererprotected boolean shouldDropOutputBuffer(long earlyUs,
long elapsedRealtimeUs,
boolean isLastBuffer)
earlyUs - The time until the buffer should be presented in microseconds. A negative value
indicates that the buffer is late.elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds,
measured at the start of the current iteration of the rendering loop.isLastBuffer - Whether the buffer is the last buffer in the current stream.protected boolean shouldDropBuffersToKeyframe(long earlyUs,
long elapsedRealtimeUs,
boolean isLastBuffer)
earlyUs - The time until the current buffer should be presented in microseconds. A
negative value indicates that the buffer is late.elapsedRealtimeUs - SystemClock.elapsedRealtime() in microseconds,
measured at the start of the current iteration of the rendering loop.isLastBuffer - Whether the buffer is the last buffer in the current stream.protected boolean shouldForceRenderOutputBuffer(long earlyUs,
long elapsedSinceLastRenderUs)
earlyUs - The time until the current buffer should be presented in microseconds. A
negative value indicates that the buffer is late.elapsedSinceLastRenderUs - The elapsed time since the last output buffer was rendered, in
microseconds.protected void skipOutputBuffer(MediaCodecAdapter codec, int index, long presentationTimeUs)
codec - The codec that owns the output buffer.index - The index of the output buffer to skip.presentationTimeUs - The presentation time of the output buffer, in microseconds.protected void dropOutputBuffer(MediaCodecAdapter codec, int index, long presentationTimeUs)
codec - The codec that owns the output buffer.index - The index of the output buffer to drop.presentationTimeUs - The presentation time of the output buffer, in microseconds.protected boolean maybeDropBuffersToKeyframe(long positionUs,
boolean treatDroppedBuffersAsSkipped)
throws ExoPlaybackException
false. Returns true otherwise.positionUs - The current playback position, in microseconds.treatDroppedBuffersAsSkipped - Whether dropped buffers should be treated as intentionally
skipped.ExoPlaybackException - If an error occurs flushing the codec.protected void updateDroppedBufferCounters(int droppedBufferCount)
DecoderCounters to reflect that droppedBufferCount
additional buffers were dropped.droppedBufferCount - The number of additional dropped buffers.protected void updateVideoFrameProcessingOffsetCounters(long processingOffsetUs)
DecoderCounters with a new video frame processing offset.processingOffsetUs - The video frame processing offset.protected void renderOutputBuffer(MediaCodecAdapter codec, int index, long presentationTimeUs)
codec - The codec that owns the output buffer.index - The index of the output buffer to drop.presentationTimeUs - The presentation time of the output buffer, in microseconds.protected void renderOutputBufferV21(MediaCodecAdapter codec, int index, long presentationTimeUs, long releaseTimeNs)
codec - The codec that owns the output buffer.index - The index of the output buffer to drop.presentationTimeUs - The presentation time of the output buffer, in microseconds.releaseTimeNs - The wallclock time at which the frame should be displayed, in nanoseconds.protected void setOutputSurfaceV23(MediaCodecAdapter codec, Surface surface)
protected MediaFormat getMediaFormat(Format format, String codecMimeType, MediaCodecVideoRenderer.CodecMaxValues codecMaxValues, float codecOperatingRate, boolean deviceNeedsNoPostProcessWorkaround, int tunnelingAudioSessionId)
MediaFormat that should be used to configure the decoder.format - The Format of media.codecMimeType - The MIME type handled by the codec.codecMaxValues - Codec max values that should be used when configuring the decoder.codecOperatingRate - The codec operating rate, or MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET if
no codec operating rate should be set.deviceNeedsNoPostProcessWorkaround - Whether the device is known to do post processing by
default that isn't compatible with ExoPlayer.tunnelingAudioSessionId - The audio session id to use for tunneling, or C.AUDIO_SESSION_ID_UNSET if tunneling should not be enabled.MediaFormat that should be used to configure the decoder.protected MediaCodecVideoRenderer.CodecMaxValues getCodecMaxValues(MediaCodecInfo codecInfo, Format format, Format[] streamFormats)
MediaCodecVideoRenderer.CodecMaxValues suitable for configuring a codec for format in a way
that will allow possible adaptation to other compatible formats in streamFormats.codecInfo - Information about the MediaCodec being configured.format - The Format for which the codec is being configured.streamFormats - The possible stream formats.MediaCodecVideoRenderer.CodecMaxValues.protected MediaCodecDecoderException createDecoderException(Throwable cause, @Nullable MediaCodecInfo codecInfo)
createDecoderException in class MediaCodecRendererprotected static int getMaxInputSize(MediaCodecInfo codecInfo, Format format)
MediaCodec and Format.codecInfo - Information about the MediaCodec being configured.format - The format.Format.NO_VALUE if a maximum could not
be determined.protected boolean codecNeedsSetOutputSurfaceWorkaround(String name)
MediaCodec.setOutputSurface(Surface)
incorrectly.
If true is returned then we fall back to releasing and re-instantiating the codec instead.
name - The name of the codec.MediaCodec.setOutputSurface(Surface)
incorrectly.protected Surface getSurface()