浏览代码

fix(SDP) Add trackID if its missing in msid. (#2667)

* fix(SDP) Add missing trackID if its missing in msid.
This is needed for older versions of Chrome. Also skip performance optimizations if encode resolution is missing in the stats.

* squash: address review comments
release-8443
Jaya Allamsetty 7 个月前
父节点
当前提交
f5964f9b82
没有帐户链接到提交者的电子邮件
共有 2 个文件被更改,包括 40 次插入12 次删除
  1. 6
    2
      modules/qualitycontrol/QualityController.ts
  2. 34
    10
      modules/sdp/SDP.js

+ 6
- 2
modules/qualitycontrol/QualityController.ts 查看文件

301
         if (!this._enableAdaptiveMode) {
301
         if (!this._enableAdaptiveMode) {
302
             return;
302
             return;
303
         }
303
         }
304
-
305
         const { encodeResolution, localTrack, qualityLimitationReason, tpc } = sourceStats;
304
         const { encodeResolution, localTrack, qualityLimitationReason, tpc } = sourceStats;
305
+
306
+        // Older browser versions might not report the resolution in the stats.
307
+        if (Number.isNaN(encodeResolution)) {
308
+            return;
309
+        }
306
         const trackId = localTrack.rtcId;
310
         const trackId = localTrack.rtcId;
307
 
311
 
308
         if (encodeResolution === tpc.calculateExpectedSendResolution(localTrack)) {
312
         if (encodeResolution === tpc.calculateExpectedSendResolution(localTrack)) {
382
             const track = tpc.getTrackBySSRC(ssrc);
386
             const track = tpc.getTrackBySSRC(ssrc);
383
             const trackId = track.rtcId;
387
             const trackId = track.rtcId;
384
             let existingStats = statsPerTrack.get(trackId);
388
             let existingStats = statsPerTrack.get(trackId);
385
-            const encodeResolution = Math.min(resolution.height, resolution.width);
389
+            const encodeResolution = Math.min(resolution?.height, resolution?.width);
386
             const ssrcStats = {
390
             const ssrcStats = {
387
                 encodeResolution,
391
                 encodeResolution,
388
                 encodeTime,
392
                 encodeTime,

+ 34
- 10
modules/sdp/SDP.js 查看文件

40
         this.removeUdpCandidates = false;
40
         this.removeUdpCandidates = false;
41
     }
41
     }
42
 
42
 
43
+    /**
44
+     * Adjusts the msid semantic for a remote source based on the media type and the index of the m-line.
45
+     * This is needed for browsers that need both the streamId and trackId to be reported in the msid attribute.
46
+     *
47
+     * @param {String} msid - The msid attribute value.
48
+     * @param {Number} idx - The index of the m-line in the SDP.
49
+     * @returns {String} - The adjusted msid semantic.
50
+     */
51
+    _adjustMsidSemantic(msid, mediaType, idx) {
52
+        if (mediaType === MediaType.AUDIO || !browser.isChromiumBased() || browser.isEngineVersionGreaterThan(116)) {
53
+            return msid;
54
+        }
55
+
56
+        const msidParts = msid.split(' ');
57
+
58
+        if (msidParts.length === 2) {
59
+            return msid;
60
+        }
61
+
62
+        return `${msid} ${msid}-${idx}`;
63
+    }
64
+
43
     /**
65
     /**
44
      * Updates the media and session sections of the SDP based on the raw SDP string.
66
      * Updates the media and session sections of the SDP based on the raw SDP string.
45
      *
67
      *
95
             updatedMidIndices.push(idx);
117
             updatedMidIndices.push(idx);
96
 
118
 
97
             if (isAdd) {
119
             if (isAdd) {
98
-                let updatedMsid = msid;
99
-
100
-                // If the msid is not in the <stream ID> <track ID> format, create msid in that format.
101
-                // Chrome's older versions (upto 117) expect the msid to be in this format.
102
-                if (msid.split(' ').length !== 2
103
-                    && browser.isChromiumBased()
104
-                    && browser.isEngineVersionLessThan(117)) {
105
-                    updatedMsid = `${msid} ${msid}-${idx}`;
106
-                }
120
+                const updatedMsid = this._adjustMsidSemantic(msid, mediaType, idx);
107
 
121
 
108
                 ssrcList.forEach(ssrc => {
122
                 ssrcList.forEach(ssrc => {
109
                     this.media[idx] += `a=ssrc:${ssrc} msid:${updatedMsid}\r\n`;
123
                     this.media[idx] += `a=ssrc:${ssrc} msid:${updatedMsid}\r\n`;
259
                 const group = mLine.ssrcGroups?.find(g => g.ssrcs.includes(ssrcId));
273
                 const group = mLine.ssrcGroups?.find(g => g.ssrcs.includes(ssrcId));
260
 
274
 
261
                 if (group) {
275
                 if (group) {
276
+                    if (ssrc.attribute === 'msid') {
277
+                        ssrc.value = this._adjustMsidSemantic(ssrc.value, type, newMline.mid);
278
+                    }
262
                     newMline.ssrcs.push(ssrc);
279
                     newMline.ssrcs.push(ssrc);
263
                     const otherSsrc = group.ssrcs.split(' ').find(s => s !== ssrcId);
280
                     const otherSsrc = group.ssrcs.split(' ').find(s => s !== ssrcId);
264
 
281
 
265
                     if (otherSsrc) {
282
                     if (otherSsrc) {
266
                         const otherSource = mLine.ssrcs.find(source => source.id.toString() === otherSsrc);
283
                         const otherSource = mLine.ssrcs.find(source => source.id.toString() === otherSsrc);
267
 
284
 
285
+                        if (otherSource.attribute === 'msid') {
286
+                            otherSource.value = this._adjustMsidSemantic(otherSource.value, type, newMline.mid);
287
+                        }
268
                         newMline.ssrcs.push(otherSource);
288
                         newMline.ssrcs.push(otherSource);
269
                     }
289
                     }
270
                     newMline.ssrcGroups.push(group);
290
                     newMline.ssrcGroups.push(group);
373
         let sdp = '';
393
         let sdp = '';
374
         const sctp = transport.find(`>sctpmap[xmlns='${XEP.SCTP_DATA_CHANNEL}']`);
394
         const sctp = transport.find(`>sctpmap[xmlns='${XEP.SCTP_DATA_CHANNEL}']`);
375
         const media = { media: desc.attr('media') };
395
         const media = { media: desc.attr('media') };
396
+        const mid = content.attr('name');
376
 
397
 
377
         media.port = '9';
398
         media.port = '9';
378
         if (content.attr('senders') === 'rejected') {
399
         if (content.attr('senders') === 'rejected') {
445
             sdp += `a=${MediaDirection.SENDRECV}\r\n`;
466
             sdp += `a=${MediaDirection.SENDRECV}\r\n`;
446
             break;
467
             break;
447
         }
468
         }
448
-        sdp += `a=mid:${content.attr('name')}\r\n`;
469
+        sdp += `a=mid:${mid}\r\n`;
449
 
470
 
450
         // <description><rtcp-mux/></description>
471
         // <description><rtcp-mux/></description>
451
         // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
472
         // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
516
                         value = SDPUtil.filterSpecialChars(value);
537
                         value = SDPUtil.filterSpecialChars(value);
517
                         sourceStr += `a=ssrc:${ssrc} ${name}`;
538
                         sourceStr += `a=ssrc:${ssrc} ${name}`;
518
 
539
 
540
+                        if (name === 'msid') {
541
+                            value = this._adjustMsidSemantic(value, media.media, mid);
542
+                        }
519
                         if (value && value.length) {
543
                         if (value && value.length) {
520
                             sourceStr += `:${value}`;
544
                             sourceStr += `:${value}`;
521
                         }
545
                         }

正在加载...
取消
保存