|
@@ -4,8 +4,10 @@ import { getLogger } from 'jitsi-meet-logger';
|
4
|
4
|
import * as ConnectionQualityEvents
|
5
|
5
|
from '../../service/connectivity/ConnectionQualityEvents';
|
6
|
6
|
import * as ConferenceEvents from '../../JitsiConferenceEvents';
|
|
7
|
+import * as MediaType from '../../service/RTC/MediaType';
|
7
|
8
|
import RTCBrowserType from '../RTC/RTCBrowserType';
|
8
|
9
|
import Statistics from './statistics';
|
|
10
|
+import * as VideoType from '../../service/RTC/VideoType';
|
9
|
11
|
|
10
|
12
|
const logger = getLogger(__filename);
|
11
|
13
|
|
|
@@ -35,11 +37,10 @@ class AverageStatReport {
|
35
|
37
|
logger.error(
|
36
|
38
|
`${this.name} - invalid value for idx: ${this.count}`,
|
37
|
39
|
nextValue);
|
38
|
|
-
|
39
|
|
- return;
|
|
40
|
+ } else if (!isNaN(nextValue)) {
|
|
41
|
+ this.sum += nextValue;
|
|
42
|
+ this.count += 1;
|
40
|
43
|
}
|
41
|
|
- this.sum += nextValue;
|
42
|
|
- this.count += 1;
|
43
|
44
|
}
|
44
|
45
|
|
45
|
46
|
/**
|
|
@@ -74,6 +75,203 @@ class AverageStatReport {
|
74
|
75
|
}
|
75
|
76
|
}
|
76
|
77
|
|
|
78
|
+/**
|
|
79
|
+ * Class gathers the stats that are calculated and reported for a
|
|
80
|
+ * {@link TraceablePeerConnection} even if it's not currently active. For
|
|
81
|
+ * example we want to monitor RTT for the JVB connection while in P2P mode.
|
|
82
|
+ */
|
|
83
|
+class ConnectionAvgStats {
|
|
84
|
+ /**
|
|
85
|
+ * Creates new <tt>ConnectionAvgStats</tt>
|
|
86
|
+ * @param {JitsiConference} conference
|
|
87
|
+ * @param {boolean} isP2P
|
|
88
|
+ * @param {number} n the number of samples, before arithmetic mean is to be
|
|
89
|
+ * calculated and values submitted to the analytics module.
|
|
90
|
+ */
|
|
91
|
+ constructor(conference, isP2P, n) {
|
|
92
|
+ /**
|
|
93
|
+ * Is this instance for JVB or P2P connection ?
|
|
94
|
+ * @type {boolean}
|
|
95
|
+ */
|
|
96
|
+ this.isP2P = isP2P;
|
|
97
|
+
|
|
98
|
+ /**
|
|
99
|
+ * How many samples are to be included in arithmetic mean calculation.
|
|
100
|
+ * @type {number}
|
|
101
|
+ * @private
|
|
102
|
+ */
|
|
103
|
+ this._n = n;
|
|
104
|
+
|
|
105
|
+ /**
|
|
106
|
+ * The current sample index. Starts from 0 and goes up to {@link _n})
|
|
107
|
+ * when analytics report will be submitted.
|
|
108
|
+ * @type {number}
|
|
109
|
+ * @private
|
|
110
|
+ */
|
|
111
|
+ this._sampleIdx = 0;
|
|
112
|
+
|
|
113
|
+ /**
|
|
114
|
+ * Average round trip time reported by the ICE candidate pair.
|
|
115
|
+ * @type {AverageStatReport}
|
|
116
|
+ */
|
|
117
|
+ this._avgRTT = new AverageStatReport('stat.avg.rtt');
|
|
118
|
+
|
|
119
|
+ /**
|
|
120
|
+ * Map stores average RTT to the JVB reported by remote participants.
|
|
121
|
+ * Mapped per participant id {@link JitsiParticipant.getId}.
|
|
122
|
+ *
|
|
123
|
+ * This is used only when {@link ConnectionAvgStats.isP2P} equals to
|
|
124
|
+ * <tt>false</tt>.
|
|
125
|
+ *
|
|
126
|
+ * @type {Map<string,AverageStatReport>}
|
|
127
|
+ * @private
|
|
128
|
+ */
|
|
129
|
+ this._avgRemoteRTTMap = new Map();
|
|
130
|
+
|
|
131
|
+ /**
|
|
132
|
+ * The conference for which stats will be collected and reported.
|
|
133
|
+ * @type {JitsiConference}
|
|
134
|
+ * @private
|
|
135
|
+ */
|
|
136
|
+ this._conference = conference;
|
|
137
|
+
|
|
138
|
+ this._onConnectionStats = (tpc, stats) => {
|
|
139
|
+ if (this.isP2P === tpc.isP2P) {
|
|
140
|
+ this._calculateAvgStats(stats);
|
|
141
|
+ }
|
|
142
|
+ };
|
|
143
|
+ conference.statistics.addConnectionStatsListener(
|
|
144
|
+ this._onConnectionStats);
|
|
145
|
+
|
|
146
|
+ if (!this.isP2P) {
|
|
147
|
+ this._onUserLeft = id => this._avgRemoteRTTMap.delete(id);
|
|
148
|
+ conference.on(ConferenceEvents.USER_LEFT, this._onUserLeft);
|
|
149
|
+
|
|
150
|
+ this._onRemoteStatsUpdated
|
|
151
|
+ = (id, data) => this._processRemoteStats(id, data);
|
|
152
|
+ conference.on(
|
|
153
|
+ ConnectionQualityEvents.REMOTE_STATS_UPDATED,
|
|
154
|
+ this._onRemoteStatsUpdated);
|
|
155
|
+ }
|
|
156
|
+ }
|
|
157
|
+
|
|
158
|
+ /**
|
|
159
|
+ * Processes next batch of stats.
|
|
160
|
+ * @param {go figure} data
|
|
161
|
+ * @private
|
|
162
|
+ */
|
|
163
|
+ _calculateAvgStats(data) {
|
|
164
|
+ if (!data) {
|
|
165
|
+ logger.error('No stats');
|
|
166
|
+
|
|
167
|
+ return;
|
|
168
|
+ }
|
|
169
|
+
|
|
170
|
+ if (RTCBrowserType.supportsRTTStatistics()) {
|
|
171
|
+ if (data.transport && data.transport.length) {
|
|
172
|
+ this._avgRTT.addNext(data.transport[0].rtt);
|
|
173
|
+ }
|
|
174
|
+ }
|
|
175
|
+
|
|
176
|
+ this._sampleIdx += 1;
|
|
177
|
+
|
|
178
|
+ if (this._sampleIdx >= this._n) {
|
|
179
|
+ if (RTCBrowserType.supportsRTTStatistics()) {
|
|
180
|
+ this._avgRTT.report(this.isP2P);
|
|
181
|
+
|
|
182
|
+ // Report end to end RTT only for JVB
|
|
183
|
+ if (!this.isP2P) {
|
|
184
|
+ const avgRemoteRTT = this._calculateAvgRemoteRTT();
|
|
185
|
+ const avgLocalRTT = this._avgRTT.calculate();
|
|
186
|
+
|
|
187
|
+ if (!isNaN(avgLocalRTT) && !isNaN(avgRemoteRTT)) {
|
|
188
|
+ Statistics.analytics.sendEvent(
|
|
189
|
+ 'stat.avg.end2endrtt',
|
|
190
|
+ { value: avgLocalRTT + avgRemoteRTT });
|
|
191
|
+ }
|
|
192
|
+ }
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ this._resetAvgStats();
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ /**
|
|
200
|
+ * Calculates arithmetic mean of all RTTs towards the JVB reported by
|
|
201
|
+ * participants.
|
|
202
|
+ * @return {number|NaN} NaN if not available (not enough data)
|
|
203
|
+ * @private
|
|
204
|
+ */
|
|
205
|
+ _calculateAvgRemoteRTT() {
|
|
206
|
+ let count = 0, sum = 0;
|
|
207
|
+
|
|
208
|
+ // FIXME should we ignore RTT for participant
|
|
209
|
+ // who "is having connectivity issues" ?
|
|
210
|
+ for (const remoteAvg of this._avgRemoteRTTMap.values()) {
|
|
211
|
+ const avg = remoteAvg.calculate();
|
|
212
|
+
|
|
213
|
+ if (!isNaN(avg)) {
|
|
214
|
+ sum += avg;
|
|
215
|
+ count += 1;
|
|
216
|
+ remoteAvg.reset();
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ return sum / count;
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ /**
|
|
224
|
+ * Processes {@link ConnectionQualityEvents.REMOTE_STATS_UPDATED} to analyse
|
|
225
|
+ * RTT towards the JVB reported by each participant.
|
|
226
|
+ * @param {string} id {@link JitsiParticipant.getId}
|
|
227
|
+ * @param {go figure in ConnectionQuality.js} data
|
|
228
|
+ * @private
|
|
229
|
+ */
|
|
230
|
+ _processRemoteStats(id, data) {
|
|
231
|
+ const validData = typeof data.jvbRTT === 'number';
|
|
232
|
+ let rttAvg = this._avgRemoteRTTMap.get(id);
|
|
233
|
+
|
|
234
|
+ if (!rttAvg && validData) {
|
|
235
|
+ rttAvg = new AverageStatReport(`${id}.stat.rtt`);
|
|
236
|
+ this._avgRemoteRTTMap.set(id, rttAvg);
|
|
237
|
+ }
|
|
238
|
+
|
|
239
|
+ if (validData) {
|
|
240
|
+ rttAvg.addNext(data.jvbRTT);
|
|
241
|
+ } else if (rttAvg) {
|
|
242
|
+ this._avgRemoteRTTMap.delete(id);
|
|
243
|
+ }
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ /**
|
|
247
|
+ * Reset cache of all averages and {@link _sampleIdx}.
|
|
248
|
+ * @private
|
|
249
|
+ */
|
|
250
|
+ _resetAvgStats() {
|
|
251
|
+ this._avgRTT.reset();
|
|
252
|
+ if (this._avgRemoteRTTMap) {
|
|
253
|
+ this._avgRemoteRTTMap.clear();
|
|
254
|
+ }
|
|
255
|
+ this._sampleIdx = 0;
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ /**
|
|
259
|
+ *
|
|
260
|
+ */
|
|
261
|
+ dispose() {
|
|
262
|
+ this._conference.statistics.removeConnectionStatsListener(
|
|
263
|
+ this._onConnectionStats);
|
|
264
|
+ if (!this.isP2P) {
|
|
265
|
+ this._conference.off(
|
|
266
|
+ ConnectionQualityEvents.REMOTE_STATS_UPDATED,
|
|
267
|
+ this._onRemoteStatsUpdated);
|
|
268
|
+ this._conference.off(
|
|
269
|
+ ConferenceEvents.USER_LEFT,
|
|
270
|
+ this._onUserLeft);
|
|
271
|
+ }
|
|
272
|
+ }
|
|
273
|
+}
|
|
274
|
+
|
77
|
275
|
/**
|
78
|
276
|
* Reports average RTP statistics values (arithmetic mean) to the analytics
|
79
|
277
|
* module for things like bit rate, bandwidth, packet loss etc. It keeps track
|
|
@@ -123,19 +321,36 @@ export default class AvgRTPStatsReporter {
|
123
|
321
|
this._conference = conference;
|
124
|
322
|
|
125
|
323
|
/**
|
126
|
|
- * Average upload bitrate
|
|
324
|
+ * Average audio upload bitrate
|
|
325
|
+ * @type {AverageStatReport}
|
|
326
|
+ * @private
|
|
327
|
+ */
|
|
328
|
+ this._avgAudioBitrateUp
|
|
329
|
+ = new AverageStatReport('stat.avg.bitrate.audio.upload');
|
|
330
|
+
|
|
331
|
+ /**
|
|
332
|
+ * Average audio download bitrate
|
|
333
|
+ * @type {AverageStatReport}
|
|
334
|
+ * @private
|
|
335
|
+ */
|
|
336
|
+ this._avgAudioBitrateDown
|
|
337
|
+ = new AverageStatReport('stat.avg.bitrate.audio.download');
|
|
338
|
+
|
|
339
|
+ /**
|
|
340
|
+ * Average video upload bitrate
|
127
|
341
|
* @type {AverageStatReport}
|
128
|
342
|
* @private
|
129
|
343
|
*/
|
130
|
|
- this._avgBitrateUp = new AverageStatReport('stat.avg.bitrate.upload');
|
|
344
|
+ this._avgVideoBitrateUp
|
|
345
|
+ = new AverageStatReport('stat.avg.bitrate.video.upload');
|
131
|
346
|
|
132
|
347
|
/**
|
133
|
|
- * Average download bitrate
|
|
348
|
+ * Average video download bitrate
|
134
|
349
|
* @type {AverageStatReport}
|
135
|
350
|
* @private
|
136
|
351
|
*/
|
137
|
|
- this._avgBitrateDown
|
138
|
|
- = new AverageStatReport('stat.avg.bitrate.download');
|
|
352
|
+ this._avgVideoBitrateDown
|
|
353
|
+ = new AverageStatReport('stat.avg.bitrate.video.download');
|
139
|
354
|
|
140
|
355
|
/**
|
141
|
356
|
* Average upload bandwidth
|
|
@@ -185,27 +400,29 @@ export default class AvgRTPStatsReporter {
|
185
|
400
|
this._avgRemoteFPS = new AverageStatReport('stat.avg.framerate.remote');
|
186
|
401
|
|
187
|
402
|
/**
|
188
|
|
- * Map stores average RTT to the JVB reported by remote participants.
|
189
|
|
- * Mapped per participant id {@link JitsiParticipant.getId}.
|
190
|
|
- * @type {Map<string,AverageStatReport>}
|
|
403
|
+ * Average FPS for remote screen streaming videos (reported only if not
|
|
404
|
+ * a <tt>NaN</tt>).
|
|
405
|
+ * @type {AverageStatReport}
|
191
|
406
|
* @private
|
192
|
407
|
*/
|
193
|
|
- this._avgRemoteRTTMap = new Map();
|
|
408
|
+ this._avgRemoteScreenFPS
|
|
409
|
+ = new AverageStatReport('stat.avg.framerate.screen.remote');
|
194
|
410
|
|
195
|
411
|
/**
|
196
|
|
- * Average round trip time reported by the ICE candidate pair.
|
197
|
|
- * FIXME currently reported only for P2P
|
|
412
|
+ * Average FPS for local video (camera)
|
198
|
413
|
* @type {AverageStatReport}
|
199
|
414
|
* @private
|
200
|
415
|
*/
|
201
|
|
- this._avgRTT = new AverageStatReport('stat.avg.rtt');
|
|
416
|
+ this._avgLocalFPS = new AverageStatReport('stat.avg.framerate.local');
|
202
|
417
|
|
203
|
418
|
/**
|
204
|
|
- * Average FPS for local video
|
|
419
|
+ * Average FPS for local screen streaming video (reported only if not
|
|
420
|
+ * a <tt>NaN</tt>).
|
205
|
421
|
* @type {AverageStatReport}
|
206
|
422
|
* @private
|
207
|
423
|
*/
|
208
|
|
- this._avgLocalFPS = new AverageStatReport('stat.avg.framerate.local');
|
|
424
|
+ this._avgLocalScreenFPS
|
|
425
|
+ = new AverageStatReport('stat.avg.framerate.screen.local');
|
209
|
426
|
|
210
|
427
|
/**
|
211
|
428
|
* Average connection quality as defined by
|
|
@@ -220,46 +437,21 @@ export default class AvgRTPStatsReporter {
|
220
|
437
|
ConnectionQualityEvents.LOCAL_STATS_UPDATED,
|
221
|
438
|
this._onLocalStatsUpdated);
|
222
|
439
|
|
223
|
|
- this._onRemoteStatsUpdated
|
224
|
|
- = (id, data) => this._processRemoteStats(id, data);
|
225
|
|
- conference.on(
|
226
|
|
- ConnectionQualityEvents.REMOTE_STATS_UPDATED,
|
227
|
|
- this._onRemoteStatsUpdated);
|
228
|
|
-
|
229
|
440
|
this._onP2PStatusChanged = () => {
|
230
|
441
|
logger.debug('Resetting average stats calculation');
|
231
|
442
|
this._resetAvgStats();
|
|
443
|
+ this.jvbStatsMonitor._resetAvgStats();
|
|
444
|
+ this.p2pStatsMonitor._resetAvgStats();
|
232
|
445
|
};
|
233
|
446
|
conference.on(
|
234
|
447
|
ConferenceEvents.P2P_STATUS,
|
235
|
448
|
this._onP2PStatusChanged);
|
236
|
449
|
|
237
|
|
- this._onUserLeft = id => this._avgRemoteRTTMap.delete(id);
|
238
|
|
- conference.on(ConferenceEvents.USER_LEFT, this._onUserLeft);
|
239
|
|
- }
|
240
|
|
-
|
241
|
|
- /**
|
242
|
|
- * Calculates arithmetic mean of all RTTs towards the JVB reported by
|
243
|
|
- * participants.
|
244
|
|
- * @return {number|NaN} NaN if not available (not enough data)
|
245
|
|
- * @private
|
246
|
|
- */
|
247
|
|
- _calculateAvgRemoteRTT() {
|
248
|
|
- let count = 0, sum = 0;
|
249
|
|
-
|
250
|
|
- // FIXME should we ignore RTT for participant
|
251
|
|
- // who "is having connectivity issues" ?
|
252
|
|
- for (const remoteAvg of this._avgRemoteRTTMap.values()) {
|
253
|
|
- const avg = remoteAvg.calculate();
|
254
|
|
-
|
255
|
|
- if (!isNaN(avg)) {
|
256
|
|
- sum += avg;
|
257
|
|
- count += 1;
|
258
|
|
- remoteAvg.reset();
|
259
|
|
- }
|
260
|
|
- }
|
|
450
|
+ this.jvbStatsMonitor
|
|
451
|
+ = new ConnectionAvgStats(conference, false /* JVB */, n);
|
261
|
452
|
|
262
|
|
- return sum / count;
|
|
453
|
+ this.p2pStatsMonitor
|
|
454
|
+ = new ConnectionAvgStats(conference, true /* P2P */, n);
|
263
|
455
|
}
|
264
|
456
|
|
265
|
457
|
/**
|
|
@@ -317,8 +509,11 @@ export default class AvgRTPStatsReporter {
|
317
|
509
|
return;
|
318
|
510
|
}
|
319
|
511
|
|
320
|
|
- this._avgBitrateUp.addNext(bitrate.upload);
|
321
|
|
- this._avgBitrateDown.addNext(bitrate.download);
|
|
512
|
+ this._avgAudioBitrateUp.addNext(bitrate.audio.upload);
|
|
513
|
+ this._avgAudioBitrateDown.addNext(bitrate.audio.download);
|
|
514
|
+
|
|
515
|
+ this._avgVideoBitrateUp.addNext(bitrate.video.upload);
|
|
516
|
+ this._avgVideoBitrateDown.addNext(bitrate.video.download);
|
322
|
517
|
|
323
|
518
|
if (RTCBrowserType.supportsBandwidthStatistics()) {
|
324
|
519
|
this._avgBandwidthUp.addNext(bandwidth.upload);
|
|
@@ -328,28 +523,34 @@ export default class AvgRTPStatsReporter {
|
328
|
523
|
this._avgPacketLossUp.addNext(packetLoss.upload);
|
329
|
524
|
this._avgPacketLossDown.addNext(packetLoss.download);
|
330
|
525
|
this._avgPacketLossTotal.addNext(packetLoss.total);
|
331
|
|
- this._avgCQ.addNext(data.connectionQuality);
|
332
|
526
|
|
333
|
|
- if (RTCBrowserType.supportsRTTStatistics()) {
|
334
|
|
- if (data.transport && data.transport.length) {
|
335
|
|
- this._avgRTT.addNext(data.transport[0].rtt);
|
336
|
|
- } else {
|
337
|
|
- this._avgRTT.reset();
|
338
|
|
- }
|
339
|
|
- }
|
|
527
|
+ this._avgCQ.addNext(data.connectionQuality);
|
340
|
528
|
|
341
|
529
|
if (frameRate) {
|
342
|
530
|
this._avgRemoteFPS.addNext(
|
343
|
|
- this._calculateAvgVideoFps(frameRate, false /* remote */));
|
|
531
|
+ this._calculateAvgVideoFps(
|
|
532
|
+ frameRate, false /* remote */, VideoType.CAMERA));
|
|
533
|
+ this._avgRemoteScreenFPS.addNext(
|
|
534
|
+ this._calculateAvgVideoFps(
|
|
535
|
+ frameRate, false /* remote */, VideoType.DESKTOP));
|
|
536
|
+
|
344
|
537
|
this._avgLocalFPS.addNext(
|
345
|
|
- this._calculateAvgVideoFps(frameRate, true /* local */));
|
|
538
|
+ this._calculateAvgVideoFps(
|
|
539
|
+ frameRate, true /* local */, VideoType.CAMERA));
|
|
540
|
+ this._avgLocalScreenFPS.addNext(
|
|
541
|
+ this._calculateAvgVideoFps(
|
|
542
|
+ frameRate, true /* local */, VideoType.DESKTOP));
|
346
|
543
|
}
|
347
|
544
|
|
348
|
545
|
this._sampleIdx += 1;
|
349
|
546
|
|
350
|
547
|
if (this._sampleIdx >= this._n) {
|
351
|
|
- this._avgBitrateUp.report(isP2P);
|
352
|
|
- this._avgBitrateDown.report(isP2P);
|
|
548
|
+ this._avgAudioBitrateUp.report(isP2P);
|
|
549
|
+ this._avgAudioBitrateDown.report(isP2P);
|
|
550
|
+
|
|
551
|
+ this._avgVideoBitrateUp.report(isP2P);
|
|
552
|
+ this._avgVideoBitrateDown.report(isP2P);
|
|
553
|
+
|
353
|
554
|
if (RTCBrowserType.supportsBandwidthStatistics()) {
|
354
|
555
|
this._avgBandwidthUp.report(isP2P);
|
355
|
556
|
this._avgBandwidthDown.report(isP2P);
|
|
@@ -357,24 +558,18 @@ export default class AvgRTPStatsReporter {
|
357
|
558
|
this._avgPacketLossUp.report(isP2P);
|
358
|
559
|
this._avgPacketLossDown.report(isP2P);
|
359
|
560
|
this._avgPacketLossTotal.report(isP2P);
|
|
561
|
+
|
360
|
562
|
this._avgRemoteFPS.report(isP2P);
|
|
563
|
+ if (!isNaN(this._avgRemoteScreenFPS.calculate())) {
|
|
564
|
+ this._avgRemoteScreenFPS.report(isP2P);
|
|
565
|
+ }
|
361
|
566
|
this._avgLocalFPS.report(isP2P);
|
362
|
|
- this._avgCQ.report(isP2P);
|
363
|
|
-
|
364
|
|
- if (RTCBrowserType.supportsRTTStatistics()) {
|
365
|
|
- this._avgRTT.report(isP2P);
|
366
|
|
- if (!isP2P) {
|
367
|
|
- const avgRemoteRTT = this._calculateAvgRemoteRTT();
|
368
|
|
- const avgLocalRTT = this._avgRTT.calculate();
|
369
|
|
-
|
370
|
|
- if (!isNaN(avgLocalRTT) && !isNaN(avgRemoteRTT)) {
|
371
|
|
- Statistics.analytics.sendEvent(
|
372
|
|
- 'stat.avg.end2endrtt',
|
373
|
|
- avgLocalRTT + avgRemoteRTT);
|
374
|
|
- }
|
375
|
|
- }
|
|
567
|
+ if (!isNaN(this._avgLocalScreenFPS.calculate())) {
|
|
568
|
+ this._avgLocalScreenFPS.report(isP2P);
|
376
|
569
|
}
|
377
|
570
|
|
|
571
|
+ this._avgCQ.report(isP2P);
|
|
572
|
+
|
378
|
573
|
this._resetAvgStats();
|
379
|
574
|
}
|
380
|
575
|
}
|
|
@@ -384,58 +579,92 @@ export default class AvgRTPStatsReporter {
|
384
|
579
|
* @param {go figure} frameRate
|
385
|
580
|
* @param {boolean} isLocal if the average is to be calculated for the local
|
386
|
581
|
* video or <tt>false</tt> if for remote videos.
|
|
582
|
+ * @param {VideoType} videoType
|
387
|
583
|
* @return {number|NaN} average FPS or <tt>NaN</tt> if there are no samples.
|
388
|
584
|
* @private
|
389
|
585
|
*/
|
390
|
|
- _calculateAvgVideoFps(frameRate, isLocal) {
|
|
586
|
+ _calculateAvgVideoFps(frameRate, isLocal, videoType) {
|
|
587
|
+ let peerFpsSum = 0;
|
391
|
588
|
let peerCount = 0;
|
392
|
|
- let subFrameAvg = 0;
|
393
|
589
|
const myID = this._conference.myUserId();
|
394
|
590
|
|
395
|
591
|
for (const peerID of Object.keys(frameRate)) {
|
396
|
592
|
if (isLocal ? peerID === myID : peerID !== myID) {
|
397
|
|
- const videos = frameRate[peerID];
|
398
|
|
- const ssrcs = Object.keys(videos);
|
399
|
|
-
|
400
|
|
- if (ssrcs.length) {
|
401
|
|
- let peerAvg = 0;
|
402
|
|
-
|
403
|
|
- for (const ssrc of ssrcs) {
|
404
|
|
- peerAvg += parseInt(videos[ssrc], 10);
|
|
593
|
+ const participant
|
|
594
|
+ = isLocal
|
|
595
|
+ ? null : this._conference.getParticipantById(peerID);
|
|
596
|
+ const videosFps = frameRate[peerID];
|
|
597
|
+
|
|
598
|
+ // Do not continue without participant for non local peerID
|
|
599
|
+ if ((isLocal || participant) && videosFps) {
|
|
600
|
+ const peerAvgFPS
|
|
601
|
+ = this._calculatePeerAvgVideoFps(
|
|
602
|
+ videosFps, participant, videoType);
|
|
603
|
+
|
|
604
|
+ if (!isNaN(peerAvgFPS)) {
|
|
605
|
+ peerFpsSum += peerAvgFPS;
|
|
606
|
+ peerCount += 1;
|
405
|
607
|
}
|
406
|
|
-
|
407
|
|
- peerAvg /= ssrcs.length;
|
408
|
|
-
|
409
|
|
- subFrameAvg += peerAvg;
|
410
|
|
- peerCount += 1;
|
411
|
608
|
}
|
412
|
609
|
}
|
413
|
610
|
}
|
414
|
611
|
|
415
|
|
- return subFrameAvg / peerCount;
|
|
612
|
+ return peerFpsSum / peerCount;
|
416
|
613
|
}
|
417
|
614
|
|
418
|
615
|
/**
|
419
|
|
- * Processes {@link ConnectionQualityEvents.REMOTE_STATS_UPDATED} to analyse
|
420
|
|
- * RTT towards the JVB reported by each participant.
|
421
|
|
- * @param {string} id {@link JitsiParticipant.getId}
|
422
|
|
- * @param {go figure in ConnectionQuality.js} data
|
|
616
|
+ * Calculate average FPS for either remote or local participant
|
|
617
|
+ * @param {object} videos maps FPS per video SSRC
|
|
618
|
+ * @param {JitsiParticipant|null} participant remote participant or
|
|
619
|
+ * <tt>null</tt> for local FPS calculation.
|
|
620
|
+ * @param {VideoType} videoType the type of the video for which an average
|
|
621
|
+ * will be calculated.
|
|
622
|
+ * @return {number|NaN} average FPS of all participant's videos or
|
|
623
|
+ * <tt>NaN</tt> if currently not available
|
423
|
624
|
* @private
|
424
|
625
|
*/
|
425
|
|
- _processRemoteStats(id, data) {
|
426
|
|
- const validData = typeof data.jvbRTT === 'number';
|
427
|
|
- let rttAvg = this._avgRemoteRTTMap.get(id);
|
428
|
|
-
|
429
|
|
- if (!rttAvg && validData) {
|
430
|
|
- rttAvg = new AverageStatReport(`${id}.stat.rtt`);
|
431
|
|
- this._avgRemoteRTTMap.set(id, rttAvg);
|
|
626
|
+ _calculatePeerAvgVideoFps(videos, participant, videoType) {
|
|
627
|
+ let ssrcs = Object.keys(videos).map(ssrc => Number(ssrc));
|
|
628
|
+ let videoTracks = null;
|
|
629
|
+
|
|
630
|
+ // NOTE that this method is supposed to be called for the stats
|
|
631
|
+ // received from the current peerconnection.
|
|
632
|
+ const tpc = this._conference.getActivePeerConnection();
|
|
633
|
+
|
|
634
|
+ if (participant) {
|
|
635
|
+ videoTracks = participant.getTracksByMediaType(MediaType.VIDEO);
|
|
636
|
+ if (videoTracks) {
|
|
637
|
+ ssrcs
|
|
638
|
+ = ssrcs.filter(
|
|
639
|
+ ssrc => videoTracks.find(
|
|
640
|
+ track => !track.isMuted()
|
|
641
|
+ && track.getSSRC() === ssrc
|
|
642
|
+ && track.videoType === videoType));
|
|
643
|
+ }
|
|
644
|
+ } else {
|
|
645
|
+ videoTracks = this._conference.getLocalTracks(MediaType.VIDEO);
|
|
646
|
+ ssrcs
|
|
647
|
+ = ssrcs.filter(
|
|
648
|
+ ssrc => videoTracks.find(
|
|
649
|
+ track => !track.isMuted()
|
|
650
|
+ && tpc.getLocalSSRC(track) === ssrc
|
|
651
|
+ && track.videoType === videoType));
|
432
|
652
|
}
|
433
|
653
|
|
434
|
|
- if (validData) {
|
435
|
|
- rttAvg.addNext(data.jvbRTT);
|
436
|
|
- } else if (rttAvg) {
|
437
|
|
- this._avgRemoteRTTMap.delete(id);
|
|
654
|
+ let peerFpsSum = 0;
|
|
655
|
+ let peerSsrcCount = 0;
|
|
656
|
+
|
|
657
|
+ for (const ssrc of ssrcs) {
|
|
658
|
+ const peerSsrcFps = Number(videos[ssrc]);
|
|
659
|
+
|
|
660
|
+ // FPS is reported as 0 for users with no video
|
|
661
|
+ if (!isNaN(peerSsrcFps) && peerSsrcFps > 0) {
|
|
662
|
+ peerFpsSum += peerSsrcFps;
|
|
663
|
+ peerSsrcCount += 1;
|
|
664
|
+ }
|
438
|
665
|
}
|
|
666
|
+
|
|
667
|
+ return peerFpsSum / peerSsrcCount;
|
439
|
668
|
}
|
440
|
669
|
|
441
|
670
|
/**
|
|
@@ -443,17 +672,26 @@ export default class AvgRTPStatsReporter {
|
443
|
672
|
* @private
|
444
|
673
|
*/
|
445
|
674
|
_resetAvgStats() {
|
446
|
|
- this._avgBitrateUp.reset();
|
447
|
|
- this._avgBitrateDown.reset();
|
|
675
|
+ this._avgAudioBitrateUp.reset();
|
|
676
|
+ this._avgAudioBitrateDown.reset();
|
|
677
|
+
|
|
678
|
+ this._avgVideoBitrateUp.reset();
|
|
679
|
+ this._avgVideoBitrateDown.reset();
|
|
680
|
+
|
448
|
681
|
this._avgBandwidthUp.reset();
|
449
|
682
|
this._avgBandwidthDown.reset();
|
|
683
|
+
|
450
|
684
|
this._avgPacketLossUp.reset();
|
451
|
685
|
this._avgPacketLossDown.reset();
|
|
686
|
+ this._avgPacketLossTotal.reset();
|
|
687
|
+
|
452
|
688
|
this._avgRemoteFPS.reset();
|
|
689
|
+ this._avgRemoteScreenFPS.reset();
|
453
|
690
|
this._avgLocalFPS.reset();
|
|
691
|
+ this._avgLocalScreenFPS.reset();
|
|
692
|
+
|
454
|
693
|
this._avgCQ.reset();
|
455
|
|
- this._avgRTT.reset();
|
456
|
|
- this._avgRemoteRTTMap.clear();
|
|
694
|
+
|
457
|
695
|
this._sampleIdx = 0;
|
458
|
696
|
}
|
459
|
697
|
|
|
@@ -467,11 +705,7 @@ export default class AvgRTPStatsReporter {
|
467
|
705
|
this._conference.off(
|
468
|
706
|
ConnectionQualityEvents.LOCAL_STATS_UPDATED,
|
469
|
707
|
this._onLocalStatsUpdated);
|
470
|
|
- this._conference.off(
|
471
|
|
- ConnectionQualityEvents.REMOTE_STATS_UPDATED,
|
472
|
|
- this._onRemoteStatsUpdated);
|
473
|
|
- this._conference.off(
|
474
|
|
- ConferenceEvents.USER_LEFT,
|
475
|
|
- this._onUserLeft);
|
|
708
|
+ this.jvbStatsMonitor.dispose();
|
|
709
|
+ this.p2pStatsMonitor.dispose();
|
476
|
710
|
}
|
477
|
711
|
}
|