浏览代码

Remove repetitive statistics lookups

master
Lyubomir Marinov 9 年前
父节点
当前提交
62f5f4db72
共有 1 个文件被更改,包括 33 次插入43 次删除
  1. 33
    43
      modules/statistics/RTPStatsCollector.js

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

490
     for (var idx in this.currentStatsReport) {
490
     for (var idx in this.currentStatsReport) {
491
         var now = this.currentStatsReport[idx];
491
         var now = this.currentStatsReport[idx];
492
         try {
492
         try {
493
-            if (getStatValue(now, 'receiveBandwidth') ||
494
-                getStatValue(now, 'sendBandwidth')) {
493
+            var receiveBandwidth = getStatValue(now, 'receiveBandwidth');
494
+            var sendBandwidth = getStatValue(now, 'sendBandwidth');
495
+            if (receiveBandwidth || sendBandwidth) {
495
                 this.conferenceStats.bandwidth = {
496
                 this.conferenceStats.bandwidth = {
496
-                    "download": Math.round(
497
-                            (getStatValue(now, 'receiveBandwidth')) / 1000),
498
-                    "upload": Math.round(
499
-                            (getStatValue(now, 'sendBandwidth')) / 1000)
497
+                    "download": Math.round(receiveBandwidth / 1000),
498
+                    "upload": Math.round(sendBandwidth / 1000)
500
                 };
499
                 };
501
             }
500
             }
502
         }
501
         }
549
         }
548
         }
550
 
549
 
551
         var before = this.baselineStatsReport[idx];
550
         var before = this.baselineStatsReport[idx];
551
+        var ssrc = getStatValue(now, 'ssrc');
552
         if (!before) {
552
         if (!before) {
553
-            logger.warn(getStatValue(now, 'ssrc') + ' not enough data');
553
+            logger.warn(ssrc + ' not enough data');
554
             continue;
554
             continue;
555
         }
555
         }
556
 
556
 
557
-        var ssrc = getStatValue(now, 'ssrc');
558
         if(!ssrc)
557
         if(!ssrc)
559
             continue;
558
             continue;
560
 
559
 
561
-        var ssrcStats = this.ssrc2stats[ssrc];
562
-        if (!ssrcStats) {
563
-            ssrcStats = new PeerStats();
564
-            this.ssrc2stats[ssrc] = ssrcStats;
565
-        }
566
-
560
+        var ssrcStats
561
+          = this.ssrc2stats[ssrc] || (this.ssrc2stats[ssrc] = new PeerStats());
567
 
562
 
568
         var isDownloadStream = true;
563
         var isDownloadStream = true;
569
         var key = 'packetsReceived';
564
         var key = 'packetsReceived';
604
             isDownloadStream: isDownloadStream
599
             isDownloadStream: isDownloadStream
605
         });
600
         });
606
 
601
 
607
-
608
         var bytesReceived = 0, bytesSent = 0;
602
         var bytesReceived = 0, bytesSent = 0;
609
-        if(getStatValue(now, "bytesReceived")) {
610
-            bytesReceived = getStatValue(now, "bytesReceived") -
611
-                getStatValue(before, "bytesReceived");
603
+        var nowBytesTransmitted = getStatValue(now, "bytesReceived");
604
+        if(nowBytesTransmitted) {
605
+            bytesReceived
606
+                = nowBytesTransmitted - getStatValue(before, "bytesReceived");
612
         }
607
         }
613
-
614
-        if (getStatValue(now, "bytesSent")) {
615
-            bytesSent = getStatValue(now, "bytesSent") -
616
-                getStatValue(before, "bytesSent");
608
+        nowBytesTransmitted = getStatValue(now, "bytesSent");
609
+        if (nowBytesTransmitted) {
610
+            bytesSent = nowBytesTransmitted - getStatValue(before, "bytesSent");
617
         }
611
         }
618
 
612
 
619
         var time = Math.round((now.timestamp - before.timestamp) / 1000);
613
         var time = Math.round((now.timestamp - before.timestamp) / 1000);
636
 
630
 
637
         var resolution = {height: null, width: null};
631
         var resolution = {height: null, width: null};
638
         try {
632
         try {
639
-            if (getStatValue(now, "googFrameHeightReceived") &&
640
-                getStatValue(now, "googFrameWidthReceived")) {
641
-                resolution.height =
642
-                    getStatValue(now, "googFrameHeightReceived");
643
-                resolution.width = getStatValue(now, "googFrameWidthReceived");
633
+            var height, width;
634
+            if ((height = getStatValue(now, "googFrameHeightReceived")) &&
635
+                (width = getStatValue(now, "googFrameWidthReceived"))) {
636
+                resolution.height = height;
637
+                resolution.width = width;
644
             }
638
             }
645
-            else if (getStatValue(now, "googFrameHeightSent") &&
646
-                getStatValue(now, "googFrameWidthSent")) {
647
-                resolution.height = getStatValue(now, "googFrameHeightSent");
648
-                resolution.width = getStatValue(now, "googFrameWidthSent");
639
+            else if ((height = getStatValue(now, "googFrameHeightSent")) &&
640
+                (width = getStatValue(now, "googFrameWidthSent"))) {
641
+                resolution.height = height;
642
+                resolution.width = width;
649
             }
643
             }
650
         }
644
         }
651
         catch(e){/*not supported*/}
645
         catch(e){/*not supported*/}
733
         }
727
         }
734
 
728
 
735
         var before = this.baselineAudioLevelsReport[idx];
729
         var before = this.baselineAudioLevelsReport[idx];
730
+        var ssrc = getStatValue(now, 'ssrc');
736
         if (!before) {
731
         if (!before) {
737
-            logger.warn(getStatValue(now, 'ssrc') + ' not enough data');
732
+            logger.warn(ssrc + ' not enough data');
738
             continue;
733
             continue;
739
         }
734
         }
740
 
735
 
741
-        var ssrc = getStatValue(now, 'ssrc');
742
         if (!ssrc) {
736
         if (!ssrc) {
743
             if ((Date.now() - now.timestamp) < 3000)
737
             if ((Date.now() - now.timestamp) < 3000)
744
                 logger.warn("No ssrc: ");
738
                 logger.warn("No ssrc: ");
745
             continue;
739
             continue;
746
         }
740
         }
747
 
741
 
748
-        var ssrcStats = this.ssrc2stats[ssrc];
749
-        if (!ssrcStats) {
750
-            ssrcStats = new PeerStats();
751
-            this.ssrc2stats[ssrc] = ssrcStats;
752
-        }
742
+        var ssrcStats
743
+            = this.ssrc2stats[ssrc]
744
+                || (this.ssrc2stats[ssrc] = new PeerStats());
753
 
745
 
754
         // Audio level
746
         // Audio level
755
-        var audioLevel = null;
756
-
757
         try {
747
         try {
758
-            audioLevel = getStatValue(now, 'audioInputLevel');
759
-            if (!audioLevel)
760
-                audioLevel = getStatValue(now, 'audioOutputLevel');
748
+            var audioLevel
749
+                = getStatValue(now, 'audioInputLevel')
750
+                    || getStatValue(now, 'audioOutputLevel');
761
         }
751
         }
762
         catch(e) {/*not supported*/
752
         catch(e) {/*not supported*/
763
             logger.warn("Audio Levels are not available in the statistics.");
753
             logger.warn("Audio Levels are not available in the statistics.");

正在加载...
取消
保存