Преглед изворни кода

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

master
Naman Jain пре 3 месеци
родитељ
комит
1192e9d0a4
No account linked to committer's email address
1 измењених фајлова са 32 додато и 10 уклоњено
  1. 32
    10
      modules/qualitycontrol/CodecSelection.ts

modules/qualitycontrol/CodecSelection.js → modules/qualitycontrol/CodecSelection.ts Прегледај датотеку

@@ -1,11 +1,13 @@
1
-
2 1
 import { getLogger } from '@jitsi/logger';
3 2
 
3
+import JitsiConference from '../../JitsiConference';
4 4
 import { CodecMimeType } from '../../service/RTC/CodecMimeType';
5 5
 import { MediaType } from '../../service/RTC/MediaType';
6 6
 import { VIDEO_CODECS_BY_COMPLEXITY } from '../../service/RTC/StandardVideoQualitySettings';
7 7
 import { VideoType } from '../../service/RTC/VideoType';
8
+import JitsiLocalTrack from '../RTC/JitsiLocalTrack';
8 9
 import browser from '../browser';
10
+import JingleSessionPC from '../xmpp/JingleSessionPC';
9 11
 
10 12
 const logger = getLogger('modules/qualitycontrol/CodecSelection');
11 13
 
@@ -14,6 +16,19 @@ const DESKTOP_VIDEO_CODEC_ORDER = [ CodecMimeType.AV1, CodecMimeType.VP9, CodecM
14 16
 const MOBILE_P2P_VIDEO_CODEC_ORDER = [ CodecMimeType.H264, CodecMimeType.VP8, CodecMimeType.VP9, CodecMimeType.AV1 ];
15 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 33
  * This class handles the codec selection mechanism for the conference based on the config.js settings.
19 34
  * The preferred codec is selected based on the settings and the list of codecs supported by the browser.
@@ -22,6 +37,13 @@ const MOBILE_VIDEO_CODEC_ORDER = [ CodecMimeType.VP8, CodecMimeType.VP9, CodecMi
22 37
  * connections.
23 38
  */
24 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 48
      * Creates a new instance for a given conference.
27 49
      *
@@ -30,7 +52,7 @@ export class CodecSelection {
30 52
      * @param {string} options.jvb settings (codec list, preferred and disabled) for the jvb connection.
31 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 56
         this.codecPreferenceOrder = {};
35 57
         this.conference = conference;
36 58
         this.encodeTimeStats = new Map();
@@ -112,7 +134,7 @@ export class CodecSelection {
112 134
      * @param {string} connectionType - media connection type, p2p or jvb.
113 135
      * @returns {Array}
114 136
      */
115
-    _getSupportedVideoCodecs(connectionType) {
137
+    _getSupportedVideoCodecs(connectionType: string): string[] {
116 138
         const videoCodecMimeTypes = browser.isMobileDevice() && connectionType === 'p2p'
117 139
             ? MOBILE_P2P_VIDEO_CODEC_ORDER
118 140
             : browser.isMobileDevice() ? MOBILE_VIDEO_CODEC_ORDER : DESKTOP_VIDEO_CODEC_ORDER;
@@ -134,7 +156,7 @@ export class CodecSelection {
134 156
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
135 157
      * @returns {Array<string>}
136 158
      */
137
-    getCodecPreferenceList(connectionType) {
159
+    getCodecPreferenceList(connectionType: string): string[] {
138 160
         return this.codecPreferenceOrder[connectionType];
139 161
     }
140 162
 
@@ -144,7 +166,7 @@ export class CodecSelection {
144 166
      * @param {String} connectionType The media connection type, 'p2p' or 'jvb'.
145 167
      * @returns CodecMimeType
146 168
      */
147
-    getScreenshareCodec(connectionType) {
169
+    getScreenshareCodec(connectionType: string): string | undefined {
148 170
         return this.screenshareCodec[connectionType];
149 171
     }
150 172
 
@@ -154,7 +176,7 @@ export class CodecSelection {
154 176
      *
155 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 180
         const session = mediaSession ? mediaSession : this.conference.jvbJingleSession;
159 181
 
160 182
         if (!session) {
@@ -179,12 +201,12 @@ export class CodecSelection {
179 201
             }
180 202
 
181 203
             return [];
182
-        });
204
+        }) ?? [];
183 205
 
184 206
         // Include the visitor codecs.
185 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 210
             let codecNotSupportedByRemote = false;
189 211
 
190 212
             // Remove any codecs that are not supported by any of the remote endpoints. The order of the supported
@@ -220,7 +242,7 @@ export class CodecSelection {
220 242
      * @param {CodecMimeType} codec - The codec used for encoding the given local video track.
221 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 246
         const session = this.conference.getActiveMediaSession();
225 247
         const connectionType = session.isP2P ? 'p2p' : 'jvb';
226 248
         const codecOrder = this.codecPreferenceOrder[connectionType];
@@ -258,7 +280,7 @@ export class CodecSelection {
258 280
      * @param {Array} codecList - visitor codecs.
259 281
      * @returns {void}
260 282
      */
261
-    updateVisitorCodecs(codecList) {
283
+    updateVisitorCodecs(codecList: string[]): void {
262 284
         if (this.visitorCodecs === codecList) {
263 285
             return;
264 286
         }

Loading…
Откажи
Сачувај