Browse Source

feat(bandwidth) send bandwidth constraints to the bridge

master
Mihaela Dumitru 2 years ago
parent
commit
5d7cb31f68
2 changed files with 61 additions and 4 deletions
  1. 9
    0
      JitsiConference.js
  2. 52
    4
      modules/qualitycontrol/ReceiveVideoController.js

+ 9
- 0
JitsiConference.js View File

@@ -3774,6 +3774,15 @@ JitsiConference.prototype.setReceiverConstraints = function(videoConstraints) {
3774 3774
     this.receiveVideoController.setReceiverConstraints(videoConstraints);
3775 3775
 };
3776 3776
 
3777
+/**
3778
+ * Sets the assumed bandwidth bps for the video that is requested from the bridge.
3779
+ *
3780
+ * @param {Number} assumedBandwidthBps - The bandwidth value expressed in bits per second.
3781
+ */
3782
+JitsiConference.prototype.setAssumedBandwidthBps = function(assumedBandwidthBps) {
3783
+    this.receiveVideoController.setAssumedBandwidthBps(assumedBandwidthBps);
3784
+};
3785
+
3777 3786
 /**
3778 3787
  * Sets the maximum video size the local participant should receive from remote
3779 3788
  * participants.

+ 52
- 4
modules/qualitycontrol/ReceiveVideoController.js View File

@@ -7,6 +7,7 @@ import { MediaType } from '../../service/RTC/MediaType';
7 7
 const logger = getLogger(__filename);
8 8
 const MAX_HEIGHT = 2160;
9 9
 const LASTN_UNLIMITED = -1;
10
+const ASSUMED_BANDWIDTH_BPS = -1;
10 11
 
11 12
 /**
12 13
  * This class translates the legacy signaling format between the client and the bridge (that affects bandwidth
@@ -15,17 +16,24 @@ const LASTN_UNLIMITED = -1;
15 16
 class ReceiverVideoConstraints {
16 17
     /**
17 18
      * Creates a new instance.
18
-     *
19
-     * @param {number} lastN - Number of videos to be requested from the bridge.
19
+     * @param {Object} options - The instance options:
20
+     * - lastN: Number of videos to be requested from the bridge.
21
+     * - assumedBandwidthBps: Number of bps to be requested from the bridge.
20 22
      */
21
-    constructor(lastN) {
23
+    constructor(options) {
24
+        const { lastN, assumedBandwidthBps } = options;
25
+
22 26
         // The number of videos requested from the bridge.
23 27
         this._lastN = lastN ?? LASTN_UNLIMITED;
24 28
 
25 29
         // The number representing the maximum video height the local client should receive from the bridge/peer.
26 30
         this._maxFrameHeight = MAX_HEIGHT;
27 31
 
32
+        // The number representing the assumed count of bps the local client should receive from the bridge.
33
+        this._assumedBandwidthBps = assumedBandwidthBps ?? ASSUMED_BANDWIDTH_BPS;
34
+
28 35
         this._receiverVideoConstraints = {
36
+            assumedBandwidthBps: this._assumedBandwidthBps,
29 37
             constraints: {},
30 38
             defaultConstraints: { 'maxHeight': this._maxFrameHeight },
31 39
             lastN: this._lastN
@@ -36,6 +44,7 @@ class ReceiverVideoConstraints {
36 44
      * Returns the receiver video constraints that need to be sent on the bridge channel or to the remote peer.
37 45
      */
38 46
     get constraints() {
47
+        this._receiverVideoConstraints.assumedBandwidthBps = this._assumedBandwidthBps;
39 48
         this._receiverVideoConstraints.lastN = this._lastN;
40 49
         if (Object.keys(this._receiverVideoConstraints.constraints)?.length) {
41 50
             /* eslint-disable no-unused-vars */
@@ -49,6 +58,24 @@ class ReceiverVideoConstraints {
49 58
         return this._receiverVideoConstraints;
50 59
     }
51 60
 
61
+
62
+    /**
63
+     * Updates the assumed bandwidth bps of the ReceiverVideoConstraints sent to the bridge.
64
+     *
65
+     * @param {number} assumedBandwidthBps
66
+     * @requires {boolean} Returns true if the the value has been updated, false otherwise.
67
+     */
68
+    updateAssumedBandwidthBps(assumedBandwidthBps) {
69
+        const changed = this._assumedBandwidthBps !== assumedBandwidthBps;
70
+
71
+        if (changed) {
72
+            this._assumedBandwidthBps = assumedBandwidthBps;
73
+            logger.debug(`Updating receive assumedBandwidthBps: ${assumedBandwidthBps}`);
74
+        }
75
+
76
+        return changed;
77
+    }
78
+
52 79
     /**
53 80
      * Updates the lastN field of the ReceiverVideoConstraints sent to the bridge.
54 81
      *
@@ -133,8 +160,16 @@ export default class ReceiveVideoController {
133 160
          */
134 161
         this._sourceReceiverConstraints = new Map();
135 162
 
163
+        /**
164
+         * The number of bps requested from the bridge.
165
+         */
166
+        this._assumedBandwidthBps = ASSUMED_BANDWIDTH_BPS;
167
+
136 168
         // The default receiver video constraints.
137
-        this._receiverVideoConstraints = new ReceiverVideoConstraints(this._lastN);
169
+        this._receiverVideoConstraints = new ReceiverVideoConstraints({
170
+            lastN: this._lastN,
171
+            assumedBandwidthBps: this._assumedBandwidthBps
172
+        });
138 173
 
139 174
         this._conference.on(
140 175
             JitsiConferenceEvents._MEDIA_SESSION_STARTED,
@@ -185,6 +220,18 @@ export default class ReceiveVideoController {
185 220
         return this._lastN;
186 221
     }
187 222
 
223
+    /**
224
+     * Sets the assumed bandwidth bps the local participant should receive from remote participants.
225
+     *
226
+     * @param {number|undefined} assumedBandwidthBps - the new value.
227
+     * @returns {void}
228
+     */
229
+    setAssumedBandwidthBps(assumedBandwidthBps) {
230
+        if (this._receiverVideoConstraints.updateAssumedBandwidthBps(assumedBandwidthBps)) {
231
+            this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
232
+        }
233
+    }
234
+
188 235
     /**
189 236
      * Selects a new value for "lastN". The requested amount of videos are going to be delivered after the value is
190 237
      * in effect. Set to -1 for unlimited or all available videos.
@@ -238,6 +285,7 @@ export default class ReceiveVideoController {
238 285
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
239 286
 
240 287
         if (constraintsChanged) {
288
+            this._assumedBandwidthBps = constraints.assumedBandwidthBps ?? this._assumedBandwidthBps;
241 289
             this._lastN = constraints.lastN ?? this._lastN;
242 290
 
243 291
             // Send the contraints on the bridge channel.

Loading…
Cancel
Save