Skip to content

Commit

Permalink
Keep dd extension id in the session
Browse files Browse the repository at this point in the history
Safari could generate different rtp extensions
for video tracks(camera and screenshare), need
to use same extension id for dependency descriptor
in the offer.
  • Loading branch information
cnderrauber committed Oct 24, 2024
1 parent 42ecb8b commit e7f81ae
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions src/room/PCTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export default class PCTransport extends EventEmitter {

private loggerOptions: LoggerOptions;

private ddExtID = 0;

pendingCandidates: RTCIceCandidateInit[] = [];

restartingIce: boolean = false;
Expand Down Expand Up @@ -288,7 +290,7 @@ export default class PCTransport extends EventEmitter {
}

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

// TODO: av1 slow starting issue already fixed in chrome 124, clean this after some versions
Expand Down Expand Up @@ -503,6 +505,36 @@ export default class PCTransport extends EventEmitter {
throw new NegotiationError(msg);
}
}

private ensureVideoDDExtensionForSVC(
media: {
type: string;
port: number;
protocol: string;
payloads?: string | undefined;
} & MediaDescription,
) {
let maxID = 0;
const ddFound = media.ext?.some((ext): boolean => {
if (ext.uri === ddExtensionURI) {
return true;
}
if (ext.value > maxID) {
maxID = ext.value;
}
return false;
});

if (!ddFound) {
if (this.ddExtID === 0) {
this.ddExtID = maxID + 1;
}
media.ext?.push({
value: this.ddExtID,
uri: ddExtensionURI,
});
}
}
}

function ensureAudioNackAndStereo(
Expand Down Expand Up @@ -555,32 +587,6 @@ function ensureAudioNackAndStereo(
}
}

function ensureVideoDDExtensionForSVC(
media: {
type: string;
port: number;
protocol: string;
payloads?: string | undefined;
} & MediaDescription,
) {
let maxID = 0;
const ddFound = media.ext?.some((ext): boolean => {
if (ext.uri === ddExtensionURI) {
return true;
}
if (ext.value > maxID) {
maxID = ext.value;
}
return false;
});

if (!ddFound) {
media.ext?.push({
value: maxID + 1,
uri: ddExtensionURI,
});
}
}

function extractStereoAndNackAudioFromOffer(offer: RTCSessionDescriptionInit): {
stereoMids: string[];
Expand Down

0 comments on commit e7f81ae

Please sign in to comment.