浏览代码

feat(TS) Migrate CodecSelection to TS (#2825)

master
Naman Jain 3 个月前
父节点
当前提交
1192e9d0a4
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 32 次插入10 次删除
  1. 32
    10
      modules/qualitycontrol/CodecSelection.ts

modules/qualitycontrol/CodecSelection.js → modules/qualitycontrol/CodecSelection.ts 查看文件

1
-
2
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
3
 
2
 
3
+import JitsiConference from '../../JitsiConference';
4
 import { CodecMimeType } from '../../service/RTC/CodecMimeType';
4
 import { CodecMimeType } from '../../service/RTC/CodecMimeType';
5
 import { MediaType } from '../../service/RTC/MediaType';
5
 import { MediaType } from '../../service/RTC/MediaType';
6
 import { VIDEO_CODECS_BY_COMPLEXITY } from '../../service/RTC/StandardVideoQualitySettings';
6
 import { VIDEO_CODECS_BY_COMPLEXITY } from '../../service/RTC/StandardVideoQualitySettings';
7
 import { VideoType } from '../../service/RTC/VideoType';
7
 import { VideoType } from '../../service/RTC/VideoType';
8
+import JitsiLocalTrack from '../RTC/JitsiLocalTrack';
8
 import browser from '../browser';
9
 import browser from '../browser';
10
+import JingleSessionPC from '../xmpp/JingleSessionPC';
9
 
11
 
10
 const logger = getLogger('modules/qualitycontrol/CodecSelection');
12
 const logger = getLogger('modules/qualitycontrol/CodecSelection');
11
 
13
 
14
 const MOBILE_P2P_VIDEO_CODEC_ORDER = [ CodecMimeType.H264, CodecMimeType.VP8, CodecMimeType.VP9, CodecMimeType.AV1 ];
16
 const MOBILE_P2P_VIDEO_CODEC_ORDER = [ CodecMimeType.H264, CodecMimeType.VP8, CodecMimeType.VP9, CodecMimeType.AV1 ];
15
 const MOBILE_VIDEO_CODEC_ORDER = [ CodecMimeType.VP8, CodecMimeType.VP9, CodecMimeType.H264, CodecMimeType.AV1 ];
17
 const MOBILE_VIDEO_CODEC_ORDER = [ CodecMimeType.VP8, CodecMimeType.VP9, CodecMimeType.H264, CodecMimeType.AV1 ];
16
 
18
 
19
+export interface ICodecSelectionOptions {
20
+    [connectionType: string]: {
21
+        disabledCodec?: string;
22
+        enableAV1ForFF?: boolean;
23
+        preferenceOrder?: string[];
24
+        preferredCodec?: string;
25
+        screenshareCodec?: string;
26
+    };
27
+}
28
+
29
+export type CodecPreferenceOrder = { [connectionType: string]: string[]; };
30
+export type ScreenshareCodec = { [connectionType: string]: string; };
31
+
17
 /**
32
 /**
18
  * This class handles the codec selection mechanism for the conference based on the config.js settings.
33
  * This class handles the codec selection mechanism for the conference based on the config.js settings.
19
  * The preferred codec is selected based on the settings and the list of codecs supported by the browser.
34
  * The preferred codec is selected based on the settings and the list of codecs supported by the browser.
22
  * connections.
37
  * connections.
23
  */
38
  */
24
 export class CodecSelection {
39
 export class CodecSelection {
40
+    private codecPreferenceOrder: CodecPreferenceOrder;
41
+    private conference: JitsiConference;
42
+    private encodeTimeStats: Map<string, unknown>;
43
+    private options: ICodecSelectionOptions;
44
+    private screenshareCodec: ScreenshareCodec;
45
+    private visitorCodecs: string[];
46
+
25
     /**
47
     /**
26
      * Creates a new instance for a given conference.
48
      * Creates a new instance for a given conference.
27
      *
49
      *
30
      * @param {string} options.jvb settings (codec list, preferred and disabled) for the jvb connection.
52
      * @param {string} options.jvb settings (codec list, preferred and disabled) for the jvb connection.
31
      * @param {string} options.p2p settings (codec list, preferred and disabled) for the p2p connection.
53
      * @param {string} options.p2p settings (codec list, preferred and disabled) for the p2p connection.
32
      */
54
      */
33
-    constructor(conference, options) {
55
+    constructor(conference: JitsiConference, options: ICodecSelectionOptions) {
34
         this.codecPreferenceOrder = {};
56
         this.codecPreferenceOrder = {};
35
         this.conference = conference;
57
         this.conference = conference;
36
         this.encodeTimeStats = new Map();
58
         this.encodeTimeStats = new Map();
112
      * @param {string} connectionType - media connection type, p2p or jvb.
134
      * @param {string} connectionType - media connection type, p2p or jvb.
113
      * @returns {Array}
135
      * @returns {Array}
114
      */
136
      */
115
-    _getSupportedVideoCodecs(connectionType) {
137
+    _getSupportedVideoCodecs(connectionType: string): string[] {
116
         const videoCodecMimeTypes = browser.isMobileDevice() && connectionType === 'p2p'
138
         const videoCodecMimeTypes = browser.isMobileDevice() && connectionType === 'p2p'
117
             ? MOBILE_P2P_VIDEO_CODEC_ORDER
139
             ? MOBILE_P2P_VIDEO_CODEC_ORDER
118
             : browser.isMobileDevice() ? MOBILE_VIDEO_CODEC_ORDER : DESKTOP_VIDEO_CODEC_ORDER;
140
             : browser.isMobileDevice() ? MOBILE_VIDEO_CODEC_ORDER : DESKTOP_VIDEO_CODEC_ORDER;
134
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
156
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
135
      * @returns {Array<string>}
157
      * @returns {Array<string>}
136
      */
158
      */
137
-    getCodecPreferenceList(connectionType) {
159
+    getCodecPreferenceList(connectionType: string): string[] {
138
         return this.codecPreferenceOrder[connectionType];
160
         return this.codecPreferenceOrder[connectionType];
139
     }
161
     }
140
 
162
 
144
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
166
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
145
      * @returns CodecMimeType
167
      * @returns CodecMimeType
146
      */
168
      */
147
-    getScreenshareCodec(connectionType) {
169
+    getScreenshareCodec(connectionType: string): string | undefined {
148
         return this.screenshareCodec[connectionType];
170
         return this.screenshareCodec[connectionType];
149
     }
171
     }
150
 
172
 
154
      *
176
      *
155
      * @param {JingleSessionPC} mediaSession session for which the codec selection has to be made.
177
      * @param {JingleSessionPC} mediaSession session for which the codec selection has to be made.
156
      */
178
      */
157
-    selectPreferredCodec(mediaSession) {
179
+    selectPreferredCodec(mediaSession?: JingleSessionPC): void {
158
         const session = mediaSession ? mediaSession : this.conference.jvbJingleSession;
180
         const session = mediaSession ? mediaSession : this.conference.jvbJingleSession;
159
 
181
 
160
         if (!session) {
182
         if (!session) {
179
             }
201
             }
180
 
202
 
181
             return [];
203
             return [];
182
-        });
204
+        }) ?? [];
183
 
205
 
184
         // Include the visitor codecs.
206
         // Include the visitor codecs.
185
         this.visitorCodecs.length && remoteCodecsPerParticipant.push(this.visitorCodecs);
207
         this.visitorCodecs.length && remoteCodecsPerParticipant.push(this.visitorCodecs);
186
 
208
 
187
-        const selectedCodecOrder = localPreferredCodecOrder.reduce((acc, localCodec) => {
209
+        const selectedCodecOrder = localPreferredCodecOrder.reduce<string[]>((acc, localCodec) => {
188
             let codecNotSupportedByRemote = false;
210
             let codecNotSupportedByRemote = false;
189
 
211
 
190
             // Remove any codecs that are not supported by any of the remote endpoints. The order of the supported
212
             // Remove any codecs that are not supported by any of the remote endpoints. The order of the supported
220
      * @param {CodecMimeType} codec - The codec used for encoding the given local video track.
242
      * @param {CodecMimeType} codec - The codec used for encoding the given local video track.
221
      * @returns boolean - Returns true if the codec order has been updated, false otherwise.
243
      * @returns boolean - Returns true if the codec order has been updated, false otherwise.
222
      */
244
      */
223
-    changeCodecPreferenceOrder(localTrack, codec) {
245
+    changeCodecPreferenceOrder(localTrack: JitsiLocalTrack, codec: string): boolean {
224
         const session = this.conference.getActiveMediaSession();
246
         const session = this.conference.getActiveMediaSession();
225
         const connectionType = session.isP2P ? 'p2p' : 'jvb';
247
         const connectionType = session.isP2P ? 'p2p' : 'jvb';
226
         const codecOrder = this.codecPreferenceOrder[connectionType];
248
         const codecOrder = this.codecPreferenceOrder[connectionType];
258
      * @param {Array} codecList - visitor codecs.
280
      * @param {Array} codecList - visitor codecs.
259
      * @returns {void}
281
      * @returns {void}
260
      */
282
      */
261
-    updateVisitorCodecs(codecList) {
283
+    updateVisitorCodecs(codecList: string[]): void {
262
         if (this.visitorCodecs === codecList) {
284
         if (this.visitorCodecs === codecList) {
263
             return;
285
             return;
264
         }
286
         }

正在加载...
取消
保存