From 461f825d4485b053252f90e34f631885ac7ddee0 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 e5251eb..4bb5e21 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 838fa7ce6cb928e99e5a3c4e10ee80d8287a4aba 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 4bb5e21..90cdc2a 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 4d171b9c007a37f9c802db6a29e28c0324ba495f 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 90cdc2a..a8ad782 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 2ea5df55f9d012654d27f0b099d241623685cab1 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 a8ad782..0ba7fb0 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); };