From da7e6eeb190ace108edf7dd988297b4abdcedfde Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 15 Mar 2024 01:11:30 -0700 Subject: [PATCH] a couple of fixups --- src/room/PCTransport.ts | 34 ++++++++++++++++++++++++ src/room/participant/LocalParticipant.ts | 7 ++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/room/PCTransport.ts b/src/room/PCTransport.ts index 52748b5b4..ca92ba325 100644 --- a/src/room/PCTransport.ts +++ b/src/room/PCTransport.ts @@ -267,6 +267,40 @@ export default class PCTransport extends EventEmitter { ensureAudioNackAndStereo(media, [], []); } else if (media.type === 'video') { ensureVideoDDExtensionForSVC(media); + // mung sdp for codec bitrate setting that can't apply by sendEncoding + this.trackBitrates.some((trackbr): boolean => { + if (!media.msid || !trackbr.cid || !media.msid.includes(trackbr.cid)) { + return false; + } + + let codecPayload = 0; + media.rtp.some((rtp): boolean => { + if (rtp.codec.toUpperCase() === trackbr.codec.toUpperCase()) { + codecPayload = rtp.payload; + return true; + } + return false; + }); + + if (codecPayload === 0) { + return true; + } + + const startBitrate = Math.round(trackbr.maxbr * startBitrateForSVC); + + for (const fmtp of media.fmtp) { + if (fmtp.payload === codecPayload) { + // if another track's fmtp already is set, we cannot override the bitrate + // this has the unfortunate consequence of being forced to use the + // initial track's bitrate for all tracks + if (!fmtp.config.includes('x-google-start-bitrate')) { + fmtp.config += `;x-google-start-bitrate=${startBitrate}`; + } + break; + } + } + return true; + }); } }); diff --git a/src/room/participant/LocalParticipant.ts b/src/room/participant/LocalParticipant.ts index 6f7c224df..f3dc9adb2 100644 --- a/src/room/participant/LocalParticipant.ts +++ b/src/room/participant/LocalParticipant.ts @@ -732,7 +732,7 @@ export default class LocalParticipant extends Participant { // for svc codecs, disable simulcast and use vp8 for backup codec if (track instanceof LocalVideoTrack) { if (isSVCCodec(videoCodec)) { - if (track.source === Track.Source.ScreenShare && videoCodec === 'vp9') { + if (track.source === Track.Source.ScreenShare) { // vp9 svc with screenshare cannot encode multiple spatial layers // doing so reduces publish resolution to minimal resolution opts.scalabilityMode = 'L1T3'; @@ -743,7 +743,7 @@ export default class LocalParticipant extends Participant { // that we need if ('contentHint' in track.mediaStreamTrack) { track.mediaStreamTrack.contentHint = 'motion'; - this.log.info('forcing contentHint to motion for screenshare with VP9', { + this.log.info('forcing contentHint to motion for screenshare with SVC codecs', { ...this.logContext, ...getLogContextFromTrack(track), }); @@ -881,7 +881,8 @@ export default class LocalParticipant extends Participant { maxbr: encodings[0]?.maxBitrate ? encodings[0].maxBitrate / 1000 : 0, }); } - } else if (track.codec && isSVCCodec(track.codec) && encodings[0]?.maxBitrate) { + } else if (track.codec && track.codec == 'av1' && encodings[0]?.maxBitrate) { + // AV1 requires setting x-start-bitrate in SDP this.engine.pcManager.publisher.setTrackCodecBitrate({ cid: req.cid, codec: track.codec,