Skip to content

Commit

Permalink
fix(SDP): Add missing msid for p2p sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
jallamsetty1 committed May 25, 2021
1 parent 1551193 commit 4b25a6f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
22 changes: 21 additions & 1 deletion modules/sdp/LocalSdpMunger.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,29 @@ export default class LocalSdpMunger {
const msid = mediaSection.ssrcs.find(s => s.attribute === 'msid');

if (!this.tpc.isP2P
&& (!msid || mediaSection.direction === 'recvonly' || mediaSection.direction === 'inactive')) {
&& (!msid
|| mediaSection.mLine?.direction === 'recvonly'
|| mediaSection.mLine?.direction === 'inactive')) {
mediaSection.ssrcs = undefined;
mediaSection.ssrcGroups = undefined;

// Add the msid attribute if it is missing for p2p sources. Firefox doesn't produce a a=ssrc line
// with msid attribute.
} else if (this.tpc.isP2P && mediaSection.mLine?.direction === 'sendrecv') {
const msidLine = mediaSection.mLine?.msid;
const trackId = msidLine && msidLine.split(' ')[1];
const sources = [ ...new Set(mediaSection.mLine?.ssrcs?.map(s => s.id)) ];

for (const source of sources) {
const msidExists = mediaSection.ssrcs
.find(ssrc => ssrc.id === source && ssrc.attribute === 'msid');

!msidExists && mediaSection.ssrcs.push({
id: source,
attribute: 'msid',
value: `${this.localEndpointId}-${mediaSection.mLine?.type}-${pcId} ${trackId}-${pcId}`
});
}
}
}

Expand Down
17 changes: 17 additions & 0 deletions modules/sdp/LocalSdpMunger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,22 @@ describe('TransformRecvOnly', () => {
}
}
});

it('should add msid', () => {
// P2P case only.
localSdpMunger.tpc.isP2P = true;

const sdpStr = transform.write(SampleSdpStrings.firefoxP2pSdp);
const desc = new RTCSessionDescription({
type: 'offer',
sdp: sdpStr
});
const transformedDesc = localSdpMunger.transformStreamIdentifiers(desc);
const newSdp = transform.parse(transformedDesc.sdp);
const videoSsrcs = getSsrcLines(newSdp, 'video');
const msidExists = videoSsrcs.find(s => s.attribute === 'msid');

expect(msidExists).toBeDefined();
});
});
});
29 changes: 29 additions & 0 deletions modules/sdp/SampleSdpStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,26 @@ const videoMlineFF = ''
+ 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/\r\n'
+ 'a=rtcp-mux\r\n';

const videoLineP2pFF = ''
+ 'm=video 9 RTP/SAVPF 100 96\r\n'
+ 'c=IN IP4 0.0.0.0\r\n'
+ 'a=rtpmap:100 VP8/90000\r\n'
+ 'a=fmtp:96 apt=100\r\n'
+ 'a=rtcp:9 IN IP4 0.0.0.0\r\n'
+ 'a=rtcp-fb:100 ccm fir\r\n'
+ 'a=rtcp-fb:100 nack\r\n'
+ 'a=rtcp-fb:100 nack pli\r\n'
+ 'a=rtcp-fb:100 goog-remb\r\n'
+ 'a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n'
+ 'a=setup:passive\r\n'
+ 'a=mid:video\r\n'
+ 'a=sendrecv\r\n'
+ 'a=ice-ufrag:adPg\r\n'
+ 'a=ice-pwd:Xsr05Mq8S7CR44DAnusZE26F\r\n'
+ 'a=fingerprint:sha-256 6A:39:DE:11:24:AD:2E:4E:63:D6:69:D3:85:05:53:C7:3C:38:A4:B7:91:74:C0:91:44:FC:94:63:7F:01:AB:A9\r\n'
+ 'a=ssrc:984899560 cname:peDGrDD6WsxUOki/\r\n'
+ 'a=rtcp-mux\r\n';

// A full sdp string representing a client doing simulcast
const simulcastSdpStr = baseSessionSdp + baseAudioMLineSdp + simulcastVideoMLineSdp + baseDataMLineSdp;

Expand All @@ -380,8 +400,12 @@ const flexFecSdpStr = baseSessionSdp + baseAudioMLineSdp + flexFecVideoMLineSdp
// A full sdp string representing a client that doesn't have local sources added on Firefox.
const recvOnlySdpStr = baseSessionSdp + recvOnlyAudioMline + recvOnlyVideoMline;

// A full sdp string representing a Firefox client with msid set to '-'.
const sdpFirefoxStr = baseSessionSdp + baseAudioMLineSdp + videoMlineFF;

// A full sdp string representing a Firefox client with missing msid attribute.
const sdpFirefoxP2pStr = baseSessionSdp + baseAudioMLineSdp + videoLineP2pFF;

export default {
get simulcastSdp() {
return transform.parse(simulcastSdpStr);
Expand Down Expand Up @@ -413,7 +437,12 @@ export default {

get firefoxSdp() {
return transform.parse(sdpFirefoxStr);
},

get firefoxP2pSdp() {
return transform.parse(sdpFirefoxP2pStr);
}

};

/* eslint-enable max-len*/

0 comments on commit 4b25a6f

Please sign in to comment.