DecoderAudioRenderer
@UnstableApi
public abstract class DecoderAudioRenderer<T extends Decoder<DecoderInputBuffer, SimpleDecoderOutputBuffer, DecoderException>> extends BaseRenderer implements MediaClock, Decoder.Callback
| java.lang.Object | ||
| ↳ | androidx.media3.exoplayer.BaseRenderer | |
| ↳ | androidx.media3.exoplayer.audio.DecoderAudioRenderer |
Decodes and renders audio using a Decoder.
This renderer accepts the following messages sent via createMessage on the playback thread:
- Message with type
MSG_SET_VOLUMEto set the volume. The message payload should be aFloatwith 0 being silence and 1 being unity gain. - Message with type
MSG_SET_AUDIO_ATTRIBUTESto set the audio attributes. The message payload should be anAudioAttributesinstance that will configure the underlying audio track. - Message with type
MSG_SET_AUX_EFFECT_INFOto set the auxiliary effect. The message payload should be anAuxEffectInfoinstance that will configure the underlying audio track. - Message with type
MSG_SET_PREFERRED_AUDIO_DEVICEto set the preferred audio output device. The message payload should be anAudioDeviceInfoinstance. - Message with type
MSG_SET_VIRTUAL_DEVICE_IDto set the virtual device id. The message payload should be anIntegerfor the virtual device id orINDEX_UNSETif unspecified. - Message with type
MSG_SET_SKIP_SILENCE_ENABLEDto enable or disable skipping silences. The message payload should be aBoolean. - Message with type
MSG_SET_AUDIO_SESSION_IDto set the audio session ID. The message payload should be a session IDIntegerthat will be attached to the underlying audio track. - Message with type
MSG_SET_AUDIO_OUTPUT_PROVIDERto set the audio output provider. The message payload must be anAudioOutputProviderinstance.
Summary
Public constructors |
|---|
DecoderAudioRenderer( |
DecoderAudioRenderer( |
DecoderAudioRenderer( |
Public methods |
|
|---|---|
long |
getDurationToProgressUs(long positionUs, long elapsedRealtimeUs)Returns minimum amount of playback clock time that must pass from |
@Nullable MediaClock |
If the renderer advances its own playback position then this method returns a corresponding |
PlaybackParameters |
Returns the active playback parameters. |
long |
Returns the current media position in microseconds. |
void |
handleMessage(Handles a message delivered to the target. |
boolean |
Returns whether there is a skipped silence since the last call to this method. |
boolean |
isEnded()Whether the renderer is ready for the |
boolean |
isReady()Whether the renderer is able to immediately render media from the current position. |
void |
Called when an input buffer becomes available to be dequeued. |
void |
Called when an output buffer becomes available to be dequeued. |
void |
render(long positionUs, long elapsedRealtimeUs)Incrementally renders the |
void |
setPlaybackParameters(PlaybackParameters playbackParameters)Attempts to set the playback parameters. |
final int |
Returns the extent to which the |
Protected methods |
|
|---|---|
DecoderReuseEvaluation |
@ForOverrideEvaluates whether the existing decoder can be reused for a new |
abstract T |
@ForOverrideCreates a decoder for the given format. |
@Nullable ImmutableIntArray |
@ForOverrideReturns the channel layout mapping that should be applied when sending this data to the output, or null to not change the channel layout. |
abstract Format |
@ForOverrideReturns the format of audio buffers output by the decoder. |
final int |
Returns the level of support that the renderer's |
final boolean |
Returns whether the renderer is ready to start or continue decoding. |
void |
Called when the renderer is disabled. |
void |
onEnabled(boolean joining, boolean mayRenderStartOfStream)Called when the renderer is enabled. |
void |
|
void |
onPositionReset(Called when the position is reset. |
void |
Called when the renderer is started. |
void |
Called when the renderer is stopped. |
void |
onStreamChanged(Called when the renderer's stream has changed. |
final boolean |
sinkSupportsFormat(Format format)Returns whether the renderer's |
abstract int |
Returns the |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited fields |
||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public constructors
DecoderAudioRenderer
public DecoderAudioRenderer(
@Nullable Handler eventHandler,
@Nullable AudioRendererEventListener eventListener,
AudioProcessor[] audioProcessors
)
| Parameters | |
|---|---|
@Nullable Handler eventHandler |
A handler to use when delivering events to |
@Nullable AudioRendererEventListener eventListener |
A listener of events. May be null if delivery of events is not required. |
AudioProcessor[] audioProcessors |
Optional |
DecoderAudioRenderer
public DecoderAudioRenderer(
@Nullable Handler eventHandler,
@Nullable AudioRendererEventListener eventListener,
AudioSink audioSink
)
| Parameters | |
|---|---|
@Nullable Handler eventHandler |
A handler to use when delivering events to |
@Nullable AudioRendererEventListener eventListener |
A listener of events. May be null if delivery of events is not required. |
AudioSink audioSink |
The sink to which audio will be output. |
DecoderAudioRenderer
public DecoderAudioRenderer(
@Nullable Handler eventHandler,
@Nullable AudioRendererEventListener eventListener,
AudioCapabilities audioCapabilities,
AudioProcessor[] audioProcessors
)
| Parameters | |
|---|---|
@Nullable Handler eventHandler |
A handler to use when delivering events to |
@Nullable AudioRendererEventListener eventListener |
A listener of events. May be null if delivery of events is not required. |
AudioCapabilities audioCapabilities |
The audio capabilities for playback on this device. Use |
AudioProcessor[] audioProcessors |
Optional |
Public methods
getDurationToProgressUs
public long getDurationToProgressUs(long positionUs, long elapsedRealtimeUs)
Returns minimum amount of playback clock time that must pass from elapsedRealtimeUs in order for the render call to make progress.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
The default return time is DEFAULT_DURATION_TO_PROGRESS_US if the renderer is in STATE_STARTED, or in STATE_ENABLED and not yet ready or ended. Otherwise, it returns DEFAULT_IDLE_DURATION_TO_PROGRESS_US.
| Parameters | |
|---|---|
long positionUs |
The current render position in microseconds, measured at the start of the current iteration of the rendering loop. |
long elapsedRealtimeUs |
|
| Returns | |
|---|---|
long |
Minimum amount of playback clock time that must pass before renderer is able to make progress. |
getMediaClock
public @Nullable MediaClock getMediaClock()
If the renderer advances its own playback position then this method returns a corresponding MediaClock. If provided, the player will use the returned MediaClock as its source of time during playback. A player may have at most one renderer that returns a MediaClock from this method.
| Returns | |
|---|---|
@Nullable MediaClock |
The |
getPlaybackParameters
public PlaybackParameters getPlaybackParameters()
Returns the active playback parameters.
handleMessage
public void handleMessage(
@Renderer.MessageType int messageType,
@Nullable Object message
)
Handles a message delivered to the target.
| Parameters | |
|---|---|
@Renderer.MessageType int messageType |
The message type. |
@Nullable Object message |
The message payload. |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurred whilst handling the message. Should only be thrown by targets that handle messages on the playback thread. |
hasSkippedSilenceSinceLastCall
public boolean hasSkippedSilenceSinceLastCall()
Returns whether there is a skipped silence since the last call to this method.
isEnded
public boolean isEnded()
Whether the renderer is ready for the ExoPlayer instance to transition to STATE_ENDED. The player will make this transition as soon as true is returned by all of its renderers.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Returns | |
|---|---|
boolean |
Whether the renderer is ready for the player to transition to the ended state. |
isReady
public boolean isReady()
Whether the renderer is able to immediately render media from the current position.
If the renderer is in the STATE_STARTED state then returning true indicates that the renderer has everything that it needs to continue playback. Returning false indicates that the player should pause until the renderer is ready.
If the renderer is in the STATE_ENABLED state then returning true indicates that the renderer is ready for playback to be started. Returning false indicates that it is not.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Returns | |
|---|---|
boolean |
Whether the renderer is ready to render media. |
onInputBufferAvailable
public void onInputBufferAvailable()
Called when an input buffer becomes available to be dequeued.
onOutputBufferAvailable
public void onOutputBufferAvailable()
Called when an output buffer becomes available to be dequeued.
render
public void render(long positionUs, long elapsedRealtimeUs)
Incrementally renders the SampleStream.
If the renderer is in the STATE_ENABLED state then each call to this method will do work toward being ready to render the SampleStream when the renderer is started. If the renderer is in the STATE_STARTED state then calls to this method will render the SampleStream in sync with the specified media positions.
The renderer may also render the very start of the media at the current position (e.g. the first frame of a video stream) while still in the STATE_ENABLED state, unless it's the initial start of the media after calling enable with
mayRenderStartOfStream set to false.
This method should return quickly, and should not block if the renderer is unable to make useful progress.
This method may be called when the renderer is in the following states: STATE_ENABLED, STATE_STARTED.
| Parameters | |
|---|---|
long positionUs |
The current media time in microseconds, measured at the start of the current iteration of the rendering loop. |
long elapsedRealtimeUs |
|
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
setPlaybackParameters
public void setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters. The media clock may override the speed if changing the playback parameters is not supported.
| Parameters | |
|---|---|
PlaybackParameters playbackParameters |
The playback parameters to attempt to set. |
supportsFormat
@RendererCapabilities.Capabilities
public final int supportsFormat(Format format)
Returns the extent to which the Renderer supports a given format.
| Parameters | |
|---|---|
Format format |
The format. |
| Returns | |
|---|---|
int |
The |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
Protected methods
canReuseDecoder
@ForOverride
protected DecoderReuseEvaluation canReuseDecoder(String decoderName, Format oldFormat, Format newFormat)
Evaluates whether the existing decoder can be reused for a new Format.
The default implementation does not allow decoder reuse.
| Parameters | |
|---|---|
String decoderName |
The name of the decoder. |
Format oldFormat |
The previous format. |
Format newFormat |
The new format. |
| Returns | |
|---|---|
DecoderReuseEvaluation |
The result of the evaluation. |
createDecoder
@ForOverride
protected abstract T createDecoder(Format format, @Nullable CryptoConfig cryptoConfig)
Creates a decoder for the given format.
| Parameters | |
|---|---|
Format format |
The format for which a decoder is required. |
@Nullable CryptoConfig cryptoConfig |
The |
| Returns | |
|---|---|
T |
The decoder. |
| Throws | |
|---|---|
androidx.media3.decoder.DecoderException |
If an error occurred creating a suitable decoder. |
getChannelMapping
@ForOverride
protected @Nullable ImmutableIntArray getChannelMapping(T decoder)
Returns the channel layout mapping that should be applied when sending this data to the output, or null to not change the channel layout.
| Parameters | |
|---|---|
T decoder |
The decoder. |
getOutputFormat
@ForOverride
protected abstract Format getOutputFormat(T decoder)
Returns the format of audio buffers output by the decoder. Will not be called until the first output buffer has been dequeued, so the decoder may use input data to determine the format.
| Parameters | |
|---|---|
T decoder |
The decoder. |
getSinkFormatSupport
@AudioSink.SinkFormatSupport
protected final int getSinkFormatSupport(Format format)
Returns the level of support that the renderer's AudioSink provides for a given Format.
| See also | |
|---|---|
getFormatSupport |
(Format) |
isReadyForDecoding
protected final boolean isReadyForDecoding()
Returns whether the renderer is ready to start or continue decoding.
onDisabled
protected void onDisabled()
Called when the renderer is disabled.
The default implementation is a no-op.
onEnabled
protected void onEnabled(boolean joining, boolean mayRenderStartOfStream)
Called when the renderer is enabled.
The default implementation is a no-op.
| Parameters | |
|---|---|
boolean joining |
Whether this renderer is being enabled to join an ongoing playback. |
boolean mayRenderStartOfStream |
Whether this renderer is allowed to render the start of the stream even if the state is not |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onPositionReset
protected void onPositionReset(
long positionUs,
boolean joining,
boolean sampleStreamIsResetToKeyFrame
)
Called when the position is reset. This occurs when the renderer is enabled after onStreamChanged has been called, and also when a position discontinuity is encountered.
After a position reset, the renderer's SampleStream is guaranteed to provide samples starting from a key frame if sampleStreamIsResetToKeyFrame is true.
sampleStreamIsResetToKeyFrame is guaranteed to be true unless the implementation overrides supportsResetPositionWithoutKeyFrameReset to return
true.
The default implementation is a no-op.
| Parameters | |
|---|---|
long positionUs |
The new playback position in microseconds. |
boolean joining |
Whether this renderer is being enabled to join an ongoing playback. |
boolean sampleStreamIsResetToKeyFrame |
Whether the renderer's |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onStarted
protected void onStarted()
Called when the renderer is started.
The default implementation is a no-op.
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
onStopped
protected void onStopped()
Called when the renderer is stopped.
The default implementation is a no-op.
onStreamChanged
protected void onStreamChanged(
Format[] formats,
long startPositionUs,
long offsetUs,
MediaSource.MediaPeriodId mediaPeriodId
)
Called when the renderer's stream has changed. This occurs when the renderer is enabled after onEnabled 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.
| Parameters | |
|---|---|
Format[] formats |
The enabled formats. |
long startPositionUs |
The start position of the new stream in renderer time (microseconds). |
long offsetUs |
The offset that will be added to the timestamps of buffers read via |
MediaSource.MediaPeriodId mediaPeriodId |
The |
| Throws | |
|---|---|
androidx.media3.exoplayer.ExoPlaybackException |
If an error occurs. |
sinkSupportsFormat
protected final boolean sinkSupportsFormat(Format format)
Returns whether the renderer's AudioSink supports a given Format.
| See also | |
|---|---|
supportsFormat |
supportsFormatInternal
@ForOverride
@C.FormatSupport
protected abstract int supportsFormatInternal(Format format)
Returns the C.FormatSupport for the given Format.
| Parameters | |
|---|---|
Format format |
The format, which has an audio |
| Returns | |
|---|---|
int |
The |