PlayerMessage.Target
, Renderer
, RendererCapabilities
CameraMotionRenderer
, DecoderAudioRenderer
, DecoderVideoRenderer
, FakeRenderer
, MediaCodecRenderer
, MetadataRenderer
, TextRenderer
public abstract class BaseRenderer extends Object implements Renderer, RendererCapabilities
Renderer
implementations.Renderer.State, Renderer.VideoScalingMode, Renderer.WakeupListener
RendererCapabilities.AdaptiveSupport, RendererCapabilities.Capabilities, RendererCapabilities.FormatSupport, RendererCapabilities.TunnelingSupport
MSG_CUSTOM_BASE, MSG_SET_AUDIO_ATTRIBUTES, MSG_SET_AUDIO_SESSION_ID, MSG_SET_AUX_EFFECT_INFO, MSG_SET_CAMERA_MOTION_LISTENER, MSG_SET_SCALING_MODE, MSG_SET_SKIP_SILENCE_ENABLED, MSG_SET_SURFACE, MSG_SET_VIDEO_DECODER_OUTPUT_BUFFER_RENDERER, MSG_SET_VIDEO_FRAME_METADATA_LISTENER, MSG_SET_VOLUME, MSG_SET_WAKEUP_LISTENER, STATE_DISABLED, STATE_ENABLED, STATE_STARTED, VIDEO_SCALING_MODE_DEFAULT, VIDEO_SCALING_MODE_SCALE_TO_FIT, VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING
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 | Description |
---|---|
BaseRenderer(int trackType) |
Modifier and Type | Method | Description |
---|---|---|
protected ExoPlaybackException |
createRendererException(Throwable cause,
Format format) |
Creates an
ExoPlaybackException of type ExoPlaybackException.TYPE_RENDERER for
this renderer. |
protected ExoPlaybackException |
createRendererException(Throwable cause,
Format format,
boolean isRecoverable) |
Creates an
ExoPlaybackException of type ExoPlaybackException.TYPE_RENDERER for
this renderer. |
void |
disable() |
Disable the renderer, transitioning it to the
Renderer.STATE_DISABLED state. |
void |
enable(RendererConfiguration configuration,
Format[] formats,
SampleStream stream,
long positionUs,
boolean joining,
boolean mayRenderStartOfStream,
long startPositionUs,
long offsetUs) |
Enables the renderer to consume from the specified
SampleStream . |
RendererCapabilities |
getCapabilities() |
Returns the capabilities of the renderer.
|
protected RendererConfiguration |
getConfiguration() |
Returns the configuration set when the renderer was most recently enabled.
|
protected FormatHolder |
getFormatHolder() |
Returns a clear
FormatHolder . |
protected int |
getIndex() |
Returns the index of the renderer within the player.
|
protected long |
getLastResetPositionUs() |
Returns the position passed to the most recent call to
enable(com.google.android.exoplayer2.RendererConfiguration, com.google.android.exoplayer2.Format[], com.google.android.exoplayer2.source.SampleStream, long, boolean, boolean, long, long) or resetPosition(long) . |
MediaClock |
getMediaClock() |
If the renderer advances its own playback position then this method returns a corresponding
MediaClock . |
long |
getReadingPositionUs() |
Returns the renderer time up to which the renderer has read samples from the current
SampleStream , in microseconds, or C.TIME_END_OF_SOURCE if the renderer has read the
current SampleStream to the end. |
int |
getState() |
Returns the current state of the renderer.
|
SampleStream |
getStream() |
Returns the
SampleStream being consumed, or null if the renderer is disabled. |
protected Format[] |
getStreamFormats() |
Returns the formats of the currently enabled stream.
|
int |
getTrackType() |
Returns the track type that the renderer handles.
|
void |
handleMessage(int what,
Object object) |
Handles a message delivered to the target.
|
boolean |
hasReadStreamToEnd() |
Returns whether the renderer has read the current
SampleStream to the end. |
boolean |
isCurrentStreamFinal() |
Returns whether the current
SampleStream will be the final one supplied before the
renderer is next disabled or reset. |
protected boolean |
isSourceReady() |
Returns whether the upstream source is ready.
|
void |
maybeThrowStreamError() |
Throws an error that's preventing the renderer from reading from its
SampleStream . |
protected void |
onDisabled() |
Called when the renderer is disabled.
|
protected void |
onEnabled(boolean joining,
boolean mayRenderStartOfStream) |
Called when the renderer is enabled.
|
protected void |
onPositionReset(long positionUs,
boolean joining) |
Called when the position is reset.
|
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 void |
onStreamChanged(Format[] formats,
long startPositionUs,
long offsetUs) |
Called when the renderer's stream has changed.
|
protected int |
readSource(FormatHolder formatHolder,
DecoderInputBuffer buffer,
boolean formatRequired) |
Reads from the enabled upstream source.
|
void |
replaceStream(Format[] formats,
SampleStream stream,
long startPositionUs,
long offsetUs) |
Replaces the
SampleStream from which samples will be consumed. |
void |
reset() |
Forces the renderer to give up any resources (e.g.
|
void |
resetPosition(long positionUs) |
Signals to the renderer that a position discontinuity has occurred.
|
void |
setCurrentStreamFinal() |
Signals to the renderer that the current
SampleStream will be the final one supplied
before it is next disabled or reset. |
void |
setIndex(int index) |
Sets the index of this renderer within the player.
|
protected int |
skipSource(long positionUs) |
Attempts to skip to the keyframe before the specified position, or to the end of the stream if
positionUs is beyond it. |
void |
start() |
Starts the renderer, meaning that calls to
Renderer.render(long, long) will cause media to be
rendered. |
void |
stop() |
Stops the renderer, transitioning it to the
Renderer.STATE_ENABLED state. |
int |
supportsMixedMimeTypeAdaptation() |
Returns the extent to which the
Renderer supports adapting between supported formats
that have different MIME types. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getName, isEnded, isReady, render, setPlaybackSpeed
getName, supportsFormat
public BaseRenderer(int trackType)
trackType
- The track type that the renderer handles. One of the C
TRACK_TYPE_*
constants.public final int getTrackType()
Renderer
getTrackType
in interface Renderer
getTrackType
in interface RendererCapabilities
TRACK_TYPE_*
constants defined in C
.Player.getRendererType(int)
public final RendererCapabilities getCapabilities()
Renderer
getCapabilities
in interface Renderer
public final void setIndex(int index)
Renderer
@Nullable 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
MediaClock
tracking the playback position of the renderer, or null.public final int getState()
Renderer
getState
in interface Renderer
Renderer.STATE_DISABLED
, Renderer.STATE_ENABLED
and Renderer.STATE_STARTED
.public final void enable(RendererConfiguration configuration, Format[] formats, SampleStream stream, long positionUs, boolean joining, boolean mayRenderStartOfStream, long startPositionUs, long offsetUs) throws ExoPlaybackException
Renderer
SampleStream
.
This method may be called when the renderer is in the following states: Renderer.STATE_DISABLED
.
enable
in interface Renderer
configuration
- The renderer configuration.formats
- The enabled formats.stream
- The SampleStream
from which the renderer should consume.positionUs
- The player's current position.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 not Renderer.STATE_STARTED
yet.startPositionUs
- The start position of the stream in renderer time (microseconds).offsetUs
- The offset to be added to timestamps of buffers read from stream
before
they are rendered.ExoPlaybackException
- If an error occurs.public final void start() throws ExoPlaybackException
Renderer
Renderer.render(long, long)
will cause media to be
rendered.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
.
start
in interface Renderer
ExoPlaybackException
- If an error occurs.public final void replaceStream(Format[] formats, SampleStream stream, long startPositionUs, long offsetUs) throws ExoPlaybackException
Renderer
SampleStream
from which samples will be consumed.
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
replaceStream
in interface Renderer
formats
- The enabled formats.stream
- The SampleStream
from which the renderer should consume.startPositionUs
- The start position of the new stream in renderer time (microseconds).offsetUs
- The offset to be added to timestamps of buffers read from stream
before
they are rendered.ExoPlaybackException
- If an error occurs.@Nullable public final SampleStream getStream()
Renderer
SampleStream
being consumed, or null if the renderer is disabled.public final boolean hasReadStreamToEnd()
Renderer
SampleStream
to the end.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
hasReadStreamToEnd
in interface Renderer
public final long getReadingPositionUs()
Renderer
SampleStream
, in microseconds, or C.TIME_END_OF_SOURCE
if the renderer has read the
current SampleStream
to the end.
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
getReadingPositionUs
in interface Renderer
public final void setCurrentStreamFinal()
Renderer
SampleStream
will be the final one supplied
before it is next disabled or reset.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
setCurrentStreamFinal
in interface Renderer
public final boolean isCurrentStreamFinal()
Renderer
SampleStream
will be the final one supplied before the
renderer is next disabled or reset.isCurrentStreamFinal
in interface Renderer
public final void maybeThrowStreamError() throws IOException
Renderer
SampleStream
. Does
nothing if no such error exists.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
maybeThrowStreamError
in interface Renderer
IOException
- An error that's preventing the renderer from making progress or buffering
more data.public final void resetPosition(long positionUs) throws ExoPlaybackException
Renderer
After a position discontinuity, the renderer's SampleStream
is guaranteed to provide
samples starting from a key frame.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
resetPosition
in interface Renderer
positionUs
- The new playback position in microseconds.ExoPlaybackException
- If an error occurs handling the reset.public final void stop()
Renderer
Renderer.STATE_ENABLED
state.
This method may be called when the renderer is in the following states: Renderer.STATE_STARTED
.
public final void disable()
Renderer
Renderer.STATE_DISABLED
state.
This method may be called when the renderer is in the following states:
Renderer.STATE_ENABLED
.
public final void reset()
Renderer
This method may be called when the renderer is in the following states: Renderer.STATE_DISABLED
.
@AdaptiveSupport public int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException
RendererCapabilities
Renderer
supports adapting between supported formats
that have different MIME types.supportsMixedMimeTypeAdaptation
in interface RendererCapabilities
RendererCapabilities.AdaptiveSupport
for adapting between supported formats that have different
MIME types.ExoPlaybackException
- If an error occurs.public void handleMessage(int what, @Nullable Object object) throws ExoPlaybackException
PlayerMessage.Target
handleMessage
in interface PlayerMessage.Target
what
- The message type.object
- The message payload.ExoPlaybackException
- If an error occurred whilst handling the message. Should only be
thrown by targets that handle messages on the playback thread.protected void onEnabled(boolean joining, boolean mayRenderStartOfStream) throws ExoPlaybackException
The default implementation is a no-op.
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 not Renderer.STATE_STARTED
yet.ExoPlaybackException
- If an error occurs.protected void onStreamChanged(Format[] formats, long startPositionUs, long offsetUs) throws ExoPlaybackException
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.
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 via readSource(FormatHolder, DecoderInputBuffer, boolean)
so that decoder input buffers have
monotonically increasing timestamps.ExoPlaybackException
- If an error occurs.protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
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.
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() throws ExoPlaybackException
The default implementation is a no-op.
ExoPlaybackException
- If an error occurs.protected void onStopped()
The default implementation is a no-op.
protected void onDisabled()
The default implementation is a no-op.
protected void onReset()
The default implementation is a no-op.
protected final long getLastResetPositionUs()
enable(com.google.android.exoplayer2.RendererConfiguration, com.google.android.exoplayer2.Format[], com.google.android.exoplayer2.source.SampleStream, long, boolean, boolean, long, long)
or resetPosition(long)
.protected final FormatHolder getFormatHolder()
FormatHolder
.protected final Format[] getStreamFormats()
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
protected final RendererConfiguration getConfiguration()
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
protected final int getIndex()
protected final ExoPlaybackException createRendererException(Throwable cause, @Nullable Format format)
ExoPlaybackException
of type ExoPlaybackException.TYPE_RENDERER
for
this renderer.cause
- The cause of the exception.format
- The current format used by the renderer. May be null.protected final ExoPlaybackException createRendererException(Throwable cause, @Nullable Format format, boolean isRecoverable)
ExoPlaybackException
of type ExoPlaybackException.TYPE_RENDERER
for
this renderer.cause
- The cause of the exception.format
- The current format used by the renderer. May be null.isRecoverable
- If the error is recoverable by disabling and re-enabling the renderer.@ReadDataResult protected final int readSource(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired)
C.RESULT_BUFFER_READ
is only returned if setCurrentStreamFinal()
has been
called. C.RESULT_NOTHING_READ
is returned otherwise.
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
formatHolder
- A FormatHolder
to populate in the case of reading a format.buffer
- A DecoderInputBuffer
to populate in the case of reading a sample or the
end of the stream. If the end of the stream has been reached, the C.BUFFER_FLAG_END_OF_STREAM
flag will be set on the buffer.formatRequired
- Whether the caller requires that the format of the stream be read even if
it's not changing. A sample will never be read if set to true, however it is still possible
for the end of stream or nothing to be read.SampleStream.ReadDataResult
.protected int skipSource(long positionUs)
positionUs
is beyond it.
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.
positionUs
- The position in microseconds.protected final boolean isSourceReady()
This method may be called when the renderer is in the following states: Renderer.STATE_ENABLED
, Renderer.STATE_STARTED
.