mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
update components
This commit is contained in:
parent
1bd4890f44
commit
e453a5b9f7
18 changed files with 387 additions and 128 deletions
|
@ -9,18 +9,19 @@ import EventHandler from '../event-handler';
|
|||
import BufferHelper from '../helper/buffer-helper';
|
||||
import {ErrorDetails} from '../errors';
|
||||
import {logger} from '../utils/logger';
|
||||
import EwmaBandWidthEstimator from './ewma-bandwidth-estimator';
|
||||
|
||||
class AbrController extends EventHandler {
|
||||
|
||||
constructor(hls) {
|
||||
super(hls, Event.FRAG_LOADING,
|
||||
Event.FRAG_LOAD_PROGRESS,
|
||||
Event.FRAG_LOADED,
|
||||
Event.ERROR);
|
||||
this.lastLoadedFragLevel = 0;
|
||||
this._autoLevelCapping = -1;
|
||||
this._nextAutoLevel = -1;
|
||||
this.hls = hls;
|
||||
this.bwEstimator = new EwmaBandWidthEstimator(hls);
|
||||
this.onCheck = this.abandonRulesCheck.bind(this);
|
||||
}
|
||||
|
||||
|
@ -36,18 +37,6 @@ class AbrController extends EventHandler {
|
|||
this.fragCurrent = data.frag;
|
||||
}
|
||||
|
||||
onFragLoadProgress(data) {
|
||||
var stats = data.stats;
|
||||
// only update stats if first frag loading
|
||||
// if same frag is loaded multiple times, it might be in browser cache, and loaded quickly
|
||||
// and leading to wrong bw estimation
|
||||
if (stats.aborted === undefined && data.frag.loadCounter === 1) {
|
||||
this.lastfetchduration = (performance.now() - stats.trequest) / 1000;
|
||||
this.lastbw = (stats.loaded * 8) / this.lastfetchduration;
|
||||
//console.log(`fetchDuration:${this.lastfetchduration},bw:${(this.lastbw/1000).toFixed(0)}/${stats.aborted}`);
|
||||
}
|
||||
}
|
||||
|
||||
abandonRulesCheck() {
|
||||
/*
|
||||
monitor fragment retrieval time...
|
||||
|
@ -100,6 +89,8 @@ class AbrController extends EventHandler {
|
|||
nextLoadLevel = Math.max(0,nextLoadLevel);
|
||||
// force next load level in auto mode
|
||||
hls.nextLoadLevel = nextLoadLevel;
|
||||
// update bw estimate for this fragment before cancelling load (this will help reducing the bw)
|
||||
this.bwEstimator.sample(requestDelay,frag.loaded);
|
||||
// abort fragment loading ...
|
||||
logger.warn(`loading too slow, abort fragment loading and switch to level ${nextLoadLevel}`);
|
||||
//abort fragment loading
|
||||
|
@ -113,6 +104,14 @@ class AbrController extends EventHandler {
|
|||
}
|
||||
|
||||
onFragLoaded(data) {
|
||||
var stats = data.stats;
|
||||
// only update stats on first frag loading
|
||||
// if same frag is loaded multiple times, it might be in browser cache, and loaded quickly
|
||||
// and leading to wrong bw estimation
|
||||
if (stats.aborted === undefined && data.frag.loadCounter === 1) {
|
||||
this.bwEstimator.sample(performance.now() - stats.trequest,stats.loaded);
|
||||
}
|
||||
|
||||
// stop monitoring bw once frag loaded
|
||||
this.clearTimer();
|
||||
// store level id after successful fragment load
|
||||
|
@ -151,9 +150,9 @@ class AbrController extends EventHandler {
|
|||
}
|
||||
|
||||
get nextAutoLevel() {
|
||||
var lastbw = this.lastbw, hls = this.hls,adjustedbw, i, maxAutoLevel;
|
||||
if (this._autoLevelCapping === -1 && hls.levels && hls.levels.length) {
|
||||
maxAutoLevel = hls.levels.length - 1;
|
||||
var hls = this.hls, i, maxAutoLevel, levels = hls.levels, config = hls.config;
|
||||
if (this._autoLevelCapping === -1 && levels && levels.length) {
|
||||
maxAutoLevel = levels.length - 1;
|
||||
} else {
|
||||
maxAutoLevel = this._autoLevelCapping;
|
||||
}
|
||||
|
@ -163,6 +162,7 @@ class AbrController extends EventHandler {
|
|||
return Math.min(this._nextAutoLevel,maxAutoLevel);
|
||||
}
|
||||
|
||||
let avgbw = this.bwEstimator.getEstimate(),adjustedbw;
|
||||
// follow algorithm captured from stagefright :
|
||||
// https://android.googlesource.com/platform/frameworks/av/+/master/media/libstagefright/httplive/LiveSession.cpp
|
||||
// Pick the highest bandwidth stream below or equal to estimated bandwidth.
|
||||
|
@ -171,11 +171,11 @@ class AbrController extends EventHandler {
|
|||
// be even more conservative (70%) to avoid overestimating and immediately
|
||||
// switching back.
|
||||
if (i <= this.lastLoadedFragLevel) {
|
||||
adjustedbw = 0.8 * lastbw;
|
||||
adjustedbw = config.abrBandWidthFactor * avgbw;
|
||||
} else {
|
||||
adjustedbw = 0.7 * lastbw;
|
||||
adjustedbw = config.abrBandWidthUpFactor * avgbw;
|
||||
}
|
||||
if (adjustedbw < hls.levels[i].bitrate) {
|
||||
if (adjustedbw < levels[i].bitrate) {
|
||||
return Math.max(0, i - 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue