Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 4941ef5

Browse files
authored
Process Firefox SDP with media port 0 (#788)
* Fix audio ranker failure during switching * Process Firefox SDP with media port 0
1 parent 6b19971 commit 4941ef5

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

source/agent/webrtc/sdpInfo.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ class SdpInfo {
2929
});
3030
}
3131

32+
bundleMids() {
33+
const bundles = this.obj.groups.find(g => g.type === 'BUNDLE');
34+
return bundles.mids.split(' ');
35+
}
36+
37+
setBundleMids(mids) {
38+
const bundles = this.obj.groups.find(g => g.type === 'BUNDLE');
39+
bundles.mids = mids.join(' ');
40+
}
41+
3242
mids() {
3343
return this.obj.media.map(mediaInfo => mediaInfo.mid.toString());
3444
}
@@ -321,6 +331,30 @@ class SdpInfo {
321331
});
322332
}
323333

334+
isMediaClosed(mid) {
335+
const mediaInfo = this.media(mid);
336+
if (!mediaInfo) {
337+
return true;
338+
}
339+
if (mediaInfo.port === 0 && mediaInfo.direction === 'inactive') {
340+
return true;
341+
}
342+
return false;
343+
}
344+
345+
closeMedia(mid) {
346+
const mediaInfo = this.media(mid);
347+
if (mediaInfo) {
348+
mediaInfo.direction = 'inactive';
349+
mediaInfo.port = 0;
350+
delete mediaInfo.ext;
351+
delete mediaInfo.ssrcs;
352+
delete mediaInfo.ssrcGroups;
353+
delete mediaInfo.simulcast;
354+
delete mediaInfo.rids;
355+
}
356+
}
357+
324358
compareMedia(sdp) {
325359
const diffMids = [];
326360
this.obj.media.forEach(m1 => {

source/agent/webrtc/wrtcConnection.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ module.exports = function (spec, on_status, on_track) {
441441
// Check Media MID with saved operation
442442
if (!operationMap.has(mid)) {
443443
log.warn(`MID ${mid} in offer has no mapped operations (disabled)`);
444-
remoteSdp.setMediaPort(mid, 0);
444+
remoteSdp.closeMedia(mid);
445445
return;
446446
}
447447
if (operationMap.get(mid).sdpDirection !== remoteSdp.mediaDirection(mid)) {
@@ -452,9 +452,10 @@ module.exports = function (spec, on_status, on_track) {
452452
log.warn(`MID ${mid} in offer has conflict media type with operation`);
453453
return;
454454
}
455-
if (operationMap.get(mid).enabled && (remoteSdp.getMediaPort(mid) === 0)) {
456-
log.warn(`MID ${mid} in offer has conflict port with operation (disabled)`);
455+
if (operationMap.get(mid).enabled && remoteSdp.isMediaClosed(mid)) {
456+
log.warn(`MID ${mid} in offer has conflict closed state (disabled)`);
457457
operationMap.get(mid).enabled = false;
458+
return;
458459
}
459460

460461
// Determine media format in offer
@@ -501,34 +502,28 @@ module.exports = function (spec, on_status, on_track) {
501502
const addedMids = [];
502503
const removedMids = [];
503504

504-
for (let cmid of changedMids) {
505+
for (let cmid of laterSdp.mids()) {
505506
const oldMedia = remoteSdp.media(cmid);
506507
if (!oldMedia) {
507508
// Add media
508509
const tempSdp = laterSdp.singleMediaSdp(cmid);
509510
remoteSdp.mergeMedia(tempSdp);
510511
addedMids.push(cmid);
511-
} else if (laterSdp.getMediaPort(cmid) === 0) {
512+
} else if (laterSdp.isMediaClosed(cmid)) {
512513
// Remove media
513-
remoteSdp.setMediaPort(cmid, 0);
514-
localSdp.setMediaPort(cmid, 0);
515-
removedMids.push(cmid);
516-
} else if (laterSdp.mediaDirection(cmid) === 'inactive') {
517-
// Disable media
518-
remoteSdp.media(cmid).direction = 'inactive';
519-
localSdp.media(cmid).direction = 'inactive';
514+
remoteSdp.closeMedia(cmid);
520515
removedMids.push(cmid);
521516
} else {
522-
// May be port or direction change
523-
log.debug(`MID ${cmid} port or direction change`);
517+
// Treat as no change
518+
log.debug(`MID ${cmid} no change`);
524519
}
525520
}
526521

527522
let opId = null;
528523
for (let mid of addedMids) {
529524
processOfferMedia(mid);
530525
localSdp.mergeMedia(remoteSdp.singleMediaSdp(mid).answer());
531-
if (remoteSdp.getMediaPort(mid) !== 0) {
526+
if (!remoteSdp.isMediaClosed(mid)) {
532527
opId = setupTransport(mid);
533528
}
534529
}
@@ -540,10 +535,11 @@ module.exports = function (spec, on_status, on_track) {
540535
}
541536

542537
for (let mid of removedMids) {
543-
// processOfferMedia(mid);
538+
localSdp.closeMedia(mid);
539+
// Should already be destroyed by 'removeTrackOperation'
544540
// destroyTransport(mid);
545541
}
546-
542+
localSdp.setBundleMids(remoteSdp.bundleMids());
547543
// Produce answer
548544
const message = localSdp.toString();
549545
log.debug('Answer SDP', message);

0 commit comments

Comments
 (0)