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" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 DISALLOW_COPY_AND_ASSIGN(TrackOwner); | 107 DISALLOW_COPY_AND_ASSIGN(TrackOwner); |
108 }; | 108 }; |
109 | 109 |
110 // static | 110 // static |
111 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { | 111 scoped_refptr<WebRtcAudioCapturer> WebRtcAudioCapturer::CreateCapturer() { |
112 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); | 112 scoped_refptr<WebRtcAudioCapturer> capturer = new WebRtcAudioCapturer(); |
113 return capturer; | 113 return capturer; |
114 } | 114 } |
115 | 115 |
116 void WebRtcAudioCapturer::Reconfigure(int sample_rate, | 116 void WebRtcAudioCapturer::Reconfigure(int sample_rate, |
117 media::ChannelLayout channel_layout) { | 117 media::ChannelLayout channel_layout, |
| 118 int effects) { |
118 DCHECK(thread_checker_.CalledOnValidThread()); | 119 DCHECK(thread_checker_.CalledOnValidThread()); |
119 int buffer_size = GetBufferSize(sample_rate); | 120 int buffer_size = GetBufferSize(sample_rate); |
120 DVLOG(1) << "Using WebRTC input buffer size: " << buffer_size; | 121 DVLOG(1) << "Using WebRTC input buffer size: " << buffer_size; |
121 | 122 |
122 media::AudioParameters::Format format = | 123 media::AudioParameters::Format format = |
123 media::AudioParameters::AUDIO_PCM_LOW_LATENCY; | 124 media::AudioParameters::AUDIO_PCM_LOW_LATENCY; |
124 | 125 |
125 // bits_per_sample is always 16 for now. | 126 // bits_per_sample is always 16 for now. |
126 int bits_per_sample = 16; | 127 int bits_per_sample = 16; |
127 media::AudioParameters params(format, channel_layout, sample_rate, | 128 media::AudioParameters params(format, channel_layout, 0, sample_rate, |
128 bits_per_sample, buffer_size); | 129 bits_per_sample, buffer_size, effects); |
129 | |
130 { | 130 { |
131 base::AutoLock auto_lock(lock_); | 131 base::AutoLock auto_lock(lock_); |
132 params_ = params; | 132 params_ = params; |
133 | 133 |
134 // Notify all tracks about the new format. | 134 // Notify all tracks about the new format. |
135 tracks_.TagAll(); | 135 tracks_.TagAll(); |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 bool WebRtcAudioCapturer::Initialize(int render_view_id, | 139 bool WebRtcAudioCapturer::Initialize(int render_view_id, |
140 media::ChannelLayout channel_layout, | 140 media::ChannelLayout channel_layout, |
141 int sample_rate, | 141 int sample_rate, |
142 int buffer_size, | 142 int buffer_size, |
143 int session_id, | 143 int session_id, |
144 const std::string& device_id, | 144 const std::string& device_id, |
145 int paired_output_sample_rate, | 145 int paired_output_sample_rate, |
146 int paired_output_frames_per_buffer) { | 146 int paired_output_frames_per_buffer, |
| 147 int effects) { |
147 DCHECK(thread_checker_.CalledOnValidThread()); | 148 DCHECK(thread_checker_.CalledOnValidThread()); |
148 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; | 149 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; |
149 | 150 |
150 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; | 151 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; |
151 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", | 152 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", |
152 channel_layout, media::CHANNEL_LAYOUT_MAX); | 153 channel_layout, media::CHANNEL_LAYOUT_MAX); |
153 | 154 |
154 WebRtcLogMessage(base::StringPrintf( | 155 WebRtcLogMessage(base::StringPrintf( |
155 "WAC::Initialize. render_view_id=%d" | 156 "WAC::Initialize. render_view_id=%d" |
156 ", channel_layout=%d, sample_rate=%d, buffer_size=%d" | 157 ", channel_layout=%d, sample_rate=%d, buffer_size=%d" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 &kValidInputRates[arraysize(kValidInputRates)]) { | 203 &kValidInputRates[arraysize(kValidInputRates)]) { |
203 DLOG(ERROR) << sample_rate << " is not a supported input rate."; | 204 DLOG(ERROR) << sample_rate << " is not a supported input rate."; |
204 return false; | 205 return false; |
205 } | 206 } |
206 | 207 |
207 // Create and configure the default audio capturing source. The |source_| | 208 // Create and configure the default audio capturing source. The |source_| |
208 // will be overwritten if an external client later calls SetCapturerSource() | 209 // will be overwritten if an external client later calls SetCapturerSource() |
209 // providing an alternative media::AudioCapturerSource. | 210 // providing an alternative media::AudioCapturerSource. |
210 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), | 211 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
211 channel_layout, | 212 channel_layout, |
212 static_cast<float>(sample_rate)); | 213 static_cast<float>(sample_rate), |
| 214 effects); |
213 | 215 |
214 return true; | 216 return true; |
215 } | 217 } |
216 | 218 |
217 WebRtcAudioCapturer::WebRtcAudioCapturer() | 219 WebRtcAudioCapturer::WebRtcAudioCapturer() |
218 : running_(false), | 220 : running_(false), |
219 render_view_id_(-1), | 221 render_view_id_(-1), |
220 hardware_buffer_size_(0), | 222 hardware_buffer_size_(0), |
221 session_id_(0), | 223 session_id_(0), |
222 volume_(0), | 224 volume_(0), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 stop_source = tracks_.IsEmpty(); | 277 stop_source = tracks_.IsEmpty(); |
276 } | 278 } |
277 | 279 |
278 if (stop_source) | 280 if (stop_source) |
279 Stop(); | 281 Stop(); |
280 } | 282 } |
281 | 283 |
282 void WebRtcAudioCapturer::SetCapturerSource( | 284 void WebRtcAudioCapturer::SetCapturerSource( |
283 const scoped_refptr<media::AudioCapturerSource>& source, | 285 const scoped_refptr<media::AudioCapturerSource>& source, |
284 media::ChannelLayout channel_layout, | 286 media::ChannelLayout channel_layout, |
285 float sample_rate) { | 287 float sample_rate, |
| 288 int effects) { |
286 DCHECK(thread_checker_.CalledOnValidThread()); | 289 DCHECK(thread_checker_.CalledOnValidThread()); |
287 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," | 290 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," |
288 << "sample_rate=" << sample_rate << ")"; | 291 << "sample_rate=" << sample_rate << ")"; |
289 scoped_refptr<media::AudioCapturerSource> old_source; | 292 scoped_refptr<media::AudioCapturerSource> old_source; |
290 bool restart_source = false; | 293 bool restart_source = false; |
291 { | 294 { |
292 base::AutoLock auto_lock(lock_); | 295 base::AutoLock auto_lock(lock_); |
293 if (source_.get() == source.get()) | 296 if (source_.get() == source.get()) |
294 return; | 297 return; |
295 | 298 |
296 source_.swap(old_source); | 299 source_.swap(old_source); |
297 source_ = source; | 300 source_ = source; |
298 | 301 |
299 // Reset the flag to allow starting the new source. | 302 // Reset the flag to allow starting the new source. |
300 restart_source = running_; | 303 restart_source = running_; |
301 running_ = false; | 304 running_ = false; |
302 } | 305 } |
303 | 306 |
304 DVLOG(1) << "Switching to a new capture source."; | 307 DVLOG(1) << "Switching to a new capture source."; |
305 if (old_source.get()) | 308 if (old_source.get()) |
306 old_source->Stop(); | 309 old_source->Stop(); |
307 | 310 |
308 // Dispatch the new parameters both to the sink(s) and to the new source. | 311 // Dispatch the new parameters both to the sink(s) and to the new source. |
309 // The idea is to get rid of any dependency of the microphone parameters | 312 // The idea is to get rid of any dependency of the microphone parameters |
310 // which would normally be used by default. | 313 // which would normally be used by default. |
311 Reconfigure(sample_rate, channel_layout); | 314 Reconfigure(sample_rate, channel_layout, effects); |
312 | 315 |
313 // Make sure to grab the new parameters in case they were reconfigured. | 316 // Make sure to grab the new parameters in case they were reconfigured. |
314 media::AudioParameters params = audio_parameters(); | 317 media::AudioParameters params = audio_parameters(); |
315 if (source.get()) | 318 if (source.get()) |
316 source->Initialize(params, this, session_id_); | 319 source->Initialize(params, this, session_id_); |
317 | 320 |
318 if (restart_source) | 321 if (restart_source) |
319 Start(); | 322 Start(); |
320 } | 323 } |
321 | 324 |
(...skipping 18 matching lines...) Expand all Loading... |
340 | 343 |
341 // Do nothing if the current buffer size is the WebRtc native buffer size. | 344 // Do nothing if the current buffer size is the WebRtc native buffer size. |
342 media::AudioParameters params = audio_parameters(); | 345 media::AudioParameters params = audio_parameters(); |
343 if (GetBufferSize(params.sample_rate()) == params.frames_per_buffer()) | 346 if (GetBufferSize(params.sample_rate()) == params.frames_per_buffer()) |
344 return; | 347 return; |
345 | 348 |
346 // Create a new audio stream as source which will open the hardware using | 349 // Create a new audio stream as source which will open the hardware using |
347 // WebRtc native buffer size. | 350 // WebRtc native buffer size. |
348 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), | 351 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), |
349 params.channel_layout(), | 352 params.channel_layout(), |
350 static_cast<float>(params.sample_rate())); | 353 static_cast<float>(params.sample_rate()), |
| 354 params.effects()); |
351 } | 355 } |
352 | 356 |
353 void WebRtcAudioCapturer::Start() { | 357 void WebRtcAudioCapturer::Start() { |
354 DVLOG(1) << "WebRtcAudioCapturer::Start()"; | 358 DVLOG(1) << "WebRtcAudioCapturer::Start()"; |
355 base::AutoLock auto_lock(lock_); | 359 base::AutoLock auto_lock(lock_); |
356 if (running_ || !source_) | 360 if (running_ || !source_) |
357 return; | 361 return; |
358 | 362 |
359 // Start the data source, i.e., start capturing data from the current source. | 363 // Start the data source, i.e., start capturing data from the current source. |
360 // We need to set the AGC control before starting the stream. | 364 // We need to set the AGC control before starting the stream. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 517 |
514 void WebRtcAudioCapturer::GetAudioProcessingParams( | 518 void WebRtcAudioCapturer::GetAudioProcessingParams( |
515 base::TimeDelta* delay, int* volume, bool* key_pressed) { | 519 base::TimeDelta* delay, int* volume, bool* key_pressed) { |
516 base::AutoLock auto_lock(lock_); | 520 base::AutoLock auto_lock(lock_); |
517 *delay = audio_delay_; | 521 *delay = audio_delay_; |
518 *volume = volume_; | 522 *volume = volume_; |
519 *key_pressed = key_pressed_; | 523 *key_pressed = key_pressed_; |
520 } | 524 } |
521 | 525 |
522 } // namespace content | 526 } // namespace content |
OLD | NEW |