public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements MediaClock
SimpleDecoder
.
This renderer accepts the following messages sent via ExoPlayer#createMessage(Target)
on the playback thread:
C.MSG_SET_VOLUME
to set the volume. The message payload should be
a Float
with 0 being silence and 1 being unity gain.
C.MSG_SET_AUDIO_ATTRIBUTES
to set the audio attributes. The
message payload should be an AudioAttributes
instance that will configure the underlying audio track.
C.MSG_SET_AUX_EFFECT_INFO
to set the auxiliary effect. The
message payload should be an AuxEffectInfo
instance that will configure the
underlying audio track.
Renderer.State
STATE_DISABLED, STATE_ENABLED, STATE_STARTED
ADAPTIVE_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 and Description |
---|
SimpleDecoderAudioRenderer() |
SimpleDecoderAudioRenderer(Handler eventHandler,
AudioRendererEventListener eventListener,
AudioCapabilities audioCapabilities) |
SimpleDecoderAudioRenderer(Handler eventHandler,
AudioRendererEventListener eventListener,
AudioCapabilities audioCapabilities,
DrmSessionManager<ExoMediaCrypto> drmSessionManager,
boolean playClearSamplesWithoutKeys,
AudioProcessor... audioProcessors) |
SimpleDecoderAudioRenderer(Handler eventHandler,
AudioRendererEventListener eventListener,
AudioProcessor... audioProcessors) |
SimpleDecoderAudioRenderer(Handler eventHandler,
AudioRendererEventListener eventListener,
DrmSessionManager<ExoMediaCrypto> drmSessionManager,
boolean playClearSamplesWithoutKeys,
AudioSink audioSink) |
Modifier and Type | Method and Description |
---|---|
protected abstract SimpleDecoder<DecoderInputBuffer,? extends SimpleOutputBuffer,? extends AudioDecoderException> |
createDecoder(Format format,
ExoMediaCrypto mediaCrypto)
Creates a decoder for the given format.
|
MediaClock |
getMediaClock()
If the renderer advances its own playback position then this method returns a corresponding
MediaClock . |
protected Format |
getOutputFormat()
Returns the format of audio buffers output by the decoder.
|
PlaybackParameters |
getPlaybackParameters()
Returns the active playback parameters.
|
long |
getPositionUs()
Returns the current media position in microseconds.
|
void |
handleMessage(int messageType,
Object message)
Handles a message delivered to the target.
|
boolean |
isEnded()
Whether the renderer is ready for the
ExoPlayer instance to transition to
Player.STATE_ENDED . |
boolean |
isReady()
Whether the renderer is able to immediately render media from the current position.
|
protected void |
onAudioSessionId(int audioSessionId)
Called when the audio session id becomes known.
|
protected void |
onAudioTrackPositionDiscontinuity() |
protected void |
onAudioTrackUnderrun(int bufferSize,
long bufferSizeMs,
long elapsedSinceLastFeedMs) |
protected void |
onDisabled()
Called when the renderer is disabled.
|
protected void |
onEnabled(boolean joining)
Called when the renderer is enabled.
|
protected void |
onPositionReset(long positionUs,
boolean joining)
Called when the position is reset.
|
protected void |
onStarted()
Called when the renderer is started.
|
protected void |
onStopped()
Called when the renderer is stopped.
|
void |
render(long positionUs,
long elapsedRealtimeUs)
Incrementally renders the
SampleStream . |
PlaybackParameters |
setPlaybackParameters(PlaybackParameters playbackParameters)
Attempts to set the playback parameters and returns the active playback parameters, which may
differ from those passed in.
|
int |
supportsFormat(Format format)
Returns the extent to which the
Renderer supports a given format. |
protected abstract int |
supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager,
Format format)
Returns the
RendererCapabilities.FORMAT_SUPPORT_MASK component of the return value for supportsFormat(Format) . |
protected boolean |
supportsOutput(int channelCount,
int encoding)
Returns whether the sink supports the audio format.
|
disable, enable, getCapabilities, getConfiguration, getIndex, getState, getStream, getStreamFormats, getTrackType, hasReadStreamToEnd, isCurrentStreamFinal, isSourceReady, maybeThrowStreamError, onStreamChanged, readSource, replaceStream, resetPosition, setCurrentStreamFinal, setIndex, skipSource, start, stop, supportsFormatDrm, supportsMixedMimeTypeAdaptation
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setOperatingRate
public SimpleDecoderAudioRenderer()
public SimpleDecoderAudioRenderer(@Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, AudioProcessor... audioProcessors)
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.audioProcessors
- Optional AudioProcessor
s that will process audio before output.public SimpleDecoderAudioRenderer(@Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, @Nullable AudioCapabilities audioCapabilities)
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.audioCapabilities
- The audio capabilities for playback on this device. May be null if the
default capabilities (no encoded audio passthrough support) should be assumed.public SimpleDecoderAudioRenderer(@Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, @Nullable AudioCapabilities audioCapabilities, @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, AudioProcessor... audioProcessors)
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.audioCapabilities
- The audio capabilities for playback on this device. May be null if the
default capabilities (no encoded audio passthrough support) should be assumed.drmSessionManager
- For use with encrypted media. May be null if support for encrypted
media is not required.playClearSamplesWithoutKeys
- Encrypted media may contain clear (un-encrypted) regions.
For example a media file may start with a short clear region so as to allow playback to
begin in parallel with key acquisition. This parameter specifies whether the renderer is
permitted to play clear regions of encrypted media files before drmSessionManager
has obtained the keys necessary to decrypt encrypted regions of the media.audioProcessors
- Optional AudioProcessor
s that will process audio before output.public SimpleDecoderAudioRenderer(@Nullable Handler eventHandler, @Nullable AudioRendererEventListener eventListener, @Nullable DrmSessionManager<ExoMediaCrypto> drmSessionManager, boolean playClearSamplesWithoutKeys, AudioSink audioSink)
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.drmSessionManager
- For use with encrypted media. May be null if support for encrypted
media is not required.playClearSamplesWithoutKeys
- Encrypted media may contain clear (un-encrypted) regions.
For example a media file may start with a short clear region so as to allow playback to
begin in parallel with key acquisition. This parameter specifies whether the renderer is
permitted to play clear regions of encrypted media files before drmSessionManager
has obtained the keys necessary to decrypt encrypted regions of the media.audioSink
- The sink to which audio will be output.public MediaClock getMediaClock()
Renderer
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.getMediaClock
in interface Renderer
getMediaClock
in class BaseRenderer
MediaClock
tracking the playback position of the renderer, or null.public final int supportsFormat(Format format)
RendererCapabilities
Renderer
supports a given format. The returned value is
the bitwise OR of three properties:
RendererCapabilities.FORMAT_HANDLED
,
RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES
, RendererCapabilities.FORMAT_UNSUPPORTED_DRM
,
RendererCapabilities.FORMAT_UNSUPPORTED_SUBTYPE
and RendererCapabilities.FORMAT_UNSUPPORTED_TYPE
.RendererCapabilities.ADAPTIVE_SEAMLESS
, RendererCapabilities.ADAPTIVE_NOT_SEAMLESS
and
RendererCapabilities.ADAPTIVE_NOT_SUPPORTED
. Only set if the level of support for the format itself is
RendererCapabilities.FORMAT_HANDLED
or RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES
.RendererCapabilities.TUNNELING_SUPPORTED
and
RendererCapabilities.TUNNELING_NOT_SUPPORTED
. Only set if the level of support for the format itself is
RendererCapabilities.FORMAT_HANDLED
or RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES
.RendererCapabilities.FORMAT_SUPPORT_MASK
, RendererCapabilities.ADAPTIVE_SUPPORT_MASK
and
RendererCapabilities.TUNNELING_SUPPORT_MASK
respectively.supportsFormat
in interface RendererCapabilities
format
- The format.protected abstract int supportsFormatInternal(DrmSessionManager<ExoMediaCrypto> drmSessionManager, Format format)
RendererCapabilities.FORMAT_SUPPORT_MASK
component of the return value for supportsFormat(Format)
.drmSessionManager
- The renderer's DrmSessionManager
.format
- The format, which has an audio Format.sampleMimeType
.protected final boolean supportsOutput(int channelCount, @C.Encoding int encoding)
AudioSink.supportsOutput(int, int)
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException
Renderer
SampleStream
.
If the renderer is in the Renderer.STATE_ENABLED
state then each call to this method will do
work toward being ready to render the SampleStream
when the renderer is started. It may
also render the very start of the media, for example the first frame of a video stream. If the
renderer is in the Renderer.STATE_STARTED
state then calls to this method will render the
SampleStream
in sync with the specified media positions.
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
.
render
in interface Renderer
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.ExoPlaybackException
- If an error occurs.protected void onAudioSessionId(int audioSessionId)
Virtualizer
in
order to spatialize the audio channels. For this use case, any Virtualizer
instances
should be released in onDisabled()
(if not before).AudioSink.Listener.onAudioSessionId(int)
protected void onAudioTrackPositionDiscontinuity()
protected void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs)
protected abstract SimpleDecoder<DecoderInputBuffer,? extends SimpleOutputBuffer,? extends AudioDecoderException> createDecoder(Format format, ExoMediaCrypto mediaCrypto) throws AudioDecoderException
format
- The format for which a decoder is required.mediaCrypto
- The ExoMediaCrypto
object required for decoding encrypted content.
Maybe null and can be ignored if decoder does not handle encrypted content.AudioDecoderException
- If an error occurred creating a suitable decoder.protected Format getOutputFormat()
The default implementation returns a 16-bit PCM format with the same channel count and sample rate as the input.
public boolean isEnded()
Renderer
ExoPlayer
instance to transition to
Player.STATE_ENDED
. The player will make this transition as soon as true
is
returned by all of its Renderer
s.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
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
.
public long getPositionUs()
MediaClock
getPositionUs
in interface MediaClock
public PlaybackParameters setPlaybackParameters(PlaybackParameters playbackParameters)
MediaClock
setPlaybackParameters
in interface MediaClock
playbackParameters
- The playback parameters.public PlaybackParameters getPlaybackParameters()
MediaClock
getPlaybackParameters
in interface MediaClock
protected void onEnabled(boolean joining) throws ExoPlaybackException
BaseRenderer
The default implementation is a no-op.
onEnabled
in class BaseRenderer
joining
- Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException
- If an error occurs.protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
BaseRenderer
BaseRenderer.onStreamChanged(Format[], 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 BaseRenderer
positionUs
- The new playback position in microseconds.joining
- Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException
- If an error occurs.protected void onStarted()
BaseRenderer
The default implementation is a no-op.
onStarted
in class BaseRenderer
protected void onStopped()
BaseRenderer
The default implementation is a no-op.
onStopped
in class BaseRenderer
protected void onDisabled()
BaseRenderer
The default implementation is a no-op.
onDisabled
in class BaseRenderer
public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException
PlayerMessage.Target
handleMessage
in interface PlayerMessage.Target
handleMessage
in class BaseRenderer
messageType
- 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.