public class ChunkSampleStream<T extends ChunkSource> extends Object implements SampleStream, SequenceableLoader, Loader.Callback<Chunk>
SequenceableLoader.Callback<T extends SequenceableLoader>
Constructor and Description |
---|
ChunkSampleStream(int trackType,
T chunkSource,
SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
Allocator allocator,
long positionUs,
int minLoadableRetryCount,
AdaptiveMediaSourceEventListener.EventDispatcher eventDispatcher) |
Modifier and Type | Method and Description |
---|---|
boolean |
continueLoading(long positionUs)
Attempts to continue loading.
|
long |
getBufferedPositionUs()
Returns an estimate of the position up to which data is buffered.
|
T |
getChunkSource()
Returns the
ChunkSource used by this stream. |
long |
getNextLoadPositionUs()
Returns the next load time, or
C.TIME_END_OF_SOURCE if loading has finished. |
boolean |
isReady()
Returns whether data is available to be read.
|
void |
maybeThrowError()
Throws an error that's preventing data from being read.
|
void |
onLoadCanceled(Chunk loadable,
long elapsedRealtimeMs,
long loadDurationMs,
boolean released)
Called when a load has been canceled.
|
void |
onLoadCompleted(Chunk loadable,
long elapsedRealtimeMs,
long loadDurationMs)
Called when a load has completed.
|
int |
onLoadError(Chunk loadable,
long elapsedRealtimeMs,
long loadDurationMs,
IOException error)
Called when a load encounters an error.
|
int |
readData(FormatHolder formatHolder,
DecoderInputBuffer buffer)
Attempts to read from the stream.
|
void |
release()
Releases the stream.
|
void |
seekToUs(long positionUs)
Seeks to the specified position in microseconds.
|
void |
skipToKeyframeBefore(long timeUs)
Attempts to skip to the keyframe before the specified time.
|
public ChunkSampleStream(int trackType, T chunkSource, SequenceableLoader.Callback<ChunkSampleStream<T>> callback, Allocator allocator, long positionUs, int minLoadableRetryCount, AdaptiveMediaSourceEventListener.EventDispatcher eventDispatcher)
trackType
- The type of the track. One of the C
TRACK_TYPE_*
constants.chunkSource
- A ChunkSource
from which chunks to load are obtained.callback
- An Callback
for the stream.allocator
- An Allocator
from which allocations can be obtained.positionUs
- The position from which to start loading media.minLoadableRetryCount
- The minimum number of times that the source should retry a load
before propagating an error.eventDispatcher
- A dispatcher to notify of events.public T getChunkSource()
ChunkSource
used by this stream.ChunkSource
.public long getBufferedPositionUs()
C.TIME_END_OF_SOURCE
if the track is fully buffered.public void seekToUs(long positionUs)
positionUs
- The seek position in microseconds.public void release()
This method should be called when the stream is no longer required.
public boolean isReady()
SampleStream
Note: If the stream has ended then a buffer with the end of stream flag can always be read from
SampleStream.readData(FormatHolder, DecoderInputBuffer)
. Hence an ended stream is always ready.
isReady
in interface SampleStream
public void maybeThrowError() throws IOException
SampleStream
maybeThrowError
in interface SampleStream
IOException
- The underlying error.public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer)
SampleStream
readData
in interface SampleStream
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
.public void skipToKeyframeBefore(long timeUs)
SampleStream
skipToKeyframeBefore
in interface SampleStream
timeUs
- The specified time.public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs)
Loader.Callback
Note: There is guaranteed to be a memory barrier between Loader.Loadable.load()
exiting and
this callback being called.
onLoadCompleted
in interface Loader.Callback<Chunk>
loadable
- The loadable whose load has completed.elapsedRealtimeMs
- SystemClock.elapsedRealtime()
when the load ended.loadDurationMs
- The duration of the load.public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released)
Loader.Callback
Note: If the Loader
has not been released then there is guaranteed to be a memory
barrier between Loader.Loadable.load()
exiting and this callback being called. If the
Loader
has been released then this callback may be called before
Loader.Loadable.load()
exits.
onLoadCanceled
in interface Loader.Callback<Chunk>
loadable
- The loadable whose load has been canceled.elapsedRealtimeMs
- SystemClock.elapsedRealtime()
when the load was canceled.loadDurationMs
- The duration of the load up to the point at which it was canceled.released
- True if the load was canceled because the Loader
was released. False
otherwise.public int onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, IOException error)
Loader.Callback
Note: There is guaranteed to be a memory barrier between Loader.Loadable.load()
exiting and
this callback being called.
onLoadError
in interface Loader.Callback<Chunk>
loadable
- The loadable whose load has encountered an error.elapsedRealtimeMs
- SystemClock.elapsedRealtime()
when the error occurred.loadDurationMs
- The duration of the load up to the point at which the error occurred.error
- The load error.Loader.RETRY
,
Loader.RETRY_RESET_ERROR_COUNT
, Loader.DONT_RETRY
and
Loader.DONT_RETRY_FATAL
.public boolean continueLoading(long positionUs)
SequenceableLoader
continueLoading
in interface SequenceableLoader
positionUs
- The current playback position.SequenceableLoader.getNextLoadPositionUs()
will return
a different value than prior to the call. False otherwise.public long getNextLoadPositionUs()
SequenceableLoader
C.TIME_END_OF_SOURCE
if loading has finished.getNextLoadPositionUs
in interface SequenceableLoader