Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add liveSyncOnStallIncrease config option #6455

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api-extractor/report/hls.js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,7 @@ export type LatencyControllerConfig = {
liveSyncDuration?: number;
liveMaxLatencyDuration?: number;
maxLiveSyncPlaybackRate: number;
liveSyncOnStallIncrease: number;
};

// Warning: (ae-missing-release-tag) "Level" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down
13 changes: 13 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ See [API Reference](https://hlsjs-dev.video-dev.org/api-docs/) for a complete li
- [`maxFragLookUpTolerance`](#maxfraglookuptolerance)
- [`maxMaxBufferLength`](#maxmaxbufferlength)
- [`liveSyncDurationCount`](#livesyncdurationcount)
- [`liveSyncOnStallIncrease`](#livesynconstallincrease)
- [`liveMaxLatencyDurationCount`](#livemaxlatencydurationcount)
- [`liveSyncDuration`](#livesyncduration)
- [`liveMaxLatencyDuration`](#livemaxlatencyduration)
Expand Down Expand Up @@ -392,6 +393,7 @@ var config = {
nudgeMaxRetry: 3,
maxFragLookUpTolerance: 0.25,
liveSyncDurationCount: 3,
liveSyncOnStallIncrease: 1,
liveMaxLatencyDurationCount: Infinity,
liveDurationInfinity: false,
preferManagedMediaSource: false,
Expand Down Expand Up @@ -662,6 +664,17 @@ edge of live delay, expressed in multiple of `EXT-X-TARGETDURATION`.
if set to 3, playback will start from fragment N-3, N being the last fragment of the live playlist.
decreasing this value is likely to cause playback stalls.

### `liveSyncOnStallIncrease`

(default: `1`)

increment to the calculated `hls.targetLatency` on each playback stall, expressed in seconds.
When `liveSyncDuration` is specified in config,
`hls.targetLatency` is calculated as `liveSyncDuration` plus `liveSyncOnStallIncrease` multiplied by number of stalls.
Otherwise `hls.targetLatency` is calculated as `liveSyncDurationCount` multiplied by `EXT-X-TARGETDURATION`
plus `liveSyncOnStallIncrease` multiplied by number of stalls.
Decreasing this value will mean that each stall will have less affect on `hls.targetLatency`.

### `liveMaxLatencyDurationCount`

(default: `Infinity`)
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export type LatencyControllerConfig = {
liveSyncDuration?: number;
liveMaxLatencyDuration?: number;
maxLiveSyncPlaybackRate: number;
liveSyncOnStallIncrease: number;
};

export type MetadataControllerConfig = {
Expand Down Expand Up @@ -352,6 +353,7 @@ export const hlsDefaultConfig: HlsConfig = {
nudgeMaxRetry: 3, // used by stream-controller
maxFragLookUpTolerance: 0.25, // used by stream-controller
liveSyncDurationCount: 3, // used by latency-controller
liveSyncOnStallIncrease: 1, // used by latency-controller
liveMaxLatencyDurationCount: Infinity, // used by latency-controller
liveSyncDuration: undefined, // used by latency-controller
liveMaxLatencyDuration: undefined, // used by latency-controller
Expand Down
3 changes: 1 addition & 2 deletions src/controller/latency-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ export default class LatencyController implements ComponentAPI {
: liveSyncDurationCount * targetduration;
}
const maxLiveSyncOnStallIncrease = targetduration;
const liveSyncOnStallIncrease = 1.0;
return (
targetLatency +
Math.min(
this.stallCount * liveSyncOnStallIncrease,
this.stallCount * this.config.liveSyncOnStallIncrease,
maxLiveSyncOnStallIncrease,
)
);
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/controller/latency-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ describe('LatencyController', function () {
latencyController['stallCount'] += 1;
expect(latencyController.targetLatency).to.equal(6.5);
});

it('liveSyncOnStallIncrease can control how fast targetduration increases on stall', function () {
latencyController['config'].lowLatencyMode = true;
latencyController['config'].liveSyncOnStallIncrease = 1.3;
levelDetails.targetduration = 3.5;
levelDetails.partHoldBack = 3;
levelDetails.age = 0;
expect(latencyController.targetLatency).to.equal(3);
latencyController['stallCount'] = 1;
expect(latencyController.targetLatency).to.equal(4.3);
latencyController['stallCount'] += 1;
expect(latencyController.targetLatency).to.equal(5.6);
latencyController['stallCount'] += 1;
expect(latencyController.targetLatency).to.equal(6.5);
});
});

describe('liveSyncPosition', function () {
Expand Down
Loading