Skip to content

Commit

Permalink
feat: Set segmentPrefetchLimit to 2 by default for low latency stream…
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jun 12, 2023
1 parent fea46d8 commit 62f24d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
12 changes: 7 additions & 5 deletions docs/tutorials/config.md
Expand Up @@ -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,
}
});

Expand Down
8 changes: 6 additions & 2 deletions lib/player.js
Expand Up @@ -3205,15 +3205,19 @@ 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;
}
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_());
Expand Down
2 changes: 2 additions & 0 deletions lib/util/player_configuration.js
Expand Up @@ -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,
};

Expand Down
8 changes: 6 additions & 2 deletions test/player_unit.js
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 62f24d2

Please sign in to comment.