Skip to content

Commit

Permalink
feat(ABR): Add cacheLoadThreshold config (shaka-project#6657)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed May 23, 2024
1 parent d58914f commit f374173
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ shakaDemo.Config = class {
'abr.clearBufferSwitch')
.addNumberInput_('Safe margin on abr switch rendition',
'abr.safeMarginSwitch',
/* canBeDecimal= */ true)
.addNumberInput_('Milliseconds to consider a request cached',
'abr.cacheLoadThreshold',
/* canBeDecimal= */ true);
this.addRetrictionsSection_('abr', 'Adaptation Restrictions');
}
Expand Down
7 changes: 6 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,8 @@ shaka.extern.AdsConfiguration;
* restrictToScreenSize: boolean,
* ignoreDevicePixelRatio: boolean,
* clearBufferSwitch: boolean,
* safeMarginSwitch: number
* safeMarginSwitch: number,
* cacheLoadThreshold: number
* }}
*
* @property {boolean} enabled
Expand Down Expand Up @@ -1625,6 +1626,10 @@ shaka.extern.AdsConfiguration;
* Can cause hiccups on some browsers if chosen too small, e.g.
* The amount of two segments is a fair minimum to consider as safeMargin
* value.
* @property {number} cacheLoadThreshold
* Indicates the value in milliseconds from which a request is not
* considered cached.
* Defaults to <code>20</code>.
* @exportDoc
*/
shaka.extern.AbrConfiguration;
Expand Down
5 changes: 5 additions & 0 deletions lib/abr/simple_abr_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ shaka.abr.SimpleAbrManager = class {
* @export
*/
segmentDownloaded(deltaTimeMs, numBytes, allowSwitch, request) {
if (deltaTimeMs < this.config_.cacheLoadThreshold) {
// The time indicates that it could be a cache response, so we should
// ignore this value.
return;
}
shaka.log.v2('Segment downloaded:',
'contentType=' + (request && request.contentType),
'deltaTimeMs=' + deltaTimeMs,
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 @@ -333,6 +333,7 @@ shaka.util.PlayerConfiguration = class {
ignoreDevicePixelRatio: false,
clearBufferSwitch: false,
safeMarginSwitch: 0,
cacheLoadThreshold: 20,
};

const cmcd = {
Expand Down

0 comments on commit f374173

Please sign in to comment.