浏览代码

feat(RTC): Add the ability to change desktop share fps.

Provide a method for changing the capture fps for desktop tracks during the call. These changes to the lib are needed for making it configurable from the UI.
dev1
Jaya Allamsetty 3 年前
父节点
当前提交
a13f4adeff
共有 5 个文件被更改,包括 79 次插入8 次删除
  1. 21
    0
      JitsiConference.js
  2. 9
    1
      modules/RTC/RTC.js
  3. 10
    0
      modules/RTC/RTCUtils.js
  4. 15
    0
      modules/RTC/ScreenObtainer.js
  5. 24
    7
      modules/RTC/TraceablePeerConnection.js

+ 21
- 0
JitsiConference.js 查看文件

@@ -3406,6 +3406,27 @@ JitsiConference.prototype.getP2PConnectionState = function() {
3406 3406
     return null;
3407 3407
 };
3408 3408
 
3409
+/**
3410
+ * Configures the peerconnection so that a given framre rate can be achieved for desktop share.
3411
+ *
3412
+ * @param {number} maxFps The capture framerate to be used for desktop tracks.
3413
+ * @returns {boolean} true if the operation is successful, false otherwise.
3414
+ */
3415
+JitsiConference.prototype.setDesktopSharingFrameRate = function(maxFps) {
3416
+    if (typeof maxFps !== 'number' || isNaN(maxFps)) {
3417
+        logger.error(`Invalid value ${maxFps} specified for desktop capture frame rate`);
3418
+
3419
+        return false;
3420
+    }
3421
+
3422
+    // Enable or disable simulcast for plan-b screensharing based on the capture fps.
3423
+    this.jvbJingleSession && this.jvbJingleSession.peerconnection.setDesktopSharingFrameRate(maxFps);
3424
+
3425
+    // Set the capture rate for desktop sharing.
3426
+    this.rtc.setDesktopSharingFrameRate(maxFps);
3427
+
3428
+    return true;
3429
+};
3409 3430
 
3410 3431
 /**
3411 3432
  * Manually starts new P2P session (should be used only in the tests).

+ 9
- 1
modules/RTC/RTC.js 查看文件

@@ -209,7 +209,6 @@ export default class RTC extends Listenable {
209 209
     static obtainAudioAndVideoPermissions(options) {
210 210
         return RTCUtils.obtainAudioAndVideoPermissions(options)
211 211
             .then(tracksInfo => _createLocalTracks(tracksInfo));
212
-
213 212
     }
214 213
 
215 214
     /**
@@ -330,6 +329,15 @@ export default class RTC extends Listenable {
330 329
         }
331 330
     }
332 331
 
332
+    /**
333
+     * Sets the capture frame rate to be used for desktop tracks.
334
+     *
335
+     * @param {number} maxFps framerate to be used for desktop track capture.
336
+     */
337
+    setDesktopSharingFrameRate(maxFps) {
338
+        RTCUtils.setDesktopSharingFrameRate(maxFps);
339
+    }
340
+
333 341
     /**
334 342
      * Sets the receiver video constraints that determine how bitrate is allocated to each of the video streams
335 343
      * requested from the bridge. The constraints are cached and sent through the bridge channel once the channel

+ 10
- 0
modules/RTC/RTCUtils.js 查看文件

@@ -832,6 +832,16 @@ class RTCUtils extends Listenable {
832 832
             });
833 833
     }
834 834
 
835
+    /**
836
+     * Sets the capture frame rate for desktop tracks.
837
+     *
838
+     * @param {number} maxFps - max fps to be used as the capture frame rate.
839
+     * @returns {void}
840
+     */
841
+    setDesktopSharingFrameRate(maxFps) {
842
+        screenObtainer.setDesktopSharingFrameRate(maxFps);
843
+    }
844
+
835 845
     /**
836 846
      * Returns currently used audio output device id, '' stands for default
837 847
      * device

+ 15
- 0
modules/RTC/ScreenObtainer.js 查看文件

@@ -276,6 +276,21 @@ const ScreenObtainer = {
276 276
                 errorCallback(new JitsiTrackError(JitsiTrackErrors
277 277
                     .SCREENSHARING_USER_CANCELED));
278 278
             });
279
+    },
280
+
281
+    /**
282
+     * Sets the max frame rate to be used for a desktop track capture.
283
+     *
284
+     * @param {number} maxFps capture frame rate to be used for desktop tracks.
285
+     * @returns {void}
286
+     */
287
+    setDesktopSharingFrameRate(maxFps) {
288
+        logger.info(`Setting the desktop capture rate to ${maxFps}`);
289
+
290
+        this.options.desktopSharingFrameRate = {
291
+            min: SS_DEFAULT_FRAME_RATE,
292
+            max: maxFps
293
+        };
279 294
     }
280 295
 };
281 296
 

+ 24
- 7
modules/RTC/TraceablePeerConnection.js 查看文件

@@ -10,6 +10,7 @@ import * as MediaType from '../../service/RTC/MediaType';
10 10
 import RTCEvents from '../../service/RTC/RTCEvents';
11 11
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
12 12
 import * as VideoType from '../../service/RTC/VideoType';
13
+import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
13 14
 import browser from '../browser';
14 15
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
15 16
 import RtxModifier from '../sdp/RtxModifier';
@@ -243,6 +244,11 @@ export default function TraceablePeerConnection(
243 244
     this.stats = {};
244 245
     this.statsinterval = null;
245 246
 
247
+    /**
248
+     * Flag used to indicate if simulcast is turned off and a cap of 500 Kbps is applied on screensharing.
249
+     */
250
+    this._capScreenshareBitrate = this.options.capScreenshareBitrate;
251
+
246 252
     /**
247 253
     * Flag used to indicate if the browser is running in unified  plan mode.
248 254
     */
@@ -1841,6 +1847,17 @@ TraceablePeerConnection.prototype.getConfiguredVideoCodec = function() {
1841 1847
     return defaultCodec;
1842 1848
 };
1843 1849
 
1850
+/**
1851
+ * Enables or disables simulcast for screenshare based on the frame rate requested for desktop track capture.
1852
+ *
1853
+ * @param {number} maxFps framerate to be used for desktop track capture.
1854
+ */
1855
+TraceablePeerConnection.prototype.setDesktopSharingFrameRate = function(maxFps) {
1856
+    const lowFps = maxFps <= SS_DEFAULT_FRAME_RATE;
1857
+
1858
+    this._capScreenshareBitrate = this.isSimulcastOn() && lowFps && !this._usesUnifiedPlan;
1859
+};
1860
+
1844 1861
 /**
1845 1862
  * Sets the codec preference on the peerconnection. The codec preference goes into effect when
1846 1863
  * the next renegotiation happens.
@@ -2296,7 +2313,7 @@ TraceablePeerConnection.prototype.setSenderVideoDegradationPreference = function
2296 2313
     const parameters = videoSender.getParameters();
2297 2314
     const preference = localVideoTrack.videoType === VideoType.CAMERA
2298 2315
         ? DEGRADATION_PREFERENCE_CAMERA
2299
-        : this.options.capScreenshareBitrate && !this._usesUnifiedPlan
2316
+        : this._capScreenshareBitrate && !this._usesUnifiedPlan
2300 2317
 
2301 2318
             // Prefer resolution for low fps share.
2302 2319
             ? DEGRADATION_PREFERENCE_DESKTOP
@@ -2340,7 +2357,7 @@ TraceablePeerConnection.prototype.setMaxBitRate = function() {
2340 2357
     // 2. Track is a desktop track and bitrate is capped using capScreenshareBitrate option in plan-b mode.
2341 2358
     // 3. The client is running in Unified plan mode.
2342 2359
     if (!((this.options.videoQuality && this.options.videoQuality.maxBitratesVideo)
2343
-        || (planBScreenSharing && this.options.capScreenshareBitrate)
2360
+        || (planBScreenSharing && this._capScreenshareBitrate)
2344 2361
         || this._usesUnifiedPlan)) {
2345 2362
         return Promise.resolve();
2346 2363
     }
@@ -2368,7 +2385,7 @@ TraceablePeerConnection.prototype.setMaxBitRate = function() {
2368 2385
                     // is enabled through config.js and presenter is not turned on.
2369 2386
                     // FIXME the top 'isSimulcastOn' condition is confusing for screensharing, because
2370 2387
                     // if capScreenshareBitrate option is enabled then the simulcast is turned off
2371
-                    bitrate = this.options.capScreenshareBitrate
2388
+                    bitrate = this._capScreenshareBitrate
2372 2389
                         ? presenterEnabled ? HD_BITRATE : DESKTOP_SHARE_RATE
2373 2390
 
2374 2391
                         // Remove the bitrate config if not capScreenshareBitrate:
@@ -2779,8 +2796,8 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
2779 2796
             // Configure simulcast for camera tracks always and for desktop tracks only when
2780 2797
             // the "capScreenshareBitrate" flag in config.js is disabled.
2781 2798
             if (this.isSimulcastOn() && browser.usesSdpMungingForSimulcast()
2782
-                && (!this.options.capScreenshareBitrate
2783
-                || (this.options.capScreenshareBitrate && !this._isSharingScreen()))) {
2799
+                && (!this._capScreenshareBitrate
2800
+                || (this._capScreenshareBitrate && !this._isSharingScreen()))) {
2784 2801
                 // eslint-disable-next-line no-param-reassign
2785 2802
                 resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
2786 2803
                 this.trace(
@@ -2983,8 +3000,8 @@ TraceablePeerConnection.prototype.generateNewStreamSSRCInfo = function(track) {
2983 3000
     // Configure simulcast for camera tracks always and for desktop tracks only when
2984 3001
     // the "capScreenshareBitrate" flag in config.js is disabled.
2985 3002
     if (this.isSimulcastOn()
2986
-        && (!this.options.capScreenshareBitrate
2987
-        || (this.options.capScreenshareBitrate && !this._isSharingScreen()))) {
3003
+        && (!this._capScreenshareBitrate
3004
+        || (this._capScreenshareBitrate && !this._isSharingScreen()))) {
2988 3005
         ssrcInfo = {
2989 3006
             ssrcs: [],
2990 3007
             groups: []

正在加载...
取消
保存