public class HlsChunkSource extends Object implements HlsTrackSelector.Output
Modifier and Type | Class and Description |
---|---|
static interface |
HlsChunkSource.EventListener
Interface definition for a callback to be notified of
HlsChunkSource events. |
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_MAX_BUFFER_TO_SWITCH_DOWN_MS
The default maximum duration of media that needs to be buffered for a switch to a lower
quality variant to be considered.
|
static long |
DEFAULT_MIN_BUFFER_TO_SWITCH_UP_MS
The default minimum duration of media that needs to be buffered for a switch to a higher
quality variant to be considered.
|
static long |
DEFAULT_PLAYLIST_BLACKLIST_MS
The default time for which a media playlist should be blacklisted.
|
Constructor and Description |
---|
HlsChunkSource(boolean isMaster,
DataSource dataSource,
HlsPlaylist playlist,
HlsTrackSelector trackSelector,
BandwidthMeter bandwidthMeter,
PtsTimestampAdjusterProvider timestampAdjusterProvider) |
HlsChunkSource(boolean isMaster,
DataSource dataSource,
HlsPlaylist playlist,
HlsTrackSelector trackSelector,
BandwidthMeter bandwidthMeter,
PtsTimestampAdjusterProvider timestampAdjusterProvider,
long minBufferDurationToSwitchUpMs,
long maxBufferDurationToSwitchDownMs) |
HlsChunkSource(boolean isMaster,
DataSource dataSource,
HlsPlaylist playlist,
HlsTrackSelector trackSelector,
BandwidthMeter bandwidthMeter,
PtsTimestampAdjusterProvider timestampAdjusterProvider,
long minBufferDurationToSwitchUpMs,
long maxBufferDurationToSwitchDownMs,
Handler eventHandler,
HlsChunkSource.EventListener eventListener) |
Modifier and Type | Method and Description |
---|---|
void |
adaptiveTrack(HlsMasterPlaylist playlist,
Variant[] variants)
Outputs an adaptive track, covering the specified representations in the specified
adaptation set.
|
protected int |
computeDefaultVariantIndex(HlsMasterPlaylist playlist,
Variant[] variants,
BandwidthMeter bandwidthMeter) |
void |
fixedTrack(HlsMasterPlaylist playlist,
Variant variant)
Outputs an fixed track corresponding to the specified representation in the specified
adaptation set.
|
void |
getChunkOperation(TsChunk previousTsChunk,
long playbackPositionUs,
ChunkOperationHolder out)
Updates the provided
ChunkOperationHolder to contain the next operation that should
be performed by the calling HlsSampleSource . |
long |
getDurationUs()
Returns the duration of the source, or
C.UNKNOWN_TIME_US if the duration is unknown. |
Variant |
getFixedTrackVariant(int index)
Returns the variant corresponding to the fixed track at the specified index, or null if the
track at the specified index is adaptive.
|
String |
getMuxedAudioLanguage()
Returns the language of the audio muxed into variants, or null if unknown.
|
String |
getMuxedCaptionLanguage()
Returns the language of the captions muxed into variants, or null if unknown.
|
int |
getSelectedTrackIndex()
Returns the currently selected track index.
|
int |
getTrackCount()
Returns the number of tracks exposed by the source.
|
boolean |
isLive()
Returns whether this is a live playback.
|
void |
maybeThrowError()
If the source is currently having difficulty providing chunks, then this method throws the
underlying error.
|
void |
onChunkLoadCompleted(Chunk chunk)
Invoked when the
HlsSampleSource has finished loading a chunk obtained from this
source. |
boolean |
onChunkLoadError(Chunk chunk,
IOException e)
Invoked when the
HlsSampleSource encounters an error loading a chunk obtained from
this source. |
boolean |
prepare()
Prepares the source.
|
void |
reset()
Resets the source.
|
void |
seek()
Notifies the source that a seek has occurred.
|
void |
selectTrack(int index)
Selects a track for use.
|
public static final long DEFAULT_MIN_BUFFER_TO_SWITCH_UP_MS
public static final long DEFAULT_MAX_BUFFER_TO_SWITCH_DOWN_MS
public static final long DEFAULT_PLAYLIST_BLACKLIST_MS
public HlsChunkSource(boolean isMaster, DataSource dataSource, HlsPlaylist playlist, HlsTrackSelector trackSelector, BandwidthMeter bandwidthMeter, PtsTimestampAdjusterProvider timestampAdjusterProvider)
isMaster
- True if this is the master source for the playback. False otherwise. Each
playback must have exactly one master source, which should be the source providing video
chunks (or audio chunks for audio only playbacks).dataSource
- A DataSource
suitable for loading the media data.playlist
- The HLS playlist.trackSelector
- Selects tracks to be exposed by this source.bandwidthMeter
- Provides an estimate of the currently available bandwidth.timestampAdjusterProvider
- A provider of PtsTimestampAdjuster
instances. If
multiple HlsChunkSource
s are used for a single playback, they should all share the
same provider.public HlsChunkSource(boolean isMaster, DataSource dataSource, HlsPlaylist playlist, HlsTrackSelector trackSelector, BandwidthMeter bandwidthMeter, PtsTimestampAdjusterProvider timestampAdjusterProvider, long minBufferDurationToSwitchUpMs, long maxBufferDurationToSwitchDownMs)
isMaster
- True if this is the master source for the playback. False otherwise. Each
playback must have exactly one master source, which should be the source providing video
chunks (or audio chunks for audio only playbacks).dataSource
- A DataSource
suitable for loading the media data.playlist
- The HLS playlist.trackSelector
- Selects tracks to be exposed by this source.bandwidthMeter
- Provides an estimate of the currently available bandwidth.timestampAdjusterProvider
- A provider of PtsTimestampAdjuster
instances. If
multiple HlsChunkSource
s are used for a single playback, they should all share the
same provider.minBufferDurationToSwitchUpMs
- The minimum duration of media that needs to be buffered
for a switch to a higher quality variant to be considered.maxBufferDurationToSwitchDownMs
- The maximum duration of media that needs to be buffered
for a switch to a lower quality variant to be considered.public HlsChunkSource(boolean isMaster, DataSource dataSource, HlsPlaylist playlist, HlsTrackSelector trackSelector, BandwidthMeter bandwidthMeter, PtsTimestampAdjusterProvider timestampAdjusterProvider, long minBufferDurationToSwitchUpMs, long maxBufferDurationToSwitchDownMs, Handler eventHandler, HlsChunkSource.EventListener eventListener)
isMaster
- True if this is the master source for the playback. False otherwise. Each
playback must have exactly one master source, which should be the source providing video
chunks (or audio chunks for audio only playbacks).dataSource
- A DataSource
suitable for loading the media data.playlist
- The HLS playlist.trackSelector
- Selects tracks to be exposed by this source.bandwidthMeter
- Provides an estimate of the currently available bandwidth.timestampAdjusterProvider
- A provider of PtsTimestampAdjuster
instances. If
multiple HlsChunkSource
s are used for a single playback, they should all share the
same provider.minBufferDurationToSwitchUpMs
- The minimum duration of media that needs to be buffered
for a switch to a higher quality variant to be considered.maxBufferDurationToSwitchDownMs
- The maximum duration of media that needs to be buffered
for a switch to a lower quality variant to be considered.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.public void maybeThrowError() throws IOException
IOException
- The underlying error.public boolean prepare()
public boolean isLive()
This method should only be called after the source has been prepared.
public long getDurationUs()
C.UNKNOWN_TIME_US
if the duration is unknown.
This method should only be called after the source has been prepared.
public int getTrackCount()
This method should only be called after the source has been prepared.
public Variant getFixedTrackVariant(int index)
This method should only be called after the source has been prepared.
index
- The track index.public String getMuxedAudioLanguage()
public String getMuxedCaptionLanguage()
public int getSelectedTrackIndex()
This method should only be called after the source has been prepared.
public void selectTrack(int index)
This method should only be called after the source has been prepared.
index
- The track index.public void seek()
This method should only be called after the source has been prepared.
public void reset()
This method should only be called after the source has been prepared.
public void getChunkOperation(TsChunk previousTsChunk, long playbackPositionUs, ChunkOperationHolder out)
ChunkOperationHolder
to contain the next operation that should
be performed by the calling HlsSampleSource
.previousTsChunk
- The previously loaded chunk that the next chunk should follow.playbackPositionUs
- The current playback position. If previousTsChunk is null 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
- The holder to populate with the result. ChunkOperationHolder.queueSize
is
unused.public void onChunkLoadCompleted(Chunk chunk)
HlsSampleSource
has finished loading a chunk obtained from this
source.chunk
- The chunk whose load has been completed.public boolean onChunkLoadError(Chunk chunk, IOException e)
HlsSampleSource
encounters an error loading a chunk obtained from
this source.chunk
- The chunk whose load encountered the error.e
- The error.public void adaptiveTrack(HlsMasterPlaylist playlist, Variant[] variants)
HlsTrackSelector.Output
adaptiveTrack
in interface HlsTrackSelector.Output
playlist
- The master playlist being processed.variants
- The variants to use for the adaptive track.public void fixedTrack(HlsMasterPlaylist playlist, Variant variant)
HlsTrackSelector.Output
fixedTrack
in interface HlsTrackSelector.Output
playlist
- The master playlist being processed.variant
- The variant to use for the track.protected int computeDefaultVariantIndex(HlsMasterPlaylist playlist, Variant[] variants, BandwidthMeter bandwidthMeter)