瀏覽代碼

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,8 +301,12 @@ export class QualityController {
301 301
         if (!this._enableAdaptiveMode) {
302 302
             return;
303 303
         }
304
-
305 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 310
         const trackId = localTrack.rtcId;
307 311
 
308 312
         if (encodeResolution === tpc.calculateExpectedSendResolution(localTrack)) {
@@ -382,7 +386,7 @@ export class QualityController {
382 386
             const track = tpc.getTrackBySSRC(ssrc);
383 387
             const trackId = track.rtcId;
384 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 390
             const ssrcStats = {
387 391
                 encodeResolution,
388 392
                 encodeTime,

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

@@ -40,6 +40,28 @@ export default class SDP {
40 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 66
      * Updates the media and session sections of the SDP based on the raw SDP string.
45 67
      *
@@ -95,15 +117,7 @@ export default class SDP {
95 117
             updatedMidIndices.push(idx);
96 118
 
97 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 122
                 ssrcList.forEach(ssrc => {
109 123
                     this.media[idx] += `a=ssrc:${ssrc} msid:${updatedMsid}\r\n`;
@@ -259,12 +273,18 @@ export default class SDP {
259 273
                 const group = mLine.ssrcGroups?.find(g => g.ssrcs.includes(ssrcId));
260 274
 
261 275
                 if (group) {
276
+                    if (ssrc.attribute === 'msid') {
277
+                        ssrc.value = this._adjustMsidSemantic(ssrc.value, type, newMline.mid);
278
+                    }
262 279
                     newMline.ssrcs.push(ssrc);
263 280
                     const otherSsrc = group.ssrcs.split(' ').find(s => s !== ssrcId);
264 281
 
265 282
                     if (otherSsrc) {
266 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 288
                         newMline.ssrcs.push(otherSource);
269 289
                     }
270 290
                     newMline.ssrcGroups.push(group);
@@ -373,6 +393,7 @@ export default class SDP {
373 393
         let sdp = '';
374 394
         const sctp = transport.find(`>sctpmap[xmlns='${XEP.SCTP_DATA_CHANNEL}']`);
375 395
         const media = { media: desc.attr('media') };
396
+        const mid = content.attr('name');
376 397
 
377 398
         media.port = '9';
378 399
         if (content.attr('senders') === 'rejected') {
@@ -445,7 +466,7 @@ export default class SDP {
445 466
             sdp += `a=${MediaDirection.SENDRECV}\r\n`;
446 467
             break;
447 468
         }
448
-        sdp += `a=mid:${content.attr('name')}\r\n`;
469
+        sdp += `a=mid:${mid}\r\n`;
449 470
 
450 471
         // <description><rtcp-mux/></description>
451 472
         // see http://code.google.com/p/libjingle/issues/detail?id=309 -- no spec though
@@ -516,6 +537,9 @@ export default class SDP {
516 537
                         value = SDPUtil.filterSpecialChars(value);
517 538
                         sourceStr += `a=ssrc:${ssrc} ${name}`;
518 539
 
540
+                        if (name === 'msid') {
541
+                            value = this._adjustMsidSemantic(value, media.media, mid);
542
+                        }
519 543
                         if (value && value.length) {
520 544
                             sourceStr += `:${value}`;
521 545
                         }

Loading…
取消
儲存