Selaa lähdekoodia

fix(TPC): make screen share bitrate configurable (#2215)

* fix(TPC): make screen share bitrate configurable

* fix(TPC): make local stream encodings configurable

* fix(TPC): fix lint error

* fix(TPC): alpha sort methods and update check for VP8
dev1
Daniel McAssey 2 vuotta sitten
vanhempi
commit
829f5ac010
No account linked to committer's email address
2 muutettua tiedostoa jossa 58 lisäystä ja 45 poistoa
  1. 55
    43
      modules/RTC/TPCUtils.js
  2. 3
    2
      modules/RTC/TraceablePeerConnection.js

+ 55
- 43
modules/RTC/TPCUtils.js Näytä tiedosto

@@ -38,48 +38,15 @@ export class TPCUtils {
38 38
         const standardBitrates = {
39 39
             low: LD_BITRATE,
40 40
             standard: SD_BITRATE,
41
-            high: HD_BITRATE
41
+            high: HD_BITRATE,
42
+            ssHigh: HD_BITRATE
42 43
         };
43 44
 
44 45
         // Check if the max. bitrates for video are specified through config.js videoQuality settings.
45 46
         // Right now only VP8 bitrates are configured on the simulcast encodings, VP9 bitrates have to be
46 47
         // configured on the SDP using b:AS line.
47 48
         this.videoBitrates = bitrateSettings ?? standardBitrates;
48
-        const encodingBitrates = this.videoBitrates.VP8 ?? this.videoBitrates;
49
-
50
-        /**
51
-         * The startup configuration for the stream encodings that are applicable to
52
-         * the video stream when a new sender is created on the peerconnection. The initial
53
-         * config takes into account the differences in browser's simulcast implementation.
54
-         *
55
-         * Encoding parameters:
56
-         * active - determine the on/off state of a particular encoding.
57
-         * maxBitrate - max. bitrate value to be applied to that particular encoding
58
-         *  based on the encoding's resolution and config.js videoQuality settings if applicable.
59
-         * rid - Rtp Stream ID that is configured for a particular simulcast stream.
60
-         * scaleResolutionDownBy - the factor by which the encoding is scaled down from the
61
-         *  original resolution of the captured video.
62
-         */
63
-        this.localStreamEncodingsConfig = [
64
-            {
65
-                active: true,
66
-                maxBitrate: browser.isFirefox() ? encodingBitrates.high : encodingBitrates.low,
67
-                rid: SIM_LAYER_1_RID,
68
-                scaleResolutionDownBy: browser.isFirefox() ? HD_SCALE_FACTOR : LD_SCALE_FACTOR
69
-            },
70
-            {
71
-                active: true,
72
-                maxBitrate: encodingBitrates.standard,
73
-                rid: SIM_LAYER_2_RID,
74
-                scaleResolutionDownBy: SD_SCALE_FACTOR
75
-            },
76
-            {
77
-                active: true,
78
-                maxBitrate: browser.isFirefox() ? encodingBitrates.low : encodingBitrates.high,
79
-                rid: SIM_LAYER_3_RID,
80
-                scaleResolutionDownBy: browser.isFirefox() ? LD_SCALE_FACTOR : HD_SCALE_FACTOR
81
-            }
82
-        ];
49
+        this.encodingBitrates = this.videoBitrates.VP8 ?? this.videoBitrates;
83 50
     }
84 51
 
85 52
     /**
@@ -89,7 +56,7 @@ export class TPCUtils {
89 56
      */
90 57
     _getStreamEncodings(localTrack) {
91 58
         if (this.pc.isSimulcastOn() && localTrack.isVideoTrack()) {
92
-            return this.localStreamEncodingsConfig;
59
+            return this._getVideoStreamEncodings(localTrack.getVideoType());
93 60
         }
94 61
 
95 62
         return localTrack.isVideoTrack()
@@ -100,6 +67,47 @@ export class TPCUtils {
100 67
             : [ { active: true } ];
101 68
     }
102 69
 
70
+    /**
71
+     * The startup configuration for the stream encodings that are applicable to
72
+     * the video stream when a new sender is created on the peerconnection. The initial
73
+     * config takes into account the differences in browser's simulcast implementation.
74
+     *
75
+     * Encoding parameters:
76
+     * active - determine the on/off state of a particular encoding.
77
+     * maxBitrate - max. bitrate value to be applied to that particular encoding
78
+     *  based on the encoding's resolution and config.js videoQuality settings if applicable.
79
+     * rid - Rtp Stream ID that is configured for a particular simulcast stream.
80
+     * scaleResolutionDownBy - the factor by which the encoding is scaled down from the
81
+     *  original resolution of the captured video.
82
+     *
83
+     *  @param {VideoType} videoType
84
+     */
85
+    _getVideoStreamEncodings(videoType) {
86
+        const maxVideoBitrate = videoType === VideoType.DESKTOP && this.encodingBitrates.ssHigh
87
+            ? this.encodingBitrates.ssHigh : this.encodingBitrates.high;
88
+
89
+        return [
90
+            {
91
+                active: true,
92
+                maxBitrate: browser.isFirefox() ? maxVideoBitrate : this.encodingBitrates.low,
93
+                rid: SIM_LAYER_1_RID,
94
+                scaleResolutionDownBy: browser.isFirefox() ? HD_SCALE_FACTOR : LD_SCALE_FACTOR
95
+            },
96
+            {
97
+                active: true,
98
+                maxBitrate: this.encodingBitrates.standard,
99
+                rid: SIM_LAYER_2_RID,
100
+                scaleResolutionDownBy: SD_SCALE_FACTOR
101
+            },
102
+            {
103
+                active: true,
104
+                maxBitrate: browser.isFirefox() ? this.encodingBitrates.low : maxVideoBitrate,
105
+                rid: SIM_LAYER_3_RID,
106
+                scaleResolutionDownBy: browser.isFirefox() ? LD_SCALE_FACTOR : HD_SCALE_FACTOR
107
+            }
108
+        ];
109
+    }
110
+
103 111
     /**
104 112
      * Ensures that the ssrcs associated with a FID ssrc-group appear in the correct order, i.e.,
105 113
      * the primary ssrc first and the secondary rtx ssrc later. This is important for unified
@@ -277,7 +285,8 @@ export class TPCUtils {
277 285
     calculateEncodingsActiveState(localVideoTrack, newHeight) {
278 286
         const localTrack = localVideoTrack.getTrack();
279 287
         const { height } = localTrack.getSettings();
280
-        const encodingsState = this.localStreamEncodingsConfig
288
+        const videoStreamEncodings = this._getVideoStreamEncodings(localVideoTrack.getVideoType());
289
+        const encodingsState = videoStreamEncodings
281 290
         .map(encoding => height / encoding.scaleResolutionDownBy)
282 291
         .map((frameHeight, idx) => {
283 292
             let active = localVideoTrack.getVideoType() === VideoType.CAMERA
@@ -286,7 +295,7 @@ export class TPCUtils {
286 295
                 // resolution. This can happen when camera is captured at resolutions higher than 720p but the
287 296
                 // requested resolution is 180. Since getParameters doesn't give us information about the resolutions
288 297
                 // of the simulcast encodings, we have to rely on our initial config for the simulcast streams.
289
-                ? newHeight > 0 && this.localStreamEncodingsConfig[idx]?.scaleResolutionDownBy === LD_SCALE_FACTOR
298
+                ? newHeight > 0 && videoStreamEncodings[idx]?.scaleResolutionDownBy === LD_SCALE_FACTOR
290 299
                     ? true
291 300
                     : frameHeight <= newHeight
292 301
 
@@ -302,7 +311,7 @@ export class TPCUtils {
302 311
                 && this.pc._capScreenshareBitrate
303 312
                 && this.pc.usesUnifiedPlan()
304 313
                 && !browser.isWebKitBased()
305
-                && this.localStreamEncodingsConfig[idx].scaleResolutionDownBy !== HD_SCALE_FACTOR) {
314
+                && videoStreamEncodings[idx].scaleResolutionDownBy !== HD_SCALE_FACTOR) {
306 315
                 active = false;
307 316
             }
308 317
 
@@ -325,7 +334,7 @@ export class TPCUtils {
325 334
         const lowFpsScreenshare = localVideoTrack.getVideoType() === VideoType.DESKTOP
326 335
             && this.pc._capScreenshareBitrate
327 336
             && !browser.isWebKitBased();
328
-        const encodingsBitrates = this.localStreamEncodingsConfig
337
+        const encodingsBitrates = this._getVideoStreamEncodings(localVideoTrack.getVideoType())
329 338
         .map(encoding => {
330 339
             const bitrate = lowFpsScreenshare
331 340
                 ? desktopShareBitrate
@@ -491,10 +500,11 @@ export class TPCUtils {
491 500
      * that were configured on the RTCRtpSender when the source was added to the peerconnection.
492 501
      * This should prevent us from overriding the default values if the browser returns
493 502
      * erroneous values when RTCRtpSender.getParameters is used for getting the encodings info.
503
+     * @param {JitsiLocalTrack} localVideoTrack The local video track.
494 504
      * @param {Object} parameters - the RTCRtpEncodingParameters obtained from the browser.
495 505
      * @returns {void}
496 506
      */
497
-    updateEncodingsResolution(parameters) {
507
+    updateEncodingsResolution(localVideoTrack, parameters) {
498 508
         if (!(browser.isWebKitBased() && parameters.encodings && Array.isArray(parameters.encodings))) {
499 509
             return;
500 510
         }
@@ -504,8 +514,10 @@ export class TPCUtils {
504 514
 
505 515
         // Implement the workaround only when all the encodings report the same resolution.
506 516
         if (allEqualEncodings(parameters.encodings)) {
517
+            const videoStreamEncodings = this._getVideoStreamEncodings(localVideoTrack.getVideoType());
518
+
507 519
             parameters.encodings.forEach((encoding, idx) => {
508
-                encoding.scaleResolutionDownBy = this.localStreamEncodingsConfig[idx].scaleResolutionDownBy;
520
+                encoding.scaleResolutionDownBy = videoStreamEncodings[idx].scaleResolutionDownBy;
509 521
             });
510 522
         }
511 523
     }

+ 3
- 2
modules/RTC/TraceablePeerConnection.js Näytä tiedosto

@@ -2396,11 +2396,12 @@ TraceablePeerConnection.prototype._setVp9MaxBitrates = function(description, isL
2396 2396
         if (this.codecPreference.mimeType === CodecMimeType.VP9) {
2397 2397
             const bitrates = this.tpcUtils.videoBitrates.VP9 || this.tpcUtils.videoBitrates;
2398 2398
             const hdBitrate = bitrates.high ? bitrates.high : HD_BITRATE;
2399
+            const ssHdBitrate = bitrates.ssHigh ? bitrates.ssHigh : HD_BITRATE;
2399 2400
             const mid = mLine.mid;
2400 2401
             const isSharingScreen = FeatureFlags.isMultiStreamSendSupportEnabled()
2401 2402
                 ? mid === this._getDesktopTrackMid()
2402 2403
                 : this._isSharingScreen();
2403
-            const limit = Math.floor((isSharingScreen ? HD_BITRATE : hdBitrate) / 1000);
2404
+            const limit = Math.floor((isSharingScreen ? ssHdBitrate : hdBitrate) / 1000);
2404 2405
 
2405 2406
             // Use only the HD bitrate for now as there is no API available yet for configuring
2406 2407
             // the bitrates on the individual SVC layers.
@@ -2641,7 +2642,7 @@ TraceablePeerConnection.prototype.setSenderVideoConstraints = function(frameHeig
2641 2642
                 }
2642 2643
             }
2643 2644
         }
2644
-        this.tpcUtils.updateEncodingsResolution(parameters);
2645
+        this.tpcUtils.updateEncodingsResolution(localVideoTrack, parameters);
2645 2646
 
2646 2647
     // For p2p and cases and where simulcast is explicitly disabled.
2647 2648
     } else if (frameHeight > 0) {

Loading…
Peruuta
Tallenna