Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ewma sampling from failing on 0 duration segments. #583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/abr/ewma.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ 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_;
this.totalWeight_ += weight;
var newEstimate = value * (1 - adjAlpha) + adjAlpha * this.estimate_;

if (!isNaN(newEstimate)) {
this.estimate_ = newEstimate;
this.totalWeight_ += weight;
}
};


Expand Down
23 changes: 23 additions & 0 deletions test/abr/simple_abr_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,29 @@ describe('SimpleAbrManager', function() {
});
});

it('can handle 0 duration segments', function() {
var audioBandwidth = 5e5;
var videoBandwidth = 2e6;
var bytesPerSecond =
sufficientBWMultiplier * (audioBandwidth + videoBandwidth) / 8.0;

abrManager.chooseStreams(streamSetsByType);

// 0 duration segment shouldn't cause us to get stuck on the lowest variant
abrManager.segmentDownloaded(1000, 1000, bytesPerSecond);
abrManager.segmentDownloaded(2000, 3000, bytesPerSecond);

abrManager.enable();

abrManager.segmentDownloaded(4000, 5000, bytesPerSecond);

expect(switchCallback).toHaveBeenCalled();
expect(switchCallback.calls.argsFor(0)[0]).toEqual({
'audio': jasmine.objectContaining({bandwidth: audioBandwidth}),
'video': jasmine.objectContaining({bandwidth: videoBandwidth})
});
});

it('picks lowest audio Stream when there is insufficient bandwidth',
function() {
// The lowest audio track will only be chosen if needed to fit the
Expand Down