diff --git a/demo/config.js b/demo/config.js index f91dd857db..50a9a4d3dc 100644 --- a/demo/config.js +++ b/demo/config.js @@ -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'); } diff --git a/externs/shaka/player.js b/externs/shaka/player.js index 00d2cbdf09..c4a12c0ca7 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -1567,7 +1567,8 @@ shaka.extern.AdsConfiguration; * restrictToScreenSize: boolean, * ignoreDevicePixelRatio: boolean, * clearBufferSwitch: boolean, - * safeMarginSwitch: number + * safeMarginSwitch: number, + * cacheLoadThreshold: number * }} * * @property {boolean} enabled @@ -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 20. * @exportDoc */ shaka.extern.AbrConfiguration; diff --git a/lib/abr/simple_abr_manager.js b/lib/abr/simple_abr_manager.js index 23640ee41d..40e10da0c6 100644 --- a/lib/abr/simple_abr_manager.js +++ b/lib/abr/simple_abr_manager.js @@ -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, diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index 6b209fa624..069ea96e29 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -333,6 +333,7 @@ shaka.util.PlayerConfiguration = class { ignoreDevicePixelRatio: false, clearBufferSwitch: false, safeMarginSwitch: 0, + cacheLoadThreshold: 20, }; const cmcd = {