瀏覽代碼

Adds frame rate statistics.

master
damencho 8 年之前
父節點
當前提交
5701b7a697
共有 3 個檔案被更改,包括 109 行新增31 行删除
  1. 72
    28
      JitsiConferenceEventManager.js
  2. 4
    2
      modules/connectivity/ConnectionQuality.js
  3. 33
    1
      modules/statistics/RTPStatsCollector.js

+ 72
- 28
JitsiConferenceEventManager.js 查看文件

@@ -31,6 +31,76 @@ function JitsiConferenceEventManager(conference) {
31 31
         });
32 32
 }
33 33
 
34
+/**
35
+ * Groups resolutions by user id, skip incorrect resolutions.
36
+ * @param conference {JitsiConference} the conference
37
+ * @param resolutions map of resolutions by ssrc
38
+ */
39
+function mapResolutionsByUserId(conference, resolutions) {
40
+
41
+    const id2resolution = {};
42
+
43
+    // preprocess resolutions: group by user id, skip incorrect
44
+    // resolutions etc.
45
+    Object.keys(resolutions).forEach(ssrc => {
46
+        const resolution = resolutions[ssrc];
47
+
48
+        if (!resolution.width || !resolution.height
49
+            || resolution.width === -1 || resolution.height === -1) {
50
+            return;
51
+        }
52
+
53
+        const id = conference.rtc.getResourceBySSRC(ssrc);
54
+
55
+        if (!id) {
56
+            return;
57
+        }
58
+
59
+        // ssrc to resolution map for user id
60
+        const idResolutions = id2resolution[id] || {};
61
+
62
+        idResolutions[ssrc] = resolution;
63
+
64
+        id2resolution[id] = idResolutions;
65
+    });
66
+
67
+    return id2resolution;
68
+}
69
+
70
+/**
71
+ * Groups framerates by user id, skip framerates with value of 0.
72
+ * @param conference {JitsiConference} the conference
73
+ * @param framerates map of framerates by ssrc
74
+ */
75
+function mapFrameratesByUserId(conference, framerates) {
76
+
77
+    const id2framerate = {};
78
+
79
+    // preprocess framerates: group by user id
80
+    Object.keys(framerates).forEach(ssrc => {
81
+        const framerate = framerates[ssrc];
82
+
83
+        if (framerate === 0) {
84
+            return;
85
+        }
86
+
87
+        const id = conference.rtc.getResourceBySSRC(ssrc);
88
+
89
+        if (!id) {
90
+            return;
91
+        }
92
+
93
+        // ssrc to framerate map for user id
94
+        const id2framerates = id2framerate[id] || {};
95
+
96
+        id2framerates[ssrc] = framerate;
97
+
98
+        id2framerate[id] = id2framerates;
99
+    });
100
+
101
+    return id2framerate;
102
+}
103
+
34 104
 /**
35 105
  * Setups event listeners related to conference.chatRoom
36 106
  */
@@ -569,35 +639,9 @@ JitsiConferenceEventManager.prototype.setupStatisticsListeners = function() {
569 639
             JitsiConferenceEvents.BEFORE_STATISTICS_DISPOSED);
570 640
     });
571 641
     conference.statistics.addConnectionStatsListener(stats => {
572
-        const ssrc2resolution = stats.resolution;
573
-
574
-        const id2resolution = {};
575
-
576
-        // preprocess resolutions: group by user id, skip incorrect
577
-        // resolutions etc.
578
-        Object.keys(ssrc2resolution).forEach(ssrc => {
579
-            const resolution = ssrc2resolution[ssrc];
580
-
581
-            if (!resolution.width || !resolution.height
582
-                || resolution.width === -1 || resolution.height === -1) {
583
-                return;
584
-            }
585
-
586
-            const id = conference.rtc.getResourceBySSRC(ssrc);
587
-
588
-            if (!id) {
589
-                return;
590
-            }
591
-
592
-            // ssrc to resolution map for user id
593
-            const idResolutions = id2resolution[id] || {};
594
-
595
-            idResolutions[ssrc] = resolution;
596
-
597
-            id2resolution[id] = idResolutions;
598
-        });
599 642
 
600
-        stats.resolution = id2resolution;
643
+        stats.resolution = mapResolutionsByUserId(conference, stats.resolution);
644
+        stats.framerate = mapFrameratesByUserId(conference, stats.framerate);
601 645
 
602 646
         conference.eventEmitter.emit(
603 647
             JitsiConferenceEvents.CONNECTION_STATS, stats);

+ 4
- 2
modules/connectivity/ConnectionQuality.js 查看文件

@@ -396,7 +396,8 @@ export default class ConnectionQuality {
396 396
         const data = {
397 397
             bitrate: this._localStats.bitrate,
398 398
             packetLoss: this._localStats.packetLoss,
399
-            connectionQuality: this._localStats.connectionQuality
399
+            connectionQuality: this._localStats.connectionQuality,
400
+            framerate: this._localStats.framerate
400 401
         };
401 402
 
402 403
         // TODO: It looks like the remote participants don't really "care"
@@ -477,7 +478,8 @@ export default class ConnectionQuality {
477 478
         this._remoteStats[id] = {
478 479
             bitrate: data.bitrate,
479 480
             packetLoss: data.packetLoss,
480
-            connectionQuality: data.connectionQuality
481
+            connectionQuality: data.connectionQuality,
482
+            framerate: data.framerate
481 483
         };
482 484
 
483 485
         this.eventEmitter.emit(

+ 33
- 1
modules/statistics/RTPStatsCollector.js 查看文件

@@ -23,7 +23,8 @@ KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_FIREFOX] = {
23 23
     'packetsLost': 'packetsLost',
24 24
     'packetsSent': 'packetsSent',
25 25
     'bytesReceived': 'bytesReceived',
26
-    'bytesSent': 'bytesSent'
26
+    'bytesSent': 'bytesSent',
27
+    'framerateMean': 'framerateMean'
27 28
 };
28 29
 KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_CHROME] = {
29 30
     'receiveBandwidth': 'googAvailableReceiveBandwidth',
@@ -42,6 +43,8 @@ KEYS_BY_BROWSER_TYPE[RTCBrowserType.RTC_BROWSER_CHROME] = {
42 43
     'googFrameWidthReceived': 'googFrameWidthReceived',
43 44
     'googFrameHeightSent': 'googFrameHeightSent',
44 45
     'googFrameWidthSent': 'googFrameWidthSent',
46
+    'googFrameRateReceived': 'googFrameRateReceived',
47
+    'googFrameRateSent': 'googFrameRateSent',
45 48
     'audioInputLevel': 'audioInputLevel',
46 49
     'audioOutputLevel': 'audioOutputLevel'
47 50
 };
@@ -85,6 +88,7 @@ function SsrcStats() {
85 88
         upload: 0
86 89
     };
87 90
     this.resolution = {};
91
+    this.framerate = 0;
88 92
 }
89 93
 
90 94
 /**
@@ -122,6 +126,14 @@ SsrcStats.prototype.resetBitrate = function() {
122 126
     this.bitrate.upload = 0;
123 127
 };
124 128
 
129
+/**
130
+ * Sets the "framerate".
131
+ * @param framerate the value to set.
132
+ */
133
+SsrcStats.prototype.setFramerate = function(framerate) {
134
+    this.framerate = framerate || 0;
135
+};
136
+
125 137
 /**
126 138
  *
127 139
  */
@@ -587,6 +599,21 @@ StatsCollector.prototype.processStatsReport = function() {
587 599
             }
588 600
         } catch (e) { /* not supported*/ }
589 601
 
602
+        // Tries to get frame rate
603
+        try {
604
+            ssrcStats.setFramerate(
605
+                getStatValue(now, 'googFrameRateReceived')
606
+                || getStatValue(now, 'googFrameRateSent')
607
+                || 0);
608
+        } catch (e) {
609
+            // if it fails with previous properties(chrome),
610
+            // let's try with another one (FF)
611
+            try {
612
+                ssrcStats.setFramerate(Math.round(
613
+                    getNonNegativeStat(now, 'framerateMean')));
614
+            } catch (err) { /* not supported*/ }
615
+        }
616
+
590 617
         if (resolution.height && resolution.width) {
591 618
             ssrcStats.setResolution(resolution);
592 619
         } else {
@@ -606,6 +633,7 @@ StatsCollector.prototype.processStatsReport = function() {
606 633
     let bitrateDownload = 0;
607 634
     let bitrateUpload = 0;
608 635
     const resolutions = {};
636
+    const framerates = {};
609 637
 
610 638
     Object.keys(this.ssrc2stats).forEach(
611 639
         function(ssrc) {
@@ -626,6 +654,9 @@ StatsCollector.prototype.processStatsReport = function() {
626 654
 
627 655
             // collect resolutions
628 656
             resolutions[ssrc] = ssrcStats.resolution;
657
+
658
+            // collect framerates
659
+            framerates[ssrc] = ssrcStats.framerate;
629 660
         },
630 661
         this
631 662
     );
@@ -650,6 +681,7 @@ StatsCollector.prototype.processStatsReport = function() {
650 681
         'bitrate': this.conferenceStats.bitrate,
651 682
         'packetLoss': this.conferenceStats.packetLoss,
652 683
         'resolution': resolutions,
684
+        'framerate': framerates,
653 685
         'transport': this.conferenceStats.transport
654 686
     });
655 687
     this.conferenceStats.transport = [];

Loading…
取消
儲存