Skip to content

Commit ff77b1f

Browse files
committed
Add BackupCodecPolicy to TrackPublishDefaults
When using advance codecs and backup codec enabled, the client can use REGRESSION or SIMULCAST codec policy to choose subscriber bandwidth efficiency or publisher device/bandwidth efficiency.
1 parent 4be40ba commit ff77b1f

File tree

7 files changed

+48
-12
lines changed

7 files changed

+48
-12
lines changed

.changeset/honest-hornets-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'livekit-client': patch
3+
---
4+
5+
Add backupCodecPolicy to TrackPublishDefaults

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: 9 additions & 9 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
@@ -936,6 +936,7 @@ export default class LocalParticipant extends Participant {
936936
stereo: isStereo,
937937
disableRed: this.isE2EEEnabled || !(opts.red ?? true),
938938
stream: opts?.stream,
939+
backupCodecPolicy: opts?.backupCodecPolicy,
939940
});
940941

941942
// compute encodings and layers for video

src/room/track/options.ts

Lines changed: 22 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+
* Advance 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,22 @@ 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 primary codec is supported. It is the default
31+
* behavior and provides maximum compatibility and reduced device performance
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+
* Defaults to `false`
39+
*/
40+
backupCodecPolicy?: BackupCodecPolicy;
41+
2742
/**
2843
* encoding parameters for screen share track
2944
*/
@@ -375,6 +390,11 @@ export function isBackupCodec(codec: string): codec is BackupVideoCodec {
375390
return !!backupCodecs.find((backup) => backup === codec);
376391
}
377392

393+
export enum BackupCodecPolicy {
394+
REGRESSION = 0,
395+
SIMULCAST = 1,
396+
}
397+
378398
/**
379399
* scalability modes for svc.
380400
*/

0 commit comments

Comments
 (0)