Index: content/renderer/media/webrtc_audio_capturer.cc |
diff --git a/content/renderer/media/webrtc_audio_capturer.cc b/content/renderer/media/webrtc_audio_capturer.cc |
index 7318cba1ba5e32b5c89f6aacfc41fa94f2106f9e..482d25f1114b2479baabcda0d4fb930c4e5ba944 100644 |
--- a/content/renderer/media/webrtc_audio_capturer.cc |
+++ b/content/renderer/media/webrtc_audio_capturer.cc |
@@ -38,6 +38,13 @@ const int kValidInputRates[] = {48000, 44100}; |
const int kValidInputRates[] = {44100}; |
#endif |
+// Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments |
+// for semantics. This value was arbitrarily chosen, but seems to work well. |
+const int kPowerMonitorTimeConstantMs = 10; |
+ |
+// The time between two audio power level samples. |
+const int kPowerMonitorLogIntervalSeconds = 10; |
+ |
} // namespace |
// Reference counted container of WebRtcLocalAudioTrack delegate. |
@@ -222,7 +229,10 @@ WebRtcAudioCapturer::WebRtcAudioCapturer( |
peer_connection_mode_(false), |
key_pressed_(false), |
need_audio_processing_(false), |
- audio_device_(audio_device) { |
+ audio_device_(audio_device), |
+ audio_power_monitor_( |
+ device_info_.device.input.sample_rate, |
+ base::TimeDelta::FromMilliseconds(kPowerMonitorTimeConstantMs)) { |
DVLOG(1) << "WebRtcAudioCapturer::WebRtcAudioCapturer()"; |
} |
@@ -483,6 +493,20 @@ void WebRtcAudioCapturer::Capture(media::AudioBus* audio_source, |
(*it)->SetAudioProcessor(audio_processor_); |
} |
+ if ((base::TimeTicks::Now() - last_audio_level_log_time_).InSeconds() > |
+ kPowerMonitorLogIntervalSeconds) { |
+ audio_power_monitor_.Scan(*audio_source, audio_source->frames()); |
+ |
+ last_audio_level_log_time_ = base::TimeTicks::Now(); |
+ |
+ std::pair<float, bool> result = |
+ audio_power_monitor_.ReadCurrentPowerAndClip(); |
+ WebRtcLogMessage(base::StringPrintf( |
+ "WAC::Capture: current_audio_power=%.2fdBFS.", result.first)); |
+ |
+ audio_power_monitor_.Reset(); |
+ } |
+ |
// Push the data to the processor for processing. |
audio_processor_->PushCaptureData(audio_source); |