Class MediaCodecRenderer
- java.lang.Object
-
- com.google.android.exoplayer2.BaseRenderer
-
- com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
-
- All Implemented Interfaces:
PlayerMessage.Target
,Renderer
,RendererCapabilities
- Direct Known Subclasses:
MediaCodecAudioRenderer
,MediaCodecVideoRenderer
@Deprecated public abstract class MediaCodecRenderer extends BaseRenderer
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.An abstract renderer that usesMediaCodec
to decode samples for rendering.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MediaCodecRenderer.DecoderInitializationException
Deprecated.Thrown when a failure occurs instantiating a decoder.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.Renderer
Renderer.MessageType, Renderer.State, Renderer.WakeupListener
-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.RendererCapabilities
RendererCapabilities.AdaptiveSupport, RendererCapabilities.Capabilities, RendererCapabilities.DecoderSupport, RendererCapabilities.FormatSupport, RendererCapabilities.HardwareAccelerationSupport, RendererCapabilities.Listener, RendererCapabilities.TunnelingSupport
-
-
Field Summary
Fields Modifier and Type Field Description protected static float
CODEC_OPERATING_RATE_UNSET
Deprecated.Indicates no codec operating rate should be set.protected DecoderCounters
decoderCounters
Deprecated.-
Fields inherited from interface com.google.android.exoplayer2.Renderer
MSG_CUSTOM_BASE, MSG_SET_AUDIO_ATTRIBUTES, MSG_SET_AUDIO_SESSION_ID, MSG_SET_AUX_EFFECT_INFO, MSG_SET_CAMERA_MOTION_LISTENER, MSG_SET_CHANGE_FRAME_RATE_STRATEGY, MSG_SET_PREFERRED_AUDIO_DEVICE, MSG_SET_SCALING_MODE, MSG_SET_SKIP_SILENCE_ENABLED, MSG_SET_VIDEO_EFFECTS, MSG_SET_VIDEO_FRAME_METADATA_LISTENER, MSG_SET_VIDEO_OUTPUT, MSG_SET_VIDEO_OUTPUT_RESOLUTION, MSG_SET_VOLUME, MSG_SET_WAKEUP_LISTENER, STATE_DISABLED, STATE_ENABLED, STATE_STARTED
-
Fields inherited from interface com.google.android.exoplayer2.RendererCapabilities
ADAPTIVE_NOT_SEAMLESS, ADAPTIVE_NOT_SUPPORTED, ADAPTIVE_SEAMLESS, ADAPTIVE_SUPPORT_MASK, DECODER_SUPPORT_FALLBACK, DECODER_SUPPORT_FALLBACK_MIMETYPE, DECODER_SUPPORT_PRIMARY, FORMAT_EXCEEDS_CAPABILITIES, FORMAT_HANDLED, FORMAT_SUPPORT_MASK, FORMAT_UNSUPPORTED_DRM, FORMAT_UNSUPPORTED_SUBTYPE, FORMAT_UNSUPPORTED_TYPE, HARDWARE_ACCELERATION_NOT_SUPPORTED, HARDWARE_ACCELERATION_SUPPORT_MASK, HARDWARE_ACCELERATION_SUPPORTED, MODE_SUPPORT_MASK, TUNNELING_NOT_SUPPORTED, TUNNELING_SUPPORT_MASK, TUNNELING_SUPPORTED
-
-
Constructor Summary
Constructors Constructor Description MediaCodecRenderer(@com.google.android.exoplayer2.C.TrackType int trackType, MediaCodecAdapter.Factory codecAdapterFactory, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, float assumedMinimumCodecOperatingRate)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected DecoderReuseEvaluation
canReuseCodec(MediaCodecInfo codecInfo, Format oldFormat, Format newFormat)
Deprecated.Evaluates whether the existingMediaCodec
can be kept for a newFormat
, and if it can whether it requires reconfiguration.protected MediaCodecDecoderException
createDecoderException(Throwable cause, MediaCodecInfo codecInfo)
Deprecated.protected boolean
flushOrReinitializeCodec()
Deprecated.Flushes the codec.protected boolean
flushOrReleaseCodec()
Deprecated.Flushes the codec.protected MediaCodecAdapter
getCodec()
Deprecated.protected MediaCodecInfo
getCodecInfo()
Deprecated.protected boolean
getCodecNeedsEosPropagation()
Deprecated.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
getCodecOperatingRate()
Deprecated.Returns the operating rate used by the current codecprotected float
getCodecOperatingRateV23(float targetPlaybackSpeed, Format format, Format[] streamFormats)
Deprecated.Returns theMediaFormat.KEY_OPERATING_RATE
value for a given playback speed, currentFormat
and set of possible stream formats.protected MediaFormat
getCodecOutputMediaFormat()
Deprecated.protected abstract List<MediaCodecInfo>
getDecoderInfos(MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder)
Deprecated.Returns a list of decoders that can decode media in the specified format, in priority order.protected abstract MediaCodecAdapter.Configuration
getMediaCodecConfiguration(MediaCodecInfo codecInfo, Format format, MediaCrypto crypto, float codecOperatingRate)
Deprecated.Returns theMediaCodecAdapter.Configuration
that will be used to create and configure aMediaCodec
to decode the givenFormat
for a playback.protected long
getOutputStreamOffsetUs()
Deprecated.Returns the offset that should be subtracted frombufferPresentationTimeUs
inprocessOutputBuffer(long, long, MediaCodecAdapter, ByteBuffer, int, int, int, long, boolean, boolean, Format)
to get the playback position with respect to the media.protected float
getPlaybackSpeed()
Deprecated.Returns the current playback speed, as set bysetPlaybackSpeed(float, float)
.protected void
handleInputBufferSupplementalData(DecoderInputBuffer buffer)
Deprecated.Handles supplemental data associated with an input buffer.protected boolean
isBypassPossible(Format format)
Deprecated.Returns whether buffers in the input format can be processed without a codec.boolean
isEnded()
Deprecated.Whether the renderer is ready for theExoPlayer
instance to transition toPlayer.STATE_ENDED
.boolean
isReady()
Deprecated.Whether the renderer is able to immediately render media from the current position.protected void
maybeInitCodecOrBypass()
Deprecated.protected void
onCodecError(Exception codecError)
Deprecated.Called when a codec error has occurred.protected void
onCodecInitialized(String name, MediaCodecAdapter.Configuration configuration, long initializedTimestampMs, long initializationDurationMs)
Deprecated.Called when aMediaCodec
has been created and configured.protected void
onCodecReleased(String name)
Deprecated.Called when aMediaCodec
has been released.protected void
onDisabled()
Deprecated.Called when the renderer is disabled.protected void
onEnabled(boolean joining, boolean mayRenderStartOfStream)
Deprecated.Called when the renderer is enabled.protected DecoderReuseEvaluation
onInputFormatChanged(FormatHolder formatHolder)
Deprecated.Called when a newFormat
is read from the upstreamMediaPeriod
.protected void
onOutputFormatChanged(Format format, MediaFormat mediaFormat)
Deprecated.Called when one of the output formats changes.protected void
onOutputStreamOffsetUsChanged(long outputStreamOffsetUs)
Deprecated.Called after the output stream offset changes.protected void
onPositionReset(long positionUs, boolean joining)
Deprecated.Called when the position is reset.protected void
onProcessedOutputBuffer(long presentationTimeUs)
Deprecated.Called when an output buffer is successfully processed.protected void
onProcessedStreamChange()
Deprecated.Called after the last output buffer before a stream change has been processed.protected void
onQueueInputBuffer(DecoderInputBuffer buffer)
Deprecated.Called immediately before an input buffer is queued into the codec.protected void
onReadyToInitializeCodec(Format format)
Deprecated.Called when ready to initialize theMediaCodecAdapter
.protected void
onReset()
Deprecated.Called when the renderer is reset.protected void
onStarted()
Deprecated.Called when the renderer is started.protected void
onStopped()
Deprecated.Called when the renderer is stopped.protected void
onStreamChanged(Format[] formats, long startPositionUs, long offsetUs)
Deprecated.Called when the renderer's stream has changed.protected abstract boolean
processOutputBuffer(long positionUs, long elapsedRealtimeUs, MediaCodecAdapter codec, ByteBuffer buffer, int bufferIndex, int bufferFlags, int sampleCount, long bufferPresentationTimeUs, boolean isDecodeOnlyBuffer, boolean isLastBuffer, Format format)
Deprecated.Processes an output media buffer.protected void
releaseCodec()
Deprecated.void
render(long positionUs, long elapsedRealtimeUs)
Deprecated.Incrementally renders theSampleStream
.protected void
renderToEndOfStream()
Deprecated.Incrementally renders any remaining output.protected void
resetCodecStateForFlush()
Deprecated.Resets the renderer internal state after a codec flush.protected void
resetCodecStateForRelease()
Deprecated.Resets the renderer internal state after a codec release.protected void
setPendingOutputEndOfStream()
Deprecated.Notifies the renderer that output end of stream is pending and should be handled on the next render.protected void
setPendingPlaybackException(ExoPlaybackException exception)
Deprecated.Sets an exception to be re-thrown by render.void
setPlaybackSpeed(float currentPlaybackSpeed, float targetPlaybackSpeed)
Deprecated.Indicates the playback speed to this renderer.void
setRenderTimeLimitMs(long renderTimeLimitMs)
Deprecated.Sets a limit on the time a singlerender(long, long)
call can spend draining and filling the decoder.protected boolean
shouldInitCodec(MediaCodecInfo codecInfo)
Deprecated.protected boolean
shouldReinitCodec()
Deprecated.Returns whether the renderer needs to re-initialize the codec, possibly as a result of a change in device capabilities.protected boolean
shouldUseBypass(Format format)
Deprecated.Returns whether buffers in the input format can be processed without a codec.@com.google.android.exoplayer2.RendererCapabilities.Capabilities int
supportsFormat(Format format)
Deprecated.Returns the extent to which theRenderer
supports a given format.protected abstract @com.google.android.exoplayer2.RendererCapabilities.Capabilities int
supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
Deprecated.Returns theRendererCapabilities.Capabilities
for the givenFormat
.protected static boolean
supportsFormatDrm(Format format)
Deprecated.Returns whether this renderer supports the givenFormat's
DRM scheme.@com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int
supportsMixedMimeTypeAdaptation()
Deprecated.Returns the extent to which theRenderer
supports adapting between supported formats that have different MIME types.protected boolean
updateCodecOperatingRate()
Deprecated.Updates the codec operating rate, or triggers codec release and re-initialization if a previously set operating rate needs to be cleared.protected void
updateOutputFormatForTime(long presentationTimeUs)
Deprecated.Updates the output formats for the specified output buffer timestamp, callingonOutputFormatChanged(com.google.android.exoplayer2.Format, android.media.MediaFormat)
if a change has occurred.-
Methods inherited from class com.google.android.exoplayer2.BaseRenderer
clearListener, createRendererException, createRendererException, disable, enable, getCapabilities, getConfiguration, getFormatHolder, getIndex, getLastResetPositionUs, getMediaClock, getPlayerId, getReadingPositionUs, getState, getStream, getStreamFormats, getTrackType, handleMessage, hasReadStreamToEnd, init, isCurrentStreamFinal, isSourceReady, maybeThrowStreamError, onRelease, onRendererCapabilitiesChanged, readSource, release, replaceStream, reset, resetPosition, setCurrentStreamFinal, setListener, skipSource, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.google.android.exoplayer2.RendererCapabilities
getName
-
-
-
-
Field Detail
-
CODEC_OPERATING_RATE_UNSET
protected static final float CODEC_OPERATING_RATE_UNSET
Deprecated.Indicates no codec operating rate should be set.- See Also:
- Constant Field Values
-
decoderCounters
protected DecoderCounters decoderCounters
Deprecated.
-
-
Constructor Detail
-
MediaCodecRenderer
public MediaCodecRenderer(@com.google.android.exoplayer2.C.TrackType int trackType, MediaCodecAdapter.Factory codecAdapterFactory, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, float assumedMinimumCodecOperatingRate)
Deprecated.- Parameters:
trackType
- Thetrack type
that the renderer handles.codecAdapterFactory
- A factory forMediaCodecAdapter
instances.mediaCodecSelector
- A decoder selector.enableDecoderFallback
- Whether to enable fallback to lower-priority decoders if decoder initialization fails. This may result in using a decoder that is less efficient or slower than the primary decoder.assumedMinimumCodecOperatingRate
- 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 usingMediaFormat.KEY_OPERATING_RATE
).
-
-
Method Detail
-
setRenderTimeLimitMs
public void setRenderTimeLimitMs(long renderTimeLimitMs)
Deprecated.Sets a limit on the time a singlerender(long, long)
call can spend draining and filling the decoder.This method should be called right after creating an instance of this class.
- Parameters:
renderTimeLimitMs
- The render time limit in milliseconds, orC.TIME_UNSET
for no limit.
-
supportsMixedMimeTypeAdaptation
public final @com.google.android.exoplayer2.RendererCapabilities.AdaptiveSupport int supportsMixedMimeTypeAdaptation()
Deprecated.Description copied from interface:RendererCapabilities
Returns the extent to which theRenderer
supports adapting between supported formats that have different MIME types.- Specified by:
supportsMixedMimeTypeAdaptation
in interfaceRendererCapabilities
- Overrides:
supportsMixedMimeTypeAdaptation
in classBaseRenderer
- Returns:
- The
RendererCapabilities.AdaptiveSupport
for adapting between supported formats that have different MIME types.
-
supportsFormat
public final @com.google.android.exoplayer2.RendererCapabilities.Capabilities int supportsFormat(Format format) throws ExoPlaybackException
Deprecated.Description copied from interface:RendererCapabilities
Returns the extent to which theRenderer
supports a given format.- Parameters:
format
- The format.- Returns:
- The
RendererCapabilities.Capabilities
for this format. - Throws:
ExoPlaybackException
- If an error occurs.
-
supportsFormat
protected abstract @com.google.android.exoplayer2.RendererCapabilities.Capabilities int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format) throws MediaCodecUtil.DecoderQueryException
Deprecated.Returns theRendererCapabilities.Capabilities
for the givenFormat
.- Parameters:
mediaCodecSelector
- The decoder selector.format
- TheFormat
.- Returns:
- The
RendererCapabilities.Capabilities
for thisFormat
. - Throws:
MediaCodecUtil.DecoderQueryException
- If there was an error querying decoders.
-
getDecoderInfos
protected abstract List<MediaCodecInfo> getDecoderInfos(MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException
Deprecated.Returns a list of decoders that can decode media in the specified format, in priority order.- Parameters:
mediaCodecSelector
- The decoder selector.format
- TheFormat
for which a decoder is required.requiresSecureDecoder
- Whether a secure decoder is required.- Returns:
- A list of
MediaCodecInfo
s corresponding to decoders. May be empty. - Throws:
MediaCodecUtil.DecoderQueryException
- Thrown if there was an error querying decoders.
-
getMediaCodecConfiguration
protected abstract MediaCodecAdapter.Configuration getMediaCodecConfiguration(MediaCodecInfo codecInfo, Format format, @Nullable MediaCrypto crypto, float codecOperatingRate)
Deprecated.Returns theMediaCodecAdapter.Configuration
that will be used to create and configure aMediaCodec
to decode the givenFormat
for a playback.- Parameters:
codecInfo
- Information about theMediaCodec
being configured.format
- TheFormat
for which the codec is being configured.crypto
- For drm protected playbacks, aMediaCrypto
to use for decryption.codecOperatingRate
- The codec operating rate, orCODEC_OPERATING_RATE_UNSET
if no codec operating rate should be set.- Returns:
- The parameters needed to call
MediaCodec.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int)
.
-
maybeInitCodecOrBypass
protected final void maybeInitCodecOrBypass() throws ExoPlaybackException
Deprecated.- Throws:
ExoPlaybackException
-
isBypassPossible
protected final boolean isBypassPossible(Format format)
Deprecated.Returns whether buffers in the input format can be processed without a codec.This method returns the possibility of bypass mode with checking both the renderer capabilities and DRM protection.
- Parameters:
format
- The inputFormat
.- Returns:
- Whether playback bypassing
MediaCodec
is possible.
-
shouldUseBypass
protected boolean shouldUseBypass(Format format)
Deprecated.Returns whether buffers in the input format can be processed without a codec.This method is only called if the content is not DRM protected, because if the content is DRM protected use of bypass is never possible.
- Parameters:
format
- The inputFormat
.- Returns:
- Whether playback bypassing
MediaCodec
is supported.
-
shouldInitCodec
protected boolean shouldInitCodec(MediaCodecInfo codecInfo)
Deprecated.
-
shouldReinitCodec
protected boolean shouldReinitCodec()
Deprecated.Returns whether the renderer needs to re-initialize the codec, possibly as a result of a change in device capabilities.
-
getCodecNeedsEosPropagation
protected boolean getCodecNeedsEosPropagation()
Deprecated.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.
-
setPendingPlaybackException
protected final void setPendingPlaybackException(ExoPlaybackException exception)
Deprecated.Sets an exception to be re-thrown by render.- Parameters:
exception
- The exception.
-
updateOutputFormatForTime
protected final void updateOutputFormatForTime(long presentationTimeUs) throws ExoPlaybackException
Deprecated.Updates the output formats for the specified output buffer timestamp, callingonOutputFormatChanged(com.google.android.exoplayer2.Format, android.media.MediaFormat)
if a change has occurred.Subclasses should only call this method if operating in a mode where buffers are not dequeued from the decoder, for example when using video tunneling).
- Throws:
ExoPlaybackException
- Thrown if an error occurs as a result of the output format change.
-
getCodec
@Nullable protected final MediaCodecAdapter getCodec()
Deprecated.
-
getCodecOutputMediaFormat
@Nullable protected final MediaFormat getCodecOutputMediaFormat()
Deprecated.
-
getCodecInfo
@Nullable protected final MediaCodecInfo getCodecInfo()
Deprecated.
-
onEnabled
protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException
Deprecated.Description copied from class:BaseRenderer
Called when the renderer is enabled.The default implementation is a no-op.
- Overrides:
onEnabled
in classBaseRenderer
- Parameters:
joining
- 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 notRenderer.STATE_STARTED
yet.- Throws:
ExoPlaybackException
- If an error occurs.
-
onStreamChanged
protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) throws ExoPlaybackException
Deprecated.Description copied from class:BaseRenderer
Called when the renderer's stream has changed. This occurs when the renderer is enabled afterBaseRenderer.onEnabled(boolean, boolean)
has been called, and also when the stream has been replaced whilst the renderer is enabled or started.The default implementation is a no-op.
- Overrides:
onStreamChanged
in classBaseRenderer
- Parameters:
formats
- The enabled formats.startPositionUs
- The start position of the new stream in renderer time (microseconds).offsetUs
- The offset that will be added to the timestamps of buffers read viaBaseRenderer.readSource(com.google.android.exoplayer2.FormatHolder, com.google.android.exoplayer2.decoder.DecoderInputBuffer, @com.google.android.exoplayer2.source.SampleStream.ReadFlags int)
so that decoder input buffers have monotonically increasing timestamps.- Throws:
ExoPlaybackException
- If an error occurs.
-
onPositionReset
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
Deprecated.Description copied from class:BaseRenderer
Called when the position is reset. This occurs when the renderer is enabled afterBaseRenderer.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.
- Overrides:
onPositionReset
in classBaseRenderer
- Parameters:
positionUs
- The new playback position in microseconds.joining
- Whether this renderer is being enabled to join an ongoing playback.- Throws:
ExoPlaybackException
- If an error occurs.
-
setPlaybackSpeed
public void setPlaybackSpeed(float currentPlaybackSpeed, float targetPlaybackSpeed) throws ExoPlaybackException
Deprecated.Description copied from interface:Renderer
Indicates the playback speed to this renderer.The default implementation is a no-op.
- Parameters:
currentPlaybackSpeed
- The factor by which playback is currently sped up.targetPlaybackSpeed
- The target factor by which playback should be sped up. This may be different fromcurrentPlaybackSpeed
, for example, if the speed is temporarily adjusted for live playback.- Throws:
ExoPlaybackException
- If an error occurs handling the playback speed.
-
onDisabled
protected void onDisabled()
Deprecated.Description copied from class:BaseRenderer
Called when the renderer is disabled.The default implementation is a no-op.
- Overrides:
onDisabled
in classBaseRenderer
-
onReset
protected void onReset()
Deprecated.Description copied from class:BaseRenderer
Called when the renderer is reset.The default implementation is a no-op.
- Overrides:
onReset
in classBaseRenderer
-
releaseCodec
protected void releaseCodec()
Deprecated.
-
onStarted
protected void onStarted()
Deprecated.Description copied from class:BaseRenderer
Called when the renderer is started.The default implementation is a no-op.
- Overrides:
onStarted
in classBaseRenderer
-
onStopped
protected void onStopped()
Deprecated.Description copied from class:BaseRenderer
Called when the renderer is stopped.The default implementation is a no-op.
- Overrides:
onStopped
in classBaseRenderer
-
render
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException
Deprecated.Description copied from interface:Renderer
Incrementally renders theSampleStream
.If the renderer is in the
Renderer.STATE_ENABLED
state then each call to this method will do work toward being ready to render theSampleStream
when the renderer is started. If the renderer is in theRenderer.STATE_STARTED
state then calls to this method will render theSampleStream
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
Renderer.STATE_ENABLED
state, unless it's the initial start of the media after callingRenderer.enable(RendererConfiguration, Format[], SampleStream, long, boolean, boolean, long, long)
withmayRenderStartOfStream
set tofalse
.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:
Renderer.STATE_ENABLED
,Renderer.STATE_STARTED
.- Parameters:
positionUs
- 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.- Throws:
ExoPlaybackException
- If an error occurs.
-
flushOrReinitializeCodec
protected final boolean flushOrReinitializeCodec() throws ExoPlaybackException
Deprecated.Flushes the codec. If flushing is not possible, the codec will be released and re-instantiated. This method is a no-op if the codec isnull
.The implementation of this method calls
flushOrReleaseCodec()
, andmaybeInitCodecOrBypass()
if the codec needs to be re-instantiated.- Returns:
- Whether the codec was released and reinitialized, rather than being flushed.
- Throws:
ExoPlaybackException
- If an error occurs re-instantiating the codec.
-
flushOrReleaseCodec
protected boolean flushOrReleaseCodec()
Deprecated.Flushes the codec. If flushing is not possible, the codec will be released. This method is a no-op if the codec isnull
.- Returns:
- Whether the codec was released.
-
resetCodecStateForFlush
@CallSuper protected void resetCodecStateForFlush()
Deprecated.Resets the renderer internal state after a codec flush.
-
resetCodecStateForRelease
@CallSuper protected void resetCodecStateForRelease()
Deprecated.Resets the renderer internal state after a codec release.Note that this only needs to reset state variables that are changed in addition to those already changed in
resetCodecStateForFlush()
.
-
createDecoderException
protected MediaCodecDecoderException createDecoderException(Throwable cause, @Nullable MediaCodecInfo codecInfo)
Deprecated.
-
onReadyToInitializeCodec
protected void onReadyToInitializeCodec(Format format) throws ExoPlaybackException
Deprecated.Called when ready to initialize theMediaCodecAdapter
.This method is called just before the renderer obtains the configuration for the
MediaCodecAdapter
and creates the adapter via the passed inMediaCodecAdapter.Factory
.The default implementation is a no-op.
- Parameters:
format
- TheFormat
for which the codec is being configured.- Throws:
ExoPlaybackException
- If an error occurs preparing for initializing the codec.
-
onCodecInitialized
protected void onCodecInitialized(String name, MediaCodecAdapter.Configuration configuration, long initializedTimestampMs, long initializationDurationMs)
Deprecated.Called when aMediaCodec
has been created and configured.The default implementation is a no-op.
- Parameters:
name
- The name of the codec that was initialized.configuration
- TheMediaCodecAdapter.Configuration
used to configure the codec.initializedTimestampMs
-SystemClock.elapsedRealtime()
when initialization finished.initializationDurationMs
- The time taken to initialize the codec in milliseconds.
-
onCodecReleased
protected void onCodecReleased(String name)
Deprecated.Called when aMediaCodec
has been released.The default implementation is a no-op.
- Parameters:
name
- The name of the codec that was released.
-
onCodecError
protected void onCodecError(Exception codecError)
Deprecated.Called when a codec error has occurred.The default implementation is a no-op.
- Parameters:
codecError
- The error.
-
onInputFormatChanged
@CallSuper @Nullable protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException
Deprecated.Called when a newFormat
is read from the upstreamMediaPeriod
.- Parameters:
formatHolder
- AFormatHolder
that holds the newFormat
.- Returns:
- 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:
ExoPlaybackException
- If an error occurs re-initializing theMediaCodec
.
-
onOutputFormatChanged
protected void onOutputFormatChanged(Format format, @Nullable MediaFormat mediaFormat) throws ExoPlaybackException
Deprecated.Called when one of the output formats changes.The default implementation is a no-op.
- Parameters:
format
- The inputFormat
to which future output now corresponds. If the renderer is in bypass mode, this is also the output format.mediaFormat
- The codec outputMediaFormat
, ornull
if the renderer is in bypass mode.- Throws:
ExoPlaybackException
- Thrown if an error occurs configuring the output.
-
handleInputBufferSupplementalData
protected void handleInputBufferSupplementalData(DecoderInputBuffer buffer) throws ExoPlaybackException
Deprecated.Handles supplemental data associated with an input buffer.The default implementation is a no-op.
- Parameters:
buffer
- The input buffer that is about to be queued.- Throws:
ExoPlaybackException
- Thrown if an error occurs handling supplemental data.
-
onQueueInputBuffer
protected void onQueueInputBuffer(DecoderInputBuffer buffer) throws ExoPlaybackException
Deprecated.Called immediately before an input buffer is queued into the codec.The default implementation is a no-op.
- Parameters:
buffer
- The buffer to be queued.- Throws:
ExoPlaybackException
- Thrown if an error occurs handling the input buffer.
-
onProcessedOutputBuffer
@CallSuper protected void onProcessedOutputBuffer(long presentationTimeUs)
Deprecated.Called when an output buffer is successfully processed.- Parameters:
presentationTimeUs
- The timestamp associated with the output buffer.
-
onProcessedStreamChange
protected void onProcessedStreamChange()
Deprecated.Called after the last output buffer before a stream change has been processed.
-
canReuseCodec
protected DecoderReuseEvaluation canReuseCodec(MediaCodecInfo codecInfo, Format oldFormat, Format newFormat)
Deprecated.Evaluates whether the existingMediaCodec
can be kept for a newFormat
, and if it can whether it requires reconfiguration.The default implementation does not allow decoder reuse.
- Parameters:
codecInfo
- AMediaCodecInfo
describing the decoder.oldFormat
- TheFormat
for which the existing instance is configured.newFormat
- The newFormat
.- Returns:
- The result of the evaluation.
-
onOutputStreamOffsetUsChanged
protected void onOutputStreamOffsetUsChanged(long outputStreamOffsetUs)
Deprecated.Called after the output stream offset changes.The default implementation is a no-op.
- Parameters:
outputStreamOffsetUs
- The output stream offset in microseconds.
-
isEnded
public boolean isEnded()
Deprecated.Description copied from interface:Renderer
Whether the renderer is ready for theExoPlayer
instance to transition toPlayer.STATE_ENDED
. The player will make this transition as soon astrue
is returned by all of its renderers.This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
,Renderer.STATE_STARTED
.- Returns:
- Whether the renderer is ready for the player to transition to the ended state.
-
isReady
public boolean isReady()
Deprecated.Description copied from interface:Renderer
Whether the renderer is able to immediately render media from the current position.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
.- Returns:
- Whether the renderer is ready to render media.
-
getPlaybackSpeed
protected float getPlaybackSpeed()
Deprecated.Returns the current playback speed, as set bysetPlaybackSpeed(float, float)
.
-
getCodecOperatingRate
protected float getCodecOperatingRate()
Deprecated.Returns the operating rate used by the current codec
-
getCodecOperatingRateV23
protected float getCodecOperatingRateV23(float targetPlaybackSpeed, Format format, Format[] streamFormats)
Deprecated.Returns theMediaFormat.KEY_OPERATING_RATE
value for a given playback speed, currentFormat
and set of possible stream formats.The default implementation returns
CODEC_OPERATING_RATE_UNSET
.- Parameters:
targetPlaybackSpeed
- 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
- TheFormat
for which the codec is being configured.streamFormats
- The possible stream formats.- Returns:
- The codec operating rate, or
CODEC_OPERATING_RATE_UNSET
if no codec operating rate should be set.
-
updateCodecOperatingRate
protected final boolean updateCodecOperatingRate() throws ExoPlaybackException
Deprecated.Updates the codec operating rate, or triggers codec release and re-initialization if a previously set operating rate needs to be cleared.- Returns:
- False if codec release and re-initialization was triggered. True in all other cases.
- Throws:
ExoPlaybackException
- If an error occurs releasing or initializing a codec.
-
processOutputBuffer
protected abstract 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
Deprecated.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(long, boolean)
will always receive a newByteBuffer
to be processed.- Parameters:
positionUs
- 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
- TheMediaCodecAdapter
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 (seeMediaCodec.getOutputBuffer(int)
). Thisbuffer
can only be null for video data. Note that the buffer data can still be rendered in this case by using thebufferIndex
.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 withC.BUFFER_FLAG_DECODE_ONLY
by the source.isLastBuffer
- 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
- TheFormat
associated with the buffer.- Returns:
- Whether the output buffer was fully processed (for example, rendered or skipped).
- Throws:
ExoPlaybackException
- If an error occurs processing the output buffer.
-
renderToEndOfStream
protected void renderToEndOfStream() throws ExoPlaybackException
Deprecated.Incrementally renders any remaining output.The default implementation is a no-op.
- Throws:
ExoPlaybackException
- Thrown if an error occurs rendering remaining output.
-
setPendingOutputEndOfStream
protected final void setPendingOutputEndOfStream()
Deprecated.Notifies the renderer that output end of stream is pending and should be handled on the next render.
-
getOutputStreamOffsetUs
protected final long getOutputStreamOffsetUs()
Deprecated.Returns the offset that should be subtracted frombufferPresentationTimeUs
inprocessOutputBuffer(long, long, MediaCodecAdapter, ByteBuffer, int, int, int, long, boolean, boolean, Format)
to get the playback position with respect to the media.
-
-