Skip to content

Commit

Permalink
Simplify Multi-Codec Simulcast usage - enabling by setting backupCode…
Browse files Browse the repository at this point in the history
…c: true
  • Loading branch information
davidzhao committed Nov 3, 2023
1 parent 339a257 commit 8ce619e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions example/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const appActions = {
const autoSubscribe = (<HTMLInputElement>$('auto-subscribe')).checked;
const e2eeEnabled = (<HTMLInputElement>$('e2ee')).checked;

setLogLevel(LogLevel.info);
setLogLevel(LogLevel.debug);
updateSearchParams(url, token, cryptoKey);

const roomOpts: RoomOptions = {
Expand All @@ -103,7 +103,7 @@ const appActions = {
roomOpts.publishDefaults?.videoCodec === 'av1' ||
roomOpts.publishDefaults?.videoCodec === 'vp9'
) {
roomOpts.publishDefaults.backupCodec = { codec: 'vp8', encoding: VideoPresets.h720.encoding };
roomOpts.publishDefaults.backupCodec = true;
}

const connectOpts: RoomConnectOptions = {
Expand Down
4 changes: 4 additions & 0 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,11 @@ export default class LocalParticipant extends Participant {
];

// set up backup
if (opts.backupCodec === true) {
opts.backupCodec = { codec: 'vp8' };
}
if (opts.backupCodec && videoCodec !== opts.backupCodec.codec) {
// multi-codec simulcast requires dynacast
if (!this.roomOptions.dynacast) {
this.roomOptions.dynacast = true;
}
Expand Down
7 changes: 6 additions & 1 deletion src/room/participant/publishUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ export function computeTrackBackupEncodings(
videoCodec: BackupVideoCodec,
opts: TrackPublishOptions,
) {
if (!opts.backupCodec || opts.backupCodec.codec === opts.videoCodec) {
// backupCodec should not be true anymore, default codec is set in LocalParticipant.publish
if (
!opts.backupCodec ||
opts.backupCodec === true ||
opts.backupCodec.codec === opts.videoCodec
) {
// backup codec publishing is disabled
return;
}
Expand Down
10 changes: 8 additions & 2 deletions src/room/track/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ export interface TrackPublishDefaults {
videoEncoding?: VideoEncoding;

/**
* @experimental
* Multi-codec Simulcast
* VP9 and AV1 are not supported by all browser clients. When backupCodec is
* set, when an incompatible client attempts to subscribe to the track, LiveKit
* will automatically publish a secondary track encoded with the backup codec.
*
* You could customize specific encoding parameters of the backup track by
* explicitly setting codec and encoding fields.
*/
backupCodec?: { codec: BackupVideoCodec; encoding: VideoEncoding } | false;
backupCodec?: true | false | { codec: BackupVideoCodec; encoding?: VideoEncoding };

/**
* encoding parameters for screen share track
Expand Down

0 comments on commit 8ce619e

Please sign in to comment.