Skip to content

Commit

Permalink
Don't always clear buffer in configure
Browse files Browse the repository at this point in the history
It appears that we were clearing the buffers when we re-configured the
ABR manager. This was not necessary, so instead we do not clear the
buffers so that any buffered data can be used.

Change-Id: I3b57278fc47eed4d36e91e0e59211f374dfdfc06
Issue: #1009
  • Loading branch information
vaage committed Sep 27, 2017
1 parent 58060f6 commit 65a90f7
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,15 +923,19 @@ shaka.Player.prototype.configure = function(config) {
shaka.util.ConfigUtils.mergeConfigObjects(
this.config_, config, this.defaultConfig_(), this.configOverrides_(), '');

this.applyConfig_();
// We only need to clear buffers is the user is changing a setting that we
// need to see reflected immediately.
var clearBuffer = 'restrictions' in config;
this.applyConfig_(clearBuffer);
};


/**
* Apply config changes.
* @param {boolean} clearBuffer
* @private
*/
shaka.Player.prototype.applyConfig_ = function() {
shaka.Player.prototype.applyConfig_ = function(clearBuffer) {
if (this.parser_) {
this.parser_.configure(this.config_.manifest);
}
Expand All @@ -952,7 +956,7 @@ shaka.Player.prototype.applyConfig_ = function() {
// May need to choose new streams.
shaka.log.debug('Choosing new streams after changing configuration');
var period = this.streamingEngine_.getCurrentPeriod();
this.chooseStreamsAndSwitch_(period);
this.chooseStreamsAndSwitch_(period, clearBuffer);
}

if (this.abrManager_) {
Expand Down Expand Up @@ -1017,7 +1021,9 @@ shaka.Player.prototype.resetConfiguration = function() {
// dictionaries like drm.servers.
this.config_ = this.defaultConfig_();

this.applyConfig_();
// Rather than checking if it makes sense to clear the buffers based on which
// values are getting reset, just clear them.
this.applyConfig_(true);
};


Expand Down Expand Up @@ -1417,7 +1423,7 @@ shaka.Player.prototype.selectAudioLanguage = function(language, opt_role) {
var period = this.streamingEngine_.getCurrentPeriod();
this.currentAudioLanguage_ = language;
this.currentVariantRole_ = opt_role || '';
this.chooseStreamsAndSwitch_(period);
this.chooseStreamsAndSwitch_(period, true);
};


Expand All @@ -1434,7 +1440,7 @@ shaka.Player.prototype.selectTextLanguage = function(language, opt_role) {
var period = this.streamingEngine_.getCurrentPeriod();
this.currentTextLanguage_ = language;
this.currentTextRole_ = opt_role || '';
this.chooseStreamsAndSwitch_(period);
this.chooseStreamsAndSwitch_(period, true);
};


Expand Down Expand Up @@ -1662,7 +1668,7 @@ shaka.Player.prototype.addTextTrack = function(
this.loadingTextStreamIds_.indexOf(stream.id), 1);

shaka.log.debug('Choosing new streams after adding a text stream');
this.chooseStreamsAndSwitch_(period);
this.chooseStreamsAndSwitch_(period, true);
this.onTracksChanged_();

return {
Expand Down Expand Up @@ -2398,9 +2404,10 @@ shaka.Player.prototype.chooseVariant_ = function(variants) {
* explicit language change.
*
* @param {!shakaExtern.Period} period
* @param {!boolean} clearBuffer
* @private
*/
shaka.Player.prototype.chooseStreamsAndSwitch_ = function(period) {
shaka.Player.prototype.chooseStreamsAndSwitch_ = function(period, clearBuffer) {
goog.asserts.assert(this.config_, 'Must not be destroyed');

var variants = shaka.util.StreamUtils.filterVariantsByLanguageAndRole(
Expand All @@ -2414,7 +2421,7 @@ shaka.Player.prototype.chooseStreamsAndSwitch_ = function(period) {
var chosenVariant = this.chooseVariant_(variants);
if (chosenVariant) {
this.addVariantToSwitchHistory_(chosenVariant, /* fromAdaptation */ true);
this.switchVariant_(chosenVariant, /* opt_clearBuffer */ true);
this.switchVariant_(chosenVariant, clearBuffer);
}

var chosenText = textStreams[0];
Expand Down Expand Up @@ -2809,7 +2816,7 @@ shaka.Player.prototype.onKeyStatus_ = function(keyStatusMap) {
period.variants);
if (activeVariant && !activeVariant.allowedByKeySystem) {
shaka.log.debug('Choosing new streams after key status changed');
this.chooseStreamsAndSwitch_(period);
this.chooseStreamsAndSwitch_(period, true);
}

if (tracksChanged)
Expand Down

0 comments on commit 65a90f7

Please sign in to comment.