Browse Source

Remove repetitive statistics lookups

master
Lyubomir Marinov 9 years ago
parent
commit
62f5f4db72
1 changed files with 33 additions and 43 deletions
  1. 33
    43
      modules/statistics/RTPStatsCollector.js

+ 33
- 43
modules/statistics/RTPStatsCollector.js View File

@@ -490,13 +490,12 @@ StatsCollector.prototype.processStatsReport = function () {
490 490
     for (var idx in this.currentStatsReport) {
491 491
         var now = this.currentStatsReport[idx];
492 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 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,21 +548,17 @@ StatsCollector.prototype.processStatsReport = function () {
549 548
         }
550 549
 
551 550
         var before = this.baselineStatsReport[idx];
551
+        var ssrc = getStatValue(now, 'ssrc');
552 552
         if (!before) {
553
-            logger.warn(getStatValue(now, 'ssrc') + ' not enough data');
553
+            logger.warn(ssrc + ' not enough data');
554 554
             continue;
555 555
         }
556 556
 
557
-        var ssrc = getStatValue(now, 'ssrc');
558 557
         if(!ssrc)
559 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 563
         var isDownloadStream = true;
569 564
         var key = 'packetsReceived';
@@ -604,16 +599,15 @@ StatsCollector.prototype.processStatsReport = function () {
604 599
             isDownloadStream: isDownloadStream
605 600
         });
606 601
 
607
-
608 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 613
         var time = Math.round((now.timestamp - before.timestamp) / 1000);
@@ -636,16 +630,16 @@ StatsCollector.prototype.processStatsReport = function () {
636 630
 
637 631
         var resolution = {height: null, width: null};
638 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 645
         catch(e){/*not supported*/}
@@ -733,31 +727,27 @@ StatsCollector.prototype.processAudioLevelReport = function () {
733 727
         }
734 728
 
735 729
         var before = this.baselineAudioLevelsReport[idx];
730
+        var ssrc = getStatValue(now, 'ssrc');
736 731
         if (!before) {
737
-            logger.warn(getStatValue(now, 'ssrc') + ' not enough data');
732
+            logger.warn(ssrc + ' not enough data');
738 733
             continue;
739 734
         }
740 735
 
741
-        var ssrc = getStatValue(now, 'ssrc');
742 736
         if (!ssrc) {
743 737
             if ((Date.now() - now.timestamp) < 3000)
744 738
                 logger.warn("No ssrc: ");
745 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 746
         // Audio level
755
-        var audioLevel = null;
756
-
757 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 752
         catch(e) {/*not supported*/
763 753
             logger.warn("Audio Levels are not available in the statistics.");

Loading…
Cancel
Save