Skip to content

Commit 57beaf5

Browse files
cnderrauberlukasIO
andauthored
Add BackupCodecPolicy to TrackPublishDefaults (#1399)
Co-authored-by: lukasIO <mail@lukasseiler.de>
1 parent 17aff2b commit 57beaf5

File tree

7 files changed

+46
-8
lines changed

7 files changed

+46
-8
lines changed

.changeset/honest-hornets-fail.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'livekit-client': minor
3+
---
4+
5+
Add backupCodecPolicy to TrackPublishDefaults
6+
7+
The default policy of backup codec is `codec regression` for maxium compatibility, which means the publisher stops sending primary codec and all subscribers will receive backup codec even primary codec is supported.
8+
It changes the default behavior `multi-codec simulcast` in the previous version, will not break the functionality of the previous version but only cause potential extra bandwidth usage. The user can set the policy to `multi-codec simulcast` to keep the previous behavior.
9+

examples/demo/demo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
VideoCodec,
1111
} from '../../src/index';
1212
import {
13+
BackupCodecPolicy,
1314
ConnectionQuality,
1415
ConnectionState,
1516
DisconnectReason,
@@ -98,6 +99,10 @@ const appActions = {
9899
const autoSubscribe = (<HTMLInputElement>$('auto-subscribe')).checked;
99100
const e2eeEnabled = (<HTMLInputElement>$('e2ee')).checked;
100101
const audioOutputId = (<HTMLSelectElement>$('audio-output')).value;
102+
let backupCodecPolicy: BackupCodecPolicy | undefined;
103+
if ((<HTMLInputElement>$('multicodec-simulcast')).checked) {
104+
backupCodecPolicy = BackupCodecPolicy.SIMULCAST;
105+
}
101106

102107
updateSearchParams(url, token, cryptoKey);
103108

@@ -116,6 +121,7 @@ const appActions = {
116121
forceStereo: false,
117122
screenShareEncoding: ScreenSharePresets.h1080fps30.encoding,
118123
scalabilityMode: 'L3T3_KEY',
124+
backupCodecPolicy: backupCodecPolicy,
119125
},
120126
videoCaptureDefaults: {
121127
resolution: VideoPresets.h720.resolution,

examples/demo/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ <h2>Livekit Sample App</h2>
8181
disabled="true"
8282
></select>
8383
</div>
84+
<div>
85+
<input type="checkbox" class="form-check-input" id="multicodec-simulcast" />
86+
<label for="multicodec-simulcast" class="form-check-label">MultiCodec-Simulcast </label>
87+
</div>
8488
</div>
8589

8690
<!-- actions -->

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
},
5656
"dependencies": {
5757
"@livekit/mutex": "1.1.1",
58-
"@livekit/protocol": "1.32.0",
58+
"@livekit/protocol": "1.33.0",
5959
"events": "^3.3.0",
6060
"loglevel": "^1.8.0",
6161
"sdp-transform": "^2.14.1",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/room/participant/LocalParticipant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ export default class LocalParticipant extends Participant {
937937
stereo: isStereo,
938938
disableRed: this.isE2EEEnabled || !(opts.red ?? true),
939939
stream: opts?.stream,
940+
backupCodecPolicy: opts?.backupCodecPolicy,
940941
});
941942

942943
// compute encodings and layers for video

src/room/track/options.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ export interface TrackPublishDefaults {
1212
videoEncoding?: VideoEncoding;
1313

1414
/**
15-
* Multi-codec Simulcast
16-
* VP9 and AV1 are not supported by all browser clients. When backupCodec is
15+
* Advanced codecs (VP9/AV1/H265) are not supported by all browser clients. When backupCodec is
1716
* set, when an incompatible client attempts to subscribe to the track, LiveKit
1817
* will automatically publish a secondary track encoded with the backup codec.
1918
*
@@ -24,6 +23,20 @@ export interface TrackPublishDefaults {
2423
*/
2524
backupCodec?: true | false | { codec: BackupVideoCodec; encoding?: VideoEncoding };
2625

26+
/**
27+
* When backup codec is enabled, there are two options to decide whether to
28+
* send the primary codec at the same time:
29+
* * codec regression: publisher stops sending primary codec and all subscribers
30+
* will receive backup codec even if the primary codec is supported on their browser. It is the default
31+
* behavior and provides maximum compatibility. It also reduces CPU
32+
* and bandwidth consumption for publisher.
33+
* * multi-codec simulcast: publisher encodes and sends both codecs at same time,
34+
* subscribers will get most efficient codec. It will provide most bandwidth
35+
* efficiency, especially in the large 1:N room but requires more device performance
36+
* and bandwidth consumption for publisher.
37+
*/
38+
backupCodecPolicy?: BackupCodecPolicy;
39+
2740
/**
2841
* encoding parameters for screen share track
2942
*/
@@ -375,6 +388,11 @@ export function isBackupCodec(codec: string): codec is BackupVideoCodec {
375388
return !!backupCodecs.find((backup) => backup === codec);
376389
}
377390

391+
export enum BackupCodecPolicy {
392+
REGRESSION = 0,
393+
SIMULCAST = 1,
394+
}
395+
378396
/**
379397
* scalability modes for svc.
380398
*/

0 commit comments

Comments
 (0)