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