Skip to content

Commit

Permalink
a couple of fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzhao committed Mar 15, 2024
1 parent 7a3d2bd commit da7e6ee
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/room/PCTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
});

Expand Down
7 changes: 4 additions & 3 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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),
});
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit da7e6ee

Please sign in to comment.