Class MediaCodecAudioRenderer
- java.lang.Object
-
- com.google.android.exoplayer2.BaseRenderer
-
- com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
-
- com.google.android.exoplayer2.audio.MediaCodecAudioRenderer
-
- All Implemented Interfaces:
PlayerMessage.Target
,Renderer
,RendererCapabilities
,MediaClock
public class MediaCodecAudioRenderer extends MediaCodecRenderer implements MediaClock
Decodes and renders audio usingMediaCodec
and anAudioSink
.This renderer accepts the following messages sent via
ExoPlayer.createMessage(Target)
on the playback thread:- Message with type
Renderer.MSG_SET_VOLUME
to set the volume. The message payload should be aFloat
with 0 being silence and 1 being unity gain. - Message with type
Renderer.MSG_SET_AUDIO_ATTRIBUTES
to set the audio attributes. The message payload should be anAudioAttributes
instance that will configure the underlying audio track. - Message with type
Renderer.MSG_SET_AUX_EFFECT_INFO
to set the auxiliary effect. The message payload should be anAuxEffectInfo
instance that will configure the underlying audio track. - Message with type
Renderer.MSG_SET_SKIP_SILENCE_ENABLED
to enable or disable skipping silences. The message payload should be aBoolean
. - Message with type
Renderer.MSG_SET_AUDIO_SESSION_ID
to set the audio session ID. The message payload should be a session IDInteger
that will be attached to the underlying audio track.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
MediaCodecRenderer.DecoderInitializationException
-
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.TunnelingSupport
-
-
Field Summary
-
Fields inherited from class com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
CODEC_OPERATING_RATE_UNSET, decoderCounters
-
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_SCALING_MODE, MSG_SET_SKIP_SILENCE_ENABLED, MSG_SET_VIDEO_FRAME_METADATA_LISTENER, MSG_SET_VIDEO_OUTPUT, 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_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 MediaCodecAudioRenderer(Context context, MediaCodecAdapter.Factory codecAdapterFactory, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, AudioRendererEventListener eventListener, AudioSink audioSink)
Creates a new instance.MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector)
MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, Handler eventHandler, AudioRendererEventListener eventListener, AudioSink audioSink)
MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, Handler eventHandler, AudioRendererEventListener eventListener)
MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, Handler eventHandler, AudioRendererEventListener eventListener, AudioCapabilities audioCapabilities, AudioProcessor... audioProcessors)
MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, Handler eventHandler, AudioRendererEventListener eventListener, AudioSink audioSink)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DecoderReuseEvaluation
canReuseCodec(MediaCodecInfo codecInfo, Format oldFormat, Format newFormat)
Evaluates whether the existingMediaCodec
can be kept for a newFormat
, and if it can whether it requires reconfiguration.void
experimentalSetEnableKeepAudioTrackOnSeek(boolean enableKeepAudioTrackOnSeek)
Sets whether to enable the experimental feature that keeps and flushes theAudioTrack
when a seek occurs, as opposed to releasing and reinitialising.protected int
getCodecMaxInputSize(MediaCodecInfo codecInfo, Format format, Format[] streamFormats)
Returns a maximum input size suitable for configuring a codec forformat
in a way that will allow possible adaptation to other compatible formats instreamFormats
.protected float
getCodecOperatingRateV23(float targetPlaybackSpeed, Format format, Format[] streamFormats)
Returns theMediaFormat.KEY_OPERATING_RATE
value for a given playback speed, currentFormat
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.MediaClock
getMediaClock()
If the renderer advances its own playback position then this method returns a correspondingMediaClock
.protected MediaCodecAdapter.Configuration
getMediaCodecConfiguration(MediaCodecInfo codecInfo, Format format, MediaCrypto crypto, float codecOperatingRate)
Returns theMediaCodecAdapter.Configuration
that will be used to create and configure aMediaCodec
to decode the givenFormat
for a playback.protected MediaFormat
getMediaFormat(Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate)
Returns the frameworkMediaFormat
that can be used to configure aMediaCodec
for decoding the givenFormat
for playback.String
getName()
Returns the name of this renderer, for logging and debugging purposes.PlaybackParameters
getPlaybackParameters()
Returns the active playback parameters.long
getPositionUs()
Returns the current media position in microseconds.void
handleMessage(@com.google.android.exoplayer2.Renderer.MessageType int messageType, Object message)
Handles a message delivered to the target.boolean
isEnded()
Whether the renderer is ready for theExoPlayer
instance to transition toPlayer.STATE_ENDED
.boolean
isReady()
Whether the renderer is able to immediately render media from the current position.protected void
onCodecError(Exception codecError)
Called when a codec error has occurred.protected void
onCodecInitialized(String name, MediaCodecAdapter.Configuration configuration, long initializedTimestampMs, long initializationDurationMs)
Called when aMediaCodec
has been created and configured.protected void
onCodecReleased(String name)
Called when aMediaCodec
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 newFormat
is read from the upstreamMediaPeriod
.protected void
onOutputFormatChanged(Format format, MediaFormat mediaFormat)
Called when one of the output formats changes.protected void
onPositionDiscontinuity()
protected void
onPositionReset(long positionUs, boolean joining)
Called when the position is reset.protected void
onProcessedStreamChange()
Called after the last output buffer before a stream change has been processed.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
renderToEndOfStream()
Incrementally renders any remaining output.void
setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters.protected boolean
shouldUseBypass(Format format)
Returns whether buffers in the input format can be processed without a codec.protected @com.google.android.exoplayer2.RendererCapabilities.Capabilities int
supportsFormat(MediaCodecSelector mediaCodecSelector, Format format)
Returns theRendererCapabilities.Capabilities
for the givenFormat
.-
Methods inherited from class com.google.android.exoplayer2.mediacodec.MediaCodecRenderer
createDecoderException, flushOrReinitializeCodec, flushOrReleaseCodec, getCodec, getCodecInfo, getCodecNeedsEosPropagation, getCodecOperatingRate, getCodecOutputMediaFormat, getOutputStreamOffsetUs, getPlaybackSpeed, handleInputBufferSupplementalData, maybeInitCodecOrBypass, onProcessedOutputBuffer, onStreamChanged, releaseCodec, render, resetCodecStateForFlush, resetCodecStateForRelease, setPendingOutputEndOfStream, setPendingPlaybackException, setPlaybackSpeed, setRenderTimeLimitMs, shouldInitCodec, shouldReinitCodec, supportsFormat, supportsFormatDrm, supportsMixedMimeTypeAdaptation, updateCodecOperatingRate, updateOutputFormatForTime
-
Methods inherited from class com.google.android.exoplayer2.BaseRenderer
createRendererException, createRendererException, disable, enable, getCapabilities, getConfiguration, getFormatHolder, getIndex, getLastResetPositionUs, getPlayerId, getReadingPositionUs, getState, getStream, getStreamFormats, getTrackType, hasReadStreamToEnd, init, isCurrentStreamFinal, isSourceReady, maybeThrowStreamError, readSource, replaceStream, reset, resetPosition, setCurrentStreamFinal, skipSource, start, stop
-
-
-
-
Constructor Detail
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector)
- Parameters:
context
- A context.mediaCodecSelector
- A decoder selector.
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, @Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener)
- Parameters:
context
- A context.mediaCodecSelector
- A decoder selector.eventHandler
- A handler to use when delivering events toeventListener
. 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.
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, @Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, AudioCapabilities audioCapabilities, AudioProcessor... audioProcessors)
- Parameters:
context
- A context.mediaCodecSelector
- A decoder selector.eventHandler
- A handler to use when delivering events toeventListener
. 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.audioCapabilities
- The audio capabilities for playback on this device. UseAudioCapabilities.DEFAULT_AUDIO_CAPABILITIES
if default capabilities (no encoded audio passthrough support) should be assumed.audioProcessors
- OptionalAudioProcessor
s that will process PCM audio before output.
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, @Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, AudioSink audioSink)
- Parameters:
context
- A context.mediaCodecSelector
- A decoder selector.eventHandler
- A handler to use when delivering events toeventListener
. 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.audioSink
- The sink to which audio will be output.
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, @Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, AudioSink audioSink)
- Parameters:
context
- A context.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 slower/less efficient than the primary decoder.eventHandler
- A handler to use when delivering events toeventListener
. 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.audioSink
- The sink to which audio will be output.
-
MediaCodecAudioRenderer
public MediaCodecAudioRenderer(Context context, MediaCodecAdapter.Factory codecAdapterFactory, MediaCodecSelector mediaCodecSelector, boolean enableDecoderFallback, @Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, AudioSink audioSink)
Creates a new instance.- Parameters:
context
- A context.codecAdapterFactory
- TheMediaCodecAdapter.Factory
used to createMediaCodecAdapter
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 slower/less efficient than the primary decoder.eventHandler
- A handler to use when delivering events toeventListener
. 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.audioSink
- The sink to which audio will be output.
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:Renderer
Returns the name of this renderer, for logging and debugging purposes. Should typically be the renderer's (un-obfuscated) class name.- Specified by:
getName
in interfaceRenderer
- Specified by:
getName
in interfaceRendererCapabilities
- Returns:
- The name of this renderer.
-
experimentalSetEnableKeepAudioTrackOnSeek
public void experimentalSetEnableKeepAudioTrackOnSeek(boolean enableKeepAudioTrackOnSeek)
Sets whether to enable the experimental feature that keeps and flushes theAudioTrack
when a seek occurs, as opposed to releasing and reinitialising. Off by default.This method is experimental, and will be renamed or removed in a future release.
- Parameters:
enableKeepAudioTrackOnSeek
- Whether to keep theAudioTrack
on seek.
-
supportsFormat
protected @com.google.android.exoplayer2.RendererCapabilities.Capabilities int supportsFormat(MediaCodecSelector mediaCodecSelector, Format format) throws MediaCodecUtil.DecoderQueryException
Description copied from class:MediaCodecRenderer
Returns theRendererCapabilities.Capabilities
for the givenFormat
.- Specified by:
supportsFormat
in classMediaCodecRenderer
- 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 List<MediaCodecInfo> getDecoderInfos(MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder) throws MediaCodecUtil.DecoderQueryException
Description copied from class:MediaCodecRenderer
Returns a list of decoders that can decode media in the specified format, in priority order.- Specified by:
getDecoderInfos
in classMediaCodecRenderer
- 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.
-
shouldUseBypass
protected boolean shouldUseBypass(Format format)
Description copied from class:MediaCodecRenderer
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.
- Overrides:
shouldUseBypass
in classMediaCodecRenderer
- Parameters:
format
- The inputFormat
.- Returns:
- Whether playback bypassing
MediaCodec
is supported.
-
getMediaCodecConfiguration
protected MediaCodecAdapter.Configuration getMediaCodecConfiguration(MediaCodecInfo codecInfo, Format format, @Nullable MediaCrypto crypto, float codecOperatingRate)
Description copied from class:MediaCodecRenderer
Returns theMediaCodecAdapter.Configuration
that will be used to create and configure aMediaCodec
to decode the givenFormat
for a playback.- Specified by:
getMediaCodecConfiguration
in classMediaCodecRenderer
- 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, orMediaCodecRenderer.CODEC_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)
.
-
canReuseCodec
protected DecoderReuseEvaluation canReuseCodec(MediaCodecInfo codecInfo, Format oldFormat, Format newFormat)
Description copied from class:MediaCodecRenderer
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.
- Overrides:
canReuseCodec
in classMediaCodecRenderer
- Parameters:
codecInfo
- AMediaCodecInfo
describing the decoder.oldFormat
- TheFormat
for which the existing instance is configured.newFormat
- The newFormat
.- Returns:
- The result of the evaluation.
-
getMediaClock
@Nullable public MediaClock getMediaClock()
Description copied from interface:Renderer
If the renderer advances its own playback position then this method returns a correspondingMediaClock
. If provided, the player will use the returnedMediaClock
as its source of time during playback. A player may have at most one renderer that returns aMediaClock
from this method.- Specified by:
getMediaClock
in interfaceRenderer
- Overrides:
getMediaClock
in classBaseRenderer
- Returns:
- The
MediaClock
tracking the playback position of the renderer, or null.
-
getCodecOperatingRateV23
protected float getCodecOperatingRateV23(float targetPlaybackSpeed, Format format, Format[] streamFormats)
Description copied from class:MediaCodecRenderer
Returns theMediaFormat.KEY_OPERATING_RATE
value for a given playback speed, currentFormat
and set of possible stream formats.The default implementation returns
MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET
.- Overrides:
getCodecOperatingRateV23
in classMediaCodecRenderer
- 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
MediaCodecRenderer.CODEC_OPERATING_RATE_UNSET
if no codec operating rate should be set.
-
onCodecInitialized
protected void onCodecInitialized(String name, MediaCodecAdapter.Configuration configuration, long initializedTimestampMs, long initializationDurationMs)
Description copied from class:MediaCodecRenderer
Called when aMediaCodec
has been created and configured.The default implementation is a no-op.
- Overrides:
onCodecInitialized
in classMediaCodecRenderer
- 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)
Description copied from class:MediaCodecRenderer
Called when aMediaCodec
has been released.The default implementation is a no-op.
- Overrides:
onCodecReleased
in classMediaCodecRenderer
- Parameters:
name
- The name of the codec that was released.
-
onCodecError
protected void onCodecError(Exception codecError)
Description copied from class:MediaCodecRenderer
Called when a codec error has occurred.The default implementation is a no-op.
- Overrides:
onCodecError
in classMediaCodecRenderer
- Parameters:
codecError
- The error.
-
onInputFormatChanged
@Nullable protected DecoderReuseEvaluation onInputFormatChanged(FormatHolder formatHolder) throws ExoPlaybackException
Description copied from class:MediaCodecRenderer
Called when a newFormat
is read from the upstreamMediaPeriod
.- Overrides:
onInputFormatChanged
in classMediaCodecRenderer
- 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
Description copied from class:MediaCodecRenderer
Called when one of the output formats changes.The default implementation is a no-op.
- Overrides:
onOutputFormatChanged
in classMediaCodecRenderer
- 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.
-
onPositionDiscontinuity
@CallSuper protected void onPositionDiscontinuity()
-
onEnabled
protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException
Description copied from class:BaseRenderer
Called when the renderer is enabled.The default implementation is a no-op.
- Overrides:
onEnabled
in classMediaCodecRenderer
- 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.
-
onPositionReset
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
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 classMediaCodecRenderer
- 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.
-
onStarted
protected void onStarted()
Description copied from class:BaseRenderer
Called when the renderer is started.The default implementation is a no-op.
- Overrides:
onStarted
in classMediaCodecRenderer
-
onStopped
protected void onStopped()
Description copied from class:BaseRenderer
Called when the renderer is stopped.The default implementation is a no-op.
- Overrides:
onStopped
in classMediaCodecRenderer
-
onDisabled
protected void onDisabled()
Description copied from class:BaseRenderer
Called when the renderer is disabled.The default implementation is a no-op.
- Overrides:
onDisabled
in classMediaCodecRenderer
-
onReset
protected void onReset()
Description copied from class:BaseRenderer
Called when the renderer is reset.The default implementation is a no-op.
- Overrides:
onReset
in classMediaCodecRenderer
-
isEnded
public boolean isEnded()
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
.- Specified by:
isEnded
in interfaceRenderer
- Overrides:
isEnded
in classMediaCodecRenderer
- Returns:
- Whether the renderer is ready for the player to transition to the ended state.
-
isReady
public boolean isReady()
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
.- Specified by:
isReady
in interfaceRenderer
- Overrides:
isReady
in classMediaCodecRenderer
- Returns:
- Whether the renderer is ready to render media.
-
getPositionUs
public long getPositionUs()
Description copied from interface:MediaClock
Returns the current media position in microseconds.- Specified by:
getPositionUs
in interfaceMediaClock
-
setPlaybackParameters
public void setPlaybackParameters(PlaybackParameters playbackParameters)
Description copied from interface:MediaClock
Attempts to set the playback parameters. The media clock may override the speed if changing the playback parameters is not supported.- Specified by:
setPlaybackParameters
in interfaceMediaClock
- Parameters:
playbackParameters
- The playback parameters to attempt to set.
-
getPlaybackParameters
public PlaybackParameters getPlaybackParameters()
Description copied from interface:MediaClock
Returns the active playback parameters.- Specified by:
getPlaybackParameters
in interfaceMediaClock
-
onQueueInputBuffer
protected void onQueueInputBuffer(DecoderInputBuffer buffer)
Description copied from class:MediaCodecRenderer
Called immediately before an input buffer is queued into the codec.The default implementation is a no-op.
- Overrides:
onQueueInputBuffer
in classMediaCodecRenderer
- Parameters:
buffer
- The buffer to be queued.
-
onProcessedStreamChange
protected void onProcessedStreamChange()
Description copied from class:MediaCodecRenderer
Called after the last output buffer before a stream change has been processed.- Overrides:
onProcessedStreamChange
in classMediaCodecRenderer
-
processOutputBuffer
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
Description copied from class:MediaCodecRenderer
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
MediaCodecRenderer.onPositionReset(long, boolean)
will always receive a newByteBuffer
to be processed.- Specified by:
processOutputBuffer
in classMediaCodecRenderer
- 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
Description copied from class:MediaCodecRenderer
Incrementally renders any remaining output.The default implementation is a no-op.
- Overrides:
renderToEndOfStream
in classMediaCodecRenderer
- Throws:
ExoPlaybackException
- Thrown if an error occurs rendering remaining output.
-
handleMessage
public void handleMessage(@com.google.android.exoplayer2.Renderer.MessageType int messageType, @Nullable Object message) throws ExoPlaybackException
Description copied from interface:PlayerMessage.Target
Handles a message delivered to the target.- Specified by:
handleMessage
in interfacePlayerMessage.Target
- Overrides:
handleMessage
in classBaseRenderer
- Parameters:
messageType
- The message type.message
- The message payload.- Throws:
ExoPlaybackException
- If an error occurred whilst handling the message. Should only be thrown by targets that handle messages on the playback thread.
-
getCodecMaxInputSize
protected int getCodecMaxInputSize(MediaCodecInfo codecInfo, Format format, Format[] streamFormats)
Returns a maximum input size suitable for configuring a codec forformat
in a way that will allow possible adaptation to other compatible formats instreamFormats
.- Parameters:
codecInfo
- AMediaCodecInfo
describing the decoder.format
- TheFormat
for which the codec is being configured.streamFormats
- The possible stream formats.- Returns:
- A suitable maximum input size.
-
getMediaFormat
protected MediaFormat getMediaFormat(Format format, String codecMimeType, int codecMaxInputSize, float codecOperatingRate)
Returns the frameworkMediaFormat
that can be used to configure aMediaCodec
for decoding the givenFormat
for playback.- Parameters:
format
- TheFormat
of the media.codecMimeType
- The MIME type handled by the codec.codecMaxInputSize
- The maximum input size supported by the codec.codecOperatingRate
- The codec operating rate, orMediaCodecRenderer.CODEC_OPERATING_RATE_UNSET
if no codec operating rate should be set.- Returns:
- The framework
MediaFormat
.
-
-