Adding stats that can be used to compute output audio levels as described here https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy.

BUG=webrtc:7982

Review-Url: https://codereview.webrtc.org/2964593002
Cr-Commit-Position: refs/heads/master@{#19027}
diff --git a/webrtc/audio/audio_receive_stream.cc b/webrtc/audio/audio_receive_stream.cc
index 6dedca5..d9829c7 100644
--- a/webrtc/audio/audio_receive_stream.cc
+++ b/webrtc/audio/audio_receive_stream.cc
@@ -187,6 +187,8 @@
   }
   stats.delay_estimate_ms = channel_proxy_->GetDelayEstimate();
   stats.audio_level = channel_proxy_->GetSpeechOutputLevelFullRange();
+  stats.total_output_energy = channel_proxy_->GetTotalOutputEnergy();
+  stats.total_output_duration = channel_proxy_->GetTotalOutputDuration();
 
   // Get jitter buffer and total delay (alg + jitter + playout) stats.
   auto ns = channel_proxy_->GetNetworkStatistics();
diff --git a/webrtc/audio/audio_receive_stream_unittest.cc b/webrtc/audio/audio_receive_stream_unittest.cc
index 127ea07..0fbfe51 100644
--- a/webrtc/audio/audio_receive_stream_unittest.cc
+++ b/webrtc/audio/audio_receive_stream_unittest.cc
@@ -57,6 +57,9 @@
 const int kJitterBufferDelay = -7;
 const int kPlayoutBufferDelay = 302;
 const unsigned int kSpeechOutputLevel = 99;
+const double kTotalOutputEnergy = 0.25;
+const double kTotalOutputDuration = 0.5;
+
 const CallStatistics kCallStats = {
     345,  678,  901, 234, -12, 3456, 7890, 567, 890, 123};
 const CodecInst kCodecInst = {
@@ -154,6 +157,10 @@
         .WillOnce(Return(kJitterBufferDelay + kPlayoutBufferDelay));
     EXPECT_CALL(*channel_proxy_, GetSpeechOutputLevelFullRange())
         .WillOnce(Return(kSpeechOutputLevel));
+    EXPECT_CALL(*channel_proxy_, GetTotalOutputEnergy())
+        .WillOnce(Return(kTotalOutputEnergy));
+    EXPECT_CALL(*channel_proxy_, GetTotalOutputDuration())
+        .WillOnce(Return(kTotalOutputDuration));
     EXPECT_CALL(*channel_proxy_, GetNetworkStatistics())
         .WillOnce(Return(kNetworkStats));
     EXPECT_CALL(*channel_proxy_, GetDecodingCallStatistics())
@@ -310,6 +317,8 @@
   EXPECT_EQ(static_cast<uint32_t>(kJitterBufferDelay + kPlayoutBufferDelay),
             stats.delay_estimate_ms);
   EXPECT_EQ(static_cast<int32_t>(kSpeechOutputLevel), stats.audio_level);
+  EXPECT_EQ(kTotalOutputEnergy, stats.total_output_energy);
+  EXPECT_EQ(kTotalOutputDuration, stats.total_output_duration);
   EXPECT_EQ(Q14ToFloat(kNetworkStats.currentExpandRate), stats.expand_rate);
   EXPECT_EQ(Q14ToFloat(kNetworkStats.currentSpeechExpandRate),
             stats.speech_expand_rate);
diff --git a/webrtc/audio/audio_send_stream.cc b/webrtc/audio/audio_send_stream.cc
index 1861cc0..0659cbf 100644
--- a/webrtc/audio/audio_send_stream.cc
+++ b/webrtc/audio/audio_send_stream.cc
@@ -279,6 +279,9 @@
   stats.audio_level = base->transmit_mixer()->AudioLevelFullRange();
   RTC_DCHECK_LE(0, stats.audio_level);
 
+  stats.total_input_energy = base->transmit_mixer()->GetTotalInputEnergy();
+  stats.total_input_duration = base->transmit_mixer()->GetTotalInputDuration();
+
   RTC_DCHECK(audio_state_->audio_processing());
   auto audio_processing_stats =
       audio_state_->audio_processing()->GetStatistics();
diff --git a/webrtc/audio/audio_send_stream_unittest.cc b/webrtc/audio/audio_send_stream_unittest.cc
index b906443..12fad6f 100644
--- a/webrtc/audio/audio_send_stream_unittest.cc
+++ b/webrtc/audio/audio_send_stream_unittest.cc
@@ -55,6 +55,8 @@
 const int kEchoReturnLossEnhancement = 101;
 const float kResidualEchoLikelihood = -1.0f;
 const int32_t kSpeechInputLevel = 96;
+const double kTotalInputEnergy = 0.25;
+const double kTotalInputDuration = 0.5;
 const CallStatistics kCallStats = {
     1345,  1678,  1901, 1234,  112, 13456, 17890, 1567, -1890, -1123};
 const ReportBlock kReportBlock = {456, 780, 123, 567, 890, 132, 143, 13354};
@@ -82,6 +84,8 @@
 class MockTransmitMixer : public voe::TransmitMixer {
  public:
   MOCK_CONST_METHOD0(AudioLevelFullRange, int16_t());
+  MOCK_CONST_METHOD0(GetTotalInputEnergy, double());
+  MOCK_CONST_METHOD0(GetTotalInputDuration, double());
 };
 
 std::unique_ptr<MockAudioEncoder> SetupAudioEncoderMock(
@@ -286,6 +290,10 @@
 
     EXPECT_CALL(transmit_mixer_, AudioLevelFullRange())
         .WillRepeatedly(Return(kSpeechInputLevel));
+    EXPECT_CALL(transmit_mixer_, GetTotalInputEnergy())
+        .WillRepeatedly(Return(kTotalInputEnergy));
+    EXPECT_CALL(transmit_mixer_, GetTotalInputDuration())
+        .WillRepeatedly(Return(kTotalInputDuration));
 
     // We have to set the instantaneous value, the average, min and max. We only
     // care about the instantaneous value, so we set all to the same value.
@@ -420,6 +428,8 @@
             stats.jitter_ms);
   EXPECT_EQ(kCallStats.rttMs, stats.rtt_ms);
   EXPECT_EQ(static_cast<int32_t>(kSpeechInputLevel), stats.audio_level);
+  EXPECT_EQ(kTotalInputEnergy, stats.total_input_energy);
+  EXPECT_EQ(kTotalInputDuration, stats.total_input_duration);
   EXPECT_EQ(-1, stats.aec_quality_min);
   EXPECT_EQ(kEchoDelayMedian, stats.echo_delay_median_ms);
   EXPECT_EQ(kEchoDelayStdDev, stats.echo_delay_std_ms);