|
@@ -5,8 +5,7 @@ import * as JitsiConferenceEvents from '../../JitsiConferenceEvents';
|
5
|
5
|
import { MediaType } from '../../service/RTC/MediaType';
|
6
|
6
|
|
7
|
7
|
const logger = getLogger(__filename);
|
8
|
|
-const MAX_HEIGHT_ONSTAGE = 2160;
|
9
|
|
-const MAX_HEIGHT_THUMBNAIL = 180;
|
|
8
|
+const MAX_HEIGHT = 2160;
|
10
|
9
|
const LASTN_UNLIMITED = -1;
|
11
|
10
|
|
12
|
11
|
/**
|
|
@@ -16,75 +15,35 @@ const LASTN_UNLIMITED = -1;
|
16
|
15
|
class ReceiverVideoConstraints {
|
17
|
16
|
/**
|
18
|
17
|
* Creates a new instance.
|
|
18
|
+ *
|
|
19
|
+ * @param {number} lastN - Number of videos to be requested from the bridge.
|
19
|
20
|
*/
|
20
|
|
- constructor() {
|
21
|
|
- // Default constraints used for endpoints that are not explicitly included in constraints.
|
22
|
|
- // These constraints are used for endpoints that are thumbnails in the stage view.
|
23
|
|
- this._defaultConstraints = { 'maxHeight': MAX_HEIGHT_THUMBNAIL };
|
24
|
|
-
|
|
21
|
+ constructor(lastN) {
|
25
|
22
|
// The number of videos requested from the bridge.
|
26
|
|
- this._lastN = LASTN_UNLIMITED;
|
27
|
|
-
|
28
|
|
- // The number representing the maximum video height the local client should receive from the bridge.
|
29
|
|
- this._maxFrameHeight = MAX_HEIGHT_ONSTAGE;
|
|
23
|
+ this._lastN = lastN ?? LASTN_UNLIMITED;
|
30
|
24
|
|
31
|
|
- // The endpoint IDs of the participants that are currently selected.
|
32
|
|
- this._selectedEndpoints = [];
|
|
25
|
+ // The number representing the maximum video height the local client should receive from the bridge/peer.
|
|
26
|
+ this._maxFrameHeight = MAX_HEIGHT;
|
33
|
27
|
|
34
|
28
|
this._receiverVideoConstraints = {
|
35
|
29
|
constraints: {},
|
36
|
|
- defaultConstraints: this.defaultConstraints,
|
37
|
|
- lastN: this._lastN,
|
38
|
|
- onStageEndpoints: [],
|
39
|
|
- selectedEndpoints: this._selectedEndpoints
|
|
30
|
+ defaultConstraints: { 'maxHeight': this._maxFrameHeight },
|
|
31
|
+ lastN: this._lastN
|
40
|
32
|
};
|
41
|
33
|
}
|
42
|
34
|
|
43
|
35
|
/**
|
44
|
|
- * Returns the receiver video constraints that need to be sent on the bridge channel.
|
|
36
|
+ * Returns the receiver video constraints that need to be sent on the bridge channel or to the remote peer.
|
45
|
37
|
*/
|
46
|
38
|
get constraints() {
|
47
|
39
|
this._receiverVideoConstraints.lastN = this._lastN;
|
48
|
|
-
|
49
|
|
- if (!this._selectedEndpoints.length) {
|
50
|
|
- return this._receiverVideoConstraints;
|
51
|
|
- }
|
52
|
|
-
|
53
|
|
- // The client is assumed to be in TileView if it has selected more than one endpoint, otherwise it is
|
54
|
|
- // assumed to be in StageView.
|
55
|
|
- this._receiverVideoConstraints.constraints = {};
|
56
|
|
- if (this._selectedEndpoints.length > 1) {
|
57
|
|
- /**
|
58
|
|
- * Tile view.
|
59
|
|
- * Only the default constraints are specified here along with lastN (if it is set).
|
60
|
|
- * {
|
61
|
|
- * 'colibriClass': 'ReceiverVideoConstraints',
|
62
|
|
- * 'defaultConstraints': { 'maxHeight': 360 }
|
63
|
|
- * }
|
64
|
|
- */
|
65
|
|
- this._receiverVideoConstraints.defaultConstraints = { 'maxHeight': this._maxFrameHeight };
|
66
|
|
- this._receiverVideoConstraints.onStageEndpoints = [];
|
67
|
|
- this._receiverVideoConstraints.selectedEndpoints = [];
|
|
40
|
+ if (Object.keys(this._receiverVideoConstraints.constraints)?.length) {
|
|
41
|
+ /* eslint-disable no-unused-vars */
|
|
42
|
+ for (const [ key, value ] of Object.entries(this._receiverVideoConstraints.constraints)) {
|
|
43
|
+ value.maxHeight = this._maxFrameHeight;
|
|
44
|
+ }
|
68
|
45
|
} else {
|
69
|
|
- /**
|
70
|
|
- * Stage view.
|
71
|
|
- * The participant on stage is specified in onStageEndpoints and a higher maxHeight is specified
|
72
|
|
- * for that endpoint while a default maxHeight of 180 is applied to all the other endpoints.
|
73
|
|
- * {
|
74
|
|
- * 'colibriClass': 'ReceiverVideoConstraints',
|
75
|
|
- * 'onStageEndpoints': ['A'],
|
76
|
|
- * 'defaultConstraints': { 'maxHeight': 180 },
|
77
|
|
- * 'constraints': {
|
78
|
|
- * 'A': { 'maxHeight': 720 }
|
79
|
|
- * }
|
80
|
|
- * }
|
81
|
|
- */
|
82
|
|
- this._receiverVideoConstraints.constraints[this._selectedEndpoints[0]] = {
|
83
|
|
- 'maxHeight': this._maxFrameHeight
|
84
|
|
- };
|
85
|
|
- this._receiverVideoConstraints.defaultConstraints = this._defaultConstraints;
|
86
|
|
- this._receiverVideoConstraints.onStageEndpoints = this._selectedEndpoints;
|
87
|
|
- this._receiverVideoConstraints.selectedEndpoints = [];
|
|
46
|
+ this._receiverVideoConstraints.defaultConstraints = { 'maxHeight': this._maxFrameHeight };
|
88
|
47
|
}
|
89
|
48
|
|
90
|
49
|
return this._receiverVideoConstraints;
|
|
@@ -141,17 +100,6 @@ class ReceiverVideoConstraints {
|
141
|
100
|
|
142
|
101
|
return changed;
|
143
|
102
|
}
|
144
|
|
-
|
145
|
|
- /**
|
146
|
|
- * Updates the list of selected endpoints.
|
147
|
|
- *
|
148
|
|
- * @param {Array<string>} ids
|
149
|
|
- * @returns {void}
|
150
|
|
- */
|
151
|
|
- updateSelectedEndpoints(ids) {
|
152
|
|
- logger.debug(`Updating selected endpoints: ${JSON.stringify(ids)}`);
|
153
|
|
- this._selectedEndpoints = ids;
|
154
|
|
- }
|
155
|
103
|
}
|
156
|
104
|
|
157
|
105
|
/**
|
|
@@ -170,37 +118,23 @@ export default class ReceiveVideoController {
|
170
|
118
|
constructor(conference, rtc) {
|
171
|
119
|
this._conference = conference;
|
172
|
120
|
this._rtc = rtc;
|
173
|
|
-
|
174
|
121
|
const { config } = conference.options;
|
175
|
122
|
|
176
|
123
|
// The number of videos requested from the bridge, -1 represents unlimited or all available videos.
|
177
|
124
|
this._lastN = config?.startLastN ?? (config?.channelLastN || LASTN_UNLIMITED);
|
178
|
125
|
|
179
|
126
|
// The number representing the maximum video height the local client should receive from the bridge.
|
180
|
|
- this._maxFrameHeight = MAX_HEIGHT_ONSTAGE;
|
|
127
|
+ this._maxFrameHeight = MAX_HEIGHT;
|
181
|
128
|
|
182
|
129
|
/**
|
183
|
|
- * The map that holds the max frame height requested for each remote source when source-name signaling is
|
184
|
|
- * enabled.
|
|
130
|
+ * The map that holds the max frame height requested per remote source for p2p connection.
|
185
|
131
|
*
|
186
|
132
|
* @type Map<string, number>
|
187
|
133
|
*/
|
188
|
134
|
this._sourceReceiverConstraints = new Map();
|
189
|
135
|
|
190
|
|
- // Enable new receiver constraints by default unless it is explicitly disabled through config.js.
|
191
|
|
- const useNewReceiverConstraints = config?.useNewBandwidthAllocationStrategy ?? true;
|
192
|
|
-
|
193
|
|
- if (useNewReceiverConstraints) {
|
194
|
|
- this._receiverVideoConstraints = new ReceiverVideoConstraints();
|
195
|
|
- const lastNUpdated = this._receiverVideoConstraints.updateLastN(this._lastN);
|
196
|
|
-
|
197
|
|
- lastNUpdated && this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
198
|
|
- } else {
|
199
|
|
- this._rtc.setLastN(this._lastN);
|
200
|
|
- }
|
201
|
|
-
|
202
|
|
- // The endpoint IDs of the participants that are currently selected.
|
203
|
|
- this._selectedEndpoints = [];
|
|
136
|
+ // The default receiver video constraints.
|
|
137
|
+ this._receiverVideoConstraints = new ReceiverVideoConstraints(this._lastN);
|
204
|
138
|
|
205
|
139
|
this._conference.on(
|
206
|
140
|
JitsiConferenceEvents._MEDIA_SESSION_STARTED,
|
|
@@ -210,15 +144,17 @@ export default class ReceiveVideoController {
|
210
|
144
|
/**
|
211
|
145
|
* Returns a map of all the remote source names and the corresponding max frame heights.
|
212
|
146
|
*
|
213
|
|
- * @param {number} maxFrameHeight
|
|
147
|
+ * @param {JingleSessionPC} mediaSession - the media session.
|
|
148
|
+ * @param {number} maxFrameHeight - the height to be requested for remote sources.
|
214
|
149
|
* @returns
|
215
|
150
|
*/
|
216
|
151
|
_getDefaultSourceReceiverConstraints(mediaSession, maxFrameHeight) {
|
|
152
|
+ const height = maxFrameHeight ?? MAX_HEIGHT;
|
217
|
153
|
const remoteVideoTracks = mediaSession.peerconnection?.getRemoteTracks(null, MediaType.VIDEO) || [];
|
218
|
154
|
const receiverConstraints = new Map();
|
219
|
155
|
|
220
|
156
|
for (const track of remoteVideoTracks) {
|
221
|
|
- receiverConstraints.set(track.getSourceName(), maxFrameHeight);
|
|
157
|
+ receiverConstraints.set(track.getSourceName(), height);
|
222
|
158
|
}
|
223
|
159
|
|
224
|
160
|
return receiverConstraints;
|
|
@@ -233,10 +169,9 @@ export default class ReceiveVideoController {
|
233
|
169
|
* @private
|
234
|
170
|
*/
|
235
|
171
|
_onMediaSessionStarted(mediaSession) {
|
236
|
|
- if (mediaSession.isP2P || !this._receiverVideoConstraints) {
|
237
|
|
- mediaSession.setReceiverVideoConstraint(this._maxFrameHeight, this._sourceReceiverConstraints);
|
|
172
|
+ if (mediaSession.isP2P) {
|
|
173
|
+ mediaSession.setReceiverVideoConstraint(this._getDefaultSourceReceiverConstraints(mediaSession));
|
238
|
174
|
} else {
|
239
|
|
- this._receiverVideoConstraints.updateReceiveResolution(this._maxFrameHeight);
|
240
|
175
|
this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
241
|
176
|
}
|
242
|
177
|
}
|
|
@@ -250,34 +185,6 @@ export default class ReceiveVideoController {
|
250
|
185
|
return this._lastN;
|
251
|
186
|
}
|
252
|
187
|
|
253
|
|
- /**
|
254
|
|
- * Elects the participants with the given ids to be the selected participants in order to always receive video
|
255
|
|
- * for this participant (even when last n is enabled).
|
256
|
|
- *
|
257
|
|
- * @param {Array<string>} ids - The user ids.
|
258
|
|
- * @returns {void}
|
259
|
|
- */
|
260
|
|
- selectEndpoints(ids) {
|
261
|
|
- this._selectedEndpoints = ids;
|
262
|
|
-
|
263
|
|
- if (this._receiverVideoConstraints) {
|
264
|
|
- // Filter out the local endpointId from the list of selected endpoints.
|
265
|
|
- const remoteEndpointIds = ids.filter(id => id !== this._conference.myUserId());
|
266
|
|
- const oldConstraints = JSON.parse(JSON.stringify(this._receiverVideoConstraints.constraints));
|
267
|
|
-
|
268
|
|
- remoteEndpointIds.length && this._receiverVideoConstraints.updateSelectedEndpoints(remoteEndpointIds);
|
269
|
|
- const newConstraints = this._receiverVideoConstraints.constraints;
|
270
|
|
-
|
271
|
|
- // Send bridge message only when the constraints change.
|
272
|
|
- if (!isEqual(newConstraints, oldConstraints)) {
|
273
|
|
- this._rtc.setReceiverVideoConstraints(newConstraints);
|
274
|
|
- }
|
275
|
|
-
|
276
|
|
- return;
|
277
|
|
- }
|
278
|
|
- this._rtc.selectEndpoints(ids);
|
279
|
|
- }
|
280
|
|
-
|
281
|
188
|
/**
|
282
|
189
|
* Selects a new value for "lastN". The requested amount of videos are going to be delivered after the value is
|
283
|
190
|
* in effect. Set to -1 for unlimited or all available videos.
|
|
@@ -288,16 +195,9 @@ export default class ReceiveVideoController {
|
288
|
195
|
setLastN(value) {
|
289
|
196
|
if (this._lastN !== value) {
|
290
|
197
|
this._lastN = value;
|
291
|
|
-
|
292
|
|
- if (this._receiverVideoConstraints) {
|
293
|
|
- const lastNUpdated = this._receiverVideoConstraints.updateLastN(value);
|
294
|
|
-
|
295
|
|
- // Send out the message on the bridge channel if lastN was updated.
|
296
|
|
- lastNUpdated && this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
297
|
|
-
|
298
|
|
- return;
|
|
198
|
+ if (this._receiverVideoConstraints.updateLastN(value)) {
|
|
199
|
+ this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
299
|
200
|
}
|
300
|
|
- this._rtc.setLastN(value);
|
301
|
201
|
}
|
302
|
202
|
}
|
303
|
203
|
|
|
@@ -311,15 +211,10 @@ export default class ReceiveVideoController {
|
311
|
211
|
this._maxFrameHeight = maxFrameHeight;
|
312
|
212
|
|
313
|
213
|
for (const session of this._conference.getMediaSessions()) {
|
314
|
|
- if (session.isP2P || !this._receiverVideoConstraints) {
|
315
|
|
- session.setReceiverVideoConstraint(
|
316
|
|
- maxFrameHeight,
|
317
|
|
- this._getDefaultSourceReceiverConstraints(this._maxFrameHeight));
|
318
|
|
- } else {
|
319
|
|
- const resolutionUpdated = this._receiverVideoConstraints.updateReceiveResolution(maxFrameHeight);
|
320
|
|
-
|
321
|
|
- resolutionUpdated
|
322
|
|
- && this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
|
214
|
+ if (session.isP2P) {
|
|
215
|
+ session.setReceiverVideoConstraint(this._getDefaultSourceReceiverConstraints(session, maxFrameHeight));
|
|
216
|
+ } else if (this._receiverVideoConstraints.updateReceiveResolution(maxFrameHeight)) {
|
|
217
|
+ this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints.constraints);
|
323
|
218
|
}
|
324
|
219
|
}
|
325
|
220
|
}
|
|
@@ -344,7 +239,8 @@ export default class ReceiveVideoController {
|
344
|
239
|
|
345
|
240
|
if (constraintsChanged) {
|
346
|
241
|
this._lastN = constraints.lastN ?? this._lastN;
|
347
|
|
- this._selectedEndpoints = constraints.selectedEndpoints ?? this._selectedEndpoints;
|
|
242
|
+
|
|
243
|
+ // Send the contraints on the bridge channel.
|
348
|
244
|
this._rtc.setReceiverVideoConstraints(constraints);
|
349
|
245
|
|
350
|
246
|
const p2pSession = this._conference.getMediaSessions().find(session => session.isP2P);
|
|
@@ -363,7 +259,7 @@ export default class ReceiveVideoController {
|
363
|
259
|
this._sourceReceiverConstraints = new Map(mappedConstraints);
|
364
|
260
|
|
365
|
261
|
// Send the receiver constraints to the peer through a "content-modify" message.
|
366
|
|
- p2pSession.setReceiverVideoConstraint(null, this._sourceReceiverConstraints);
|
|
262
|
+ p2pSession.setReceiverVideoConstraint(this._sourceReceiverConstraints);
|
367
|
263
|
}
|
368
|
264
|
}
|
369
|
265
|
}
|