Browse Source

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 months ago
parent
commit
7bf185f6e4
No account linked to committer's email address
1 changed files with 55 additions and 24 deletions
  1. 55
    24
      modules/qualitycontrol/ReceiveVideoController.ts

modules/qualitycontrol/ReceiveVideoController.js → modules/qualitycontrol/ReceiveVideoController.ts View File

@@ -1,31 +1,63 @@
1 1
 import { getLogger } from '@jitsi/logger';
2 2
 import { isEqual } from 'lodash-es';
3 3
 
4
+import JitsiConference from '../../JitsiConference';
4 5
 import { MediaType } from '../../service/RTC/MediaType';
5 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 10
 const logger = getLogger('modules/qualitycontrol/ReceiveVideoController');
8 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 25
  * This class manages the receive video contraints for a given {@link JitsiConference}. These constraints are
12 26
  * determined by the application based on how the remote video streams need to be displayed. This class is responsible
13 27
  * for communicating these constraints to the bridge over the bridge channel.
14 28
  */
15 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 49
      * Creates a new instance for a given conference.
18 50
      *
19 51
      * @param {JitsiConference} conference the conference instance for which the new instance will be managing
20 52
      * the receive video quality constraints.
21 53
      */
22
-    constructor(conference) {
54
+    constructor(conference: JitsiConference) {
23 55
         this._conference = conference;
24 56
         this._rtc = conference.rtc;
25 57
         const { config } = conference.options;
26 58
 
27 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 62
         // The number representing the maximum video height the local client should receive from the bridge.
31 63
         this._maxFrameHeight = MAX_HEIGHT;
@@ -59,10 +91,13 @@ export default class ReceiveVideoController {
59 91
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
60 92
      * @returns
61 93
      */
62
-    _getDefaultSourceReceiverConstraints(mediaSession, maxFrameHeight) {
94
+    _getDefaultSourceReceiverConstraints(
95
+            mediaSession: JingleSessionPC,
96
+            maxFrameHeight?: number
97
+    ): Map<string, number> {
63 98
         const height = maxFrameHeight ?? MAX_HEIGHT;
64 99
         const remoteVideoTracks = mediaSession.peerconnection?.getRemoteTracks(null, MediaType.VIDEO) || [];
65
-        const receiverConstraints = new Map();
100
+        const receiverConstraints = new Map<string, number>();
66 101
 
67 102
         for (const track of remoteVideoTracks) {
68 103
             receiverConstraints.set(track.getSourceName(), height);
@@ -77,7 +112,7 @@ export default class ReceiveVideoController {
77 112
      * @param {number} maxFrameHeight - the height to be requested for remote sources.
78 113
      * @returns {void}
79 114
      */
80
-    _updateIndividualConstraints(maxFrameHeight) {
115
+    _updateIndividualConstraints(maxFrameHeight?: number): void {
81 116
         const individualConstraints = this._receiverVideoConstraints.constraints;
82 117
 
83 118
         if (individualConstraints && Object.keys(individualConstraints).length) {
@@ -92,9 +127,9 @@ export default class ReceiveVideoController {
92 127
     /**
93 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 133
         return this._receiverVideoConstraints;
99 134
     }
100 135
 
@@ -103,7 +138,7 @@ export default class ReceiveVideoController {
103 138
      *
104 139
      * @returns {number}
105 140
      */
106
-    getLastN() {
141
+    getLastN(): number {
107 142
         return this._lastN;
108 143
     }
109 144
 
@@ -112,7 +147,7 @@ export default class ReceiveVideoController {
112 147
      *
113 148
      * @returns {boolean}
114 149
      */
115
-    isLastNLimitedByCpu() {
150
+    isLastNLimitedByCpu(): boolean {
116 151
         return this._lastNLimitedByCpu;
117 152
     }
118 153
 
@@ -123,7 +158,7 @@ export default class ReceiveVideoController {
123 158
      * @param {JingleSessionPC} mediaSession - the started media session.
124 159
      * @returns {void}
125 160
      */
126
-    onMediaSessionStarted(mediaSession) {
161
+    onMediaSessionStarted(mediaSession: JingleSessionPC): void {
127 162
         if (mediaSession.isP2P) {
128 163
             mediaSession.setReceiverVideoConstraint(this._getDefaultSourceReceiverConstraints(mediaSession));
129 164
         } else {
@@ -137,7 +172,7 @@ export default class ReceiveVideoController {
137 172
      * @param {number|undefined} assumedBandwidthBps - the new value.
138 173
      * @returns {void}
139 174
      */
140
-    setAssumedBandwidthBps(assumedBandwidthBps) {
175
+    setAssumedBandwidthBps(assumedBandwidthBps?: number): void {
141 176
         if (this._receiverVideoConstraints.assumedBandwidthBps !== assumedBandwidthBps) {
142 177
             this._receiverVideoConstraints.assumedBandwidthBps = assumedBandwidthBps;
143 178
             this._rtc.setReceiverVideoConstraints(this._receiverVideoConstraints);
@@ -151,7 +186,7 @@ export default class ReceiveVideoController {
151 186
      * @param {number} value the new value for lastN.
152 187
      * @returns {void}
153 188
      */
154
-    setLastN(value) {
189
+    setLastN(value: number): void {
155 190
         if (this._lastN !== value) {
156 191
             this._lastN = value;
157 192
             this._receiverVideoConstraints.lastN = value;
@@ -165,7 +200,7 @@ export default class ReceiveVideoController {
165 200
      * @param {boolean} enabled
166 201
      * @returns {void}
167 202
      */
168
-    setLastNLimitedByCpu(enabled) {
203
+    setLastNLimitedByCpu(enabled: boolean): void {
169 204
         if (this._lastNLimitedByCpu !== enabled) {
170 205
             this._lastNLimitedByCpu = enabled;
171 206
             logger.info(`ReceiveVideoController - Setting the lastNLimitedByCpu flag to ${enabled}`);
@@ -178,7 +213,7 @@ export default class ReceiveVideoController {
178 213
      * @param {number|undefined} maxFrameHeight - the new value.
179 214
      * @returns {void}
180 215
      */
181
-    setPreferredReceiveMaxFrameHeight(maxFrameHeight) {
216
+    setPreferredReceiveMaxFrameHeight(maxFrameHeight?: number): void {
182 217
         this._maxFrameHeight = maxFrameHeight;
183 218
 
184 219
         for (const session of this._conference.getMediaSessions()) {
@@ -194,9 +229,9 @@ export default class ReceiveVideoController {
194 229
     /**
195 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 235
         if (!constraints) {
201 236
             return;
202 237
         }
@@ -221,12 +256,8 @@ export default class ReceiveVideoController {
221 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 262
             this._sourceReceiverConstraints = new Map(mappedConstraints);
232 263
 
@@ -238,10 +269,10 @@ export default class ReceiveVideoController {
238 269
     /**
239 270
      * Updates the receivedResolutioLimitedByCpu field.
240 271
      *
241
-     * @param {booem} enabled
272
+     * @param {boolean} enabled
242 273
      * @return {void}
243 274
      */
244
-    setReceiveResolutionLimitedByCpu(enabled) {
275
+    setReceiveResolutionLimitedByCpu(enabled: boolean): void {
245 276
         if (this._receiveResolutionLimitedByCpu !== enabled) {
246 277
             this._receiveResolutionLimitedByCpu = enabled;
247 278
             logger.info(`ReceiveVideoController - Setting the receiveResolutionLimitedByCpu flag to ${enabled}`);

Loading…
Cancel
Save