public class SmoothStreamingChunkSource extends Object implements ChunkSource, SmoothStreamingTrackSelector.Output
ChunkSource
for SmoothStreaming.Constructor and Description |
---|
SmoothStreamingChunkSource(ManifestFetcher<SmoothStreamingManifest> manifestFetcher,
SmoothStreamingTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator,
long liveEdgeLatencyMs)
Constructor to use for live streaming.
|
SmoothStreamingChunkSource(SmoothStreamingManifest manifest,
SmoothStreamingTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator)
Constructor to use for fixed duration content.
|
Modifier and Type | Method and Description |
---|---|
void |
adaptiveTrack(SmoothStreamingManifest manifest,
int element,
int[] trackIndices)
Outputs an adaptive track, covering the specified tracks in the specified element.
|
void |
continueBuffering(long playbackPositionUs)
Indicates to the source that it should still be checking for updates to the stream.
|
void |
disable(List<? extends MediaChunk> queue)
Disables the source.
|
void |
enable(int track)
Enable the source for the specified track.
|
void |
fixedTrack(SmoothStreamingManifest manifest,
int element,
int trackIndex)
Outputs a fixed track corresponding to the specified track in the specified element.
|
void |
getChunkOperation(List<? extends MediaChunk> queue,
long playbackPositionUs,
ChunkOperationHolder out)
Updates the provided
ChunkOperationHolder to contain the next operation that should
be performed by the calling ChunkSampleSource . |
MediaFormat |
getFormat(int track)
Gets the format of the specified track.
|
int |
getTrackCount()
Returns the number of tracks exposed by the source.
|
void |
maybeThrowError()
If the source is currently having difficulty preparing or providing chunks, then this method
throws the underlying error.
|
void |
onChunkLoadCompleted(Chunk chunk)
Invoked when the
ChunkSampleSource has finished loading a chunk obtained from this
source. |
void |
onChunkLoadError(Chunk chunk,
Exception e)
Invoked when the
ChunkSampleSource encounters an error loading a chunk obtained from
this source. |
boolean |
prepare()
Prepares the source.
|
public SmoothStreamingChunkSource(ManifestFetcher<SmoothStreamingManifest> manifestFetcher, SmoothStreamingTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator, long liveEdgeLatencyMs)
May also be used for fixed duration content, in which case the call is equivalent to calling
the other constructor, passing manifestFetcher.getManifest()
is the first argument.
manifestFetcher
- A fetcher for the manifest, which must have already successfully
completed an initial load.trackSelector
- Selects tracks from the manifest to be exposed by this source.dataSource
- A DataSource
suitable for loading the media data.adaptiveFormatEvaluator
- For adaptive tracks, selects from the available formats.liveEdgeLatencyMs
- For live streams, the number of milliseconds that the playback should
lag behind the "live edge" (i.e. the end of the most recently defined media in the
manifest). Choosing a small value will minimize latency introduced by the player, however
note that the value sets an upper bound on the length of media that the player can buffer.
Hence a small value may increase the probability of rebuffering and playback failures.public SmoothStreamingChunkSource(SmoothStreamingManifest manifest, SmoothStreamingTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator)
manifest
- The manifest parsed from baseUrl + "/Manifest"
.trackSelector
- Selects tracks from the manifest to be exposed by this source.dataSource
- A DataSource
suitable for loading the media data.adaptiveFormatEvaluator
- For adaptive tracks, selects from the available formats.public void maybeThrowError() throws IOException
ChunkSource
maybeThrowError
in interface ChunkSource
IOException
- The underlying error.public boolean prepare()
ChunkSource
The method can be called repeatedly until the return value indicates success.
prepare
in interface ChunkSource
public int getTrackCount()
ChunkSource
This method should only be called after the source has been prepared.
getTrackCount
in interface ChunkSource
public final MediaFormat getFormat(int track)
ChunkSource
This method should only be called after the source has been prepared.
getFormat
in interface ChunkSource
track
- The track index.public void enable(int track)
ChunkSource
This method should only be called after the source has been prepared, and when the source is disabled.
enable
in interface ChunkSource
track
- The track index.public void continueBuffering(long playbackPositionUs)
ChunkSource
This method should only be called when the source is enabled.
continueBuffering
in interface ChunkSource
playbackPositionUs
- The current playback position.public final void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs, ChunkOperationHolder out)
ChunkSource
ChunkOperationHolder
to contain the next operation that should
be performed by the calling ChunkSampleSource
.
This method should only be called when the source is enabled.
getChunkOperation
in interface ChunkSource
queue
- A representation of the currently buffered MediaChunk
s.playbackPositionUs
- The current playback position. If the queue is empty then this
parameter is the position from which playback is expected to start (or restart) and hence
should be interpreted as a seek position.out
- A holder for the next operation, whose ChunkOperationHolder.endOfStream
is
initially set to false, whose ChunkOperationHolder.queueSize
is initially equal to
the length of the queue, and whose ChunkOperationHolder.chunk
is initially equal to
null or a Chunk
previously supplied by the ChunkSource
that the caller has
not yet finished loading. In the latter case the chunk can either be replaced or left
unchanged. Note that leaving the chunk unchanged is both preferred and more efficient than
replacing it with a new but identical chunk.public void onChunkLoadCompleted(Chunk chunk)
ChunkSource
ChunkSampleSource
has finished loading a chunk obtained from this
source.
This method should only be called when the source is enabled.
onChunkLoadCompleted
in interface ChunkSource
chunk
- The chunk whose load has been completed.public void onChunkLoadError(Chunk chunk, Exception e)
ChunkSource
ChunkSampleSource
encounters an error loading a chunk obtained from
this source.
This method should only be called when the source is enabled.
onChunkLoadError
in interface ChunkSource
chunk
- The chunk whose load encountered the error.e
- The error.public void disable(List<? extends MediaChunk> queue)
ChunkSource
This method should only be called when the source is enabled.
disable
in interface ChunkSource
queue
- A representation of the currently buffered MediaChunk
s.public void adaptiveTrack(SmoothStreamingManifest manifest, int element, int[] trackIndices)
SmoothStreamingTrackSelector.Output
adaptiveTrack
in interface SmoothStreamingTrackSelector.Output
manifest
- The manifest being processed.element
- The index of the element within which the adaptive tracks are located.trackIndices
- The indices of the tracks within the element.public void fixedTrack(SmoothStreamingManifest manifest, int element, int trackIndex)
SmoothStreamingTrackSelector.Output
fixedTrack
in interface SmoothStreamingTrackSelector.Output
manifest
- The manifest being processed.element
- The index of the element within which the track is located.trackIndex
- The index of the track within the element.