public abstract class BaseRenderer extends java.lang.Object implements Renderer, RendererCapabilities
Renderer
implementations.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_SUBTYPE, FORMAT_UNSUPPORTED_TYPE
Constructor and Description |
---|
BaseRenderer(int trackType) |
Modifier and Type | Method and Description |
---|---|
void |
disable()
Disable the renderer, transitioning it to the
Renderer.STATE_DISABLED state. |
void |
enable(Format[] formats,
SampleStream stream,
long positionUs,
boolean joining,
long offsetUs)
Enables the renderer to consume from the specified
SampleStream . |
RendererCapabilities |
getCapabilities()
Returns the capabilities of the renderer.
|
protected int |
getIndex()
Returns the index of the renderer within the player.
|
MediaClock |
getMediaClock()
If the renderer advances its own playback position then this method returns a corresponding
MediaClock . |
int |
getState()
Returns the current state of the renderer.
|
SampleStream |
getStream()
Returns the
SampleStream being consumed, or null if the renderer is disabled. |
int |
getTrackType()
Returns the track type that the
Renderer handles. |
void |
handleMessage(int what,
java.lang.Object object)
Handles a message delivered to the component.
|
boolean |
hasReadStreamToEnd()
Returns whether the renderer has read the current
SampleStream to the end. |
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)
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.
|
protected void |
onStreamChanged(Format[] formats)
Called when the renderer's stream has changed.
|
protected int |
readSource(FormatHolder formatHolder,
DecoderInputBuffer buffer)
Reads from the enabled upstream source.
|
void |
replaceStream(Format[] formats,
SampleStream stream,
long offsetUs)
Replaces the
SampleStream from which samples will be consumed. |
void |
resetPosition(long positionUs)
Signals to the renderer that a position discontinuity has occurred.
|
void |
setCurrentStreamIsFinal()
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 void |
skipToKeyframeBefore(long timeUs)
Attempts to skip to the keyframe before the specified time.
|
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
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
Renderer
handles. For example, a video renderer will
return C.TRACK_TYPE_VIDEO
, an audio renderer will return C.TRACK_TYPE_AUDIO
, a
text renderer will return C.TRACK_TYPE_TEXT
, and so on.getTrackType
in interface Renderer
getTrackType
in interface RendererCapabilities
TRACK_TYPE_*
constants defined in C
.Renderer.getTrackType()
public final RendererCapabilities getCapabilities()
Renderer
getCapabilities
in interface Renderer
public final void setIndex(int index)
Renderer
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
public final void enable(Format[] formats, SampleStream stream, long positionUs, boolean joining, 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
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.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 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.offsetUs
- The offset to be added to timestamps of buffers read from stream
before
they are rendered.ExoPlaybackException
- If an error occurs.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 void setCurrentStreamIsFinal()
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
.
setCurrentStreamIsFinal
in interface Renderer
public final void maybeThrowStreamError() throws java.io.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
java.io.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() throws ExoPlaybackException
Renderer
Renderer.STATE_ENABLED
state.
This method may be called when the renderer is in the following states:
Renderer.STATE_STARTED
.
stop
in interface Renderer
ExoPlaybackException
- If an error occurs.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 int supportsMixedMimeTypeAdaptation() throws ExoPlaybackException
RendererCapabilities
Renderer
supports adapting between supported formats
that have different mime types.supportsMixedMimeTypeAdaptation
in interface RendererCapabilities
RendererCapabilities.ADAPTIVE_SEAMLESS
, RendererCapabilities.ADAPTIVE_NOT_SEAMLESS
and
RendererCapabilities.ADAPTIVE_NOT_SUPPORTED
.ExoPlaybackException
- If an error occurs.public void handleMessage(int what, java.lang.Object object) throws ExoPlaybackException
ExoPlayer.ExoPlayerComponent
handleMessage
in interface ExoPlayer.ExoPlayerComponent
what
- The message type.object
- The message.ExoPlaybackException
- If an error occurred whilst handling the message.protected void onEnabled(boolean joining) throws ExoPlaybackException
The default implementation is a no-op.
joining
- Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException
- If an error occurs.protected void onStreamChanged(Format[] formats) throws ExoPlaybackException
onEnabled(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.ExoPlaybackException
- If an error occurs.protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException
onStreamChanged(Format[])
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() throws ExoPlaybackException
The default implementation is a no-op.
ExoPlaybackException
- If an error occurs.protected void onDisabled()
The default implementation is a no-op.
protected final int getIndex()
protected final int readSource(FormatHolder formatHolder, DecoderInputBuffer buffer)
C.RESULT_BUFFER_READ
is only returned if setCurrentStreamIsFinal()
has been
called. C.RESULT_NOTHING_READ
is returned otherwise.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.C.RESULT_NOTHING_READ
, C.RESULT_FORMAT_READ
or
C.RESULT_BUFFER_READ
.SampleStream.readData(FormatHolder, DecoderInputBuffer)
protected final boolean isSourceReady()
protected void skipToKeyframeBefore(long timeUs)
timeUs
- The specified time.