浏览代码

feat(bandwidth) send bandwidth constraints to the bridge

master
Mihaela Dumitru 2 年前
父节点
当前提交
5d7cb31f68
共有 2 个文件被更改,包括 61 次插入4 次删除
  1. 9
    0
      JitsiConference.js
  2. 52
    4
      modules/qualitycontrol/ReceiveVideoController.js

+ 9
- 0
JitsiConference.js 查看文件

3774
     this.receiveVideoController.setReceiverConstraints(videoConstraints);
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
  * Sets the maximum video size the local participant should receive from remote
3787
  * Sets the maximum video size the local participant should receive from remote
3779
  * participants.
3788
  * participants.

+ 52
- 4
modules/qualitycontrol/ReceiveVideoController.js 查看文件

7
 const logger = getLogger(__filename);
7
 const logger = getLogger(__filename);
8
 const MAX_HEIGHT = 2160;
8
 const MAX_HEIGHT = 2160;
9
 const LASTN_UNLIMITED = -1;
9
 const LASTN_UNLIMITED = -1;
10
+const ASSUMED_BANDWIDTH_BPS = -1;
10
 
11
 
11
 /**
12
 /**
12
  * This class translates the legacy signaling format between the client and the bridge (that affects bandwidth
13
  * This class translates the legacy signaling format between the client and the bridge (that affects bandwidth
15
 class ReceiverVideoConstraints {
16
 class ReceiverVideoConstraints {
16
     /**
17
     /**
17
      * Creates a new instance.
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
         // The number of videos requested from the bridge.
26
         // The number of videos requested from the bridge.
23
         this._lastN = lastN ?? LASTN_UNLIMITED;
27
         this._lastN = lastN ?? LASTN_UNLIMITED;
24
 
28
 
25
         // The number representing the maximum video height the local client should receive from the bridge/peer.
29
         // The number representing the maximum video height the local client should receive from the bridge/peer.
26
         this._maxFrameHeight = MAX_HEIGHT;
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
         this._receiverVideoConstraints = {
35
         this._receiverVideoConstraints = {
36
+            assumedBandwidthBps: this._assumedBandwidthBps,
29
             constraints: {},
37
             constraints: {},
30
             defaultConstraints: { 'maxHeight': this._maxFrameHeight },
38
             defaultConstraints: { 'maxHeight': this._maxFrameHeight },
31
             lastN: this._lastN
39
             lastN: this._lastN
36
      * Returns the receiver video constraints that need to be sent on the bridge channel or to the remote peer.
44
      * Returns the receiver video constraints that need to be sent on the bridge channel or to the remote peer.
37
      */
45
      */
38
     get constraints() {
46
     get constraints() {
47
+        this._receiverVideoConstraints.assumedBandwidthBps = this._assumedBandwidthBps;
39
         this._receiverVideoConstraints.lastN = this._lastN;
48
         this._receiverVideoConstraints.lastN = this._lastN;
40
         if (Object.keys(this._receiverVideoConstraints.constraints)?.length) {
49
         if (Object.keys(this._receiverVideoConstraints.constraints)?.length) {
41
             /* eslint-disable no-unused-vars */
50
             /* eslint-disable no-unused-vars */
49
         return this._receiverVideoConstraints;
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
      * Updates the lastN field of the ReceiverVideoConstraints sent to the bridge.
80
      * Updates the lastN field of the ReceiverVideoConstraints sent to the bridge.
54
      *
81
      *
133
          */
160
          */
134
         this._sourceReceiverConstraints = new Map();
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
         // The default receiver video constraints.
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
         this._conference.on(
174
         this._conference.on(
140
             JitsiConferenceEvents._MEDIA_SESSION_STARTED,
175
             JitsiConferenceEvents._MEDIA_SESSION_STARTED,
185
         return this._lastN;
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
      * Selects a new value for "lastN". The requested amount of videos are going to be delivered after the value is
236
      * Selects a new value for "lastN". The requested amount of videos are going to be delivered after the value is
190
      * in effect. Set to -1 for unlimited or all available videos.
237
      * in effect. Set to -1 for unlimited or all available videos.
238
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
285
         const constraintsChanged = this._receiverVideoConstraints.updateReceiverVideoConstraints(constraints);
239
 
286
 
240
         if (constraintsChanged) {
287
         if (constraintsChanged) {
288
+            this._assumedBandwidthBps = constraints.assumedBandwidthBps ?? this._assumedBandwidthBps;
241
             this._lastN = constraints.lastN ?? this._lastN;
289
             this._lastN = constraints.lastN ?? this._lastN;
242
 
290
 
243
             // Send the contraints on the bridge channel.
291
             // Send the contraints on the bridge channel.

正在加载...
取消
保存