|
@@ -1,10 +1,17 @@
|
1
|
1
|
import { getLogger } from '@jitsi/logger';
|
2
|
2
|
|
|
3
|
+import JitsiConference from '../../JitsiConference';
|
|
4
|
+import JingleSessionPC from '../xmpp/JingleSessionPC';
|
3
|
5
|
import MediaSessionEvents from '../xmpp/MediaSessionEvents';
|
4
|
6
|
|
5
|
7
|
const logger = getLogger('modules/qualitycontrol/SendVideoController');
|
6
|
8
|
const MAX_LOCAL_RESOLUTION = 2160;
|
7
|
9
|
|
|
10
|
+export interface IVideoConstraint {
|
|
11
|
+ maxHeight: number;
|
|
12
|
+ sourceName: string;
|
|
13
|
+}
|
|
14
|
+
|
8
|
15
|
/**
|
9
|
16
|
* The class manages send video constraints across media sessions({@link JingleSessionPC}) which belong to
|
10
|
17
|
* {@link JitsiConference}. It finds the lowest common value, between the local user's send preference and
|
|
@@ -13,13 +20,21 @@ const MAX_LOCAL_RESOLUTION = 2160;
|
13
|
20
|
* different.
|
14
|
21
|
*/
|
15
|
22
|
export default class SendVideoController {
|
|
23
|
+ private _conference: JitsiConference;
|
|
24
|
+ private _preferredSendMaxFrameHeight: number;
|
|
25
|
+ /**
|
|
26
|
+ * Source name based sender constraints.
|
|
27
|
+ * @type {Map<string, number>};
|
|
28
|
+ */
|
|
29
|
+ private _sourceSenderConstraints: Map<string, number>;
|
|
30
|
+
|
16
|
31
|
/**
|
17
|
32
|
* Creates new instance for a given conference.
|
18
|
33
|
*
|
19
|
34
|
* @param {JitsiConference} conference - the conference instance for which the new instance will be managing
|
20
|
35
|
* the send video quality constraints.
|
21
|
36
|
*/
|
22
|
|
- constructor(conference) {
|
|
37
|
+ constructor(conference: JitsiConference) {
|
23
|
38
|
this._conference = conference;
|
24
|
39
|
this._preferredSendMaxFrameHeight = MAX_LOCAL_RESOLUTION;
|
25
|
40
|
|
|
@@ -35,23 +50,23 @@ export default class SendVideoController {
|
35
|
50
|
* sessions for the reasons mentioned in this class description.
|
36
|
51
|
*
|
37
|
52
|
* @param {string} sourceName - The source for which sender constraints have changed.
|
38
|
|
- * @returns {Promise<void[]>}
|
|
53
|
+ * @returns {Promise<void>}
|
39
|
54
|
* @private
|
40
|
55
|
*/
|
41
|
|
- _propagateSendMaxFrameHeight(sourceName) {
|
|
56
|
+ async _propagateSendMaxFrameHeight(sourceName: string): Promise<void> {
|
42
|
57
|
if (!sourceName) {
|
43
|
58
|
throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
|
44
|
59
|
}
|
45
|
60
|
const sendMaxFrameHeight = this._selectSendMaxFrameHeight(sourceName);
|
46
|
61
|
const promises = [];
|
47
|
62
|
|
48
|
|
- if (sendMaxFrameHeight >= 0) {
|
|
63
|
+ if (sendMaxFrameHeight !== undefined && sendMaxFrameHeight >= 0) {
|
49
|
64
|
for (const session of this._conference.getMediaSessions()) {
|
50
|
65
|
promises.push(session.setSenderVideoConstraint(sendMaxFrameHeight, sourceName));
|
51
|
66
|
}
|
52
|
67
|
}
|
53
|
68
|
|
54
|
|
- return Promise.all(promises);
|
|
69
|
+ await Promise.all(promises);
|
55
|
70
|
}
|
56
|
71
|
|
57
|
72
|
/**
|
|
@@ -62,7 +77,7 @@ export default class SendVideoController {
|
62
|
77
|
* @returns {number|undefined}
|
63
|
78
|
* @private
|
64
|
79
|
*/
|
65
|
|
- _selectSendMaxFrameHeight(sourceName) {
|
|
80
|
+ _selectSendMaxFrameHeight(sourceName: string): number | undefined {
|
66
|
81
|
if (!sourceName) {
|
67
|
82
|
throw new Error('sourceName missing for calculating the sendMaxHeight for video tracks');
|
68
|
83
|
}
|
|
@@ -71,9 +86,9 @@ export default class SendVideoController {
|
71
|
86
|
? this._sourceSenderConstraints.get(sourceName)
|
72
|
87
|
: undefined;
|
73
|
88
|
|
74
|
|
- if (this._preferredSendMaxFrameHeight >= 0 && remoteRecvMaxFrameHeight >= 0) {
|
|
89
|
+ if (this._preferredSendMaxFrameHeight >= 0 && remoteRecvMaxFrameHeight !== undefined && remoteRecvMaxFrameHeight >= 0) {
|
75
|
90
|
return Math.min(this._preferredSendMaxFrameHeight, remoteRecvMaxFrameHeight);
|
76
|
|
- } else if (remoteRecvMaxFrameHeight >= 0) {
|
|
91
|
+ } else if (remoteRecvMaxFrameHeight !== undefined && remoteRecvMaxFrameHeight >= 0) {
|
77
|
92
|
return remoteRecvMaxFrameHeight;
|
78
|
93
|
}
|
79
|
94
|
|
|
@@ -85,7 +100,7 @@ export default class SendVideoController {
|
85
|
100
|
*
|
86
|
101
|
* @returns {void}
|
87
|
102
|
*/
|
88
|
|
- configureConstraintsForLocalSources() {
|
|
103
|
+ configureConstraintsForLocalSources(): void {
|
89
|
104
|
for (const track of this._conference.getLocalVideoTracks()) {
|
90
|
105
|
const sourceName = track.getSourceName();
|
91
|
106
|
|
|
@@ -100,10 +115,10 @@ export default class SendVideoController {
|
100
|
115
|
*
|
101
|
116
|
* @param {JingleSessionPC} mediaSession - the started media session.
|
102
|
117
|
*/
|
103
|
|
- onMediaSessionStarted(mediaSession) {
|
|
118
|
+ onMediaSessionStarted(mediaSession: JingleSessionPC): void {
|
104
|
119
|
mediaSession.addListener(
|
105
|
120
|
MediaSessionEvents.REMOTE_SOURCE_CONSTRAINTS_CHANGED,
|
106
|
|
- (session, sourceConstraints) => {
|
|
121
|
+ (session: JingleSessionPC, sourceConstraints: Array<IVideoConstraint>) => {
|
107
|
122
|
session === this._conference.getActiveMediaSession()
|
108
|
123
|
&& sourceConstraints.forEach(constraint => this.onSenderConstraintsReceived(constraint));
|
109
|
124
|
});
|
|
@@ -112,10 +127,10 @@ export default class SendVideoController {
|
112
|
127
|
/**
|
113
|
128
|
* Propagates the video constraints if they have changed.
|
114
|
129
|
*
|
115
|
|
- * @param {Object} videoConstraints - The sender video constraints received from the bridge.
|
116
|
|
- * @returns {Promise<void[]>}
|
|
130
|
+ * @param {IVideoConstraint} videoConstraints - The sender video constraints received from the bridge.
|
|
131
|
+ * @returns {Promise<void>}
|
117
|
132
|
*/
|
118
|
|
- onSenderConstraintsReceived(videoConstraints) {
|
|
133
|
+ async onSenderConstraintsReceived(videoConstraints: IVideoConstraint): Promise<void> {
|
119
|
134
|
const { maxHeight, sourceName } = videoConstraints;
|
120
|
135
|
const localVideoTracks = this._conference.getLocalVideoTracks() ?? [];
|
121
|
136
|
|
|
@@ -129,7 +144,7 @@ export default class SendVideoController {
|
129
|
144
|
? Math.min(MAX_LOCAL_RESOLUTION, this._preferredSendMaxFrameHeight)
|
130
|
145
|
: maxHeight);
|
131
|
146
|
logger.debug(`Sender constraints for source:${sourceName} changed to maxHeight:${maxHeight}`);
|
132
|
|
- this._propagateSendMaxFrameHeight(sourceName);
|
|
147
|
+ await this._propagateSendMaxFrameHeight(sourceName);
|
133
|
148
|
}
|
134
|
149
|
}
|
135
|
150
|
}
|
|
@@ -138,16 +153,16 @@ export default class SendVideoController {
|
138
|
153
|
* Sets local preference for max send video frame height.
|
139
|
154
|
*
|
140
|
155
|
* @param {number} maxFrameHeight - the new value to set.
|
141
|
|
- * @returns {Promise<void[]>} - resolved when the operation is complete.
|
|
156
|
+ * @returns {Promise<void>} - resolved when the operation is complete.
|
142
|
157
|
*/
|
143
|
|
- setPreferredSendMaxFrameHeight(maxFrameHeight) {
|
|
158
|
+ async setPreferredSendMaxFrameHeight(maxFrameHeight: number): Promise<void> {
|
144
|
159
|
this._preferredSendMaxFrameHeight = maxFrameHeight;
|
145
|
|
- const promises = [];
|
|
160
|
+ const promises: Promise<void>[] = [];
|
146
|
161
|
|
147
|
162
|
for (const sourceName of this._sourceSenderConstraints.keys()) {
|
148
|
163
|
promises.push(this._propagateSendMaxFrameHeight(sourceName));
|
149
|
164
|
}
|
150
|
165
|
|
151
|
|
- return Promise.allSettled(promises);
|
|
166
|
+ await Promise.allSettled(promises);
|
152
|
167
|
}
|
153
|
168
|
}
|