Browse Source

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 years ago
parent
commit
a13f4adeff

+ 21
- 0
JitsiConference.js View File

3406
     return null;
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
  * Manually starts new P2P session (should be used only in the tests).
3432
  * Manually starts new P2P session (should be used only in the tests).

+ 9
- 1
modules/RTC/RTC.js View File

209
     static obtainAudioAndVideoPermissions(options) {
209
     static obtainAudioAndVideoPermissions(options) {
210
         return RTCUtils.obtainAudioAndVideoPermissions(options)
210
         return RTCUtils.obtainAudioAndVideoPermissions(options)
211
             .then(tracksInfo => _createLocalTracks(tracksInfo));
211
             .then(tracksInfo => _createLocalTracks(tracksInfo));
212
-
213
     }
212
     }
214
 
213
 
215
     /**
214
     /**
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
      * Sets the receiver video constraints that determine how bitrate is allocated to each of the video streams
342
      * Sets the receiver video constraints that determine how bitrate is allocated to each of the video streams
335
      * requested from the bridge. The constraints are cached and sent through the bridge channel once the channel
343
      * requested from the bridge. The constraints are cached and sent through the bridge channel once the channel

+ 10
- 0
modules/RTC/RTCUtils.js View File

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
      * Returns currently used audio output device id, '' stands for default
846
      * Returns currently used audio output device id, '' stands for default
837
      * device
847
      * device

+ 15
- 0
modules/RTC/ScreenObtainer.js View File

276
                 errorCallback(new JitsiTrackError(JitsiTrackErrors
276
                 errorCallback(new JitsiTrackError(JitsiTrackErrors
277
                     .SCREENSHARING_USER_CANCELED));
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 View File

10
 import RTCEvents from '../../service/RTC/RTCEvents';
10
 import RTCEvents from '../../service/RTC/RTCEvents';
11
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
11
 import * as SignalingEvents from '../../service/RTC/SignalingEvents';
12
 import * as VideoType from '../../service/RTC/VideoType';
12
 import * as VideoType from '../../service/RTC/VideoType';
13
+import { SS_DEFAULT_FRAME_RATE } from '../RTC/ScreenObtainer';
13
 import browser from '../browser';
14
 import browser from '../browser';
14
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
15
 import LocalSdpMunger from '../sdp/LocalSdpMunger';
15
 import RtxModifier from '../sdp/RtxModifier';
16
 import RtxModifier from '../sdp/RtxModifier';
243
     this.stats = {};
244
     this.stats = {};
244
     this.statsinterval = null;
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
     * Flag used to indicate if the browser is running in unified  plan mode.
253
     * Flag used to indicate if the browser is running in unified  plan mode.
248
     */
254
     */
1841
     return defaultCodec;
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
  * Sets the codec preference on the peerconnection. The codec preference goes into effect when
1862
  * Sets the codec preference on the peerconnection. The codec preference goes into effect when
1846
  * the next renegotiation happens.
1863
  * the next renegotiation happens.
2296
     const parameters = videoSender.getParameters();
2313
     const parameters = videoSender.getParameters();
2297
     const preference = localVideoTrack.videoType === VideoType.CAMERA
2314
     const preference = localVideoTrack.videoType === VideoType.CAMERA
2298
         ? DEGRADATION_PREFERENCE_CAMERA
2315
         ? DEGRADATION_PREFERENCE_CAMERA
2299
-        : this.options.capScreenshareBitrate && !this._usesUnifiedPlan
2316
+        : this._capScreenshareBitrate && !this._usesUnifiedPlan
2300
 
2317
 
2301
             // Prefer resolution for low fps share.
2318
             // Prefer resolution for low fps share.
2302
             ? DEGRADATION_PREFERENCE_DESKTOP
2319
             ? DEGRADATION_PREFERENCE_DESKTOP
2340
     // 2. Track is a desktop track and bitrate is capped using capScreenshareBitrate option in plan-b mode.
2357
     // 2. Track is a desktop track and bitrate is capped using capScreenshareBitrate option in plan-b mode.
2341
     // 3. The client is running in Unified plan mode.
2358
     // 3. The client is running in Unified plan mode.
2342
     if (!((this.options.videoQuality && this.options.videoQuality.maxBitratesVideo)
2359
     if (!((this.options.videoQuality && this.options.videoQuality.maxBitratesVideo)
2343
-        || (planBScreenSharing && this.options.capScreenshareBitrate)
2360
+        || (planBScreenSharing && this._capScreenshareBitrate)
2344
         || this._usesUnifiedPlan)) {
2361
         || this._usesUnifiedPlan)) {
2345
         return Promise.resolve();
2362
         return Promise.resolve();
2346
     }
2363
     }
2368
                     // is enabled through config.js and presenter is not turned on.
2385
                     // is enabled through config.js and presenter is not turned on.
2369
                     // FIXME the top 'isSimulcastOn' condition is confusing for screensharing, because
2386
                     // FIXME the top 'isSimulcastOn' condition is confusing for screensharing, because
2370
                     // if capScreenshareBitrate option is enabled then the simulcast is turned off
2387
                     // if capScreenshareBitrate option is enabled then the simulcast is turned off
2371
-                    bitrate = this.options.capScreenshareBitrate
2388
+                    bitrate = this._capScreenshareBitrate
2372
                         ? presenterEnabled ? HD_BITRATE : DESKTOP_SHARE_RATE
2389
                         ? presenterEnabled ? HD_BITRATE : DESKTOP_SHARE_RATE
2373
 
2390
 
2374
                         // Remove the bitrate config if not capScreenshareBitrate:
2391
                         // Remove the bitrate config if not capScreenshareBitrate:
2779
             // Configure simulcast for camera tracks always and for desktop tracks only when
2796
             // Configure simulcast for camera tracks always and for desktop tracks only when
2780
             // the "capScreenshareBitrate" flag in config.js is disabled.
2797
             // the "capScreenshareBitrate" flag in config.js is disabled.
2781
             if (this.isSimulcastOn() && browser.usesSdpMungingForSimulcast()
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
                 // eslint-disable-next-line no-param-reassign
2801
                 // eslint-disable-next-line no-param-reassign
2785
                 resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
2802
                 resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
2786
                 this.trace(
2803
                 this.trace(
2983
     // Configure simulcast for camera tracks always and for desktop tracks only when
3000
     // Configure simulcast for camera tracks always and for desktop tracks only when
2984
     // the "capScreenshareBitrate" flag in config.js is disabled.
3001
     // the "capScreenshareBitrate" flag in config.js is disabled.
2985
     if (this.isSimulcastOn()
3002
     if (this.isSimulcastOn()
2986
-        && (!this.options.capScreenshareBitrate
2987
-        || (this.options.capScreenshareBitrate && !this._isSharingScreen()))) {
3003
+        && (!this._capScreenshareBitrate
3004
+        || (this._capScreenshareBitrate && !this._isSharingScreen()))) {
2988
         ssrcInfo = {
3005
         ssrcInfo = {
2989
             ssrcs: [],
3006
             ssrcs: [],
2990
             groups: []
3007
             groups: []

Loading…
Cancel
Save