public class DashChunkSource extends Object implements ChunkSource, DashTrackSelector.Output
ChunkSource for DASH streams.
This implementation currently supports fMP4, webm, webvtt and ttml.
This implementation makes the following assumptions about multi-period manifests:
| Modifier and Type | Class and Description |
|---|---|
static interface |
DashChunkSource.EventListener
Interface definition for a callback to be notified of
DashChunkSource events. |
protected static class |
DashChunkSource.ExposedTrack |
static class |
DashChunkSource.NoAdaptationSetException
Thrown when an AdaptationSet is missing from the MPD.
|
protected static class |
DashChunkSource.PeriodHolder |
protected static class |
DashChunkSource.RepresentationHolder |
| Constructor and Description |
|---|
DashChunkSource(DashTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator,
long durationMs,
int adaptationSetType,
List<Representation> representations)
Lightweight constructor to use for fixed duration content.
|
DashChunkSource(DashTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator,
long durationMs,
int adaptationSetType,
Representation... representations)
Lightweight constructor to use for fixed duration content.
|
DashChunkSource(ManifestFetcher<MediaPresentationDescription> manifestFetcher,
DashTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator,
long liveEdgeLatencyMs,
long elapsedRealtimeOffsetMs,
boolean startAtLiveEdge,
Handler eventHandler,
DashChunkSource.EventListener eventListener,
int eventSourceId)
Constructor to use for live DVR streaming.
|
DashChunkSource(ManifestFetcher<MediaPresentationDescription> manifestFetcher,
DashTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator,
long liveEdgeLatencyMs,
long elapsedRealtimeOffsetMs,
Handler eventHandler,
DashChunkSource.EventListener eventListener,
int eventSourceId)
Constructor to use for live streaming.
|
DashChunkSource(MediaPresentationDescription manifest,
DashTrackSelector trackSelector,
DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator)
Constructor to use for fixed duration content.
|
| Modifier and Type | Method and Description |
|---|---|
void |
adaptiveTrack(MediaPresentationDescription manifest,
int periodIndex,
int adaptationSetIndex,
int[] representationIndices)
Outputs an adaptive track, covering the specified representations in the specified
adaptation set.
|
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(MediaPresentationDescription manifest,
int periodIndex,
int adaptationSetIndex,
int representationIndex)
Outputs an fixed track corresponding to the specified representation in the specified
adaptation set.
|
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.
|
protected Chunk |
newMediaChunk(DashChunkSource.PeriodHolder periodHolder,
DashChunkSource.RepresentationHolder representationHolder,
DataSource dataSource,
MediaFormat mediaFormat,
DashChunkSource.ExposedTrack enabledTrack,
int segmentNum,
int trigger,
boolean isMediaFormatFinal) |
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 DashChunkSource(DashTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator, long durationMs, int adaptationSetType, Representation... representations)
trackSelector - Selects tracks to be exposed by this source.dataSource - A DataSource suitable for loading the media data.adaptiveFormatEvaluator - For adaptive tracks, selects from the available formats.durationMs - The duration of the content.adaptationSetType - The type of the adaptation set to which the representations belong.
One of AdaptationSet.TYPE_AUDIO, AdaptationSet.TYPE_VIDEO and
AdaptationSet.TYPE_TEXT.representations - The representations to be considered by the source.public DashChunkSource(DashTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator, long durationMs, int adaptationSetType, List<Representation> representations)
trackSelector - Selects tracks to be exposed by this source.dataSource - A DataSource suitable for loading the media data.adaptiveFormatEvaluator - For adaptive tracks, selects from the available formats.durationMs - The duration of the content.adaptationSetType - The type of the adaptation set to which the representations belong.
One of AdaptationSet.TYPE_AUDIO, AdaptationSet.TYPE_VIDEO and
AdaptationSet.TYPE_TEXT.representations - The representations to be considered by the source.public DashChunkSource(MediaPresentationDescription manifest, DashTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator)
manifest - The manifest.trackSelector - Selects tracks from manifest periods 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 DashChunkSource(ManifestFetcher<MediaPresentationDescription> manifestFetcher, DashTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator, long liveEdgeLatencyMs, long elapsedRealtimeOffsetMs, Handler eventHandler, DashChunkSource.EventListener eventListener, int eventSourceId)
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 manifest periods 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.elapsedRealtimeOffsetMs - If known, an estimate of the instantaneous difference between
server-side unix time and SystemClock.elapsedRealtime() in milliseconds, specified
as the server's unix time minus the local elapsed time. It unknown, set to 0.eventHandler - A handler to use when delivering events to EventListener. May be
null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.eventSourceId - An identifier that gets passed to eventListener methods.public DashChunkSource(ManifestFetcher<MediaPresentationDescription> manifestFetcher, DashTrackSelector trackSelector, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator, long liveEdgeLatencyMs, long elapsedRealtimeOffsetMs, boolean startAtLiveEdge, Handler eventHandler, DashChunkSource.EventListener eventListener, int eventSourceId)
manifestFetcher - A fetcher for the manifest, which must have already successfully
completed an initial load.trackSelector - Selects tracks from manifest periods 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.elapsedRealtimeOffsetMs - If known, an estimate of the instantaneous difference between
server-side unix time and SystemClock.elapsedRealtime() in milliseconds, specified
as the server's unix time minus the local elapsed time. It unknown, set to 0.startAtLiveEdge - True if the stream should start at the live edge; false if it should
at the beginning of the live window.eventHandler - A handler to use when delivering events to EventListener. May be
null if delivery of events is not required.eventListener - A listener of events. May be null if delivery of events is not required.eventSourceId - An identifier that gets passed to eventListener methods.public void maybeThrowError()
throws IOException
ChunkSourcemaybeThrowError in interface ChunkSourceIOException - The underlying error.public boolean prepare()
ChunkSourceThe method can be called repeatedly until the return value indicates success.
prepare in interface ChunkSourcepublic int getTrackCount()
ChunkSourceThis method should only be called after the source has been prepared.
getTrackCount in interface ChunkSourcepublic final MediaFormat getFormat(int track)
ChunkSourceThis method should only be called after the source has been prepared.
getFormat in interface ChunkSourcetrack - The track index.public void enable(int track)
ChunkSourceThis method should only be called after the source has been prepared, and when the source is disabled.
enable in interface ChunkSourcetrack - The track index.public void continueBuffering(long playbackPositionUs)
ChunkSourceThis method should only be called when the source is enabled.
continueBuffering in interface ChunkSourceplaybackPositionUs - The current playback position.public final void getChunkOperation(List<? extends MediaChunk> queue, long playbackPositionUs, ChunkOperationHolder out)
ChunkSourceChunkOperationHolder 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 ChunkSourcequeue - A representation of the currently buffered MediaChunks.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)
ChunkSourceChunkSampleSource has finished loading a chunk obtained from this
source.
This method should only be called when the source is enabled.
onChunkLoadCompleted in interface ChunkSourcechunk - The chunk whose load has been completed.public void onChunkLoadError(Chunk chunk, Exception e)
ChunkSourceChunkSampleSource encounters an error loading a chunk obtained from
this source.
This method should only be called when the source is enabled.
onChunkLoadError in interface ChunkSourcechunk - The chunk whose load encountered the error.e - The error.public void disable(List<? extends MediaChunk> queue)
ChunkSourceThis method should only be called when the source is enabled.
disable in interface ChunkSourcequeue - A representation of the currently buffered MediaChunks.public void adaptiveTrack(MediaPresentationDescription manifest, int periodIndex, int adaptationSetIndex, int[] representationIndices)
DashTrackSelector.OutputadaptiveTrack in interface DashTrackSelector.Outputmanifest - The media presentation description being processed.periodIndex - The index of the period being processed.adaptationSetIndex - The index of the adaptation set within which the representations
are located.representationIndices - The indices of the track within the element.public void fixedTrack(MediaPresentationDescription manifest, int periodIndex, int adaptationSetIndex, int representationIndex)
DashTrackSelector.OutputfixedTrack in interface DashTrackSelector.Outputmanifest - The media presentation description being processed.periodIndex - The index of the period being processed.adaptationSetIndex - The index of the adaptation set within which the track is located.representationIndex - The index of the representation within the adaptation set.protected Chunk newMediaChunk(DashChunkSource.PeriodHolder periodHolder, DashChunkSource.RepresentationHolder representationHolder, DataSource dataSource, MediaFormat mediaFormat, DashChunkSource.ExposedTrack enabledTrack, int segmentNum, int trigger, boolean isMediaFormatFinal)