Skip to content

Commit

Permalink
Make AbrManager less agressive.
Browse files Browse the repository at this point in the history
We used to wait until 8 seconds after the last adaptation began.
Now we wait until 30 seconds after the last adaptation completed.

Change-Id: Ibb673d1a2ca45d403a77a037fa3eeea9698d3e31
  • Loading branch information
joeyparrish committed Apr 7, 2015
1 parent 8f56871 commit 612b320
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
25 changes: 23 additions & 2 deletions lib/media/abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ shaka.media.AbrManager = function(estimator, videoSource) {

this.eventManager_.listen(this.estimator_, 'bandwidth',
this.onBandwidth_.bind(this));
this.eventManager_.listen(this.videoSource_, 'adaptation',
this.onAdaptation_.bind(this));
};


Expand All @@ -84,7 +86,7 @@ shaka.media.AbrManager.FIRST_SWITCH_INTERVAL_ = 4.0;
* @private
* @const {number}
*/
shaka.media.AbrManager.MIN_SWITCH_INTERVAL_ = 8.0;
shaka.media.AbrManager.MIN_SWITCH_INTERVAL_ = 30.0;


/**
Expand Down Expand Up @@ -205,7 +207,26 @@ shaka.media.AbrManager.prototype.onBandwidth_ = function(event) {
this.videoSource_.selectVideoTrack(chosen.id, false);
}

this.nextAdaptationTime_ = now + AbrManager.MIN_SWITCH_INTERVAL_;
// Can't adapt again until we get confirmation of this one.
this.nextAdaptationTime_ = Number.POSITIVE_INFINITY;
};


/**
* Handles adaptation events.
*
* @param {!Event} event
* @private
*/
shaka.media.AbrManager.prototype.onAdaptation_ = function(event) {
// This check allows us to ignore the initial adaptation events, which would
// otherwise cause us not to honor FIRST_SWITCH_INTERVAL_.
if (this.nextAdaptationTime_ == Number.POSITIVE_INFINITY) {
// Adaptation is complete, so schedule the next adaptation.
var now = Date.now() / 1000.0;
this.nextAdaptationTime_ =
now + shaka.media.AbrManager.MIN_SWITCH_INTERVAL_;
}
};


Expand Down
3 changes: 1 addition & 2 deletions lib/media/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,6 @@ shaka.media.Stream.prototype.switch = function(streamInfo, immediate) {

this.sbm_.reset();

this.fireAdaptationEvent_(streamInfo);

// Stop updating and abort |sbm_|'s current operation. This will reject
// |sbm_|'s current promise.
this.cancelUpdateTimer_();
Expand Down Expand Up @@ -405,6 +403,7 @@ shaka.media.Stream.prototype.switch = function(streamInfo, immediate) {
}
}
shaka.timer.end('switch logic');
this.fireAdaptationEvent_(streamInfo);
this.switchStreamOrUpdate_();
})
).catch(shaka.util.TypedBind(this,
Expand Down

0 comments on commit 612b320

Please sign in to comment.