Skip to content

Commit

Permalink
Avoid ewma sampling from failing on 0 duration segments.
Browse files Browse the repository at this point in the history
Fixes #582
  • Loading branch information
Sanborn Hilland committed Nov 10, 2016
1 parent f7fd3c9 commit 3a64b0d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/abr/ewma.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ shaka.abr.Ewma = function(halfLife) {
*/
shaka.abr.Ewma.prototype.sample = function(weight, value) {
var adjAlpha = Math.pow(this.alpha_, weight);
this.estimate_ = value * (1 - adjAlpha) + adjAlpha * this.estimate_;
var newEstimate = value * (1 - adjAlpha) + adjAlpha * this.estimate_;
// In rare circumstances newEstimate may come out to NaN. In these
// cases ignore it so that subsequent sampling doesn't fail.
this.estimate_ = newEstimate || this.estimate_;
this.totalWeight_ += weight;
};

Expand Down

0 comments on commit 3a64b0d

Please sign in to comment.