瀏覽代碼

ref(sdp): Add a more generic option for codec preference

Use 'preferredCodec' and 'disabledCodec' under videoQuality config.js settings for setting codec preferences.
Do not prefer VP9 on Firefox because of https://bugzilla.mozilla.org/show_bug.cgi?id=1633876.
release-8443
Jaya Allamsetty 5 年之前
父節點
當前提交
c4c20b9126
共有 4 個文件被更改,包括 82 次插入17 次删除
  1. 42
    14
      modules/RTC/TraceablePeerConnection.js
  2. 12
    2
      modules/xmpp/JingleSessionPC.js
  3. 4
    1
      modules/xmpp/SDPUtil.js
  4. 24
    0
      service/RTC/CodecMimeType.js

+ 42
- 14
modules/RTC/TraceablePeerConnection.js 查看文件

@@ -4,6 +4,7 @@ import { Interop } from '@jitsi/sdp-interop';
4 4
 import { getLogger } from 'jitsi-meet-logger';
5 5
 import transform from 'sdp-transform';
6 6
 
7
+import * as CodecMimeType from '../../service/RTC/CodecMimeType';
7 8
 import * as MediaType from '../../service/RTC/MediaType';
8 9
 import RTCEvents from '../../service/RTC/RTCEvents';
9 10
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
@@ -268,27 +269,54 @@ export default function TraceablePeerConnection(
268 269
      */
269 270
     this.senderVideoMaxHeight = null;
270 271
 
271
-    // Set the codec preference that will be applied on the SDP
272
-    // based on the config.js settings.
273
-    if (this.options.preferH264 || this.options.preferVP9) {
272
+    // We currently support preferring/disabling video codecs only.
273
+    const getCodecMimeType
274
+        = codec => Object.values(CodecMimeType).find(value => value === codec.toLowerCase());
275
+
276
+    // Set the codec preference that will be applied on the SDP based on the config.js settings.
277
+    if (this.options.preferH264 || this.options.preferredCodec) {
278
+        let prefferedCodec = null;
279
+
280
+        // Do not prefer VP9 on Firefox because of the following bug.
281
+        // https://bugzilla.mozilla.org/show_bug.cgi?id=1633876
282
+        if (this.options.preferredCodec) {
283
+            const mimeType = getCodecMimeType(this.options.preferredCodec);
284
+
285
+            if (!(browser.isFirefox() && mimeType === CodecMimeType.VP9)) {
286
+                prefferedCodec = mimeType;
287
+            }
288
+        }
289
+
274 290
         this.codecPreference = {
275 291
             enable: true,
276 292
             mediaType: MediaType.VIDEO,
277 293
             mimeType: this.options.preferH264
278
-                ? 'h264'
279
-                : 'vp9'
294
+                ? CodecMimeType.H264
295
+                : prefferedCodec
280 296
         };
281 297
     }
282 298
 
283
-    // If both enable and disable are set for the same codec, disable
284
-    // setting will prevail.
285
-    if (this.options.disableH264 || this.options.disableVP9) {
299
+    // If both enable and disable are set for the same codec, disable setting will prevail.
300
+    if (this.options.disableH264 || this.options.disabledCodec) {
301
+        let disabledCodec = null;
302
+
303
+        // Make sure we don't disable VP8 since it is a mandatory codec.
304
+        if (this.options.disabledCodec) {
305
+            const mimeType = getCodecMimeType(this.options.disabledCodec);
306
+
307
+            if (mimeType === CodecMimeType.VP8) {
308
+                logger.warn('Disabling VP8 is not permitted, setting is ignored!');
309
+            } else {
310
+                disabledCodec = mimeType;
311
+            }
312
+        }
313
+
286 314
         this.codecPreference = {
287 315
             enable: false,
288 316
             mediaType: MediaType.VIDEO,
289 317
             mimeType: this.options.disableH264
290
-                ? 'h264'
291
-                : 'vp9'
318
+                ? CodecMimeType.H264
319
+                : disabledCodec
292 320
         };
293 321
     }
294 322
 
@@ -1503,14 +1531,14 @@ TraceablePeerConnection.prototype._getSSRC = function(rtcId) {
1503 1531
  * @returns {RTCSessionDescription} the munged description.
1504 1532
  */
1505 1533
 TraceablePeerConnection.prototype._mungeCodecOrder = function(description) {
1506
-    if (!this.codecPreference || browser.supportsCodecPreferences()) {
1534
+    if (!(this.codecPreference && this.codecPreference.mimeType) || browser.supportsCodecPreferences()) {
1507 1535
         return description;
1508 1536
     }
1509 1537
 
1510 1538
     const parsedSdp = transform.parse(description.sdp);
1511 1539
     const mLine = parsedSdp.media.find(m => m.type === this.codecPreference.mediaType);
1512 1540
 
1513
-    if (this.codecPreference.enable && this.codecPreference.mimeType) {
1541
+    if (this.codecPreference.enable) {
1514 1542
         SDPUtil.preferCodec(mLine, this.codecPreference.mimeType);
1515 1543
 
1516 1544
         // Strip the high profile H264 codecs on mobile clients for p2p connection.
@@ -1518,10 +1546,10 @@ TraceablePeerConnection.prototype._mungeCodecOrder = function(description) {
1518 1546
         // we do not want on mobile clients.
1519 1547
         // Jicofo offers only the baseline code for the jvb connection.
1520 1548
         // TODO - add check for mobile browsers once js-utils provides that check.
1521
-        if (this.codecPreference.mimeType === 'h264' && browser.isReactNative() && this.isP2P) {
1549
+        if (this.codecPreference.mimeType === CodecMimeType.H264 && browser.isReactNative() && this.isP2P) {
1522 1550
             SDPUtil.stripCodec(mLine, this.codecPreference.mimeType, true /* high profile */);
1523 1551
         }
1524
-    } else if (this.codecPreference.mimeType) {
1552
+    } else {
1525 1553
         SDPUtil.stripCodec(mLine, this.codecPreference.mimeType);
1526 1554
     }
1527 1555
 

+ 12
- 2
modules/xmpp/JingleSessionPC.js 查看文件

@@ -331,12 +331,23 @@ export default class JingleSessionPC extends JingleSession {
331 331
         pcOptions.enableInsertableStreams = options.enableInsertableStreams;
332 332
         pcOptions.videoQuality = options.videoQuality;
333 333
 
334
+        // codec preference options for jvb connection.
335
+        if (pcOptions.videoQuality) {
336
+            pcOptions.disabledCodec = pcOptions.videoQuality.disabledCodec;
337
+            pcOptions.preferredCodec = pcOptions.videoQuality.preferredCodec;
338
+        }
339
+
334 340
         if (this.isP2P) {
335 341
             // simulcast needs to be disabled for P2P (121) calls
336 342
             pcOptions.disableSimulcast = true;
337 343
             pcOptions.disableH264 = options.p2p && options.p2p.disableH264;
338 344
             pcOptions.preferH264 = options.p2p && options.p2p.preferH264;
339
-            pcOptions.preferVP9 = options.p2p && options.p2p.preferVP9;
345
+
346
+            // codec preference options for p2p.
347
+            if (options.p2p) {
348
+                pcOptions.disabledCodec = options.p2p.disabledCodec;
349
+                pcOptions.preferredCodec = options.p2p.preferredCodec;
350
+            }
340 351
 
341 352
             const abtestSuspendVideo = this._abtestSuspendVideoEnabled(options);
342 353
 
@@ -349,7 +360,6 @@ export default class JingleSessionPC extends JingleSession {
349 360
                 = options.disableSimulcast
350 361
                     || (options.preferH264 && !options.disableH264);
351 362
             pcOptions.preferH264 = options.preferH264;
352
-            pcOptions.preferVP9 = options.preferVP9;
353 363
 
354 364
             // disable simulcast for screenshare and set the max bitrate to
355 365
             // 500Kbps if the testing flag is present in config.js.

+ 4
- 1
modules/xmpp/SDPUtil.js 查看文件

@@ -1,6 +1,7 @@
1 1
 import { getLogger } from 'jitsi-meet-logger';
2 2
 const logger = getLogger(__filename);
3 3
 
4
+import CodecMimeType from '../../service/RTC/CodecMimeType';
4 5
 import browser from '../browser';
5 6
 import RandomUtil from '../util/RandomUtil';
6 7
 
@@ -605,6 +606,8 @@ const SDPUtil = {
605 606
      *
606 607
      * @param {object} mLine the mline object from an sdp as parsed by transform.parse.
607 608
      * @param {string} codecName the name of the codec which will be stripped.
609
+     * @param {boolean} highProfile determines if only the high profile H264 codec needs to be
610
+     * stripped from the sdp when the passed codecName is H264.
608 611
      */
609 612
     stripCodec(mLine, codecName, highProfile = false) {
610 613
         if (!mLine || !codecName) {
@@ -613,7 +616,7 @@ const SDPUtil = {
613 616
 
614 617
         const h264Pts = [];
615 618
         let removePts = [];
616
-        const stripH264HighCodec = codecName.toLowerCase() === 'h264' && highProfile;
619
+        const stripH264HighCodec = codecName.toLowerCase() === CodecMimeType.H264 && highProfile;
617 620
 
618 621
         for (const rtp of mLine.rtp) {
619 622
             if (rtp.codec

+ 24
- 0
service/RTC/CodecMimeType.js 查看文件

@@ -0,0 +1,24 @@
1
+/* global module */
2
+/**
3
+ * Enumeration of the codec mime types
4
+ * @type {{H264: string, VP8: string, VP9: string}}
5
+ */
6
+const CodecMimeType = {
7
+    /**
8
+     * The h264 codec mime type
9
+     */
10
+    H264: 'h264',
11
+
12
+    /**
13
+     * The vp8 codec mime type.
14
+     */
15
+    VP8: 'vp8',
16
+
17
+    /**
18
+     * The vp9 codec mime type.
19
+     */
20
+    VP9: 'vp9'
21
+
22
+};
23
+
24
+module.exports = CodecMimeType;

Loading…
取消
儲存