Skip to content

Commit 5f482b8

Browse files
authored
Merge branch 'master' into moderator
2 parents 0bf3d11 + 819cdfb commit 5f482b8

29 files changed

+419
-294
lines changed

modules/RTC/MockClasses.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,13 @@ class MockRTCPeerConnection {
121121
* Mock {@link TraceablePeerConnection} - add things as needed, but only things useful for all tests.
122122
*/
123123
export class MockPeerConnection {
124-
private id: string;
125124
private _usesUnifiedPlan: boolean;
126125
private peerconnection: MockRTCPeerConnection;
127126
private _simulcast: boolean;
128-
127+
/**
128+
* @internal
129+
*/
130+
id: string;
129131
/**
130132
* Constructor.
131133
*

modules/RTC/SourceInfo.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

modules/RTC/TPCUtils.js renamed to modules/RTC/TPCUtils.ts

Lines changed: 87 additions & 53 deletions
Large diffs are not rendered by default.

modules/RTC/TraceablePeerConnection.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ import JitsiRemoteTrack from './JitsiRemoteTrack';
3030
import RTC from './RTC';
3131
import RTCUtils from './RTCUtils';
3232
import { SS_DEFAULT_FRAME_RATE } from './ScreenObtainer';
33-
import { ITPCSourceInfo } from './SourceInfo';
34-
import { TPCUtils } from './TPCUtils';
35-
33+
import { ICodecConfig, TPCUtils } from './TPCUtils';
3634

3735
const logger = getLogger('modules/RTC/TraceablePeerConnection');
3836
const DEGRADATION_PREFERENCE_CAMERA = 'maintain-framerate';
@@ -55,7 +53,9 @@ interface ILegacyStatsResponse {
5553
}
5654
export interface IRTCRtpEncodingParameters extends RTCRtpEncodingParameters {
5755
codec?: RTCRtpCodec;
58-
degradationPreference?: string; // Firefox only supports the non-standard way.
56+
degradationPreference?: string;
57+
rid: string;
58+
// Firefox only supports the non-standard way.
5959
scalabilityMode?: VideoEncoderScalabilityMode;
6060
}
6161

@@ -82,14 +82,32 @@ export interface ITPCOptions {
8282
videoQuality: IVideoQuality;
8383
}
8484

85+
interface ITPCSourceInfo {
86+
groups: ISsrcGroupInfo;
87+
mediaType?: MediaType;
88+
msid: string;
89+
ssrcList?: Array<string>;
90+
videoType?: VideoType;
91+
}
8592
export interface IAudioQuality {
93+
enableOpusDtx?: boolean;
8694
opusMaxAverageBitrate?: number;
8795
stereo?: boolean;
8896
}
8997

9098
export interface IVideoQuality {
99+
desktopbitrate?: number;
91100
maxBitratesVideo?: Record<string, number>;
92101
preferredCodec?: CodecMimeType;
102+
[CodecMimeType.AV1]?: ICodecConfig;
103+
[CodecMimeType.H264]?: ICodecConfig;
104+
[CodecMimeType.VP8]?: ICodecConfig;
105+
[CodecMimeType.VP9]?: ICodecConfig;
106+
maxbitratesvideo?: {
107+
[codec: string]: {
108+
[quality: string]: number;
109+
};
110+
};
93111
}
94112

95113
export interface ICodecSettings {
@@ -125,7 +143,6 @@ export default class TraceablePeerConnection {
125143
private _dtmfSender?: RTCDTMFSender;
126144
private _dtmfTonesQueue: ITouchToneRequest[];
127145
private _dtlsTransport?: RTCDtlsTransport;
128-
private _capScreenshareBitrate: boolean;
129146
private _usesCodecSelectionAPI: boolean;
130147
private _senderMaxHeights: Map<string, number>;
131148
private _localSsrcMap?: Map<string, ISsrcInfo>;
@@ -134,7 +151,10 @@ export default class TraceablePeerConnection {
134151
private _localUfrag: string;
135152
private _remoteUfrag: string;
136153
private _signalingLayer: SignalingLayer;
137-
154+
/**
155+
* @internal
156+
*/
157+
_capScreenshareBitrate: boolean;
138158
/**
139159
* @internal
140160
*/
@@ -649,7 +669,7 @@ export default class TraceablePeerConnection {
649669
return;
650670
}
651671

652-
parameters.encodings = this.tpcUtils.getStreamEncodings(localTrack);
672+
parameters.encodings = this.tpcUtils.getStreamEncodings(localTrack) as RTCRtpEncodingParameters[];
653673
await transceiver.sender.setParameters(parameters);
654674
};
655675

@@ -914,7 +934,7 @@ export default class TraceablePeerConnection {
914934

915935
// Calculate the encodings active state based on the resolution requested by the bridge.
916936
const codecForCamera = preferredCodec ?? this.tpcUtils.getConfiguredVideoCodec(localVideoTrack);
917-
const codec = isScreensharingTrack ? this._getPreferredCodecForScreenshare(codecForCamera) : codecForCamera;
937+
const codec = isScreensharingTrack ? this._getPreferredCodecForScreenshare(codecForCamera as CodecMimeType) : codecForCamera as CodecMimeType;
918938
const activeState = this.tpcUtils.calculateEncodingsActiveState(localVideoTrack, codec, frameHeight);
919939
let bitrates = this.tpcUtils.calculateEncodingsBitrates(localVideoTrack, codec, frameHeight);
920940
const scalabilityModes = this.tpcUtils.calculateEncodingsScalabilityMode(localVideoTrack, codec, frameHeight);
@@ -936,7 +956,7 @@ export default class TraceablePeerConnection {
936956

937957
for (const idx in parameters.encodings) {
938958
if (parameters.encodings.hasOwnProperty(idx)) {
939-
const encoding: IRTCRtpEncodingParameters = parameters.encodings[idx];
959+
const encoding = parameters.encodings[idx] as IRTCRtpEncodingParameters;
940960
const {
941961
active = undefined,
942962
codec: currentCodec = undefined,
@@ -1233,8 +1253,7 @@ export default class TraceablePeerConnection {
12331253
* <tt>false</tt> if it's turned off.
12341254
*/
12351255
isSpatialScalabilityOn(): boolean {
1236-
const h264SimulcastEnabled = this.tpcUtils.codecSettings[CodecMimeType.H264].scalabilityModeEnabled
1237-
&& this.tpcUtils.supportsDDHeaderExt;
1256+
const h264SimulcastEnabled = this.tpcUtils.codecSettings[CodecMimeType.H264].scalabilityModeEnabled;
12381257

12391258
return !this.options.disableSimulcast
12401259
&& (this.codecSettings.codecList[0] !== CodecMimeType.H264 || h264SimulcastEnabled);
@@ -1280,7 +1299,7 @@ export default class TraceablePeerConnection {
12801299
doesTrueSimulcast(localTrack: JitsiLocalTrack): boolean {
12811300
const currentCodec = this.tpcUtils.getConfiguredVideoCodec(localTrack);
12821301

1283-
return this.isSpatialScalabilityOn() && this.tpcUtils.isRunningInSimulcastMode(currentCodec);
1302+
return this.isSpatialScalabilityOn() && this.tpcUtils.isRunningInSimulcastMode(currentCodec as CodecMimeType);
12841303
}
12851304

12861305
/**
@@ -1299,7 +1318,7 @@ export default class TraceablePeerConnection {
12991318
const ssrcGroup = this.isSpatialScalabilityOn() ? SSRC_GROUP_SEMANTICS.SIM : SSRC_GROUP_SEMANTICS.FID;
13001319

13011320
return this.localSSRCs.get(localTrack.rtcId)
1302-
?.groups?.find(group => group.semantics === ssrcGroup)?.ssrcs || ssrcs;
1321+
?.groups?.find(group => group.semantics === ssrcGroup)?.ssrcs || ssrcs;
13031322
}
13041323

13051324
/**
@@ -1763,7 +1782,7 @@ export default class TraceablePeerConnection {
17631782

17641783
if (ssrcGroups?.length) {
17651784
for (const group of ssrcGroups) {
1766-
const parsedGroup: ISsrcGroupInfo = {
1785+
const parsedGroup = {
17671786
semantics: group.semantics,
17681787
ssrcs: group.ssrcs.split(' ').map(ssrcStr => parseInt(ssrcStr, 10))
17691788
};

modules/connectivity/IceFailedHandling.spec.js renamed to modules/connectivity/IceFailedHandling.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IMockConferenceOptions } from '../qualitycontrol/ReceiveVideoController.spec';
12
import Listenable from '../util/Listenable';
23
import { nextTick } from '../util/TestUtils';
34

@@ -7,6 +8,8 @@ import IceFailedHandling from './IceFailedHandling';
78
* Mock conference for the purpose of this test.
89
*/
910
class MockConference extends Listenable {
11+
options: IMockConferenceOptions;
12+
1013
/**
1114
* A constructor...
1215
*/

modules/e2ee/Context.spec.js renamed to modules/e2ee/Context.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('E2EE Context', () => {
165165

166166
const encodeFunction = async () => {
167167
// Ratchet the key. We reimport from the raw bytes.
168-
const material = await importKey(key);
168+
const material = await importKey(key.buffer);
169169

170170
await sender.setKey(await ratchet(material), 0);
171171

modules/qualitycontrol/CodecSelection.spec.js renamed to modules/qualitycontrol/CodecSelection.spec.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { ISourceInfo } from '../../JitsiParticipant';
2+
import { CodecMimeType } from '../../service/RTC/CodecMimeType';
3+
import { VideoType } from '../../service/RTC/VideoType';
14
import { MockPeerConnection, MockRTC } from '../RTC/MockClasses';
25
import { nextTick } from '../util/TestUtils';
36
import JingleSessionPC from '../xmpp/JingleSessionPC';
47
import { MockChatRoom, MockStropheConnection } from '../xmpp/MockClasses';
58

69
import { MockConference, MockLocalTrack, MockParticipant } from './MockClasses';
7-
import { FixedSizeArray, QualityController } from './QualityController';
10+
import { FixedSizeArray, ISourceStats, QualityController } from './QualityController';
811

912
describe('Codec Selection', () => {
1013
let qualityController;
@@ -192,7 +195,7 @@ describe('Codec Selection', () => {
192195
});
193196

194197
it('and encode resolution is limited by cpu for camera tracks', async () => {
195-
const localTrack = new MockLocalTrack('1', 720, 'camera');
198+
const localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
196199

197200
participant1 = new MockParticipant('remote-1');
198201
conference.addParticipant(participant1, [ 'av1', 'vp9', 'vp8' ]);
@@ -219,7 +222,7 @@ describe('Codec Selection', () => {
219222
});
220223

221224
it('and does not change codec if the current codec is already the lowest complexity codec', async () => {
222-
const localTrack = new MockLocalTrack('1', 720, 'camera');
225+
const localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
223226

224227
qualityController.codecController.codecPreferenceOrder.jvb = [ 'vp8', 'vp9', 'av1' ];
225228

@@ -256,7 +259,7 @@ describe('Codec Selection', () => {
256259
p2p: {}
257260
};
258261
jasmine.clock().install();
259-
tpc = new MockPeerConnection();
262+
tpc = new MockPeerConnection('tpc-id', false, false);
260263
qualityController = new QualityController(conference, options);
261264
spyOn(jingleSession, 'setVideoCodecs');
262265
});
@@ -266,7 +269,7 @@ describe('Codec Selection', () => {
266269
});
267270

268271
it('and encode resolution is limited by cpu for camera tracks', async () => {
269-
const localTrack = new MockLocalTrack('1', 720, 'camera');
272+
const localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
270273

271274
participant1 = new MockParticipant('remote-1');
272275
conference.addParticipant(participant1, [ 'av1', 'vp9', 'vp8' ]);
@@ -281,12 +284,12 @@ describe('Codec Selection', () => {
281284

282285
const sourceStats = {
283286
avgEncodeTime: 12,
284-
codec: 'AV1',
287+
codec: CodecMimeType.AV1,
285288
encodeResolution: 360,
286-
qualityLimitationReason: 'cpu',
287-
localTrack,
289+
qualityLimitationReason: 'cpu' as any,
290+
localTrack: localTrack as any,
288291
timestamp: 1,
289-
tpc
292+
tpc: tpc as any
290293
};
291294

292295
qualityController._encodeTimeStats = new Map();
@@ -311,12 +314,12 @@ describe('Codec Selection', () => {
311314
// If the cpu limitation continues to exist, client should switch to vp8.
312315
const updatedStats = {
313316
avgEncodeTime: 12,
314-
codec: 'VP9',
317+
codec: CodecMimeType.VP9,
315318
encodeResolution: 360,
316-
qualityLimitationReason: 'cpu',
317-
localTrack,
319+
qualityLimitationReason: 'cpu' as any,
320+
localTrack: localTrack as any,
318321
timestamp: 1,
319-
tpc
322+
tpc: tpc as any
320323
};
321324

322325
data.add(updatedStats);
@@ -337,7 +340,7 @@ describe('Codec Selection', () => {
337340
p2p: {}
338341
};
339342
jasmine.clock().install();
340-
tpc = new MockPeerConnection();
343+
tpc = new MockPeerConnection('tpc-id', false, false);
341344
qualityController = new QualityController(conference, options);
342345
spyOn(jingleSession, 'setVideoCodecs');
343346
});
@@ -347,15 +350,15 @@ describe('Codec Selection', () => {
347350
});
348351

349352
it('and the client encounters cpu limitation with high complexity codec', async () => {
350-
const localTrack = new MockLocalTrack('1', 720, 'camera');
353+
const localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
351354
const sourceStats = {
352355
avgEncodeTime: 12,
353-
codec: 'AV1',
356+
codec: CodecMimeType.AV1,
354357
encodeResolution: 360,
355-
qualityLimitationReason: 'cpu',
356-
localTrack,
358+
qualityLimitationReason: 'cpu' as any,
359+
localTrack: localTrack as any,
357360
timestamp: 1,
358-
tpc
361+
tpc: tpc as any
359362
};
360363

361364
qualityController._performQualityOptimizations(sourceStats);

modules/qualitycontrol/QualityController.spec.js renamed to modules/qualitycontrol/QualityController.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { VideoType } from '../../service/RTC/VideoType';
12
import { MockPeerConnection, MockRTC } from '../RTC/MockClasses';
23
import { nextTick } from '../util/TestUtils';
34

@@ -18,7 +19,7 @@ describe('QualityController', () => {
1819
beforeEach(() => {
1920
rtc = new MockRTC();
2021
conference = new MockConference(rtc);
21-
tpc = new MockPeerConnection();
22+
tpc = new MockPeerConnection('test-id', false, false);
2223
});
2324

2425
describe('When adaptive mode is enabled', () => {
@@ -32,7 +33,7 @@ describe('QualityController', () => {
3233
lastNRampupTime: 60000,
3334
p2p: {}
3435
};
35-
localTrack = new MockLocalTrack('1', 720, 'camera');
36+
localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
3637
qualityController = new QualityController(conference, options);
3738
sourceStats = {
3839
avgEncodeTime: 12,
@@ -164,7 +165,7 @@ describe('QualityController', () => {
164165
lastNRampupTime: 60000,
165166
p2p: {}
166167
};
167-
localTrack = new MockLocalTrack('1', 720, 'camera');
168+
localTrack = new MockLocalTrack('1', 720, VideoType.CAMERA);
168169
qualityController = new QualityController(conference, options);
169170
sourceStats = {
170171
avgEncodeTime: 12,

modules/qualitycontrol/QualityController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface IOutboundRtpStats {
4949
timestamp: number;
5050
}
5151

52-
interface ISourceStats {
52+
export interface ISourceStats {
5353
avgEncodeTime: number;
5454
codec: CodecMimeType;
5555
encodeResolution: number;

modules/qualitycontrol/ReceiveVideoController.spec.js renamed to modules/qualitycontrol/ReceiveVideoController.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import FeatureFlags from '../flags/FeatureFlags';
22
import Listenable from '../util/Listenable';
3+
import JingleSessionPC from '../xmpp/JingleSessionPC';
34

45
import ReceiveVideoController from './ReceiveVideoController';
56

7+
/**
8+
* Mock conference options interface for testing.
9+
*/
10+
export interface IMockConferenceOptions {
11+
config: {
12+
[key: string]: any;
13+
};
14+
}
15+
616
// JSDocs disabled for Mock classes to avoid duplication - check on the original classes for info.
717
/* eslint-disable require-jsdoc */
818
/**
919
* Mock conference for the purpose of this test file.
1020
*/
1121
class MockConference extends Listenable {
22+
23+
options: IMockConferenceOptions;
24+
activeMediaSession: JingleSessionPC | undefined;
25+
mediaSessions: JingleSessionPC[];
26+
1227
/**
1328
* A constructor...
1429
*/
@@ -22,7 +37,7 @@ class MockConference extends Listenable {
2237
this.mediaSessions = [];
2338
}
2439

25-
getMediaSessions() {
40+
getMediaSessions(): JingleSessionPC[] {
2641
return this.mediaSessions;
2742
}
2843
}

0 commit comments

Comments
 (0)