Skip to content

Commit

Permalink
Ensure DD ext for svc codecs (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnderrauber authored May 13, 2024
1 parent c38d133 commit 55afc67
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-coats-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'livekit-client': patch
---

Ensure DD ext for svc codecs
17 changes: 10 additions & 7 deletions src/room/PCTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ export default class PCTransport extends EventEmitter {
if (media.type === 'audio') {
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;
Expand All @@ -286,6 +284,16 @@ export default class PCTransport extends EventEmitter {
return true;
}

if (isSVCCodec(trackbr.codec)) {
ensureVideoDDExtensionForSVC(media);
}

// TODO: av1 slow starting issue already fixed in chrome 124, clean this after some versions
// mung sdp for av1 bitrate setting that can't apply by sendEncoding
if (trackbr.codec !== 'av1') {
return true;
}

const startBitrate = Math.round(trackbr.maxbr * startBitrateForSVC);

for (const fmtp of media.fmtp) {
Expand Down Expand Up @@ -552,11 +560,6 @@ function ensureVideoDDExtensionForSVC(
payloads?: string | undefined;
} & MediaDescription,
) {
const codec = media.rtp[0]?.codec?.toLowerCase();
if (!isSVCCodec(codec)) {
return;
}

let maxID = 0;
const ddFound = media.ext?.some((ext): boolean => {
if (ext.uri === ddExtensionURI) {
Expand Down
3 changes: 1 addition & 2 deletions src/room/participant/LocalParticipant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,7 @@ export default class LocalParticipant extends Participant {
maxbr: encodings[0]?.maxBitrate ? encodings[0].maxBitrate / 1000 : 0,
});
}
} else if (track.codec && track.codec == 'av1' && encodings[0]?.maxBitrate) {
// AV1 requires setting x-start-bitrate in SDP
} else if (track.codec && isSVCCodec(track.codec) && encodings[0]?.maxBitrate) {
this.engine.pcManager.publisher.setTrackCodecBitrate({
cid: req.cid,
codec: track.codec,
Expand Down
5 changes: 5 additions & 0 deletions src/room/participant/publishUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export function computeVideoEncodings(
});
}

if (original.encoding.priority) {
encodings[0].priority = original.encoding.priority;
encodings[0].networkPriority = original.encoding.priority;
}

log.debug(`using svc encoding`, { encodings });
return encodings;
}
Expand Down

0 comments on commit 55afc67

Please sign in to comment.