|
|
@@ -6,25 +6,19 @@ import CodecMimeType from '../../service/RTC/CodecMimeType';
|
|
6
|
6
|
import { MediaDirection } from '../../service/RTC/MediaDirection';
|
|
7
|
7
|
import { MediaType } from '../../service/RTC/MediaType';
|
|
8
|
8
|
import { getSourceIndexFromSourceName } from '../../service/RTC/SignalingLayer';
|
|
9
|
|
-import { STANDARD_CODEC_SETTINGS } from '../../service/RTC/StandardVideoSettings';
|
|
|
9
|
+import {
|
|
|
10
|
+ SIM_LAYERS,
|
|
|
11
|
+ STANDARD_CODEC_SETTINGS,
|
|
|
12
|
+ VIDEO_QUALITY_LEVELS,
|
|
|
13
|
+ VIDEO_QUALITY_SETTINGS
|
|
|
14
|
+} from '../../service/RTC/StandardVideoSettings';
|
|
10
|
15
|
import VideoEncoderScalabilityMode from '../../service/RTC/VideoEncoderScalabilityMode';
|
|
11
|
16
|
import { VideoType } from '../../service/RTC/VideoType';
|
|
12
|
17
|
import browser from '../browser';
|
|
13
|
18
|
|
|
14
|
19
|
const logger = getLogger(__filename);
|
|
15
|
|
-const DESKTOP_SHARE_RATE = 500000;
|
|
16
|
|
-const SIM_LAYER_1_RID = '1';
|
|
17
|
|
-const SIM_LAYER_2_RID = '2';
|
|
18
|
|
-const SIM_LAYER_3_RID = '3';
|
|
19
|
20
|
const VIDEO_CODECS = [ CodecMimeType.AV1, CodecMimeType.H264, CodecMimeType.VP8, CodecMimeType.VP9 ];
|
|
20
|
21
|
|
|
21
|
|
-// TODO - need to revisit these settings when 4K is the captured resolution. We can change the LD scale factor to 6
|
|
22
|
|
-// instead of 4 so that the lowest resolution will be 360p instead of 540p.
|
|
23
|
|
-export const HD_SCALE_FACTOR = 1.0;
|
|
24
|
|
-export const LD_SCALE_FACTOR = 4.0;
|
|
25
|
|
-export const SD_SCALE_FACTOR = 2.0;
|
|
26
|
|
-export const SIM_LAYER_RIDS = [ SIM_LAYER_1_RID, SIM_LAYER_2_RID, SIM_LAYER_3_RID ];
|
|
27
|
|
-
|
|
28
|
22
|
/**
|
|
29
|
23
|
* Handles track related operations on TraceablePeerConnection when browser is
|
|
30
|
24
|
* running in unified plan mode.
|
|
|
@@ -38,6 +32,9 @@ export class TPCUtils {
|
|
38
|
32
|
constructor(peerconnection) {
|
|
39
|
33
|
this.pc = peerconnection;
|
|
40
|
34
|
this.codecSettings = clonedeep(STANDARD_CODEC_SETTINGS);
|
|
|
35
|
+ this.l0ScaleFactor = SIM_LAYERS[0].scaleFactor;
|
|
|
36
|
+ this.l1ScaleFactor = SIM_LAYERS[1].scaleFactor;
|
|
|
37
|
+ this.l2ScaleFactor = SIM_LAYERS[2].scaleFactor;
|
|
41
|
38
|
const videoQualitySettings = this.pc.options?.videoQuality;
|
|
42
|
39
|
|
|
43
|
40
|
if (videoQualitySettings) {
|
|
|
@@ -50,7 +47,9 @@ export class TPCUtils {
|
|
50
|
47
|
&& videoQualitySettings.maxbitratesvideo[codec.toUpperCase()]);
|
|
51
|
48
|
|
|
52
|
49
|
if (bitrateSettings) {
|
|
53
|
|
- [ 'low', 'standard', 'high', 'ssHigh' ].forEach(value => {
|
|
|
50
|
+ const settings = Object.values(VIDEO_QUALITY_SETTINGS);
|
|
|
51
|
+
|
|
|
52
|
+ [ ...settings, 'ssHigh' ].forEach(value => {
|
|
54
|
53
|
if (bitrateSettings[value]) {
|
|
55
|
54
|
this.codecSettings[codec].maxBitratesVideo[value] = bitrateSettings[value];
|
|
56
|
55
|
}
|
|
|
@@ -88,40 +87,56 @@ export class TPCUtils {
|
|
88
|
87
|
*/
|
|
89
|
88
|
_calculateActiveEncodingParams(localVideoTrack, codec, newHeight) {
|
|
90
|
89
|
const codecBitrates = this.codecSettings[codec].maxBitratesVideo;
|
|
91
|
|
- const height = localVideoTrack.getHeight();
|
|
92
|
|
- const desktopShareBitrate = this.pc.options?.videoQuality?.desktopbitrate || DESKTOP_SHARE_RATE;
|
|
|
90
|
+ const trackCaptureHeight = localVideoTrack.getHeight();
|
|
|
91
|
+ const effectiveNewHeight = newHeight > trackCaptureHeight ? trackCaptureHeight : newHeight;
|
|
|
92
|
+ const desktopShareBitrate = this.pc.options?.videoQuality?.desktopbitrate || codecBitrates.ssHigh;
|
|
93
|
93
|
const isScreenshare = localVideoTrack.getVideoType() === VideoType.DESKTOP;
|
|
94
|
94
|
let scalabilityMode = this.codecSettings[codec].useKSVC
|
|
95
|
95
|
? VideoEncoderScalabilityMode.L3T3_KEY : VideoEncoderScalabilityMode.L3T3;
|
|
96
|
|
- let maxBitrate = codecBitrates.high;
|
|
|
96
|
+ const { height, level } = VIDEO_QUALITY_LEVELS.find(lvl => lvl.height <= effectiveNewHeight);
|
|
|
97
|
+ let maxBitrate;
|
|
|
98
|
+ let scaleResolutionDownBy = this.l2ScaleFactor;
|
|
97
|
99
|
|
|
98
|
100
|
if (this._isScreenshareBitrateCapped(localVideoTrack)) {
|
|
99
|
101
|
scalabilityMode = VideoEncoderScalabilityMode.L1T3;
|
|
100
|
102
|
maxBitrate = desktopShareBitrate;
|
|
101
|
|
- } else if (localVideoTrack.getVideoType() === VideoType.DESKTOP) {
|
|
|
103
|
+ } else if (isScreenshare) {
|
|
102
|
104
|
maxBitrate = codecBitrates.ssHigh;
|
|
|
105
|
+ } else {
|
|
|
106
|
+ maxBitrate = codecBitrates[level];
|
|
|
107
|
+ effectiveNewHeight && (scaleResolutionDownBy = trackCaptureHeight / effectiveNewHeight);
|
|
|
108
|
+
|
|
|
109
|
+ if (height !== effectiveNewHeight) {
|
|
|
110
|
+ logger.debug(`Quality level with height=${height} was picked when requested height=${newHeight} for`
|
|
|
111
|
+ + `track with capture height=${trackCaptureHeight}`);
|
|
|
112
|
+ }
|
|
103
|
113
|
}
|
|
104
|
114
|
|
|
105
|
115
|
const config = {
|
|
106
|
|
- active: newHeight > 0,
|
|
|
116
|
+ active: effectiveNewHeight > 0,
|
|
107
|
117
|
maxBitrate,
|
|
108
|
118
|
scalabilityMode,
|
|
109
|
|
- scaleResolutionDownBy: HD_SCALE_FACTOR
|
|
|
119
|
+ scaleResolutionDownBy
|
|
110
|
120
|
};
|
|
111
|
121
|
|
|
112
|
|
- if (newHeight >= height || newHeight === 0 || isScreenshare) {
|
|
|
122
|
+ if (!config.active || isScreenshare) {
|
|
113
|
123
|
return config;
|
|
114
|
124
|
}
|
|
115
|
125
|
|
|
116
|
|
- if (newHeight >= height / SD_SCALE_FACTOR) {
|
|
117
|
|
- config.maxBitrate = codecBitrates.standard;
|
|
|
126
|
+ // Configure the sender to send all 3 spatial layers for resolutions 720p and higher.
|
|
|
127
|
+ switch (level) {
|
|
|
128
|
+ case VIDEO_QUALITY_SETTINGS.ULTRA:
|
|
|
129
|
+ case VIDEO_QUALITY_SETTINGS.FULL:
|
|
|
130
|
+ case VIDEO_QUALITY_SETTINGS.HIGH:
|
|
|
131
|
+ config.scalabilityMode = this.codecSettings[codec].useKSVC
|
|
|
132
|
+ ? VideoEncoderScalabilityMode.L3T3_KEY : VideoEncoderScalabilityMode.L3T3;
|
|
|
133
|
+ break;
|
|
|
134
|
+ case VIDEO_QUALITY_SETTINGS.STANDARD:
|
|
118
|
135
|
config.scalabilityMode = this.codecSettings[codec].useKSVC
|
|
119
|
136
|
? VideoEncoderScalabilityMode.L2T3_KEY : VideoEncoderScalabilityMode.L2T3;
|
|
120
|
|
- config.scaleResolutionDownBy = SD_SCALE_FACTOR;
|
|
121
|
|
- } else {
|
|
122
|
|
- config.maxBitrate = codecBitrates.low;
|
|
|
137
|
+ break;
|
|
|
138
|
+ default:
|
|
123
|
139
|
config.scalabilityMode = VideoEncoderScalabilityMode.L1T3;
|
|
124
|
|
- config.scaleResolutionDownBy = LD_SCALE_FACTOR;
|
|
125
|
140
|
}
|
|
126
|
141
|
|
|
127
|
142
|
return config;
|
|
|
@@ -133,19 +148,21 @@ export class TPCUtils {
|
|
133
|
148
|
* @param {JitsiLocalTrack} localTrack
|
|
134
|
149
|
*/
|
|
135
|
150
|
_getStreamEncodings(localTrack) {
|
|
|
151
|
+ if (localTrack.isAudioTrack()) {
|
|
|
152
|
+ return [ { active: this.pc.audioTransferActive } ];
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
136
|
155
|
const codec = this.pc.getConfiguredVideoCodec();
|
|
137
|
|
- const encodings = this._getVideoStreamEncodings(localTrack.getVideoType(), codec);
|
|
|
156
|
+ const encodings = this._getVideoStreamEncodings(localTrack, codec);
|
|
138
|
157
|
|
|
139
|
|
- if (this.pc.isSpatialScalabilityOn() && localTrack.isVideoTrack()) {
|
|
|
158
|
+ if (this.pc.isSpatialScalabilityOn()) {
|
|
140
|
159
|
return encodings;
|
|
141
|
160
|
}
|
|
142
|
161
|
|
|
143
|
|
- return localTrack.isVideoTrack()
|
|
144
|
|
- ? [ {
|
|
145
|
|
- active: this.pc.videoTransferActive,
|
|
146
|
|
- maxBitrate: this.codecSettings[codec].maxBitratesVideo.high
|
|
147
|
|
- } ]
|
|
148
|
|
- : [ { active: this.pc.audioTransferActive } ];
|
|
|
162
|
+ return [ {
|
|
|
163
|
+ active: this.pc.videoTransferActive,
|
|
|
164
|
+ maxBitrate: this.codecSettings[codec].maxBitratesVideo.high
|
|
|
165
|
+ } ];
|
|
149
|
166
|
}
|
|
150
|
167
|
|
|
151
|
168
|
/**
|
|
|
@@ -161,13 +178,26 @@ export class TPCUtils {
|
|
161
|
178
|
* scaleResolutionDownBy - the factor by which the encoding is scaled down from the
|
|
162
|
179
|
* original resolution of the captured video.
|
|
163
|
180
|
*
|
|
164
|
|
- * @param {VideoType} videoType
|
|
|
181
|
+ * @param {JitsiLocalTrack} localTrack
|
|
165
|
182
|
* @param {String} codec
|
|
166
|
183
|
*/
|
|
167
|
|
- _getVideoStreamEncodings(videoType, codec) {
|
|
|
184
|
+ _getVideoStreamEncodings(localTrack, codec) {
|
|
|
185
|
+ const captureResolution = localTrack.getHeight();
|
|
168
|
186
|
const codecBitrates = this.codecSettings[codec].maxBitratesVideo;
|
|
|
187
|
+ const videoType = localTrack.getVideoType();
|
|
|
188
|
+ const { level } = VIDEO_QUALITY_LEVELS.find(lvl => lvl.height <= captureResolution);
|
|
|
189
|
+ const maxBitrate = codecBitrates[level];
|
|
|
190
|
+
|
|
|
191
|
+ if (level === VIDEO_QUALITY_SETTINGS.ULTRA) {
|
|
|
192
|
+ this.l1ScaleFactor = 6.0; // 360p
|
|
|
193
|
+ this.l0ScaleFactor = 12.0; // 180p
|
|
|
194
|
+ } else if (level === VIDEO_QUALITY_SETTINGS.FULL) {
|
|
|
195
|
+ this.l1ScaleFactor = 3.0; // 360p
|
|
|
196
|
+ this.l0ScaleFactor = 6.0; // 180p
|
|
|
197
|
+ }
|
|
|
198
|
+
|
|
169
|
199
|
const maxVideoBitrate = videoType === VideoType.DESKTOP
|
|
170
|
|
- ? codecBitrates.ssHigh : codecBitrates.high;
|
|
|
200
|
+ ? codecBitrates.ssHigh : maxBitrate;
|
|
171
|
201
|
|
|
172
|
202
|
// The SSRCs on older versions of Firefox are reversed in SDP, i.e., they have resolution order of 1:2:4 as
|
|
173
|
203
|
// opposed to Chromium and other browsers. This has been reverted in Firefox 117 as part of the below commit.
|
|
|
@@ -181,20 +211,20 @@ export class TPCUtils {
|
|
181
|
211
|
{
|
|
182
|
212
|
active: this.pc.videoTransferActive,
|
|
183
|
213
|
maxBitrate: reversedEncodings ? maxVideoBitrate : codecBitrates.low,
|
|
184
|
|
- rid: SIM_LAYER_1_RID,
|
|
185
|
|
- scaleResolutionDownBy: reversedEncodings ? HD_SCALE_FACTOR : LD_SCALE_FACTOR
|
|
|
214
|
+ rid: SIM_LAYERS[0].rid,
|
|
|
215
|
+ scaleResolutionDownBy: reversedEncodings ? this.l2ScaleFactor : this.l0ScaleFactor
|
|
186
|
216
|
},
|
|
187
|
217
|
{
|
|
188
|
218
|
active: this.pc.videoTransferActive,
|
|
189
|
219
|
maxBitrate: codecBitrates.standard,
|
|
190
|
|
- rid: SIM_LAYER_2_RID,
|
|
191
|
|
- scaleResolutionDownBy: SD_SCALE_FACTOR
|
|
|
220
|
+ rid: SIM_LAYERS[1].rid,
|
|
|
221
|
+ scaleResolutionDownBy: this.l1ScaleFactor
|
|
192
|
222
|
},
|
|
193
|
223
|
{
|
|
194
|
224
|
active: this.pc.videoTransferActive,
|
|
195
|
225
|
maxBitrate: reversedEncodings ? codecBitrates.low : maxVideoBitrate,
|
|
196
|
|
- rid: SIM_LAYER_3_RID,
|
|
197
|
|
- scaleResolutionDownBy: reversedEncodings ? LD_SCALE_FACTOR : HD_SCALE_FACTOR
|
|
|
226
|
+ rid: SIM_LAYERS[2].rid,
|
|
|
227
|
+ scaleResolutionDownBy: reversedEncodings ? this.l0ScaleFactor : this.l2ScaleFactor
|
|
198
|
228
|
}
|
|
199
|
229
|
];
|
|
200
|
230
|
|
|
|
@@ -214,8 +244,8 @@ export class TPCUtils {
|
|
214
|
244
|
{
|
|
215
|
245
|
active: this.pc.videoTransferActive,
|
|
216
|
246
|
maxBitrate: maxVideoBitrate,
|
|
217
|
|
- rid: SIM_LAYER_1_RID,
|
|
218
|
|
- scaleResolutionDownBy: HD_SCALE_FACTOR,
|
|
|
247
|
+ rid: SIM_LAYERS[0].rid,
|
|
|
248
|
+ scaleResolutionDownBy: this.l2ScaleFactor,
|
|
219
|
249
|
scalabilityMode: this.codecSettings[codec].useKSVC
|
|
220
|
250
|
? VideoEncoderScalabilityMode.L3T3_KEY : VideoEncoderScalabilityMode.L3T3
|
|
221
|
251
|
},
|
|
|
@@ -329,7 +359,7 @@ export class TPCUtils {
|
|
329
|
359
|
*/
|
|
330
|
360
|
calculateEncodingsActiveState(localVideoTrack, codec, newHeight) {
|
|
331
|
361
|
const height = localVideoTrack.getHeight();
|
|
332
|
|
- const videoStreamEncodings = this._getVideoStreamEncodings(localVideoTrack.getVideoType(), codec);
|
|
|
362
|
+ const videoStreamEncodings = this._getVideoStreamEncodings(localVideoTrack, codec);
|
|
333
|
363
|
const encodingsState = videoStreamEncodings
|
|
334
|
364
|
.map(encoding => height / encoding.scaleResolutionDownBy)
|
|
335
|
365
|
.map((frameHeight, idx) => {
|
|
|
@@ -353,11 +383,11 @@ export class TPCUtils {
|
|
353
|
383
|
// but the requested resolution is 180. Since getParameters doesn't give us information about
|
|
354
|
384
|
// the resolutions of the simulcast encodings, we have to rely on our initial config for the
|
|
355
|
385
|
// simulcast streams.
|
|
356
|
|
- || videoStreamEncodings[idx]?.scaleResolutionDownBy === LD_SCALE_FACTOR;
|
|
|
386
|
+ || videoStreamEncodings[idx]?.scaleResolutionDownBy === this.l0ScaleFactor;
|
|
357
|
387
|
} else {
|
|
358
|
388
|
// For screenshare, keep the HD layer enabled always and the lower layers only for high fps
|
|
359
|
389
|
// screensharing.
|
|
360
|
|
- active = videoStreamEncodings[idx].scaleResolutionDownBy === HD_SCALE_FACTOR
|
|
|
390
|
+ active = videoStreamEncodings[idx].scaleResolutionDownBy === this.l2ScaleFactor
|
|
361
|
391
|
|| !this._isScreenshareBitrateCapped(localVideoTrack);
|
|
362
|
392
|
}
|
|
363
|
393
|
}
|
|
|
@@ -378,8 +408,9 @@ export class TPCUtils {
|
|
378
|
408
|
* @returns {Array<number>}
|
|
379
|
409
|
*/
|
|
380
|
410
|
calculateEncodingsBitrates(localVideoTrack, codec, newHeight) {
|
|
381
|
|
- const desktopShareBitrate = this.pc.options?.videoQuality?.desktopbitrate || DESKTOP_SHARE_RATE;
|
|
382
|
|
- const encodingsBitrates = this._getVideoStreamEncodings(localVideoTrack.getVideoType(), codec)
|
|
|
411
|
+ const codecBitrates = this.codecSettings[codec].maxBitratesVideo;
|
|
|
412
|
+ const desktopShareBitrate = this.pc.options?.videoQuality?.desktopbitrate || codecBitrates.ssHigh;
|
|
|
413
|
+ const encodingsBitrates = this._getVideoStreamEncodings(localVideoTrack, codec)
|
|
383
|
414
|
.map((encoding, idx) => {
|
|
384
|
415
|
let bitrate = encoding.maxBitrate;
|
|
385
|
416
|
|
|
|
@@ -447,7 +478,7 @@ export class TPCUtils {
|
|
447
|
478
|
*/
|
|
448
|
479
|
calculateEncodingsScaleFactor(localVideoTrack, codec, maxHeight) {
|
|
449
|
480
|
if (this.pc.isSpatialScalabilityOn() && this.isRunningInSimulcastMode(codec)) {
|
|
450
|
|
- return this._getVideoStreamEncodings(localVideoTrack.getVideoType(), codec)
|
|
|
481
|
+ return this._getVideoStreamEncodings(localVideoTrack, codec)
|
|
451
|
482
|
.map(encoding => encoding.scaleResolutionDownBy);
|
|
452
|
483
|
}
|
|
453
|
484
|
|
|
|
@@ -537,19 +568,18 @@ export class TPCUtils {
|
|
537
|
568
|
const hasIncorrectConfig = this.pc._capScreenshareBitrate
|
|
538
|
569
|
? parameters.encodings.every(encoding => encoding.active)
|
|
539
|
570
|
: parameters.encodings.some(encoding => !encoding.active);
|
|
540
|
|
- const videoType = localVideoTrack.getVideoType();
|
|
541
|
571
|
|
|
542
|
572
|
// Check if every encoding is active for screenshare track when low fps screenshare is configured or some
|
|
543
|
573
|
// of the encodings are disabled when high fps screenshare is configured. In both these cases, the track
|
|
544
|
574
|
// encodings need to be reconfigured. This is needed when p2p->jvb switch happens and new sender constraints
|
|
545
|
575
|
// are not received by the client.
|
|
546
|
|
- if (videoType === VideoType.DESKTOP && hasIncorrectConfig) {
|
|
|
576
|
+ if (localVideoTrack.getVideoType() === VideoType.DESKTOP && hasIncorrectConfig) {
|
|
547
|
577
|
return null;
|
|
548
|
578
|
}
|
|
549
|
579
|
|
|
550
|
580
|
for (const encoding in parameters.encodings) {
|
|
551
|
581
|
if (parameters.encodings[encoding].active) {
|
|
552
|
|
- const encodingConfig = this._getVideoStreamEncodings(videoType, codec);
|
|
|
582
|
+ const encodingConfig = this._getVideoStreamEncodings(localVideoTrack, codec);
|
|
553
|
583
|
const scaleResolutionDownBy
|
|
554
|
584
|
= this.pc.isSpatialScalabilityOn()
|
|
555
|
585
|
? encodingConfig[encoding].scaleResolutionDownBy
|
|
|
@@ -579,15 +609,15 @@ export class TPCUtils {
|
|
579
|
609
|
}
|
|
580
|
610
|
const rids = [
|
|
581
|
611
|
{
|
|
582
|
|
- id: SIM_LAYER_1_RID,
|
|
|
612
|
+ id: SIM_LAYERS[0].rid,
|
|
583
|
613
|
direction: 'recv'
|
|
584
|
614
|
},
|
|
585
|
615
|
{
|
|
586
|
|
- id: SIM_LAYER_2_RID,
|
|
|
616
|
+ id: SIM_LAYERS[1].rid,
|
|
587
|
617
|
direction: 'recv'
|
|
588
|
618
|
},
|
|
589
|
619
|
{
|
|
590
|
|
- id: SIM_LAYER_3_RID,
|
|
|
620
|
+ id: SIM_LAYERS[2].rid,
|
|
591
|
621
|
direction: 'recv'
|
|
592
|
622
|
}
|
|
593
|
623
|
];
|
|
|
@@ -595,9 +625,10 @@ export class TPCUtils {
|
|
595
|
625
|
// Firefox 72 has stopped parsing the legacy rid= parameters in simulcast attributes.
|
|
596
|
626
|
// eslint-disable-next-line max-len
|
|
597
|
627
|
// https://www.fxsitecompat.dev/en-CA/docs/2019/pt-and-rid-in-webrtc-simulcast-attributes-are-no-longer-supported/
|
|
|
628
|
+ const ridLine = rids.map(val => val.id).join(';');
|
|
598
|
629
|
const simulcastLine = browser.isFirefox() && browser.isVersionGreaterThan(71)
|
|
599
|
|
- ? `recv ${SIM_LAYER_RIDS.join(';')}`
|
|
600
|
|
- : `recv rid=${SIM_LAYER_RIDS.join(';')}`;
|
|
|
630
|
+ ? `recv ${ridLine}`
|
|
|
631
|
+ : `recv rid=${ridLine}`;
|
|
601
|
632
|
const sdp = transform.parse(desc.sdp);
|
|
602
|
633
|
const mLines = sdp.media.filter(m => m.type === MediaType.VIDEO);
|
|
603
|
634
|
const senderMids = Array.from(this.pc._localTrackTransceiverMids.values());
|