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

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

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

Powered by Google App Engine
This is Rietveld 408576698