public class AdaptiveTrackSelection extends BaseTrackSelection
TrackSelection, whose selected track is updated to be the one
of highest quality given the current network conditions and the state of the buffer.| Modifier and Type | Class and Description |
|---|---|
static class |
AdaptiveTrackSelection.Factory
Factory for
AdaptiveTrackSelection instances. |
| Modifier and Type | Field and Description |
|---|---|
static float |
DEFAULT_BANDWIDTH_FRACTION |
static float |
DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE |
static int |
DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS |
static int |
DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS |
static int |
DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS |
static long |
DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS |
group, length, tracks| Constructor and Description |
|---|
AdaptiveTrackSelection(TrackGroup group,
int[] tracks,
BandwidthMeter bandwidthMeter) |
AdaptiveTrackSelection(TrackGroup group,
int[] tracks,
BandwidthMeter bandwidthMeter,
long minDurationForQualityIncreaseMs,
long maxDurationForQualityDecreaseMs,
long minDurationToRetainAfterDiscardMs,
float bandwidthFraction,
float bufferedFractionToLiveEdgeForQualityIncrease,
long minTimeBetweenBufferReevaluationMs,
Clock clock) |
| Modifier and Type | Method and Description |
|---|---|
void |
enable()
Enables the track selection.
|
int |
evaluateQueueSize(long playbackPositionUs,
java.util.List<? extends MediaChunk> queue)
May be called periodically by sources that load media in discrete
MediaChunks and
support discarding of buffered chunks in order to re-buffer using a different selected track. |
int |
getSelectedIndex()
Returns the index of the selected track.
|
java.lang.Object |
getSelectionData()
Returns optional data associated with the current track selection.
|
int |
getSelectionReason()
Returns the reason for the current track selection.
|
void |
onPlaybackSpeed(float playbackSpeed)
Called to notify the selection of the current playback speed.
|
void |
updateSelectedTrack(long playbackPositionUs,
long bufferedDurationUs,
long availableDurationUs)
Updates the selected track.
|
blacklist, disable, equals, getFormat, getIndexInTrackGroup, getSelectedFormat, getSelectedIndexInTrackGroup, getTrackGroup, hashCode, indexOf, indexOf, isBlacklisted, lengthpublic static final int DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS
public static final int DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS
public static final int DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS
public static final float DEFAULT_BANDWIDTH_FRACTION
public static final float DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE
public static final long DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS
public AdaptiveTrackSelection(TrackGroup group, int[] tracks, BandwidthMeter bandwidthMeter)
group - The TrackGroup.tracks - The indices of the selected tracks within the TrackGroup. Must not be
empty. May be in any order.bandwidthMeter - Provides an estimate of the currently available bandwidth.public AdaptiveTrackSelection(TrackGroup group, int[] tracks, BandwidthMeter bandwidthMeter, long minDurationForQualityIncreaseMs, long maxDurationForQualityDecreaseMs, long minDurationToRetainAfterDiscardMs, float bandwidthFraction, float bufferedFractionToLiveEdgeForQualityIncrease, long minTimeBetweenBufferReevaluationMs, Clock clock)
group - The TrackGroup.tracks - The indices of the selected tracks within the TrackGroup. Must not be
empty. May be in any order.bandwidthMeter - Provides an estimate of the currently available bandwidth.minDurationForQualityIncreaseMs - The minimum duration of buffered data required for the
selected track to switch to one of higher quality.maxDurationForQualityDecreaseMs - The maximum duration of buffered data required for the
selected track to switch to one of lower quality.minDurationToRetainAfterDiscardMs - When switching to a track of significantly higher
quality, the selection may indicate that media already buffered at the lower quality can be
discarded to speed up the switch. This is the minimum duration of media that must be
retained at the lower quality.bandwidthFraction - The fraction of the available bandwidth that the selection should
consider available for use. Setting to a value less than 1 is recommended to account for
inaccuracies in the bandwidth estimator.bufferedFractionToLiveEdgeForQualityIncrease - For live streaming, the fraction of the
duration from current playback position to the live edge that has to be buffered before the
selected track can be switched to one of higher quality. This parameter is only applied
when the playback position is closer to the live edge than minDurationForQualityIncreaseMs, which would otherwise prevent switching to a higher
quality from happening.minTimeBetweenBufferReevaluationMs - The track selection may periodically reevaluate its
buffer and discard some chunks of lower quality to improve the playback quality if network
condition has changed. This is the minimum duration between 2 consecutive buffer
reevaluation calls.public void enable()
TrackSelectionThis method may not be called when the track selection is already enabled.
enable in interface TrackSelectionenable in class BaseTrackSelectionpublic void onPlaybackSpeed(float playbackSpeed)
TrackSelectiononPlaybackSpeed in interface TrackSelectiononPlaybackSpeed in class BaseTrackSelectionplaybackSpeed - The playback speed.public void updateSelectedTrack(long playbackPositionUs,
long bufferedDurationUs,
long availableDurationUs)
TrackSelectionThis method may only be called when the selection is enabled.
playbackPositionUs - The current playback position in microseconds. If playback of the
period to which this track selection 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.bufferedDurationUs - The duration of media currently buffered from the current playback
position, in microseconds. Note that the next load position can be calculated as
(playbackPositionUs + bufferedDurationUs).availableDurationUs - The duration of media available for buffering from the current
playback position, in microseconds, or C.TIME_UNSET if media can be buffered
to the end of the current period. Note that if not set to C.TIME_UNSET, the
position up to which media is available for buffering can be calculated as
(playbackPositionUs + availableDurationUs).public int getSelectedIndex()
TrackSelectionpublic int getSelectionReason()
TrackSelection@Nullable public java.lang.Object getSelectionData()
TrackSelectionpublic int evaluateQueueSize(long playbackPositionUs,
java.util.List<? extends MediaChunk> queue)
TrackSelectionMediaChunks and
support discarding of buffered chunks in order to re-buffer using a different selected track.
Returns the number of chunks that should be retained in the queue.
To avoid excessive re-buffering, implementations should normally return the size of the queue. An example of a case where a smaller value may be returned is if network conditions have improved dramatically, allowing chunks to be discarded and re-buffered in a track of significantly higher quality. Discarding chunks may allow faster switching to a higher quality track in this case. This method may only be called when the selection is enabled.
evaluateQueueSize in interface TrackSelectionevaluateQueueSize in class BaseTrackSelectionplaybackPositionUs - The current playback position in microseconds. If playback of the
period to which this track selection 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.queue - The queue of buffered MediaChunks. Must not be modified.