|
@@ -4,7 +4,6 @@ import transform from 'sdp-transform';
|
4
|
4
|
import * as JitsiTrackEvents from '../../JitsiTrackEvents';
|
5
|
5
|
import * as MediaType from '../../service/RTC/MediaType';
|
6
|
6
|
import RTCEvents from '../../service/RTC/RTCEvents';
|
7
|
|
-import * as VideoType from '../../service/RTC/VideoType';
|
8
|
7
|
import browser from '../browser';
|
9
|
8
|
|
10
|
9
|
const logger = getLogger(__filename);
|
|
@@ -23,18 +22,27 @@ export class TPCUtils {
|
23
|
22
|
* Creates a new instance for a given TraceablePeerConnection
|
24
|
23
|
*
|
25
|
24
|
* @param peerconnection - the tpc instance for which we have utility functions.
|
26
|
|
- * @param videoBitrates - the bitrates to be configured on the video senders when
|
27
|
|
- * simulcast is enabled.
|
|
25
|
+ * @param videoBitrates - the bitrates to be configured on the video senders for
|
|
26
|
+ * different resolutions both in unicast and simulcast mode.
|
28
|
27
|
*/
|
29
|
28
|
constructor(peerconnection, videoBitrates) {
|
30
|
29
|
this.pc = peerconnection;
|
31
|
30
|
this.videoBitrates = videoBitrates;
|
32
|
31
|
|
33
|
32
|
/**
|
34
|
|
- * The simulcast encodings that will be configured on the RTCRtpSender
|
35
|
|
- * for the video tracks in the unified plan mode.
|
|
33
|
+ * The startup configuration for the stream encodings that are applicable to
|
|
34
|
+ * the video stream when a new sender is created on the peerconnection. The initial
|
|
35
|
+ * config takes into account the differences in browser's simulcast implementation.
|
|
36
|
+ *
|
|
37
|
+ * Encoding parameters:
|
|
38
|
+ * active - determine the on/off state of a particular encoding.
|
|
39
|
+ * maxBitrate - max. bitrate value to be applied to that particular encoding
|
|
40
|
+ * based on the encoding's resolution and config.js videoQuality settings if applicable.
|
|
41
|
+ * rid - Rtp Stream ID that is configured for a particular simulcast stream.
|
|
42
|
+ * scaleResolutionDownBy - the factor by which the encoding is scaled down from the
|
|
43
|
+ * original resolution of the captured video.
|
36
|
44
|
*/
|
37
|
|
- this.simulcastEncodings = [
|
|
45
|
+ this.localStreamEncodingsConfig = [
|
38
|
46
|
{
|
39
|
47
|
active: true,
|
40
|
48
|
maxBitrate: browser.isFirefox() ? this.videoBitrates.high : this.videoBitrates.low,
|
|
@@ -54,12 +62,6 @@ export class TPCUtils {
|
54
|
62
|
scaleResolutionDownBy: browser.isFirefox() ? 4.0 : 1.0
|
55
|
63
|
}
|
56
|
64
|
];
|
57
|
|
-
|
58
|
|
- /**
|
59
|
|
- * Resolution height constraints for the simulcast encodings that
|
60
|
|
- * are configured for the video tracks.
|
61
|
|
- */
|
62
|
|
- this.simulcastStreamConstraints = [];
|
63
|
65
|
}
|
64
|
66
|
|
65
|
67
|
/**
|
|
@@ -97,15 +99,21 @@ export class TPCUtils {
|
97
|
99
|
}
|
98
|
100
|
|
99
|
101
|
/**
|
100
|
|
- * Obtains stream encodings that need to be configured on the given track.
|
|
102
|
+ * Obtains stream encodings that need to be configured on the given track based
|
|
103
|
+ * on the track media type and the simulcast setting.
|
101
|
104
|
* @param {JitsiLocalTrack} localTrack
|
102
|
105
|
*/
|
103
|
106
|
_getStreamEncodings(localTrack) {
|
104
|
107
|
if (this.pc.isSimulcastOn() && localTrack.isVideoTrack()) {
|
105
|
|
- return this.simulcastEncodings;
|
|
108
|
+ return this.localStreamEncodingsConfig;
|
106
|
109
|
}
|
107
|
110
|
|
108
|
|
- return [ { active: true } ];
|
|
111
|
+ return localTrack.isVideoTrack()
|
|
112
|
+ ? [ {
|
|
113
|
+ active: true,
|
|
114
|
+ maxBitrate: this.videoBitrates.high
|
|
115
|
+ } ]
|
|
116
|
+ : [ { active: true } ];
|
109
|
117
|
}
|
110
|
118
|
|
111
|
119
|
/**
|
|
@@ -181,29 +189,6 @@ export class TPCUtils {
|
181
|
189
|
});
|
182
|
190
|
}
|
183
|
191
|
|
184
|
|
- /**
|
185
|
|
- * Constructs resolution height constraints for the simulcast encodings that are
|
186
|
|
- * created for a given local video track.
|
187
|
|
- * @param {MediaStreamTrack} track - the local video track.
|
188
|
|
- * @returns {void}
|
189
|
|
- */
|
190
|
|
- setSimulcastStreamConstraints(track) {
|
191
|
|
- if (browser.isReactNative()) {
|
192
|
|
- return;
|
193
|
|
- }
|
194
|
|
-
|
195
|
|
- const height = track.getSettings().height;
|
196
|
|
-
|
197
|
|
- for (const encoding in this.simulcastEncodings) {
|
198
|
|
- if (this.simulcastEncodings.hasOwnProperty(encoding)) {
|
199
|
|
- this.simulcastStreamConstraints.push({
|
200
|
|
- height: height / this.simulcastEncodings[encoding].scaleResolutionDownBy,
|
201
|
|
- rid: this.simulcastEncodings[encoding].rid
|
202
|
|
- });
|
203
|
|
- }
|
204
|
|
- }
|
205
|
|
- }
|
206
|
|
-
|
207
|
192
|
/**
|
208
|
193
|
* Adds {@link JitsiLocalTrack} to the WebRTC peerconnection for the first time.
|
209
|
194
|
* @param {JitsiLocalTrack} track - track to be added to the peerconnection.
|
|
@@ -231,11 +216,6 @@ export class TPCUtils {
|
231
|
216
|
// unused "recv-only" transceiver.
|
232
|
217
|
this.pc.peerconnection.addTrack(track);
|
233
|
218
|
}
|
234
|
|
-
|
235
|
|
- // Construct the stream constraints for the newly added track.
|
236
|
|
- if (localTrack.isVideoTrack() && localTrack.videoType === VideoType.CAMERA) {
|
237
|
|
- this.setSimulcastStreamConstraints(localTrack.getTrack());
|
238
|
|
- }
|
239
|
219
|
}
|
240
|
220
|
|
241
|
221
|
/**
|
|
@@ -268,11 +248,6 @@ export class TPCUtils {
|
268
|
248
|
return this.setEncodings(localTrack).then(() => {
|
269
|
249
|
this.pc.localTracks.set(localTrack.rtcId, localTrack);
|
270
|
250
|
transceiver.direction = 'sendrecv';
|
271
|
|
-
|
272
|
|
- // Construct the stream constraints for the newly added track.
|
273
|
|
- if (localTrack.isVideoTrack() && localTrack.videoType === VideoType.CAMERA) {
|
274
|
|
- this.setSimulcastStreamConstraints(localTrack.getTrack());
|
275
|
|
- }
|
276
|
251
|
});
|
277
|
252
|
}
|
278
|
253
|
|
|
@@ -285,6 +260,30 @@ export class TPCUtils {
|
285
|
260
|
});
|
286
|
261
|
}
|
287
|
262
|
|
|
263
|
+ /**
|
|
264
|
+ * Obtains the current local video track's height constraints based on the
|
|
265
|
+ * initial stream encodings configuration on the sender and the resolution
|
|
266
|
+ * of the current local track added to the peerconnection.
|
|
267
|
+ * @param {MediaStreamTrack} localTrack local video track
|
|
268
|
+ * @returns {Array[number]} an array containing the resolution heights of
|
|
269
|
+ * simulcast streams configured on the video sender.
|
|
270
|
+ */
|
|
271
|
+ getLocalStreamHeightConstraints(localTrack) {
|
|
272
|
+ // React-native hasn't implemented MediaStreamTrack getSettings yet.
|
|
273
|
+ if (browser.isReactNative()) {
|
|
274
|
+ return null;
|
|
275
|
+ }
|
|
276
|
+
|
|
277
|
+ const localVideoHeightConstraints = [];
|
|
278
|
+ const height = localTrack.getSettings().height;
|
|
279
|
+
|
|
280
|
+ for (const encoding of this.localStreamEncodingsConfig) {
|
|
281
|
+ localVideoHeightConstraints.push(height / encoding.scaleResolutionDownBy);
|
|
282
|
+ }
|
|
283
|
+
|
|
284
|
+ return localVideoHeightConstraints;
|
|
285
|
+ }
|
|
286
|
+
|
288
|
287
|
/**
|
289
|
288
|
* Removes the track from the RTCRtpSender as part of the mute operation.
|
290
|
289
|
* @param {JitsiLocalTrack} localTrack - track to be removed.
|