LoadControl
public class DefaultLoadControl extends Object implements LoadControl
LoadControl
implementation.Modifier and Type | Class | Description |
---|---|---|
static class |
DefaultLoadControl.Builder |
Builder for
DefaultLoadControl . |
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_AUDIO_BUFFER_SIZE |
A default size in bytes for an audio buffer.
|
static int |
DEFAULT_BACK_BUFFER_DURATION_MS |
The default back buffer duration in milliseconds.
|
static int |
DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS |
The default duration of media that must be buffered for playback to resume after a rebuffer, in
milliseconds.
|
static int |
DEFAULT_BUFFER_FOR_PLAYBACK_MS |
The default duration of media that must be buffered for playback to start or resume following a
user action such as a seek, in milliseconds.
|
static int |
DEFAULT_CAMERA_MOTION_BUFFER_SIZE |
A default size in bytes for a camera motion buffer.
|
static int |
DEFAULT_MAX_BUFFER_MS |
The default maximum duration of media that the player will attempt to buffer, in milliseconds.
|
static int |
DEFAULT_METADATA_BUFFER_SIZE |
A default size in bytes for a metadata buffer.
|
static int |
DEFAULT_MIN_BUFFER_MS |
The default minimum duration of media that the player will attempt to ensure is buffered at all
times, in milliseconds.
|
static int |
DEFAULT_MIN_BUFFER_SIZE |
The buffer size in bytes that will be used as a minimum target buffer in all cases.
|
static int |
DEFAULT_MUXED_BUFFER_SIZE |
A default size in bytes for a muxed buffer (e.g.
|
static boolean |
DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS |
The default prioritization of buffer time constraints over size constraints.
|
static boolean |
DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME |
The default for whether the back buffer is retained from the previous keyframe.
|
static int |
DEFAULT_TARGET_BUFFER_BYTES |
The default target buffer size in bytes.
|
static int |
DEFAULT_TEXT_BUFFER_SIZE |
A default size in bytes for a text buffer.
|
static int |
DEFAULT_VIDEO_BUFFER_SIZE |
A default size in bytes for a video buffer.
|
Modifier | Constructor | Description |
---|---|---|
|
DefaultLoadControl() |
Constructs a new instance, using the
DEFAULT_* constants defined in this class. |
protected |
DefaultLoadControl(DefaultAllocator allocator,
int minBufferMs,
int maxBufferMs,
int bufferForPlaybackMs,
int bufferForPlaybackAfterRebufferMs,
int targetBufferBytes,
boolean prioritizeTimeOverSizeThresholds,
int backBufferDurationMs,
boolean retainBackBufferFromKeyframe) |
Modifier and Type | Method | Description |
---|---|---|
protected int |
calculateTargetBufferBytes(Renderer[] renderers,
ExoTrackSelection[] trackSelectionArray) |
Calculate target buffer size in bytes based on the selected tracks.
|
Allocator |
getAllocator() |
Returns the
Allocator that should be used to obtain media buffer allocations. |
long |
getBackBufferDurationUs() |
Returns the duration of media to retain in the buffer prior to the current playback position,
for fast backward seeking.
|
void |
onPrepared() |
Called by the player when prepared with a new source.
|
void |
onReleased() |
Called by the player when released.
|
void |
onStopped() |
Called by the player when stopped.
|
void |
onTracksSelected(Renderer[] renderers,
TrackGroupArray trackGroups,
ExoTrackSelection[] trackSelections) |
Called by the player when a track selection occurs.
|
boolean |
retainBackBufferFromKeyframe() |
Returns whether media should be retained from the keyframe before the current playback position
minus
LoadControl.getBackBufferDurationUs() , rather than any sample before or at that position. |
boolean |
shouldContinueLoading(long playbackPositionUs,
long bufferedDurationUs,
float playbackSpeed) |
Called by the player to determine whether it should continue to load the source.
|
boolean |
shouldStartPlayback(long bufferedDurationUs,
float playbackSpeed,
boolean rebuffering,
long targetLiveOffsetUs) |
Called repeatedly by the player when it's loading the source, has yet to start playback, and
has the minimum amount of data necessary for playback to be started.
|
public static final int DEFAULT_MIN_BUFFER_MS
public static final int DEFAULT_MAX_BUFFER_MS
public static final int DEFAULT_BUFFER_FOR_PLAYBACK_MS
public static final int DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
public static final int DEFAULT_TARGET_BUFFER_BYTES
C.LENGTH_UNSET
) means that the load
control will calculate the target buffer size based on the selected tracks.public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS
public static final int DEFAULT_BACK_BUFFER_DURATION_MS
public static final boolean DEFAULT_RETAIN_BACK_BUFFER_FROM_KEYFRAME
public static final int DEFAULT_VIDEO_BUFFER_SIZE
public static final int DEFAULT_AUDIO_BUFFER_SIZE
public static final int DEFAULT_TEXT_BUFFER_SIZE
public static final int DEFAULT_METADATA_BUFFER_SIZE
public static final int DEFAULT_CAMERA_MOTION_BUFFER_SIZE
public static final int DEFAULT_MUXED_BUFFER_SIZE
public static final int DEFAULT_MIN_BUFFER_SIZE
public DefaultLoadControl()
DEFAULT_*
constants defined in this class.protected DefaultLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, int backBufferDurationMs, boolean retainBackBufferFromKeyframe)
public void onPrepared()
LoadControl
onPrepared
in interface LoadControl
public void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, ExoTrackSelection[] trackSelections)
LoadControl
onTracksSelected
in interface LoadControl
renderers
- The renderers.trackGroups
- The TrackGroup
s from which the selection was made.trackSelections
- The track selections that were made.public void onStopped()
LoadControl
onStopped
in interface LoadControl
public void onReleased()
LoadControl
onReleased
in interface LoadControl
public Allocator getAllocator()
LoadControl
Allocator
that should be used to obtain media buffer allocations.getAllocator
in interface LoadControl
public long getBackBufferDurationUs()
LoadControl
Note: If LoadControl.retainBackBufferFromKeyframe()
is false then seeking in the back-buffer
will only be fast if the back-buffer contains a keyframe prior to the seek position.
Note: Implementations should return a single value. Dynamic changes to the back-buffer are not currently supported.
getBackBufferDurationUs
in interface LoadControl
public boolean retainBackBufferFromKeyframe()
LoadControl
LoadControl.getBackBufferDurationUs()
, rather than any sample before or at that position.
Warning: Returning true will cause the back-buffer size to depend on the spacing of
keyframes in the media being played. Returning true is not recommended unless you control the
media and are comfortable with the back-buffer size exceeding LoadControl.getBackBufferDurationUs()
by as much as the maximum duration between adjacent keyframes in
the media.
Note: Implementations should return a single value. Dynamic changes to the back-buffer are not currently supported.
retainBackBufferFromKeyframe
in interface LoadControl
LoadControl.getBackBufferDurationUs()
, rather than any sample before or at that
position.public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed)
LoadControl
shouldContinueLoading
in interface LoadControl
playbackPositionUs
- The current playback position in microseconds, relative to the start
of the period
that will continue to be loaded if this method
returns true
. If playback of this period has not yet started, the value will be
negative and equal in magnitude to the duration of any media in previous periods still to
be played.bufferedDurationUs
- The duration of media that's currently buffered.playbackSpeed
- The current factor by which playback is sped up.public boolean shouldStartPlayback(long bufferedDurationUs, float playbackSpeed, boolean rebuffering, long targetLiveOffsetUs)
LoadControl
false
until some condition has been met (e.g. a certain amount of media is buffered).shouldStartPlayback
in interface LoadControl
bufferedDurationUs
- The duration of media that's currently buffered.playbackSpeed
- The current factor by which playback is sped up.rebuffering
- Whether the player is rebuffering. A rebuffer is defined to be caused by
buffer depletion rather than a user action. Hence this parameter is false during initial
buffering and when buffering as a result of a seek operation.targetLiveOffsetUs
- The desired playback position offset to the live edge in
microseconds, or C.TIME_UNSET
if the media is not a live stream or no offset is
configured.protected int calculateTargetBufferBytes(Renderer[] renderers, ExoTrackSelection[] trackSelectionArray)
targetBufferBytes
is C.LENGTH_UNSET
.renderers
- The renderers for which the track were selected.trackSelectionArray
- The selected tracks.