diff --git a/src/playlist-selectors.js b/src/playlist-selectors.js index 93c993115..2dabc0815 100644 --- a/src/playlist-selectors.js +++ b/src/playlist-selectors.js @@ -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,