Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/webrtc_audio_capturer.h" | 5 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "content/child/child_process.h" | 12 #include "content/child/child_process.h" |
| 13 #include "content/renderer/media/audio_device_factory.h" | 13 #include "content/renderer/media/audio_device_factory.h" |
| 14 #include "content/renderer/media/media_stream_audio_processor.h" | 14 #include "content/renderer/media/media_stream_audio_processor.h" |
| 15 #include "content/renderer/media/media_stream_audio_processor_options.h" | 15 #include "content/renderer/media/media_stream_audio_processor_options.h" |
| 16 #include "content/renderer/media/media_stream_audio_source.h" | 16 #include "content/renderer/media/media_stream_audio_source.h" |
| 17 #include "content/renderer/media/webrtc_audio_device_impl.h" | 17 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 18 #include "content/renderer/media/webrtc_local_audio_track.h" | 18 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 19 #include "content/renderer/media/webrtc_logging.h" | 19 #include "content/renderer/media/webrtc_logging.h" |
| 20 #include "media/audio/sample_rates.h" | 20 #include "media/audio/sample_rates.h" |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Supported hardware sample rates for input and output sides. | |
| 27 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 28 // media::GetAudioInputHardwareSampleRate() asks the audio layer | |
| 29 // for its current sample rate (set by the user) on Windows and Mac OS X. | |
| 30 // The listed rates below adds restrictions and WebRtcAudioDeviceImpl::Init() | |
| 31 // will fail if the user selects any rate outside these ranges. | |
| 32 const int kValidInputRates[] = | |
| 33 {192000, 96000, 48000, 44100, 32000, 16000, 8000}; | |
| 34 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 35 const int kValidInputRates[] = {48000, 44100}; | |
| 36 #elif defined(OS_ANDROID) | |
| 37 const int kValidInputRates[] = {48000, 44100}; | |
| 38 #else | |
| 39 const int kValidInputRates[] = {44100}; | |
| 40 #endif | |
| 41 | |
| 42 // Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments | 26 // Time constant for AudioPowerMonitor. See AudioPowerMonitor ctor comments |
| 43 // for semantics. This value was arbitrarily chosen, but seems to work well. | 27 // for semantics. This value was arbitrarily chosen, but seems to work well. |
| 44 const int kPowerMonitorTimeConstantMs = 10; | 28 const int kPowerMonitorTimeConstantMs = 10; |
| 45 | 29 |
| 46 // The time between two audio power level samples. | 30 // The time between two audio power level samples. |
| 47 const int kPowerMonitorLogIntervalSeconds = 10; | 31 const int kPowerMonitorLogIntervalSeconds = 10; |
| 48 | 32 |
| 49 } // namespace | 33 } // namespace |
| 50 | 34 |
| 51 // Reference counted container of WebRtcLocalAudioTrack delegate. | 35 // Reference counted container of WebRtcLocalAudioTrack delegate. |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 channel_layout != media::CHANNEL_LAYOUT_STEREO && | 165 channel_layout != media::CHANNEL_LAYOUT_STEREO && |
| 182 channel_layout != media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) { | 166 channel_layout != media::CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC) { |
| 183 DLOG(ERROR) << channel_layout | 167 DLOG(ERROR) << channel_layout |
| 184 << " is not a supported input channel configuration."; | 168 << " is not a supported input channel configuration."; |
| 185 return false; | 169 return false; |
| 186 } | 170 } |
| 187 | 171 |
| 188 DVLOG(1) << "Audio input hardware sample rate: " | 172 DVLOG(1) << "Audio input hardware sample rate: " |
| 189 << device_info_.device.input.sample_rate; | 173 << device_info_.device.input.sample_rate; |
| 190 media::AudioSampleRate asr; | 174 media::AudioSampleRate asr; |
| 191 if (media::ToAudioSampleRate(device_info_.device.input.sample_rate, &asr)) { | 175 if (media::ToAudioSampleRate(device_info_.device.input.sample_rate, &asr)) { |
|
henrika (OOO until Aug 14)
2014/09/05 13:08:28
Still valid to populate this histogram, right?
no longer working on chromium
2014/09/05 13:11:57
Yes, we would like to keep the uma.
| |
| 192 UMA_HISTOGRAM_ENUMERATION( | 176 UMA_HISTOGRAM_ENUMERATION( |
| 193 "WebRTC.AudioInputSampleRate", asr, media::kAudioSampleRateMax + 1); | 177 "WebRTC.AudioInputSampleRate", asr, media::kAudioSampleRateMax + 1); |
| 194 } else { | 178 } else { |
| 195 UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected", | 179 UMA_HISTOGRAM_COUNTS("WebRTC.AudioInputSampleRateUnexpected", |
| 196 device_info_.device.input.sample_rate); | 180 device_info_.device.input.sample_rate); |
| 197 } | 181 } |
| 198 | 182 |
| 199 // Verify that the reported input hardware sample rate is supported | |
| 200 // on the current platform. | |
| 201 if (std::find(&kValidInputRates[0], | |
| 202 &kValidInputRates[0] + arraysize(kValidInputRates), | |
| 203 device_info_.device.input.sample_rate) == | |
| 204 &kValidInputRates[arraysize(kValidInputRates)]) { | |
| 205 DLOG(ERROR) << device_info_.device.input.sample_rate | |
| 206 << " is not a supported input rate."; | |
| 207 return false; | |
| 208 } | |
| 209 | |
| 210 // Create and configure the default audio capturing source. | 183 // Create and configure the default audio capturing source. |
| 211 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id_), | 184 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id_), |
| 212 channel_layout, | 185 channel_layout, |
| 213 static_cast<float>(device_info_.device.input.sample_rate)); | 186 static_cast<float>(device_info_.device.input.sample_rate)); |
| 214 | 187 |
| 215 // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware | 188 // Add the capturer to the WebRtcAudioDeviceImpl since it needs some hardware |
| 216 // information from the capturer. | 189 // information from the capturer. |
| 217 if (audio_device_) | 190 if (audio_device_) |
| 218 audio_device_->AddAudioCapturer(this); | 191 audio_device_->AddAudioCapturer(this); |
| 219 | 192 |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 | 582 |
| 610 void WebRtcAudioCapturer::SetCapturerSourceForTesting( | 583 void WebRtcAudioCapturer::SetCapturerSourceForTesting( |
| 611 const scoped_refptr<media::AudioCapturerSource>& source, | 584 const scoped_refptr<media::AudioCapturerSource>& source, |
| 612 media::AudioParameters params) { | 585 media::AudioParameters params) { |
| 613 // Create a new audio stream as source which uses the new source. | 586 // Create a new audio stream as source which uses the new source. |
| 614 SetCapturerSource(source, params.channel_layout(), | 587 SetCapturerSource(source, params.channel_layout(), |
| 615 static_cast<float>(params.sample_rate())); | 588 static_cast<float>(params.sample_rate())); |
| 616 } | 589 } |
| 617 | 590 |
| 618 } // namespace content | 591 } // namespace content |
| OLD | NEW |