Skip to content

Commit

Permalink
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/playlist-selectors.js
Original file line number Diff line number Diff line change
@@ -364,6 +364,7 @@ export const lastBandwidthSelector = function() {
*/
export const movingAverageBandwidthSelector = function(decay) {
let average = -1;
let lastSystemBandwidth = -1;

if (decay < 0 || decay > 1) {
throw new Error('Moving average bandwidth decay must be between 0 and 1.');
@@ -374,9 +375,20 @@ export const movingAverageBandwidthSelector = function(decay) {

if (average < 0) {
average = this.systemBandwidth;
lastSystemBandwidth = this.systemBandwidth;
}

// stop the average value from decaying for every 250ms
// when the systemBandwidth is constant
// and
// stop average from setting to a very low value when the
// systemBandwidth becomes 0 in case of chunk cancellation

if (this.systemBandwidth > 0 && this.systemBandwidth !== lastSystemBandwidth) {
average = decay * this.systemBandwidth + (1 - decay) * average;
lastSystemBandwidth = this.systemBandwidth;
}

average = decay * this.systemBandwidth + (1 - decay) * average;
return simpleSelector(
this.playlists.master,
average,

0 comments on commit c22749b

Please sign in to comment.