public abstract class SampleSourceTrackRenderer extends TrackRenderer
TrackRenderer implementations that render samples obtained from a
SampleSource.END_OF_TRACK_US, MATCH_LONGEST_US, STATE_ENABLED, STATE_PREPARED, STATE_RELEASED, STATE_STARTED, STATE_UNPREPARED, UNKNOWN_TIME_US| Constructor and Description |
|---|
SampleSourceTrackRenderer(SampleSource... sources) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
doPrepare(long positionUs)
Invoked to make progress when the renderer is in the
TrackRenderer.STATE_UNPREPARED state. |
protected void |
doSomeWork(long positionUs,
long elapsedRealtimeUs)
Invoked to make progress when the renderer is in the
TrackRenderer.STATE_ENABLED or
TrackRenderer.STATE_STARTED states. |
protected abstract void |
doSomeWork(long positionUs,
long elapsedRealtimeUs,
boolean sourceIsReady)
Called by
doSomeWork(long, long). |
protected long |
getBufferedPositionUs()
Returns an estimate of the absolute position in microseconds up to which data is buffered.
|
protected long |
getDurationUs()
Returns the duration of the media being rendered.
|
protected MediaFormat |
getFormat(int track)
Returns the format of the specified track.
|
protected int |
getTrackCount()
Returns the number of tracks exposed by the renderer.
|
protected abstract boolean |
handlesTrack(MediaFormat mediaFormat)
Returns whether this renderer is capable of handling the provided track.
|
protected void |
maybeThrowError()
Throws an error that's preventing the renderer from making progress or buffering more data at
this point in time.
|
protected void |
onDisabled()
Called when the renderer is disabled.
|
protected abstract void |
onDiscontinuity(long positionUs)
Invoked when a discontinuity is encountered.
|
protected void |
onEnabled(int track,
long positionUs,
boolean joining)
Called when the renderer is enabled.
|
protected void |
onReleased()
Called when the renderer is released.
|
protected int |
readSource(long positionUs,
MediaFormatHolder formatHolder,
SampleHolder sampleHolder)
Reads from the enabled upstream source.
|
protected void |
seekTo(long positionUs)
Seeks to a specified time in the track.
|
protected long |
shiftInputPosition(long positionUs)
|
getMediaClock, getState, handleMessage, isEnded, isReady, onStarted, onStoppedpublic SampleSourceTrackRenderer(SampleSource... sources)
sources - One or more upstream sources from which the renderer can obtain samples.protected final boolean doPrepare(long positionUs)
throws ExoPlaybackException
TrackRendererTrackRenderer.STATE_UNPREPARED state. This
method will be called repeatedly until true is returned.
This method should return quickly, and should not block if the renderer is currently unable to make any useful progress.
doPrepare in class TrackRendererpositionUs - The player's current playback position.ExoPlaybackException - If an error occurs.protected void onEnabled(int track,
long positionUs,
boolean joining)
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onEnabled in class TrackRenderertrack - The track for which the renderer is being enabled.positionUs - The player's current position.joining - Whether this renderer is being enabled to join an ongoing playback.ExoPlaybackException - If an error occurs.protected void seekTo(long positionUs)
throws ExoPlaybackException
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED
seekTo in class TrackRendererpositionUs - The desired playback position in microseconds.ExoPlaybackException - If an error occurs.protected final void doSomeWork(long positionUs,
long elapsedRealtimeUs)
throws ExoPlaybackException
TrackRendererTrackRenderer.STATE_ENABLED or
TrackRenderer.STATE_STARTED states.
If the renderer's state is TrackRenderer.STATE_STARTED, then repeated calls to this method should
cause the media track to be rendered. If the state is TrackRenderer.STATE_ENABLED, then repeated
calls should make progress towards getting the renderer into a position where it is ready to
render the track.
This method should return quickly, and should not block if the renderer is currently unable to make any useful progress.
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
doSomeWork in class TrackRendererpositionUs - 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 long getBufferedPositionUs()
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
getBufferedPositionUs in class TrackRendererTrackRenderer.END_OF_TRACK_US if the track is fully buffered, or TrackRenderer.UNKNOWN_TIME_US if
no estimate is available.protected long getDurationUs()
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_PREPARED, TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
getDurationUs in class TrackRendererTrackRenderer.MATCH_LONGEST_US if
the track's duration should match that of the longest track whose duration is known, or
or TrackRenderer.UNKNOWN_TIME_US if the duration is not known.protected void maybeThrowError()
throws ExoPlaybackException
TrackRenderermaybeThrowError in class TrackRendererExoPlaybackException - An error that's preventing the renderer from making progress or
buffering more data.protected void onDisabled()
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onDisabled in class TrackRendererExoPlaybackException - If an error occurs.protected void onReleased()
throws ExoPlaybackException
TrackRendererThe default implementation is a no-op.
onReleased in class TrackRendererExoPlaybackException - If an error occurs.protected final int getTrackCount()
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_PREPARED, TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
getTrackCount in class TrackRendererprotected final MediaFormat getFormat(int track)
TrackRenderer
This method may be called when the renderer is in the following states:
TrackRenderer.STATE_PREPARED, TrackRenderer.STATE_ENABLED, TrackRenderer.STATE_STARTED
getFormat in class TrackRenderertrack - The track index.protected long shiftInputPosition(long positionUs)
onEnabled(int, long, boolean), seekTo(long) and
doSomeWork(long, long).
The default implementation does not modify the position. Except in very specific cases, subclasses should not override this method.
positionUs - The position in microseconds.protected final int readSource(long positionUs,
MediaFormatHolder formatHolder,
SampleHolder sampleHolder)
positionUs - The current playback position.formatHolder - A MediaFormatHolder object to populate in the case of a new format.sampleHolder - A SampleHolder object to populate in the case of a new sample.
If the caller requires the sample data then it must ensure that SampleHolder.data
references a valid output buffer.SampleSource.SAMPLE_READ,
SampleSource.FORMAT_READ, SampleSource.NOTHING_READ or
SampleSource.END_OF_STREAM.protected abstract boolean handlesTrack(MediaFormat mediaFormat) throws MediaCodecUtil.DecoderQueryException
mediaFormat - The format of the track.MediaCodecUtil.DecoderQueryException - Thrown if there was an error querying decoders.protected abstract void onDiscontinuity(long positionUs)
throws ExoPlaybackException
positionUs - The playback position after the discontinuity, or the position at which
the renderer is being enabled.ExoPlaybackException - If an error occurs handling the discontinuity.protected abstract void doSomeWork(long positionUs,
long elapsedRealtimeUs,
boolean sourceIsReady)
throws ExoPlaybackException
doSomeWork(long, long).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.sourceIsReady - The result of the most recent call to
SampleSource.SampleSourceReader.continueBuffering(int, long).ExoPlaybackException - If an error occurs.ExoPlaybackException