Ver código fonte

feat: Apply max bitrates on video sender (#1275)

* feat: Apply max bitrates on video sender
Add the ability to control the max bitrates on the video sender through a config.js videoQuality setting.

* ref: Use '_' prefix only for internal methods
master
Jaya Allamsetty 4 anos atrás
pai
commit
f74cd0abe9
Nenhuma conta vinculada ao e-mail do autor do commit

+ 14
- 9
modules/RTC/TPCUtils.js Ver arquivo

20
  */
20
  */
21
 export class TPCUtils {
21
 export class TPCUtils {
22
     /**
22
     /**
23
-     * @constructor
23
+     * Creates a new instance for a given TraceablePeerConnection
24
+     *
25
+     * @param peerconnection - the tpc instance for which we have utility functions.
26
+     * @param videoBitrates - the bitrates to be configured on the video senders when
27
+     * simulcast is enabled.
24
      */
28
      */
25
-    constructor(peerconnection) {
29
+    constructor(peerconnection, videoBitrates) {
26
         this.pc = peerconnection;
30
         this.pc = peerconnection;
31
+        this.videoBitrates = videoBitrates;
27
 
32
 
28
         /**
33
         /**
29
          * The simulcast encodings that will be configured on the RTCRtpSender
34
          * The simulcast encodings that will be configured on the RTCRtpSender
32
         this.simulcastEncodings = [
37
         this.simulcastEncodings = [
33
             {
38
             {
34
                 active: true,
39
                 active: true,
35
-                maxBitrate: browser.isFirefox() ? 2500000 : 200000,
40
+                maxBitrate: browser.isFirefox() ? this.videoBitrates.high : this.videoBitrates.low,
36
                 rid: SIM_LAYER_1_RID,
41
                 rid: SIM_LAYER_1_RID,
37
                 scaleResolutionDownBy: browser.isFirefox() ? 1.0 : 4.0
42
                 scaleResolutionDownBy: browser.isFirefox() ? 1.0 : 4.0
38
             },
43
             },
39
             {
44
             {
40
                 active: true,
45
                 active: true,
41
-                maxBitrate: 700000,
46
+                maxBitrate: this.videoBitrates.standard,
42
                 rid: SIM_LAYER_2_RID,
47
                 rid: SIM_LAYER_2_RID,
43
                 scaleResolutionDownBy: 2.0
48
                 scaleResolutionDownBy: 2.0
44
             },
49
             },
45
             {
50
             {
46
                 active: true,
51
                 active: true,
47
-                maxBitrate: browser.isFirefox() ? 200000 : 2500000,
52
+                maxBitrate: browser.isFirefox() ? this.videoBitrates.low : this.videoBitrates.high,
48
                 rid: SIM_LAYER_3_RID,
53
                 rid: SIM_LAYER_3_RID,
49
                 scaleResolutionDownBy: browser.isFirefox() ? 4.0 : 1.0
54
                 scaleResolutionDownBy: browser.isFirefox() ? 4.0 : 1.0
50
             }
55
             }
65
      * description.
70
      * description.
66
      * @private
71
      * @private
67
      */
72
      */
68
-    _ensureCorrectOrderOfSsrcs(description) {
73
+    ensureCorrectOrderOfSsrcs(description) {
69
         const parsedSdp = transform.parse(description.sdp);
74
         const parsedSdp = transform.parse(description.sdp);
70
 
75
 
71
         parsedSdp.media.forEach(mLine => {
76
         parsedSdp.media.forEach(mLine => {
113
      * @return {Object} A session description (same format as above) object
118
      * @return {Object} A session description (same format as above) object
114
      * with its sdp field modified to advertise simulcast receive support
119
      * with its sdp field modified to advertise simulcast receive support
115
      */
120
      */
116
-    _insertUnifiedPlanSimulcastReceive(desc) {
121
+    insertUnifiedPlanSimulcastReceive(desc) {
117
         // a=simulcast line is not needed on browsers where
122
         // a=simulcast line is not needed on browsers where
118
         // we munge SDP for turning on simulcast. Remove this check
123
         // we munge SDP for turning on simulcast. Remove this check
119
         // when we move to RID/MID based simulcast on all browsers.
124
         // when we move to RID/MID based simulcast on all browsers.
182
      * @param {MediaStreamTrack} track - the local video track.
187
      * @param {MediaStreamTrack} track - the local video track.
183
      * @returns {void}
188
      * @returns {void}
184
      */
189
      */
185
-    _setSimulcastStreamConstraints(track) {
190
+    setSimulcastStreamConstraints(track) {
186
         if (browser.isReactNative()) {
191
         if (browser.isReactNative()) {
187
             return;
192
             return;
188
         }
193
         }
230
 
235
 
231
         // Construct the simulcast stream constraints for the newly added track.
236
         // Construct the simulcast stream constraints for the newly added track.
232
         if (localTrack.isVideoTrack() && localTrack.videoType === VideoType.CAMERA && this.pc.isSimulcastOn()) {
237
         if (localTrack.isVideoTrack() && localTrack.videoType === VideoType.CAMERA && this.pc.isSimulcastOn()) {
233
-            this._setSimulcastStreamConstraints(localTrack.getTrack());
238
+            this.setSimulcastStreamConstraints(localTrack.getTrack());
234
         }
239
         }
235
     }
240
     }
236
 
241
 

+ 37
- 12
modules/RTC/TraceablePeerConnection.js Ver arquivo

25
 // FIXME SDP tools should end up in some kind of util module
25
 // FIXME SDP tools should end up in some kind of util module
26
 
26
 
27
 const logger = getLogger(__filename);
27
 const logger = getLogger(__filename);
28
-const MAX_BITRATE = 2500000;
29
-const DESKSTOP_SHARE_RATE = 500000;
30
 const DEGRADATION_PREFERENCE_CAMERA = 'maintain-framerate';
28
 const DEGRADATION_PREFERENCE_CAMERA = 'maintain-framerate';
31
 const DEGRADATION_PREFERENCE_DESKTOP = 'maintain-resolution';
29
 const DEGRADATION_PREFERENCE_DESKTOP = 'maintain-resolution';
30
+const DESKSTOP_SHARE_RATE = 500000;
31
+const HD_BITRATE = 2500000;
32
+const LD_BITRATE = 200000;
33
+const SD_BITRATE = 700000;
34
+
32
 /* eslint-disable max-params */
35
 /* eslint-disable max-params */
33
 
36
 
34
 /**
37
 /**
209
 
212
 
210
     this.peerconnection
213
     this.peerconnection
211
         = new RTCUtils.RTCPeerConnectionType(iceConfig, constraints);
214
         = new RTCUtils.RTCPeerConnectionType(iceConfig, constraints);
212
-    this.tpcUtils = new TPCUtils(this);
215
+
216
+    // The standard video bitrates are used in Unified plan when switching
217
+    // between camera/desktop tracks on the same sender.
218
+    const standardVideoBitrates = {
219
+        low: LD_BITRATE,
220
+        standard: SD_BITRATE,
221
+        high: HD_BITRATE
222
+    };
223
+
224
+    // Check if the max. bitrates for video are specified through config.js
225
+    // videoQuality settings. These bitrates will be applied on all browsers
226
+    // for camera sources in simulcast mode.
227
+    const videoBitrates = this.options.videoQuality
228
+        ? this.options.videoQuality.maxBitratesVideo
229
+        : standardVideoBitrates;
230
+
231
+    this.tpcUtils = new TPCUtils(this, videoBitrates);
213
     this.updateLog = [];
232
     this.updateLog = [];
214
     this.stats = {};
233
     this.stats = {};
215
     this.statsinterval = null;
234
     this.statsinterval = null;
1526
 
1545
 
1527
     // Construct the simulcast stream constraints for the newly added track.
1546
     // Construct the simulcast stream constraints for the newly added track.
1528
     if (track.isVideoTrack() && track.videoType === VideoType.CAMERA && this.isSimulcastOn()) {
1547
     if (track.isVideoTrack() && track.videoType === VideoType.CAMERA && this.isSimulcastOn()) {
1529
-        this.tpcUtils._setSimulcastStreamConstraints(track.getTrack());
1548
+        this.tpcUtils.setSimulcastStreamConstraints(track.getTrack());
1530
     }
1549
     }
1531
 };
1550
 };
1532
 
1551
 
1982
  * @param {JitsiLocalTrack} localTrack - the local track whose
2001
  * @param {JitsiLocalTrack} localTrack - the local track whose
1983
  * max bitrate is to be configured.
2002
  * max bitrate is to be configured.
1984
  */
2003
  */
1985
-TraceablePeerConnection.prototype.setMaxBitRate = function(localTrack) {
2004
+TraceablePeerConnection.prototype.setMaxBitRate = function(localTrack = null) {
2005
+    if (!localTrack) {
2006
+        // eslint-disable-next-line no-param-reassign
2007
+        localTrack = Array.from(this.localTracks.values()).find(t => t.isVideoTrack());
2008
+    }
1986
     const trackId = localTrack.track.id;
2009
     const trackId = localTrack.track.id;
1987
     const videoType = localTrack.videoType;
2010
     const videoType = localTrack.videoType;
1988
 
2011
 
1989
     // No need to set max bitrates on the streams in the following cases.
2012
     // No need to set max bitrates on the streams in the following cases.
1990
     // 1. When a 'camera' track is replaced in plan-b mode, since its a new sender.
2013
     // 1. When a 'camera' track is replaced in plan-b mode, since its a new sender.
1991
     // 2. When the config.js option for capping the SS bitrate is not enabled.
2014
     // 2. When the config.js option for capping the SS bitrate is not enabled.
1992
-    if ((browser.usesPlanB() && !this.options.capScreenshareBitrate)
1993
-        || (browser.usesPlanB() && videoType === VideoType.CAMERA)) {
2015
+    // The above two conditions are ignored When max video bitrates are specified through config.js.
2016
+    if (((browser.usesPlanB() && !this.options.capScreenshareBitrate)
2017
+        || (browser.usesPlanB() && videoType === VideoType.CAMERA))
2018
+        && !(this.options.videoQuality && this.options.videoQuality.maxBitratesVideo)) {
1994
         return;
2019
         return;
1995
     }
2020
     }
1996
     if (!this.peerconnection.getSenders) {
2021
     if (!this.peerconnection.getSenders) {
2017
                         // capScreenshareBitrate is enabled through config.js and presenter
2042
                         // capScreenshareBitrate is enabled through config.js and presenter
2018
                         // is not turned on.
2043
                         // is not turned on.
2019
                         parameters.encodings[encoding].maxBitrate
2044
                         parameters.encodings[encoding].maxBitrate
2020
-                            = browser.usesPlanB()
2021
-                                ? presenterEnabled ? MAX_BITRATE : DESKSTOP_SHARE_RATE
2045
+                            = browser.usesPlanB() && videoType === VideoType.DESKTOP
2046
+                                ? presenterEnabled ? HD_BITRATE : DESKSTOP_SHARE_RATE
2022
 
2047
 
2023
                                 // In unified plan, simulcast for SS is on by default.
2048
                                 // In unified plan, simulcast for SS is on by default.
2024
                                 // When simulcast is disabled through a config.js option,
2049
                                 // When simulcast is disabled through a config.js option,
2025
                                 // we cap the bitrate on desktop and camera tracks to 2500 Kbps.
2050
                                 // we cap the bitrate on desktop and camera tracks to 2500 Kbps.
2026
                                 : this.isSimulcastOn()
2051
                                 : this.isSimulcastOn()
2027
                                     ? this.tpcUtils.simulcastEncodings[encoding].maxBitrate
2052
                                     ? this.tpcUtils.simulcastEncodings[encoding].maxBitrate
2028
-                                    : MAX_BITRATE;
2053
+                                    : HD_BITRATE;
2029
                     }
2054
                     }
2030
                 }
2055
                 }
2031
                 sender.setParameters(parameters);
2056
                 sender.setParameters(parameters);
2078
             description = this.simulcast.mungeRemoteDescription(description);
2103
             description = this.simulcast.mungeRemoteDescription(description);
2079
 
2104
 
2080
             // eslint-disable-next-line no-param-reassign
2105
             // eslint-disable-next-line no-param-reassign
2081
-            description = this.tpcUtils._insertUnifiedPlanSimulcastReceive(description);
2106
+            description = this.tpcUtils.insertUnifiedPlanSimulcastReceive(description);
2082
             this.trace(
2107
             this.trace(
2083
                 'setRemoteDescription::postTransform (sim receive)',
2108
                 'setRemoteDescription::postTransform (sim receive)',
2084
                 dumpSDP(description));
2109
                 dumpSDP(description));
2085
 
2110
 
2086
             // eslint-disable-next-line no-param-reassign
2111
             // eslint-disable-next-line no-param-reassign
2087
-            description = this.tpcUtils._ensureCorrectOrderOfSsrcs(description);
2112
+            description = this.tpcUtils.ensureCorrectOrderOfSsrcs(description);
2088
         }
2113
         }
2089
     }
2114
     }
2090
 
2115
 

+ 3
- 0
modules/qualitycontrol/QualityController.js Ver arquivo

46
 
46
 
47
         // Set the degradation preference on the local video track.
47
         // Set the degradation preference on the local video track.
48
         mediaSession.setSenderVideoDegradationPreference();
48
         mediaSession.setSenderVideoDegradationPreference();
49
+
50
+        // Set the max bitrates on video sender if they are specified in config.js videoQuality settings.
51
+        mediaSession.setSenderMaxBitrates();
49
     }
52
     }
50
 
53
 
51
     /**
54
     /**

+ 17
- 3
modules/xmpp/JingleSessionPC.js Ver arquivo

329
         }
329
         }
330
         pcOptions.capScreenshareBitrate = false;
330
         pcOptions.capScreenshareBitrate = false;
331
         pcOptions.enableInsertableStreams = options.enableInsertableStreams;
331
         pcOptions.enableInsertableStreams = options.enableInsertableStreams;
332
+        pcOptions.videoQuality = options.videoQuality;
332
 
333
 
333
         if (this.isP2P) {
334
         if (this.isP2P) {
334
             // simulcast needs to be disabled for P2P (121) calls
335
             // simulcast needs to be disabled for P2P (121) calls
1394
             IQ_TIMEOUT);
1395
             IQ_TIMEOUT);
1395
     }
1396
     }
1396
 
1397
 
1398
+    /**
1399
+     * Sets the maximum bitrates on the local video track if the current
1400
+     * session is a JVB session. Bitrate values from videoQuality settings
1401
+     * in config.js will be used for configuring the sender.
1402
+     * @returns {void}
1403
+     */
1404
+    setSenderMaxBitrates() {
1405
+        if (this._assertNotEnded() && !this.isP2P) {
1406
+            return this.peerconnection.setMaxBitRate();
1407
+        }
1408
+    }
1409
+
1397
     /**
1410
     /**
1398
      * Sets the resolution constraint on the local camera track.
1411
      * Sets the resolution constraint on the local camera track.
1399
      * @param {number} maxFrameHeight - The user preferred max frame height.
1412
      * @param {number} maxFrameHeight - The user preferred max frame height.
2071
         return this._addRemoveTrackAsMuteUnmute(
2084
         return this._addRemoveTrackAsMuteUnmute(
2072
             false /* add as unmute */, track)
2085
             false /* add as unmute */, track)
2073
             .then(() => {
2086
             .then(() => {
2074
-                // Apply the video constraints and degradation preference on
2087
+                // Apply the video constraints, max bitrates and degradation preference on
2075
                 // the video sender if needed.
2088
                 // the video sender if needed.
2076
                 if (track.isVideoTrack() && browser.doesVideoMuteByStreamRemove()) {
2089
                 if (track.isVideoTrack() && browser.doesVideoMuteByStreamRemove()) {
2077
-                    this.peerconnection.setSenderVideoDegradationPreference();
2078
-                    this.peerconnection.setSenderVideoConstraint();
2090
+                    this.setSenderMaxBitrates();
2091
+                    this.setSenderVideoDegradationPreference();
2092
+                    this.setSenderVideoConstraint();
2079
                 }
2093
                 }
2080
             });
2094
             });
2081
     }
2095
     }

Carregando…
Cancelar
Salvar