Class: shaka.media.BufferingObserver

Constructor

new BufferingObserver(thresholdWhenStarving, initialState, getSecondsBufferedAfter, isBufferedToEnd)

Parameters:
Name Type Description
thresholdWhenStarving number The threshold for how many seconds worth of content must be buffered ahead of the playhead position to leave a STARVING state.
initialState shaka.media.BufferingObserver.State The state that the observer starts in. We allow this so that it is easier to test, rather than having to "force" the observer into a particular state through simulation in the test.
getSecondsBufferedAfter function Get the number of seconds after the given time (in seconds) that have buffered.
isBufferedToEnd function When we call |poll|, we need to know if we are buffered to the end of the presentation. This method should return |true| when we have buffered to the end of the current presentation. In terms of live content, this will return |true| when we are buffered to the live edge.
Implements:
Source:

Members

(static) State :number

Rather than using booleans to communicate what state we are in, we have this enum.
Type:
  • number
Properties:
Name Value Type Description
STARVING 0 number
SATISFIED 1 number
Source:

(private) getSecondsBufferedAfter_ :function(number):number

A callback to get the number of seconds of buffered content that comes after the given presentation time (in seconds).
Type:
  • function(number):number
Source:

(private) isBufferedToEnd_ :function():boolean

When we call |poll|, we need to know if we are buffered to the end of the presentation. This method should return |true| when we have buffered to the end of the current presentation. In terms of live content, this will return |true| when we are buffered to the live edge. Checking if we are buffered to the end of the presentation relies on a number of factors. Which factors can even depend on what it loaded. To avoid having all those factors here, we use an external callback so that this implementation can be move flexible and easier to test.
Type:
  • function():boolean
Source:

(private) previousState_ :shaka.media.BufferingObserver.State

The state (SATISFIED vs STARVING) at last check. This value will always be "old", and we will compare it to what we evaluate in the "present" to see when the state has changed.
Type:
Source:

(private, non-null) rules_ :Array.<shaka.media.BufferingObserver.Rule_>

A series of rules that we will use to determine what callback to use when the playhead moves.
Type:
Source:

(private) thresholdWhenSatisfied_ :number

The minimum amount of content that must be buffered ahead of the playhead to avoid a transition from SATISFIED to STARVING, i.e. to remain in SATISFIED. This will be used when we the previous state is SATISFIED. Combined with |thresholdWhenStarving_|, this adds hysteresis to the state machine to avoid frequent switches around a single threshold. https://bit.ly/2QLQNtG
Type:
  • number
Source:

(private) thresholdWhenStarving_ :number

The minimum amount of content that must be buffered ahead of the playhead to transition from STARVING to SATISFIED. This will be used when the previous state is STARVING. Combined with |thresholdWhenSatisfied_|, this adds hysteresis to the state machine to avoid frequent switches around a single threshold. https://bit.ly/2QLQNtG
Type:
  • number
Source:

Methods

(private) onSatisfied_()

Source:

(private) onStarving_()

Source:

poll(positionInSeconds, wasSeeking)

Check again (using an update playhead summary) if an event should be fired. If an event should be fired, fire it.
Parameters:
Name Type Description
positionInSeconds number
wasSeeking boolean
Implements:
Source:

(export) release()

Request that this object release all internal references.
Inherited From:
Implements:
Source:

setListeners(onStarving, onSatisfied)

Set the listeners. This will override any previous calls to |setListeners|.
Parameters:
Name Type Description
onStarving function() The callback for when we change from "satisfied" to "starving".
onSatisfied function() The callback for when we change from "starving" to "satisfied".
Source:

Type Definitions