Skip to content

Commit f374173

Browse files
authored
feat(ABR): Add cacheLoadThreshold config (#6657)
Close #6623
1 parent d58914f commit f374173

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

demo/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ shakaDemo.Config = class {
305305
'abr.clearBufferSwitch')
306306
.addNumberInput_('Safe margin on abr switch rendition',
307307
'abr.safeMarginSwitch',
308+
/* canBeDecimal= */ true)
309+
.addNumberInput_('Milliseconds to consider a request cached',
310+
'abr.cacheLoadThreshold',
308311
/* canBeDecimal= */ true);
309312
this.addRetrictionsSection_('abr', 'Adaptation Restrictions');
310313
}

externs/shaka/player.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,8 @@ shaka.extern.AdsConfiguration;
15671567
* restrictToScreenSize: boolean,
15681568
* ignoreDevicePixelRatio: boolean,
15691569
* clearBufferSwitch: boolean,
1570-
* safeMarginSwitch: number
1570+
* safeMarginSwitch: number,
1571+
* cacheLoadThreshold: number
15711572
* }}
15721573
*
15731574
* @property {boolean} enabled
@@ -1625,6 +1626,10 @@ shaka.extern.AdsConfiguration;
16251626
* Can cause hiccups on some browsers if chosen too small, e.g.
16261627
* The amount of two segments is a fair minimum to consider as safeMargin
16271628
* value.
1629+
* @property {number} cacheLoadThreshold
1630+
* Indicates the value in milliseconds from which a request is not
1631+
* considered cached.
1632+
* Defaults to <code>20</code>.
16281633
* @exportDoc
16291634
*/
16301635
shaka.extern.AbrConfiguration;

lib/abr/simple_abr_manager.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ shaka.abr.SimpleAbrManager = class {
308308
* @export
309309
*/
310310
segmentDownloaded(deltaTimeMs, numBytes, allowSwitch, request) {
311+
if (deltaTimeMs < this.config_.cacheLoadThreshold) {
312+
// The time indicates that it could be a cache response, so we should
313+
// ignore this value.
314+
return;
315+
}
311316
shaka.log.v2('Segment downloaded:',
312317
'contentType=' + (request && request.contentType),
313318
'deltaTimeMs=' + deltaTimeMs,

lib/util/player_configuration.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ shaka.util.PlayerConfiguration = class {
333333
ignoreDevicePixelRatio: false,
334334
clearBufferSwitch: false,
335335
safeMarginSwitch: 0,
336+
cacheLoadThreshold: 20,
336337
};
337338

338339
const cmcd = {

0 commit comments

Comments
 (0)