Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.cc

Issue 99033003: Enable platform echo cancellation through the AudioRecord path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add PlatformEffects, unittests and clean up. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 const media::AudioParameters::PlatformEffects& 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, sample_rate,
118 bits_per_sample, buffer_size); 119 bits_per_sample, buffer_size);
119 120 params.SetPlatformEffects(effects);
120 { 121 {
121 base::AutoLock auto_lock(lock_); 122 base::AutoLock auto_lock(lock_);
122 params_ = params; 123 params_ = params;
123 124
124 // Copy |tracks_| to |tracks_to_notify_format_| to notify all the tracks 125 // Copy |tracks_| to |tracks_to_notify_format_| to notify all the tracks
125 // on the new format. 126 // on the new format.
126 tracks_to_notify_format_ = tracks_; 127 tracks_to_notify_format_ = tracks_;
127 } 128 }
128 } 129 }
129 130
130 bool WebRtcAudioCapturer::Initialize(int render_view_id, 131 bool WebRtcAudioCapturer::Initialize(int render_view_id,
tommi (sloooow) - chröme 2013/12/11 12:14:36 nit: move render_view_id on a new line as well
131 media::ChannelLayout channel_layout, 132 media::ChannelLayout channel_layout,
132 int sample_rate, 133 int sample_rate,
133 int buffer_size, 134 int buffer_size,
134 int session_id, 135 int session_id,
135 const std::string& device_id, 136 const std::string& device_id,
136 int paired_output_sample_rate, 137 int paired_output_sample_rate,
137 int paired_output_frames_per_buffer) { 138 int paired_output_frames_per_buffer,
139 const media::AudioParameters::PlatformEffects& effects) {
138 DCHECK(thread_checker_.CalledOnValidThread()); 140 DCHECK(thread_checker_.CalledOnValidThread());
139 DVLOG(1) << "WebRtcAudioCapturer::Initialize()"; 141 DVLOG(1) << "WebRtcAudioCapturer::Initialize()";
140 142
141 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout; 143 DVLOG(1) << "Audio input hardware channel layout: " << channel_layout;
142 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout", 144 UMA_HISTOGRAM_ENUMERATION("WebRTC.AudioInputChannelLayout",
143 channel_layout, media::CHANNEL_LAYOUT_MAX); 145 channel_layout, media::CHANNEL_LAYOUT_MAX);
144 146
145 WebRtcLogMessage(base::StringPrintf( 147 WebRtcLogMessage(base::StringPrintf(
146 "WAC::Initialize. render_view_id=%d" 148 "WAC::Initialize. render_view_id=%d"
147 ", channel_layout=%d, sample_rate=%d, buffer_size=%d" 149 ", channel_layout=%d, sample_rate=%d, buffer_size=%d"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 &kValidInputRates[arraysize(kValidInputRates)]) { 195 &kValidInputRates[arraysize(kValidInputRates)]) {
194 DLOG(ERROR) << sample_rate << " is not a supported input rate."; 196 DLOG(ERROR) << sample_rate << " is not a supported input rate.";
195 return false; 197 return false;
196 } 198 }
197 199
198 // Create and configure the default audio capturing source. The |source_| 200 // Create and configure the default audio capturing source. The |source_|
199 // will be overwritten if an external client later calls SetCapturerSource() 201 // will be overwritten if an external client later calls SetCapturerSource()
200 // providing an alternative media::AudioCapturerSource. 202 // providing an alternative media::AudioCapturerSource.
201 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), 203 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id),
202 channel_layout, 204 channel_layout,
203 static_cast<float>(sample_rate)); 205 static_cast<float>(sample_rate),
206 effects);
204 207
205 return true; 208 return true;
206 } 209 }
207 210
208 WebRtcAudioCapturer::WebRtcAudioCapturer() 211 WebRtcAudioCapturer::WebRtcAudioCapturer()
209 : running_(false), 212 : running_(false),
210 render_view_id_(-1), 213 render_view_id_(-1),
211 hardware_buffer_size_(0), 214 hardware_buffer_size_(0),
212 session_id_(0), 215 session_id_(0),
213 volume_(0), 216 volume_(0),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 stop_source = tracks_.empty(); 282 stop_source = tracks_.empty();
280 } 283 }
281 284
282 if (stop_source) 285 if (stop_source)
283 Stop(); 286 Stop();
284 } 287 }
285 288
286 void WebRtcAudioCapturer::SetCapturerSource( 289 void WebRtcAudioCapturer::SetCapturerSource(
287 const scoped_refptr<media::AudioCapturerSource>& source, 290 const scoped_refptr<media::AudioCapturerSource>& source,
288 media::ChannelLayout channel_layout, 291 media::ChannelLayout channel_layout,
289 float sample_rate) { 292 float sample_rate,
293 const media::AudioParameters::PlatformEffects& effects) {
290 DCHECK(thread_checker_.CalledOnValidThread()); 294 DCHECK(thread_checker_.CalledOnValidThread());
291 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << "," 295 DVLOG(1) << "SetCapturerSource(channel_layout=" << channel_layout << ","
292 << "sample_rate=" << sample_rate << ")"; 296 << "sample_rate=" << sample_rate << ")";
293 scoped_refptr<media::AudioCapturerSource> old_source; 297 scoped_refptr<media::AudioCapturerSource> old_source;
294 bool restart_source = false; 298 bool restart_source = false;
295 { 299 {
296 base::AutoLock auto_lock(lock_); 300 base::AutoLock auto_lock(lock_);
297 if (source_.get() == source.get()) 301 if (source_.get() == source.get())
298 return; 302 return;
299 303
300 source_.swap(old_source); 304 source_.swap(old_source);
301 source_ = source; 305 source_ = source;
302 306
303 // Reset the flag to allow starting the new source. 307 // Reset the flag to allow starting the new source.
304 restart_source = running_; 308 restart_source = running_;
305 running_ = false; 309 running_ = false;
306 } 310 }
307 311
308 DVLOG(1) << "Switching to a new capture source."; 312 DVLOG(1) << "Switching to a new capture source.";
309 if (old_source.get()) 313 if (old_source.get())
310 old_source->Stop(); 314 old_source->Stop();
311 315
312 // Dispatch the new parameters both to the sink(s) and to the new source. 316 // 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 317 // The idea is to get rid of any dependency of the microphone parameters
314 // which would normally be used by default. 318 // which would normally be used by default.
315 Reconfigure(sample_rate, channel_layout); 319 Reconfigure(sample_rate, channel_layout, effects);
316 320
317 // Make sure to grab the new parameters in case they were reconfigured. 321 // Make sure to grab the new parameters in case they were reconfigured.
318 media::AudioParameters params = audio_parameters(); 322 media::AudioParameters params = audio_parameters();
319 if (source.get()) 323 if (source.get())
320 source->Initialize(params, this, session_id_); 324 source->Initialize(params, this, session_id_);
321 325
322 if (restart_source) 326 if (restart_source)
323 Start(); 327 Start();
324 } 328 }
325 329
(...skipping 18 matching lines...) Expand all
344 348
345 // Do nothing if the current buffer size is the WebRtc native buffer size. 349 // Do nothing if the current buffer size is the WebRtc native buffer size.
346 media::AudioParameters params = audio_parameters(); 350 media::AudioParameters params = audio_parameters();
347 if (GetBufferSize(params.sample_rate()) == params.frames_per_buffer()) 351 if (GetBufferSize(params.sample_rate()) == params.frames_per_buffer())
348 return; 352 return;
349 353
350 // Create a new audio stream as source which will open the hardware using 354 // Create a new audio stream as source which will open the hardware using
351 // WebRtc native buffer size. 355 // WebRtc native buffer size.
352 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), 356 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id),
353 params.channel_layout(), 357 params.channel_layout(),
354 static_cast<float>(params.sample_rate())); 358 static_cast<float>(params.sample_rate()),
359 params.effects());
355 } 360 }
356 361
357 void WebRtcAudioCapturer::Start() { 362 void WebRtcAudioCapturer::Start() {
358 DVLOG(1) << "WebRtcAudioCapturer::Start()"; 363 DVLOG(1) << "WebRtcAudioCapturer::Start()";
359 base::AutoLock auto_lock(lock_); 364 base::AutoLock auto_lock(lock_);
360 if (running_ || !source_) 365 if (running_ || !source_)
361 return; 366 return;
362 367
363 // Start the data source, i.e., start capturing data from the current source. 368 // 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. 369 // We need to set the AGC control before starting the stream.
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 515
511 void WebRtcAudioCapturer::GetAudioProcessingParams( 516 void WebRtcAudioCapturer::GetAudioProcessingParams(
512 base::TimeDelta* delay, int* volume, bool* key_pressed) { 517 base::TimeDelta* delay, int* volume, bool* key_pressed) {
513 base::AutoLock auto_lock(lock_); 518 base::AutoLock auto_lock(lock_);
514 *delay = audio_delay_; 519 *delay = audio_delay_;
515 *volume = volume_; 520 *volume = volume_;
516 *key_pressed = key_pressed_; 521 *key_pressed = key_pressed_;
517 } 522 }
518 523
519 } // namespace content 524 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698