瀏覽代碼

feat(TS) Migrate ReceiveVideoController to TS (#2823)

* fixup

* Update modules/qualitycontrol/ReceiveVideoController.ts

Co-authored-by: Saúl Ibarra Corretgé <saghul@jitsi.org>

* fixup

* changes done as per comment

---------

Co-authored-by: naman9271 <naman9271@gmail.com>
Co-authored-by: Saúl Ibarra Corretgé <saghul@jitsi.org>
master
Naman Jain 3 月之前
父節點
當前提交
7bf185f6e4
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 55 行新增24 行删除
  1. 55
    24
      modules/qualitycontrol/ReceiveVideoController.ts

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

1
 import { getLogger } from '@jitsi/logger';
1
 import { getLogger } from '@jitsi/logger';
2
 import { isEqual } from 'lodash-es';
2
 import { isEqual } from 'lodash-es';
3
 
3
 
4
+import JitsiConference from '../../JitsiConference';
4
 import { MediaType } from '../../service/RTC/MediaType';
5
 import { MediaType } from '../../service/RTC/MediaType';
5
 import { ASSUMED_BANDWIDTH_BPS, LAST_N_UNLIMITED } from '../../service/RTC/StandardVideoQualitySettings';
6
 import { ASSUMED_BANDWIDTH_BPS, LAST_N_UNLIMITED } from '../../service/RTC/StandardVideoQualitySettings';
7
+import RTC from '../RTC/RTC';
8
+import JingleSessionPC from '../xmpp/JingleSessionPC';
6
 
9
 
7
 const logger = getLogger('modules/qualitycontrol/ReceiveVideoController');
10
 const logger = getLogger('modules/qualitycontrol/ReceiveVideoController');
8
 const MAX_HEIGHT = 2160;
11
 const MAX_HEIGHT = 2160;
9
 
12
 
13
+export interface IReceiverVideoConstraint {
14
+    maxHeight: number;
15
+}
16
+
17
+export interface IReceiverVideoConstraints {
18
+    assumedBandwidthBps?: number;
19
+    constraints?: { [sourceName: string]: IReceiverVideoConstraint; };
20
+    defaultConstraints?: IReceiverVideoConstraint;
21
+    lastN?: number;
22
+}
23
+
10
 /**
24
 /**
11
  * This class manages the receive video contraints for a given {@link JitsiConference}. These constraints are
25
  * This class manages the receive video contraints for a given {@link JitsiConference}. These constraints are
12
  * determined by the application based on how the remote video streams need to be displayed. This class is responsible
26
  * determined by the application based on how the remote video streams need to be displayed. This class is responsible
13
  * for communicating these constraints to the bridge over the bridge channel.
27
  * for communicating these constraints to the bridge over the bridge channel.
14
  */
28
  */
15
 export default class ReceiveVideoController {
29
 export default class ReceiveVideoController {
30
+    private _conference: JitsiConference;
31
+    private _rtc: RTC;
32
+    private _lastN: number;
33
+    private _maxFrameHeight: number;
34
+    /**
35
+     * The map that holds the max frame height requested per remote source for p2p connection.
36
+     *
37
+     * @type Map<string, number>
38
+     */
39
+    private _sourceReceiverConstraints: Map<string, number>;
40
+    /**
41
+     * The number of bps requested from the bridge.
42
+     */
43
+    private _assumedBandwidthBps: number;
44
+    private _lastNLimitedByCpu: boolean;
45
+    private _receiveResolutionLimitedByCpu: boolean;
46
+    private _receiverVideoConstraints: IReceiverVideoConstraints;
47
+
16
     /**
48
     /**
17
      * Creates a new instance for a given conference.
49
      * Creates a new instance for a given conference.
18
      *
50
      *
19
      * @param {JitsiConference} conference the conference instance for which the new instance will be managing
51
      * @param {JitsiConference} conference the conference instance for which the new instance will be managing
20
      * the receive video quality constraints.
52
      * the receive video quality constraints.
21
      */
53
      */
22
-    constructor(conference) {
54
+    constructor(conference: JitsiConference) {
23
         this._conference = conference;
55
         this._conference = conference;
24
         this._rtc = conference.rtc;
56
         this._rtc = conference.rtc;
25
         const { config } = conference.options;
57
         const { config } = conference.options;
26
 
58
 
27
         // The number of videos requested from the bridge, -1 represents unlimited or all available videos.
59
         // The number of videos requested from the bridge, -1 represents unlimited or all available videos.
28
-        this._lastN = config?.startLastN ?? (config?.channelLastN || LAST_N_UNLIMITED);
60
+        this._lastN = config?.startLastN ?? config?.channelLastN ?? LAST_N_UNLIMITED;
29
 
61
 
30
         // The number representing the maximum video height the local client should receive from the bridge.
62
         // The number representing the maximum video height the local client should receive from the bridge.
31
         this._maxFrameHeight = MAX_HEIGHT;
63
         this._maxFrameHeight = MAX_HEIGHT;
59
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
91
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
60
      * @returns
92
      * @returns
61
      */
93
      */
62
-    _getDefaultSourceReceiverConstraints(mediaSession, maxFrameHeight) {
94
+    _getDefaultSourceReceiverConstraints(
95
+            mediaSession: JingleSessionPC,
96
+            maxFrameHeight?: number
97
+    ): Map<string, number> {
63
         const height = maxFrameHeight ?? MAX_HEIGHT;
98
         const height = maxFrameHeight ?? MAX_HEIGHT;
64
         const remoteVideoTracks = mediaSession.peerconnection?.getRemoteTracks(null, MediaType.VIDEO) || [];
99
         const remoteVideoTracks = mediaSession.peerconnection?.getRemoteTracks(null, MediaType.VIDEO) || [];
65
-        const receiverConstraints = new Map();
100
+        const receiverConstraints = new Map<string, number>();
66
 
101
 
67
         for (const track of remoteVideoTracks) {
102
         for (const track of remoteVideoTracks) {
68
             receiverConstraints.set(track.getSourceName(), height);
103
             receiverConstraints.set(track.getSourceName(), height);
77
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
112
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
78
      * @returns {void}
113
      * @returns {void}
79
      */
114
      */
80
-    _updateIndividualConstraints(maxFrameHeight) {
115
+    _updateIndividualConstraints(maxFrameHeight?: number): void {
81
         const individualConstraints = this._receiverVideoConstraints.constraints;
116
         const individualConstraints = this._receiverVideoConstraints.constraints;
82
 
117
 
83
         if (individualConstraints && Object.keys(individualConstraints).length) {
118
         if (individualConstraints && Object.keys(individualConstraints).length) {
92
     /**
127
     /**
93
      * Returns the last set of receiver constraints that were set on the bridge channel.
128
      * Returns the last set of receiver constraints that were set on the bridge channel.
94
      *
129
      *
95
-     * @returns {Object}
130
+     * @returns {IReceiverVideoConstraints}
96
      */
131
      */
97
-    getCurrentReceiverConstraints() {
132
+    getCurrentReceiverConstraints(): IReceiverVideoConstraints {
98
         return this._receiverVideoConstraints;
133
         return this._receiverVideoConstraints;
99
     }
134
     }
100
 
135
 
103
      *
138
      *
104
      * @returns {number}
139
      * @returns {number}
105
      */
140
      */
106
-    getLastN() {
141
+    getLastN(): number {
107
         return this._lastN;
142
         return this._lastN;
108
     }
143
     }
109
 
144
 
112
      *
147
      *
113
      * @returns {boolean}
148
      * @returns {boolean}
114
      */
149
      */
115
-    isLastNLimitedByCpu() {
150
+    isLastNLimitedByCpu(): boolean {
116
         return this._lastNLimitedByCpu;
151
         return this._lastNLimitedByCpu;
117
     }
152
     }
118
 
153
 
123
      * @param {JingleSessionPC} mediaSession - the started media session.
158
      * @param {JingleSessionPC} mediaSession - the started media session.
124
      * @returns {void}
159
      * @returns {void}
125
      */
160
      */
126
-    onMediaSessionStarted(mediaSession) {
161
+    onMediaSessionStarted(mediaSession: JingleSessionPC): void {
127
         if (mediaSession.isP2P) {
162
         if (mediaSession.isP2P) {
128
             mediaSession.setReceiverVideoConstraint(this._getDefaultSourceReceiverConstraints(mediaSession));
163
             mediaSession.setReceiverVideoConstraint(this._getDefaultSourceReceiverConstraints(mediaSession));
129
         } else {
164
         } else {
137
      * @param {number|undefined} assumedBandwidthBps - the new value.
172
      * @param {number|undefined} assumedBandwidthBps - the new value.
138
      * @returns {void}
173
      * @returns {void}
139
      */
174
      */
140
-    setAssumedBandwidthBps(assumedBandwidthBps) {
175
+    setAssumedBandwidthBps(assumedBandwidthBps?: number): void {
141
         if (this._receiverVideoConstraints.assumedBandwidthBps !== assumedBandwidthBps) {
176
         if (this._receiverVideoConstraints.assumedBandwidthBps !== assumedBandwidthBps) {
142
             this._receiverVideoConstraints.assumedBandwidthBps = assumedBandwidthBps;
177
             this._receiverVideoConstraints.assumedBandwidthBps = assumedBandwidthBps;
143
             this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints);
178
             this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints);
151
      * @param {number} value the new value for lastN.
186
      * @param {number} value the new value for lastN.
152
      * @returns {void}
187
      * @returns {void}
153
      */
188
      */
154
-    setLastN(value) {
189
+    setLastN(value: number): void {
155
         if (this._lastN !== value) {
190
         if (this._lastN !== value) {
156
             this._lastN = value;
191
             this._lastN = value;
157
             this._receiverVideoConstraints.lastN = value;
192
             this._receiverVideoConstraints.lastN = value;
165
      * @param {boolean} enabled
200
      * @param {boolean} enabled
166
      * @returns {void}
201
      * @returns {void}
167
      */
202
      */
168
-    setLastNLimitedByCpu(enabled) {
203
+    setLastNLimitedByCpu(enabled: boolean): void {
169
         if (this._lastNLimitedByCpu !== enabled) {
204
         if (this._lastNLimitedByCpu !== enabled) {
170
             this._lastNLimitedByCpu = enabled;
205
             this._lastNLimitedByCpu = enabled;
171
             logger.info(`ReceiveVideoController - Setting the lastNLimitedByCpu flag to ${enabled}`);
206
             logger.info(`ReceiveVideoController - Setting the lastNLimitedByCpu flag to ${enabled}`);
178
      * @param {number|undefined} maxFrameHeight - the new value.
213
      * @param {number|undefined} maxFrameHeight - the new value.
179
      * @returns {void}
214
      * @returns {void}
180
      */
215
      */
181
-    setPreferredReceiveMaxFrameHeight(maxFrameHeight) {
216
+    setPreferredReceiveMaxFrameHeight(maxFrameHeight?: number): void {
182
         this._maxFrameHeight = maxFrameHeight;
217
         this._maxFrameHeight = maxFrameHeight;
183
 
218
 
184
         for (const session of this._conference.getMediaSessions()) {
219
         for (const session of this._conference.getMediaSessions()) {
194
     /**
229
     /**
195
      * Sets the receiver constraints for the conference.
230
      * Sets the receiver constraints for the conference.
196
      *
231
      *
197
-     * @param {Object} constraints The video constraints.
232
+     * @param {IReceiverVideoConstraints} constraints The video constraints.
198
      */
233
      */
199
-    setReceiverConstraints(constraints) {
234
+    setReceiverConstraints(constraints: IReceiverVideoConstraints): void {
200
         if (!constraints) {
235
         if (!constraints) {
201
             return;
236
             return;
202
         }
237
         }
221
                 return;
256
                 return;
222
             }
257
             }
223
 
258
 
224
-            const mappedConstraints = Array.from(Object.entries(this._receiverVideoConstraints.constraints))
225
-                .map(constraint => {
226
-                    constraint[1] = constraint[1].maxHeight;
227
-
228
-                    return constraint;
229
-                });
259
+            const mappedConstraints: [string, number][] = Array.from(Object.entries(this._receiverVideoConstraints.constraints))
260
+                .map(([ key, value ]) => [ key, value.maxHeight ]);
230
 
261
 
231
             this._sourceReceiverConstraints = new Map(mappedConstraints);
262
             this._sourceReceiverConstraints = new Map(mappedConstraints);
232
 
263
 
238
     /**
269
     /**
239
      * Updates the receivedResolutioLimitedByCpu field.
270
      * Updates the receivedResolutioLimitedByCpu field.
240
      *
271
      *
241
-     * @param {booem} enabled
272
+     * @param {boolean} enabled
242
      * @return {void}
273
      * @return {void}
243
      */
274
      */
244
-    setReceiveResolutionLimitedByCpu(enabled) {
275
+    setReceiveResolutionLimitedByCpu(enabled: boolean): void {
245
         if (this._receiveResolutionLimitedByCpu !== enabled) {
276
         if (this._receiveResolutionLimitedByCpu !== enabled) {
246
             this._receiveResolutionLimitedByCpu = enabled;
277
             this._receiveResolutionLimitedByCpu = enabled;
247
             logger.info(`ReceiveVideoController - Setting the receiveResolutionLimitedByCpu flag to ${enabled}`);
278
             logger.info(`ReceiveVideoController - Setting the receiveResolutionLimitedByCpu flag to ${enabled}`);

Loading…
取消
儲存