瀏覽代碼

ref: Add a function to check if screen sharing is in progress.

Make sure screenshare w/ presenter gets the full 2500 Kbps bitrate.
dev1
Jaya Allamsetty 4 年之前
父節點
當前提交
77978f0e62
共有 1 個檔案被更改,包括 20 行新增23 行删除
  1. 20
    23
      modules/RTC/TraceablePeerConnection.js

+ 20
- 23
modules/RTC/TraceablePeerConnection.js 查看文件

1493
     return this.localSSRCs.get(rtcId);
1493
     return this.localSSRCs.get(rtcId);
1494
 };
1494
 };
1495
 
1495
 
1496
+/**
1497
+ * Checks if screensharing is in progress.
1498
+ *
1499
+ * @returns {boolean}  Returns true if a desktop track has been added to the
1500
+ * peerconnection, false otherwise.
1501
+ */
1502
+TraceablePeerConnection.prototype._isSharingScreen = function() {
1503
+    const track = this.getLocalVideoTrack();
1504
+
1505
+    return track && track.videoType === VideoType.DESKTOP;
1506
+};
1507
+
1496
 /**
1508
 /**
1497
  * Munges the order of the codecs in the SDP passed based on the preference
1509
  * Munges the order of the codecs in the SDP passed based on the preference
1498
  * set through config.js settings. All instances of the specified codec are
1510
  * set through config.js settings. All instances of the specified codec are
1526
         // as soon as the browser switches to VP9.
1538
         // as soon as the browser switches to VP9.
1527
         if (this.codecPreference.mimeType === CodecMimeType.VP9) {
1539
         if (this.codecPreference.mimeType === CodecMimeType.VP9) {
1528
             const bitrates = Object.values(this.videoBitrates.VP9 || this.videoBitrates);
1540
             const bitrates = Object.values(this.videoBitrates.VP9 || this.videoBitrates);
1529
-            const localVideoTrack = this.getLocalVideoTrack();
1530
-            const isSharingScreen = localVideoTrack && localVideoTrack.videoType === VideoType.DESKTOP;
1531
 
1541
 
1532
             // Use only the HD bitrate for now as there is no API available yet for configuring
1542
             // Use only the HD bitrate for now as there is no API available yet for configuring
1533
             // the bitrates on the individual SVC layers.
1543
             // the bitrates on the individual SVC layers.
1534
             mLine.bandwidth = [ {
1544
             mLine.bandwidth = [ {
1535
                 type: 'AS',
1545
                 type: 'AS',
1536
-                limit: isSharingScreen ? HD_BITRATE : Math.floor(bitrates[2] / 1000)
1546
+                limit: this._isSharingScreen() ? HD_BITRATE : Math.floor(bitrates[2] / 1000)
1537
             } ];
1547
             } ];
1538
         }
1548
         }
1539
     } else {
1549
     } else {
2182
                     // FIXME the top 'isSimulcastOn' condition is confusing for screensharing, because
2192
                     // FIXME the top 'isSimulcastOn' condition is confusing for screensharing, because
2183
                     // if capScreenshareBitrate option is enabled then the simulcast is turned off
2193
                     // if capScreenshareBitrate option is enabled then the simulcast is turned off
2184
                     bitrate = this.options.capScreenshareBitrate
2194
                     bitrate = this.options.capScreenshareBitrate
2185
-                        ? presenterEnabled ? this.videoBitrates.high : DESKTOP_SHARE_RATE
2195
+                        ? presenterEnabled ? HD_BITRATE : DESKTOP_SHARE_RATE
2186
 
2196
 
2187
                         // Remove the bitrate config if not capScreenshareBitrate:
2197
                         // Remove the bitrate config if not capScreenshareBitrate:
2188
                         // When switching from camera to desktop and videoQuality.maxBitratesVideo were set,
2198
                         // When switching from camera to desktop and videoQuality.maxBitratesVideo were set,
2549
     return this._createOfferOrAnswer(true /* offer */, constraints);
2559
     return this._createOfferOrAnswer(true /* offer */, constraints);
2550
 };
2560
 };
2551
 
2561
 
2552
-/**
2553
- * Checks if a camera track has been added to the peerconnection
2554
- * @param {TraceablePeerConnection} peerConnection
2555
- * @return {boolean} <tt>true</tt> if the peerconnection has
2556
- * a camera track for its video source <tt>false</tt> otherwise.
2557
- */
2558
-function hasCameraTrack(peerConnection) {
2559
-    return peerConnection.getLocalTracks()
2560
-        .some(t => t.videoType === 'camera');
2561
-}
2562
-
2563
 TraceablePeerConnection.prototype._createOfferOrAnswer = function(
2562
 TraceablePeerConnection.prototype._createOfferOrAnswer = function(
2564
         isOffer,
2563
         isOffer,
2565
         constraints) {
2564
         constraints) {
2593
                     dumpSDP(resultSdp));
2592
                     dumpSDP(resultSdp));
2594
             }
2593
             }
2595
 
2594
 
2596
-            // configure simulcast for camera tracks always and for
2597
-            // desktop tracks only when the testing flag for maxbitrates
2598
-            // in config.js is disabled.
2595
+            // Configure simulcast for camera tracks always and for desktop tracks only when
2596
+            // the "capScreenshareBitrate" flag in config.js is disabled.
2599
             if (this.isSimulcastOn() && browser.usesSdpMungingForSimulcast()
2597
             if (this.isSimulcastOn() && browser.usesSdpMungingForSimulcast()
2600
                 && (!this.options.capScreenshareBitrate
2598
                 && (!this.options.capScreenshareBitrate
2601
-                || (this.options.capScreenshareBitrate && hasCameraTrack(this)))) {
2599
+                || (this.options.capScreenshareBitrate && !this._isSharingScreen()))) {
2602
                 // eslint-disable-next-line no-param-reassign
2600
                 // eslint-disable-next-line no-param-reassign
2603
                 resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
2601
                 resultSdp = this.simulcast.mungeLocalDescription(resultSdp);
2604
                 this.trace(
2602
                 this.trace(
2783
         logger.error(`Will overwrite local SSRCs for track ID: ${rtcId}`);
2781
         logger.error(`Will overwrite local SSRCs for track ID: ${rtcId}`);
2784
     }
2782
     }
2785
 
2783
 
2786
-    // configure simulcast for camera tracks always and for
2787
-    // desktop tracks only when the testing flag for maxbitrates
2788
-    // in config.js is disabled.
2784
+    // Configure simulcast for camera tracks always and for desktop tracks only when
2785
+    // the "capScreenshareBitrate" flag in config.js is disabled.
2789
     if (this.isSimulcastOn()
2786
     if (this.isSimulcastOn()
2790
         && (!this.options.capScreenshareBitrate
2787
         && (!this.options.capScreenshareBitrate
2791
-        || (this.options.capScreenshareBitrate && hasCameraTrack(this)))) {
2788
+        || (this.options.capScreenshareBitrate && !this._isSharingScreen()))) {
2792
         ssrcInfo = {
2789
         ssrcInfo = {
2793
             ssrcs: [],
2790
             ssrcs: [],
2794
             groups: []
2791
             groups: []

Loading…
取消
儲存