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

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

Powered by Google App Engine
This is Rietveld 408576698