Просмотр исходного кода

feat: report avg RTT for P2P

tags/v0.0.2
paweldomas 8 лет назад
Родитель
Сommit
cc6b5c8f04

+ 17
- 0
modules/RTC/RTCBrowserType.js Просмотреть файл

@@ -218,6 +218,23 @@ const RTCBrowserType = {
218 218
         return !RTCBrowserType.isFirefox();
219 219
     },
220 220
 
221
+    /**
222
+     * Checks if the current browser reports round trip time statistics for
223
+     * the ICE candidate pair.
224
+     * @return {boolean}
225
+     */
226
+    supportsRTTStatistics() {
227
+        // Firefox does not seem to report RTT for ICE candidate pair:
228
+        // eslint-disable-next-line max-len
229
+        // https://www.w3.org/TR/webrtc-stats/#dom-rtcicecandidatepairstats-currentroundtriptime
230
+        // It does report mozRTT for RTP streams, but at the time of this
231
+        // writing it's value does not make sense most of the time
232
+        // (is reported as 1):
233
+        // https://bugzilla.mozilla.org/show_bug.cgi?id=1241066
234
+        // For Chrome and others we rely on 'googRtt'.
235
+        return !RTCBrowserType.isFirefox();
236
+    },
237
+
221 238
     /**
222 239
      * Whether jitsi-meet supports simulcast on the current browser.
223 240
      * @returns {boolean}

+ 23
- 0
modules/statistics/AvgRTPStatsReporter.js Просмотреть файл

@@ -184,6 +184,14 @@ export default class AvgRTPStatsReporter {
184 184
          */
185 185
         this._avgRemoteFPS = new AverageStatReport('stat.avg.framerate.remote');
186 186
 
187
+        /**
188
+         * Average round trip time reported by the ICE candidate pair.
189
+         * FIXME currently reported only for P2P
190
+         * @type {AverageStatReport}
191
+         * @private
192
+         */
193
+        this._avgRTT = new AverageStatReport('stat.avg.rtt');
194
+
187 195
         /**
188 196
          * Average FPS for local video
189 197
          * @type {AverageStatReport}
@@ -281,6 +289,15 @@ export default class AvgRTPStatsReporter {
281 289
         this._avgPacketLossTotal.addNext(packetLoss.total);
282 290
         this._avgCQ.addNext(data.connectionQuality);
283 291
 
292
+        if (RTCBrowserType.supportsRTTStatistics()) {
293
+            // FIXME implement JVB end-to-end RTT
294
+            if (isP2P && data.transport && data.transport.length) {
295
+                this._avgRTT.addNext(data.transport[0].rtt);
296
+            } else {
297
+                this._avgRTT.reset();
298
+            }
299
+        }
300
+
284 301
         if (frameRate) {
285 302
             this._avgRemoteFPS.addNext(
286 303
                 this._calculateAvgVideoFps(frameRate, false /* remote */));
@@ -304,6 +321,11 @@ export default class AvgRTPStatsReporter {
304 321
             this._avgLocalFPS.report(isP2P);
305 322
             this._avgCQ.report(isP2P);
306 323
 
324
+            // FIXME implement JVB end-to-end RTT
325
+            if (isP2P && RTCBrowserType.supportsRTTStatistics()) {
326
+                this._avgRTT.report(isP2P);
327
+            }
328
+
307 329
             this._resetAvgStats();
308 330
         }
309 331
     }
@@ -358,6 +380,7 @@ export default class AvgRTPStatsReporter {
358 380
         this._avgRemoteFPS.reset();
359 381
         this._avgLocalFPS.reset();
360 382
         this._avgCQ.reset();
383
+        this._avgRTT.reset();
361 384
         this._sampleIdx = 0;
362 385
     }
363 386
 

+ 6
- 3
modules/statistics/RTPStatsCollector.js Просмотреть файл

@@ -44,7 +44,8 @@ KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_CHROME] = {
44 44
     'googFrameRateReceived': 'googFrameRateReceived',
45 45
     'googFrameRateSent': 'googFrameRateSent',
46 46
     'audioInputLevel': 'audioInputLevel',
47
-    'audioOutputLevel': 'audioOutputLevel'
47
+    'audioOutputLevel': 'audioOutputLevel',
48
+    'currentRoundTripTime': 'googRtt'
48 49
 };
49 50
 KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_OPERA]
50 51
     = KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_CHROME];
@@ -457,13 +458,14 @@ StatsCollector.prototype.processStatsReport = function() {
457 458
         } catch (e) { /* not supported*/ }
458 459
 
459 460
         if (now.type === 'googCandidatePair') {
460
-            let active, ip, localip, type;
461
+            let active, ip, localip, rtt, type;
461 462
 
462 463
             try {
463 464
                 ip = getStatValue(now, 'remoteAddress');
464 465
                 type = getStatValue(now, 'transportType');
465 466
                 localip = getStatValue(now, 'localAddress');
466 467
                 active = getStatValue(now, 'activeConnection');
468
+                rtt = getNonNegativeStat(now, 'currentRoundTripTime');
467 469
             } catch (e) { /* not supported*/ }
468 470
             if (!ip || !type || !localip || active !== 'true') {
469 471
                 continue;
@@ -481,7 +483,8 @@ StatsCollector.prototype.processStatsReport = function() {
481 483
                     ip,
482 484
                     type,
483 485
                     localip,
484
-                    p2p: this.peerconnection.isP2P
486
+                    p2p: this.peerconnection.isP2P,
487
+                    rtt
485 488
                 });
486 489
             }
487 490
             continue;

Загрузка…
Отмена
Сохранить