Skip to content

Commit

Permalink
Keep the last bandwidth as an exponential moving average in an attemp…
Browse files Browse the repository at this point in the history
…t to smooth out the actual numbers a bit.
  • Loading branch information
JHartman5 authored and mangui committed Jun 9, 2016
1 parent 82c18aa commit 2391495
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/controller/abr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class AbrController extends EventHandler {
this._nextAutoLevel = -1;
this.hls = hls;
this.onCheck = this.abandonRulesCheck.bind(this);

// This factor weights the last bandwidth measurement as an exponential moving average.
this.exponentialWeighting = 0.8;
}

destroy() {
Expand All @@ -43,7 +46,11 @@ class AbrController extends EventHandler {
// 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;
if (this.lastbw) {
this.lastbw = this.exponentialWeighting * ((stats.loaded * 8) / this.lastfetchduration) + (1 - this.exponentialWeighting) * this.lastbw;
} else {
this.lastbw = (stats.loaded * 8) / this.lastfetchduration;
}
//console.log(`fetchDuration:${this.lastfetchduration},bw:${(this.lastbw/1000).toFixed(0)}/${stats.aborted}`);
}
}
Expand Down

0 comments on commit 2391495

Please sign in to comment.