Skip to content

Commit

Permalink
fix(ABR): Not change to another quality without respecting a min time (
Browse files Browse the repository at this point in the history
…#6979)

Fixes #6315

---------

Co-authored-by: Casey Occhialini <[email protected]>
  • Loading branch information
avelad and littlespex committed Jul 4, 2024
1 parent 660b0ae commit eb088a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
6 changes: 5 additions & 1 deletion demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,11 @@ shakaDemo.Config = class {
/* canBeDecimal= */ true)
.addNumberInput_('Milliseconds to consider a request cached',
'abr.cacheLoadThreshold',
/* canBeDecimal= */ true);
/* canBeDecimal= */ true)
.addNumberInput_('Minimum time to switch',
'abr.minTimeToSwitch',
/* canBeDecimal= */ true,
/* canBeZero= */ true);
this.addRetrictionsSection_('abr', 'Adaptation Restrictions');
}

Expand Down
8 changes: 7 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,8 @@ shaka.extern.AdsConfiguration;
* ignoreDevicePixelRatio: boolean,
* clearBufferSwitch: boolean,
* safeMarginSwitch: number,
* cacheLoadThreshold: number
* cacheLoadThreshold: number,
* minTimeToSwitch: number
* }}
*
* @property {boolean} enabled
Expand Down Expand Up @@ -1769,6 +1770,11 @@ shaka.extern.AdsConfiguration;
* Indicates the value in milliseconds from which a request is not
* considered cached.
* Defaults to <code>20</code>.
* @property {number} minTimeToSwitch
* Indicates the minimum time to change quality once the real bandwidth is
* available, in seconds. This time is only used on the first load.
* Defaults to <code>0</code> seconds except in Apple browsers whose default
* value is <code>0.5</code> seconds.
* @exportDoc
*/
shaka.extern.AbrConfiguration;
Expand Down
19 changes: 11 additions & 8 deletions lib/abr/simple_abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,17 @@ shaka.abr.SimpleAbrManager = class {
return;
}
this.startupComplete_ = true;
} else {
// Check if we've left the switch interval.
const now = Date.now();
const delta = now - this.lastTimeChosenMs_;
if (delta < this.config_.switchInterval * 1000) {
shaka.log.v2('Still within switch interval...');
return;
}

this.lastTimeChosenMs_ -=
(this.config_.switchInterval - this.config_.minTimeToSwitch) * 1000;
}

// Check if we've left the switch interval.
const now = Date.now();
const delta = now - this.lastTimeChosenMs_;
if (delta < this.config_.switchInterval * 1000) {
shaka.log.v2('Still within switch interval...');
return;
}

const chosenVariant = this.chooseVariant();
Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ shaka.util.PlayerConfiguration = class {
clearBufferSwitch: false,
safeMarginSwitch: 0,
cacheLoadThreshold: 20,
minTimeToSwitch: shaka.util.Platform.isApple() ? 0.5 : 0,
};

const cmcd = {
Expand Down
1 change: 1 addition & 0 deletions test/abr/simple_abr_manager_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('SimpleAbrManager', () => {
config = shaka.util.PlayerConfiguration.createDefault().abr;
config.defaultBandwidthEstimate = defaultBandwidthEstimate;
config.useNetworkInformation = false;
config.minTimeToSwitch = 0;

variants = manifest.variants;

Expand Down

0 comments on commit eb088a4

Please sign in to comment.