瀏覽代碼

change connection quality to take layer suspension into account (#762)

* change connection quality to take layer suspension into account
master
bbaldino 6 年之前
父節點
當前提交
733b105a7d
共有 2 個文件被更改,包括 50 次插入4 次删除
  1. 11
    0
      modules/RTC/BandwidthLimiter.js
  2. 39
    4
      modules/connectivity/ConnectionQuality.js

+ 11
- 0
modules/RTC/BandwidthLimiter.js 查看文件

40
         this._bandwidthLimits.set(mediaType, limitKbps);
40
         this._bandwidthLimits.set(mediaType, limitKbps);
41
     }
41
     }
42
 
42
 
43
+    /**
44
+     * Get the current bandwidth limit
45
+     * @param {String} mediaType the mline media type for which to get the
46
+     * bandwidth limit
47
+     * @return {Number} the bandwidth limit in kbps if it exists, undefined
48
+     * otherwise
49
+     */
50
+    getBandwidthLimit(mediaType) {
51
+        return this._bandwidthLimits.get(mediaType);
52
+    }
53
+
43
     /**
54
     /**
44
      * Enforce any configured bandwidth limits (or lack thereof) in the given
55
      * Enforce any configured bandwidth limits (or lack thereof) in the given
45
      * sdp
56
      * sdp

+ 39
- 4
modules/connectivity/ConnectionQuality.js 查看文件

69
  */
69
  */
70
 let startBitrate = 800;
70
 let startBitrate = 800;
71
 
71
 
72
+
73
+/**
74
+ * The current cap (in kbps) put on the video stream (or null if there isn't
75
+ * a cap).  If there is a cap, we'll take it into account when calculating
76
+ * the current quality.
77
+ */
78
+let videoBitrateCap = null;
79
+
72
 /**
80
 /**
73
  * Gets the expected bitrate (in kbps) in perfect network conditions.
81
  * Gets the expected bitrate (in kbps) in perfect network conditions.
74
  * @param simulcast {boolean} whether simulcast is enabled or not.
82
  * @param simulcast {boolean} whether simulcast is enabled or not.
196
          */
204
          */
197
         this._timeVideoUnmuted = -1;
205
         this._timeVideoUnmuted = -1;
198
 
206
 
207
+        /**
208
+         * The time at which a video bitrate cap was last removed.  We use
209
+         * this to calculate how much time we, as a sender, have had to
210
+         * ramp-up
211
+         */
212
+        this._timeLastBwCapRemoved = -1;
199
 
213
 
200
         // We assume a global startBitrate value for the sake of simplicity.
214
         // We assume a global startBitrate value for the sake of simplicity.
201
         if (options.startBitrate && options.startBitrate > 0) {
215
         if (options.startBitrate && options.startBitrate > 0) {
343
         } else {
357
         } else {
344
             // Calculate a value based on the sending bitrate.
358
             // Calculate a value based on the sending bitrate.
345
 
359
 
346
-            // time since sending of video was enabled.
347
-            const millisSinceStart = window.performance.now()
348
-                    - Math.max(this._timeVideoUnmuted, this._timeIceConnected);
349
-
350
             // Figure out if simulcast is in use
360
             // Figure out if simulcast is in use
351
             const activeTPC = this._conference.getActivePeerConnection();
361
             const activeTPC = this._conference.getActivePeerConnection();
352
             const isSimulcastOn
362
             const isSimulcastOn
353
                 = Boolean(activeTPC && activeTPC.isSimulcastOn());
363
                 = Boolean(activeTPC && activeTPC.isSimulcastOn());
354
 
364
 
365
+            const newVideoBitrateCap
366
+                = activeTPC && activeTPC.bandwidthLimiter
367
+                && activeTPC.bandwidthLimiter.getBandwidthLimit('video');
368
+
369
+            // If we had a cap set but there isn't one now, then it has
370
+            // just been 'lifted', so we should treat this like a new
371
+            // ramp up.
372
+            if (!newVideoBitrateCap && videoBitrateCap) {
373
+                this._timeLastBwCapRemoved = window.performance.now();
374
+
375
+                // Set the start bitrate to whatever we were just capped to
376
+                startBitrate = videoBitrateCap;
377
+            }
378
+            videoBitrateCap = newVideoBitrateCap;
379
+
380
+            // time since sending of video was enabled.
381
+            const millisSinceStart = window.performance.now()
382
+                - Math.max(this._timeVideoUnmuted,
383
+                    this._timeIceConnected,
384
+                    this._timeLastBwCapRemoved);
385
+
355
             // expected sending bitrate in perfect conditions
386
             // expected sending bitrate in perfect conditions
356
             let target
387
             let target
357
                 = getTarget(isSimulcastOn, resolution, millisSinceStart);
388
                 = getTarget(isSimulcastOn, resolution, millisSinceStart);
358
 
389
 
359
             target = Math.min(0.9 * target, MAX_TARGET_BITRATE);
390
             target = Math.min(0.9 * target, MAX_TARGET_BITRATE);
360
 
391
 
392
+            if (videoBitrateCap) {
393
+                target = Math.min(target, videoBitrateCap);
394
+            }
395
+
361
             quality = 100 * this._localStats.bitrate.upload / target;
396
             quality = 100 * this._localStats.bitrate.upload / target;
362
 
397
 
363
             // Whatever the bitrate, drop early if there is significant loss
398
             // Whatever the bitrate, drop early if there is significant loss

Loading…
取消
儲存