public class DefaultLoadControl extends java.lang.Object implements LoadControl
LoadControl implementation.| Modifier and Type | Field and Description |
|---|---|
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_MAX_BUFFER_MS
The default maximum duration of media that the player will attempt to buffer, in milliseconds.
|
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 boolean |
DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS
The default prioritization of buffer time constraints over size constraints.
|
static int |
DEFAULT_TARGET_BUFFER_BYTES
The default target buffer size in bytes.
|
| Constructor and Description |
|---|
DefaultLoadControl()
Constructs a new instance, using the
DEFAULT_* constants defined in this class. |
DefaultLoadControl(DefaultAllocator allocator)
Constructs a new instance, using the
DEFAULT_* constants defined in this class. |
DefaultLoadControl(DefaultAllocator allocator,
int minBufferMs,
int maxBufferMs,
int bufferForPlaybackMs,
int bufferForPlaybackAfterRebufferMs,
int targetBufferBytes,
boolean prioritizeTimeOverSizeThresholds)
Constructs a new instance.
|
DefaultLoadControl(DefaultAllocator allocator,
int minBufferMs,
int maxBufferMs,
int bufferForPlaybackMs,
int bufferForPlaybackAfterRebufferMs,
int targetBufferBytes,
boolean prioritizeTimeOverSizeThresholds,
PriorityTaskManager priorityTaskManager)
Constructs a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
calculateTargetBufferSize(Renderer[] renderers,
TrackSelectionArray 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,
TrackSelectionArray 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 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)
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, the load control
automatically determines its target buffer size.public static final boolean DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS
public DefaultLoadControl()
DEFAULT_* constants defined in this class.public DefaultLoadControl(DefaultAllocator allocator)
DEFAULT_* constants defined in this class.allocator - The DefaultAllocator used by the loader.public DefaultLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds)
allocator - The DefaultAllocator used by the loader.minBufferMs - The minimum duration of media that the player will attempt to ensure is
buffered at all times, in milliseconds.maxBufferMs - The maximum duration of media that the player will attempt buffer, in
milliseconds.bufferForPlaybackMs - The duration of media that must be buffered for playback to start or
resume following a user action such as a seek, in milliseconds.bufferForPlaybackAfterRebufferMs - The default duration of media that must be buffered for
playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by
buffer depletion rather than a user action.targetBufferBytes - The target buffer size in bytes. If set to C.LENGTH_UNSET, the
target buffer size will be calculated using calculateTargetBufferSize(Renderer[],
TrackSelectionArray).prioritizeTimeOverSizeThresholds - Whether the load control prioritizes buffer timepublic DefaultLoadControl(DefaultAllocator allocator, int minBufferMs, int maxBufferMs, int bufferForPlaybackMs, int bufferForPlaybackAfterRebufferMs, int targetBufferBytes, boolean prioritizeTimeOverSizeThresholds, PriorityTaskManager priorityTaskManager)
allocator - The DefaultAllocator used by the loader.minBufferMs - The minimum duration of media that the player will attempt to ensure is
buffered at all times, in milliseconds.maxBufferMs - The maximum duration of media that the player will attempt buffer, in
milliseconds.bufferForPlaybackMs - The duration of media that must be buffered for playback to start or
resume following a user action such as a seek, in milliseconds.bufferForPlaybackAfterRebufferMs - The default duration of media that must be buffered for
playback to resume after a rebuffer, in milliseconds. A rebuffer is defined to be caused by
buffer depletion rather than a user action.targetBufferBytes - The target buffer size in bytes. If set to C.LENGTH_UNSET, the
target buffer size will be calculated using calculateTargetBufferSize(Renderer[],
TrackSelectionArray).prioritizeTimeOverSizeThresholds - Whether the load control prioritizes buffer time
constraints over buffer size constraints.priorityTaskManager - If not null, registers itself as a task with priority C.PRIORITY_PLAYBACK during loading periods, and unregisters itself during drainingpublic void onPrepared()
LoadControlonPrepared in interface LoadControlpublic void onTracksSelected(Renderer[] renderers, TrackGroupArray trackGroups, TrackSelectionArray trackSelections)
LoadControlonTracksSelected in interface LoadControlrenderers - The renderers.trackGroups - The TrackGroups from which the selection was made.trackSelections - The track selections that were made.public void onStopped()
LoadControlonStopped in interface LoadControlpublic void onReleased()
LoadControlonReleased in interface LoadControlpublic Allocator getAllocator()
LoadControlAllocator that should be used to obtain media buffer allocations.getAllocator in interface LoadControlpublic 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 LoadControlpublic boolean retainBackBufferFromKeyframe()
LoadControlLoadControl.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 LoadControlLoadControl.getBackBufferDurationUs(), rather than any sample before or at that position.public boolean shouldContinueLoading(long bufferedDurationUs,
float playbackSpeed)
LoadControlshouldContinueLoading in interface LoadControlbufferedDurationUs - The duration of media that's currently buffered.playbackSpeed - The current playback speed.public boolean shouldStartPlayback(long bufferedDurationUs,
float playbackSpeed,
boolean rebuffering)
LoadControlfalse until some condition has been met (e.g. a certain amount of media is buffered).shouldStartPlayback in interface LoadControlbufferedDurationUs - The duration of media that's currently buffered.playbackSpeed - The current playback speed.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.protected int calculateTargetBufferSize(Renderer[] renderers, TrackSelectionArray trackSelectionArray)
targetBufferBytes is C.LENGTH_UNSET.renderers - The renderers for which the track were selected.trackSelectionArray - The selected tracks.