public class ChunkSampleStream<T extends ChunkSource> extends java.lang.Object implements SampleStream, SequenceableLoader, Loader.Callback<Chunk>, Loader.ReleaseCallback
SampleStream that loads media in Chunks, obtained from a ChunkSource.
May also be configured to expose additional embedded SampleStreams.| Modifier and Type | Class and Description |
|---|---|
class |
ChunkSampleStream.EmbeddedSampleStream
A
SampleStream embedded in a ChunkSampleStream. |
static interface |
ChunkSampleStream.ReleaseCallback<T extends ChunkSource>
A callback to be notified when a sample stream has finished being released.
|
SequenceableLoader.Callback<T extends SequenceableLoader>| Modifier and Type | Field and Description |
|---|---|
int |
primaryTrackType |
| Constructor and Description |
|---|
ChunkSampleStream(int primaryTrackType,
int[] embeddedTrackTypes,
Format[] embeddedTrackFormats,
T chunkSource,
SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
Allocator allocator,
long positionUs,
int minLoadableRetryCount,
MediaSourceEventListener.EventDispatcher eventDispatcher)
Deprecated.
Use
#ChunkSampleStream(int, int[], Format[], ChunkSource, Callback,
Allocator, long, LoadErrorHandlingPolicy, EventDispatcher) instead. |
ChunkSampleStream(int primaryTrackType,
int[] embeddedTrackTypes,
Format[] embeddedTrackFormats,
T chunkSource,
SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
Allocator allocator,
long positionUs,
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
MediaSourceEventListener.EventDispatcher eventDispatcher)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
continueLoading(long positionUs)
Attempts to continue loading.
|
void |
discardBuffer(long positionUs,
boolean toKeyframe)
Discards buffered media up to the specified position.
|
long |
getAdjustedSeekPositionUs(long positionUs,
SeekParameters seekParameters)
Adjusts a seek position given the specified
SeekParameters. |
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.
|
void |
onLoaderReleased()
Called when the
Loader has finished being released. |
Loader.LoadErrorAction |
onLoadError(Chunk loadable,
long elapsedRealtimeMs,
long loadDurationMs,
java.io.IOException error,
int errorCount)
Called when a load encounters an error.
|
int |
readData(FormatHolder formatHolder,
DecoderInputBuffer buffer,
boolean formatRequired)
Attempts to read from the stream.
|
void |
reevaluateBuffer(long positionUs)
Re-evaluates the buffer given the playback position.
|
void |
release()
Releases the stream.
|
void |
release(ChunkSampleStream.ReleaseCallback<T> callback)
Releases the stream.
|
void |
seekToUs(long positionUs)
Seeks to the specified position in microseconds.
|
ChunkSampleStream.EmbeddedSampleStream |
selectEmbeddedTrack(long positionUs,
int trackType)
Selects the embedded track, returning a new
ChunkSampleStream.EmbeddedSampleStream from which the track's
samples can be consumed. |
int |
skipData(long positionUs)
Attempts to skip to the keyframe before the specified position, or to the end of the stream if
positionUs is beyond it. |
@Deprecated
public ChunkSampleStream(int primaryTrackType,
int[] embeddedTrackTypes,
Format[] embeddedTrackFormats,
T chunkSource,
SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
Allocator allocator,
long positionUs,
int minLoadableRetryCount,
MediaSourceEventListener.EventDispatcher eventDispatcher)
#ChunkSampleStream(int, int[], Format[], ChunkSource, Callback,
Allocator, long, LoadErrorHandlingPolicy, EventDispatcher) instead.primaryTrackType - The type of the primary track. One of the C TRACK_TYPE_* constants.embeddedTrackTypes - The types of any embedded tracks, or null.embeddedTrackFormats - The formats of the embedded tracks, or null.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 ChunkSampleStream(int primaryTrackType,
int[] embeddedTrackTypes,
Format[] embeddedTrackFormats,
T chunkSource,
SequenceableLoader.Callback<ChunkSampleStream<T>> callback,
Allocator allocator,
long positionUs,
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
MediaSourceEventListener.EventDispatcher eventDispatcher)
primaryTrackType - The type of the primary track. One of the C TRACK_TYPE_* constants.embeddedTrackTypes - The types of any embedded tracks, or null.embeddedTrackFormats - The formats of the embedded tracks, or null.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.loadErrorHandlingPolicy - The LoadErrorHandlingPolicy.eventDispatcher - A dispatcher to notify of events.public void discardBuffer(long positionUs,
boolean toKeyframe)
positionUs - The position to discard up to, in microseconds.toKeyframe - If true then for each track discards samples up to the keyframe before or at
the specified position, rather than any sample before or at that position.public ChunkSampleStream.EmbeddedSampleStream selectEmbeddedTrack(long positionUs, int trackType)
ChunkSampleStream.EmbeddedSampleStream from which the track's
samples can be consumed. ChunkSampleStream.EmbeddedSampleStream.release() must be called on the returned
stream when the track is no longer required, and before calling this method again to obtain
another stream for the same track.positionUs - The current playback position in microseconds.trackType - The type of the embedded track to enable.ChunkSampleStream.EmbeddedSampleStream for the embedded track.public T getChunkSource()
ChunkSource used by this stream.public long getBufferedPositionUs()
getBufferedPositionUs in interface SequenceableLoaderC.TIME_END_OF_SOURCE if the track is fully buffered.public long getAdjustedSeekPositionUs(long positionUs,
SeekParameters seekParameters)
SeekParameters. Chunk boundaries are used
as sync points.positionUs - The seek position in microseconds.seekParameters - Parameters that control how the seek is performed.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. Either this method or
release(ReleaseCallback) can be used to release this stream.
public void release(@Nullable
ChunkSampleStream.ReleaseCallback<T> callback)
This method should be called when the stream is no longer required. Either this method or
release() can be used to release this stream.
callback - An optional callback to be called on the loading thread once the loader has
been released.public void onLoaderReleased()
Loader.ReleaseCallbackLoader has finished being released.onLoaderReleased in interface Loader.ReleaseCallbackpublic 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, boolean). Hence an ended stream is always
ready.
isReady in interface SampleStreampublic void maybeThrowError()
throws java.io.IOException
SampleStreammaybeThrowError in interface SampleStreamjava.io.IOException - The underlying error.public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired)
SampleStream
If the stream has ended then C.BUFFER_FLAG_END_OF_STREAM flag is set on buffer
and C.RESULT_BUFFER_READ is returned. Else if no data is available then
C.RESULT_NOTHING_READ is returned. Else if the format of the media is changing or if
formatRequired is set then formatHolder is populated and
C.RESULT_FORMAT_READ is returned. Else buffer is populated and
C.RESULT_BUFFER_READ is returned.
readData in interface SampleStreamformatHolder - 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.C.RESULT_NOTHING_READ, C.RESULT_FORMAT_READ or
C.RESULT_BUFFER_READ.public int skipData(long positionUs)
SampleStreampositionUs is beyond it.skipData in interface SampleStreampositionUs - The specified time.public void onLoadCompleted(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs)
Loader.CallbackNote: 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 in milliseconds of the load since Loader.startLoading(T, com.google.android.exoplayer2.upstream.Loader.Callback<T>, int)
was called.public void onLoadCanceled(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, boolean released)
Loader.CallbackNote: 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 in milliseconds of the load since Loader.startLoading(T, com.google.android.exoplayer2.upstream.Loader.Callback<T>, int)
was called up to the point at which it was canceled.released - True if the load was canceled because the Loader was released. False
otherwise.public Loader.LoadErrorAction onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs, java.io.IOException error, int errorCount)
Loader.CallbackNote: 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 in milliseconds of the load since Loader.startLoading(T, com.google.android.exoplayer2.upstream.Loader.Callback<T>, int)
was called up to the point at which the error occurred.error - The load error.errorCount - The number of errors this load has encountered, including this one.Loader.RETRY, Loader.RETRY_RESET_ERROR_COUNT, Loader.DONT_RETRY, Loader.DONT_RETRY_FATAL or a retry action created by Loader.createRetryAction(boolean, long).public boolean continueLoading(long positionUs)
SequenceableLoadercontinueLoading in interface SequenceableLoaderpositionUs - The current playback position in microseconds. If playback of the period to
which this loader belongs has not yet started, the value will be the starting position
in the period minus the duration of any media in previous periods still to be played.SequenceableLoader.getNextLoadPositionUs() will return
a different value than prior to the call. False otherwise.public long getNextLoadPositionUs()
SequenceableLoaderC.TIME_END_OF_SOURCE if loading has finished.getNextLoadPositionUs in interface SequenceableLoaderpublic void reevaluateBuffer(long positionUs)
SequenceableLoaderRe-evaluation may discard buffered media so that it can be re-buffered in a different quality.
reevaluateBuffer in interface SequenceableLoaderpositionUs - The current playback position in microseconds. If playback of this period has
not yet started, the value will be the starting position in this period minus the duration
of any media in previous periods still to be played.