From 62f24d22491353bf3a37f451c74a26b77f892197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Mon, 12 Jun 2023 18:13:30 +0200 Subject: [PATCH] feat: Set segmentPrefetchLimit to 2 by default for low latency streaming (#5275) --- docs/tutorials/config.md | 12 +++++++----- lib/player.js | 8 ++++++-- lib/util/player_configuration.js | 2 ++ test/player_unit.js | 8 ++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/docs/tutorials/config.md b/docs/tutorials/config.md index b147be4cc1..3d94cc5392 100644 --- a/docs/tutorials/config.md +++ b/docs/tutorials/config.md @@ -122,18 +122,20 @@ buffering settings) while some will not have any effect until the next call to #### Low latency streaming With `.streaming.lowLatencyMode` set to true, -`.streaming.inaccurateManifestTolerance` is set to 0 by default, and -`.streaming.rebufferingGoal` is set to 0.01 by default. +`.streaming.inaccurateManifestTolerance` is set to 0 by default, +`.streaming.rebufferingGoal` is set to 0.01 by default, and +`.streaming.segmentPrefetchLimit` is set to 2 by default. -To customize the values of inaccurateManifestTolerance and rebufferingGoal -with low latency mode, you can set the fields in the same or subsequent -call to configure(). +To customize the values of inaccurateManifestTolerance, rebufferingGoal and +segmentPrefetchLimit with low latency mode, you can set the fields in the same +or subsequent call to configure(). ```js player.configure({ streaming: { lowLatencyMode: true, inaccurateManifestTolerance: 0, rebufferingGoal: 0.01, + segmentPrefetchLimit: 2, } }); diff --git a/lib/player.js b/lib/player.js index d704cd5eb9..67adda8146 100644 --- a/lib/player.js +++ b/lib/player.js @@ -3205,8 +3205,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget { } // If lowLatencyMode is enabled, and inaccurateManifestTolerance and - // rebufferingGoal are not specified, set inaccurateManifestTolerance to 0 - // and rebufferingGoal to 0.01 by default for low latency streaming. + // rebufferingGoal and segmentPrefetchLimit are not specified, set + // inaccurateManifestTolerance to 0 and rebufferingGoal to 0.01 and + // segmentPrefetchLimit to 2 by default for low latency streaming. if (config['streaming'] && config['streaming']['lowLatencyMode']) { if (config['streaming']['inaccurateManifestTolerance'] == undefined) { config['streaming']['inaccurateManifestTolerance'] = 0; @@ -3214,6 +3215,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget { if (config['streaming']['rebufferingGoal'] == undefined) { config['streaming']['rebufferingGoal'] = 0.01; } + if (config['streaming']['segmentPrefetchLimit'] == undefined) { + config['streaming']['segmentPrefetchLimit'] = 2; + } } const ret = shaka.util.PlayerConfiguration.mergeConfigObjects( this.config_, config, this.defaultConfig_()); diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index af23f1d24b..71b1105cc3 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -206,6 +206,8 @@ shaka.util.PlayerConfiguration = class { observeQualityChanges: false, maxDisabledTime: 30, parsePrftBox: false, + // When low latency streaming is enabled, segmentPrefetchLimit will + // default to 2 if not specified. segmentPrefetchLimit: 0, }; diff --git a/test/player_unit.js b/test/player_unit.js index c7f7dea61b..54c892aff9 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -1291,19 +1291,23 @@ describe('Player', () => { lowLatencyMode: true, rebufferingGoal: 1, inaccurateManifestTolerance: 1, + segmentPrefetchLimit: 1, }, }); expect(player.getConfiguration().streaming.rebufferingGoal).toBe(1); expect(player.getConfiguration().streaming.inaccurateManifestTolerance) .toBe(1); + expect(player.getConfiguration().streaming.segmentPrefetchLimit).toBe(1); // When low latency streaming gets enabled, rebufferingGoal will default - // to 0.01 if unless specified, and inaccurateManifestTolerance will - // default to 0 unless specified. + // to 0.01 if unless specified, inaccurateManifestTolerance will + // default to 0 unless specified, and segmentPrefetchLimit will + // default to 2 unless specified. player.configure('streaming.lowLatencyMode', true); expect(player.getConfiguration().streaming.rebufferingGoal).toBe(0.01); expect(player.getConfiguration().streaming.inaccurateManifestTolerance) .toBe(0); + expect(player.getConfiguration().streaming.segmentPrefetchLimit).toBe(2); }); });