Skip to content

Commit

Permalink
fix: don't decay average bandwidth value if system bandwidth did not …
Browse files Browse the repository at this point in the history
…change (#1137)
  • Loading branch information
KVPasupuleti authored and gkatsev committed Jun 22, 2021
1 parent 98d8368 commit d26abb1
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
Expand Up @@ -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.');
Expand All @@ -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,
Expand Down

0 comments on commit d26abb1

Please sign in to comment.