From 8baee24aff48dfff34b04f99a6cf06a6276e3a21 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 24 Jan 2025 10:30:35 +0100 Subject: [PATCH 1/4] Filter ssrcs after rid-to-mid conversion Firefox includes ssrcs in its sdp, but will misbehave if three m-sections include the same six ssrcs (3 media, 3 rtx) and 3 ssrc-groups. --- index.html | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 8db2ed1..655b4b1 100644 --- a/index.html +++ b/index.html @@ -686,6 +686,12 @@ ) .map((line) => line.replace('a=extmap:', '').split(' ')[0])[0]; + const ssrcGroups = mSection + .filter((line) => + line.includes('a=ssrc-group:FID '), + ) + .map((line) => line.replace('a=ssrc-group:FID ', '').split(' ')); + sdpLines = sdpLines.map((line) => { if (line.startsWith('a=group:BUNDLE')) { return 'a=group:BUNDLE ' + layerRIDS.map(removeTilde).join(' '); @@ -694,7 +700,10 @@ return line; }); - for (const layerName of layerRIDS) { + for (const [i, layerName] of layerRIDS.entries()) { + const ssrcGroup = ssrcGroups.at(i); + const ssrc = ssrcGroup?.at(0); + const rtxSsrc = ssrcGroup?.at(1); sdpLines = sdpLines.concat( mSection.map((line) => { if (line.match(/a=msid:/)) { @@ -725,6 +734,17 @@ return null; } + if (line.startsWith('a=ssrc:') && + !line.startsWith(`a=ssrc:${ssrc}`) && + !line.startsWith(`a=ssrc:${rtxSsrc}`)) { + return null; + } + + if (line.startsWith('a=ssrc-group:FID') && + !line.startsWith(`a=ssrc-group:FID ${ssrc}`)) { + return null; + } + return line; }), ); From a0fdc6e4f733ec6f1e4a166593092726dd606f55 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 24 Jan 2025 10:31:16 +0100 Subject: [PATCH 2/4] Handle /sendonly after extmap ids --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 655b4b1..f56c30c 100644 --- a/index.html +++ b/index.html @@ -678,13 +678,13 @@ .filter((line) => line.includes('urn:ietf:params:rtp-hdrext:sdes:mid'), ) - .map((line) => line.replace('a=extmap:', '').split(' ')[0])[0]; + .map((line) => /a=extmap:(\d+)/.exec(line).at(1)); const ridExtmapId = mSection .filter((line) => line.includes('urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id'), ) - .map((line) => line.replace('a=extmap:', '').split(' ')[0])[0]; + .map((line) => /a=extmap:(\d+)/.exec(line).at(1)); const ssrcGroups = mSection .filter((line) => From fcef7ce113e81ab3b1abe255b6607a63bb49083c Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 24 Jan 2025 10:31:46 +0100 Subject: [PATCH 3/4] Remove mid, rid and rrid extensions when ssrcs are know and RTX enabled This bypasses an issue where Firefox would block RTX packets because they don't carry the mid header extension, while media packets do (translated from rid). --- index.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index f56c30c..02761de 100644 --- a/index.html +++ b/index.html @@ -692,6 +692,8 @@ ) .map((line) => line.replace('a=ssrc-group:FID ', '').split(' ')); + const hasSsrcGroups = ssrcGroups.length == layerRIDS.length; + sdpLines = sdpLines.map((line) => { if (line.startsWith('a=group:BUNDLE')) { return 'a=group:BUNDLE ' + layerRIDS.map(removeTilde).join(' '); @@ -715,6 +717,9 @@ } if (line.startsWith('a=extmap:' + midExtmapId + ' ')) { + if (hasSsrcGroups) { + return null; + } return ( 'a=extmap:' + midExtmapId + @@ -722,7 +727,10 @@ ); } - if (line.startsWith('a=extmap:' + ridExtmapId + ' ')) { + if (line.match(/^a=extmap:.* urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id/)) { + if (hasSsrcGroups) { + return null; + } return ( 'a=extmap:' + ridExtmapId + @@ -730,6 +738,11 @@ ); } + if (hasSsrcGroups && + line.match(/^a=extmap:.* urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id/)) { + return null; + } + if (line.startsWith('a=rid:') || line.startsWith('a=simulcast:')) { return null; } From 890d212652a5ad53b1d44062c819aa2e624102b6 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Fri, 24 Jan 2025 10:32:41 +0100 Subject: [PATCH 4/4] Log all 4 sdps --- index.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 02761de..2738e5f 100644 --- a/index.html +++ b/index.html @@ -628,7 +628,8 @@ } } - console.log('pc2 offer: ' + pc2Offer.sdp); + console.log('pc1 local offer: ' + pc1Offer.sdp); + console.log('pc2 remote offer: ' + pc2Offer.sdp); await pc2.setRemoteDescription(pc2Offer); const answer = await pc2.createAnswer(); @@ -647,7 +648,8 @@ pc1Answer = addConferenceFlag(pc1Answer); } - console.log('pc1 answer: ' + pc1Answer.sdp); + console.log('pc2 local answer: ' + answer.sdp); + console.log('pc1 remote answer: ' + pc1Answer.sdp); await pc1.setRemoteDescription(pc1Answer); };