Function: createThroughputSelector()
function createThroughputSelector(options?): BitrateSelector;Defined in: createThroughputSelector.ts:42
Beta
Creates a rate-based bitrate selector.
The selector divides the throughput by the playback rate to get the effective throughput. It picks the highest rung at or below effectiveThroughput * safetyFactor, or rung 0 when no rung fits. Two rules refine the pick:
- Hysteresis. If the pick is above the current rung, the selector recomputes the pick with
upgradeFactorand returns the higher of the current rung and that pick. - Starvation guard. When the input has a positive
segmentDuration, the first pass keeps the highest rung, at or below the pick, that downloads withinbufferLevel / playbackRate. If no rung passes, the second pass allowsmin(segmentDuration, starvationTolerance)more. Rung 0 passes the second pass in every case.
The current rung is the bandwidth of the last sample that was not aborted, mapped to the highest rung at or below it in the ladder of the call. When the throughput is unknown, the selector returns the current rung, or rung 0 before the first sample. The delay is always 0.
Parameters
options?
The safety factor, the upgrade factor, and the starvation tolerance
Returns
The selector
Example
const selector = createThroughputSelector()
const ladder = [
{ bandwidth: 300_000 },
{ bandwidth: 750_000 },
{ bandwidth: 1_500_000 },
{ bandwidth: 3_000_000 },
{ bandwidth: 6_000_000 },
]
const { index } = selector.select({ ladder, bufferLevel: 4, throughput: 3_000_000, now: 0 })
// The highest rung at or below 0.9 * 3 Mbps is 1.5 Mbps.
equal(index, 2)Throws
RangeError when a factor is not a finite number above 0 and at most 1, when upgradeFactor exceeds safetyFactor, or when starvationTolerance is not a finite number of 0 or more