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

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

Issue 187913002: Support the Aec dump for the APM in chrome (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 9 months 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 const blink::WebMediaConstraints& constraints, 205 const blink::WebMediaConstraints& constraints,
206 WebRtcAudioDeviceImpl* audio_device) 206 WebRtcAudioDeviceImpl* audio_device)
207 : constraints_(constraints), 207 : constraints_(constraints),
208 running_(false), 208 running_(false),
209 render_view_id_(render_view_id), 209 render_view_id_(render_view_id),
210 device_info_(device_info), 210 device_info_(device_info),
211 volume_(0), 211 volume_(0),
212 peer_connection_mode_(false), 212 peer_connection_mode_(false),
213 key_pressed_(false), 213 key_pressed_(false),
214 need_audio_processing_(false), 214 need_audio_processing_(false),
215 audio_device_(audio_device) { 215 audio_device_(audio_device),
216 aec_dump_file_(base::kInvalidPlatformFileValue) {
216 DVLOG(1) << "WebRtcAudioCapturer::WebRtcAudioCapturer()"; 217 DVLOG(1) << "WebRtcAudioCapturer::WebRtcAudioCapturer()";
217 } 218 }
218 219
219 WebRtcAudioCapturer::~WebRtcAudioCapturer() { 220 WebRtcAudioCapturer::~WebRtcAudioCapturer() {
220 DCHECK(thread_checker_.CalledOnValidThread()); 221 DCHECK(thread_checker_.CalledOnValidThread());
221 DCHECK(tracks_.IsEmpty()); 222 DCHECK(tracks_.IsEmpty());
222 DCHECK(!running_); 223 DCHECK(!running_);
223 DVLOG(1) << "WebRtcAudioCapturer::~WebRtcAudioCapturer()"; 224 DVLOG(1) << "WebRtcAudioCapturer::~WebRtcAudioCapturer()";
224 } 225 }
225 226
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 // The idea is to get rid of any dependency of the microphone parameters 292 // The idea is to get rid of any dependency of the microphone parameters
292 // which would normally be used by default. 293 // which would normally be used by default.
293 // bits_per_sample is always 16 for now. 294 // bits_per_sample is always 16 for now.
294 int buffer_size = GetBufferSize(sample_rate); 295 int buffer_size = GetBufferSize(sample_rate);
295 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 296 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
296 channel_layout, 0, sample_rate, 297 channel_layout, 0, sample_rate,
297 16, buffer_size, effects); 298 16, buffer_size, effects);
298 scoped_refptr<MediaStreamAudioProcessor> new_audio_processor( 299 scoped_refptr<MediaStreamAudioProcessor> new_audio_processor(
299 new MediaStreamAudioProcessor(params, constraints, effects, 300 new MediaStreamAudioProcessor(params, constraints, effects,
300 audio_device_)); 301 audio_device_));
302 // Start the Aec dump on the new audio processor object.
303 if (aec_dump_file_ != base::kInvalidPlatformFileValue)
304 new_audio_processor->StartAecDump(aec_dump_file_);
305
301 { 306 {
302 base::AutoLock auto_lock(lock_); 307 base::AutoLock auto_lock(lock_);
303 audio_processor_ = new_audio_processor; 308 audio_processor_ = new_audio_processor;
304 need_audio_processing_ = NeedsAudioProcessing(constraints, effects); 309 need_audio_processing_ = NeedsAudioProcessing(constraints, effects);
305 310
306 // Notify all tracks about the new format. 311 // Notify all tracks about the new format.
307 tracks_.TagAll(); 312 tracks_.TagAll();
308 } 313 }
309 314
310 if (source.get()) 315 if (source.get())
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 // 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
345 // WebRtc native buffer size. 350 // WebRtc native buffer size.
346 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id), 351 SetCapturerSource(AudioDeviceFactory::NewInputDevice(render_view_id),
347 input_params.channel_layout(), 352 input_params.channel_layout(),
348 static_cast<float>(input_params.sample_rate()), 353 static_cast<float>(input_params.sample_rate()),
349 input_params.effects(), 354 input_params.effects(),
350 constraints_); 355 constraints_);
351 } 356 }
352 357
353 void WebRtcAudioCapturer::Start() { 358 void WebRtcAudioCapturer::Start() {
359 DCHECK(thread_checker_.CalledOnValidThread());
354 DVLOG(1) << "WebRtcAudioCapturer::Start()"; 360 DVLOG(1) << "WebRtcAudioCapturer::Start()";
355 base::AutoLock auto_lock(lock_); 361 base::AutoLock auto_lock(lock_);
356 if (running_ || !source_) 362 if (running_ || !source_)
357 return; 363 return;
358 364
359 // Start the data source, i.e., start capturing data from the current source. 365 // 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. 366 // We need to set the AGC control before starting the stream.
361 source_->SetAutomaticGainControl(true); 367 source_->SetAutomaticGainControl(true);
362 source_->Start(); 368 source_->Start();
363 running_ = true; 369 running_ = true;
364 } 370 }
365 371
366 void WebRtcAudioCapturer::Stop() { 372 void WebRtcAudioCapturer::Stop() {
373 DCHECK(thread_checker_.CalledOnValidThread());
367 DVLOG(1) << "WebRtcAudioCapturer::Stop()"; 374 DVLOG(1) << "WebRtcAudioCapturer::Stop()";
368 scoped_refptr<media::AudioCapturerSource> source; 375 scoped_refptr<media::AudioCapturerSource> source;
369 TrackList::ItemList tracks; 376 TrackList::ItemList tracks;
370 { 377 {
371 base::AutoLock auto_lock(lock_); 378 base::AutoLock auto_lock(lock_);
372 if (!running_) 379 if (!running_)
373 return; 380 return;
374 381
375 source = source_; 382 source = source_;
376 tracks = tracks_.Items(); 383 tracks = tracks_.Items();
377 tracks_.Clear(); 384 tracks_.Clear();
378 running_ = false; 385 running_ = false;
379 } 386 }
380 387
381 // Remove the capturer object from the WebRtcAudioDeviceImpl. 388 // Remove the capturer object from the WebRtcAudioDeviceImpl.
382 if (audio_device_) 389 if (audio_device_)
383 audio_device_->RemoveAudioCapturer(this); 390 audio_device_->RemoveAudioCapturer(this);
384 391
392 // Stop the Aec dump.
393 StopAecDump();
394
385 for (TrackList::ItemList::const_iterator it = tracks.begin(); 395 for (TrackList::ItemList::const_iterator it = tracks.begin();
386 it != tracks.end(); 396 it != tracks.end();
387 ++it) { 397 ++it) {
388 (*it)->Stop(); 398 (*it)->Stop();
389 } 399 }
390 400
391 if (source.get()) 401 if (source.get())
392 source->Stop(); 402 source->Stop();
393 } 403 }
394 404
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 void WebRtcAudioCapturer::SetCapturerSourceForTesting( 569 void WebRtcAudioCapturer::SetCapturerSourceForTesting(
560 const scoped_refptr<media::AudioCapturerSource>& source, 570 const scoped_refptr<media::AudioCapturerSource>& source,
561 media::AudioParameters params) { 571 media::AudioParameters params) {
562 // Create a new audio stream as source which uses the new source. 572 // Create a new audio stream as source which uses the new source.
563 SetCapturerSource(source, params.channel_layout(), 573 SetCapturerSource(source, params.channel_layout(),
564 static_cast<float>(params.sample_rate()), 574 static_cast<float>(params.sample_rate()),
565 params.effects(), 575 params.effects(),
566 constraints_); 576 constraints_);
567 } 577 }
568 578
579 void WebRtcAudioCapturer::StartAecDump(
580 const base::PlatformFile& aec_dump_file) {
581 DCHECK(thread_checker_.CalledOnValidThread());
582 DCHECK_NE(aec_dump_file, base::kInvalidPlatformFileValue);
583 DCHECK(aec_dump_file_ == base::kInvalidPlatformFileValue ||
584 aec_dump_file_ == aec_dump_file);
Henrik Grunell 2014/03/06 10:12:20 IS it expected to be called multiple times with th
no longer working on chromium 2014/03/06 18:57:21 The code was removed.
585 // Do nothing if the Aec dump has been started.
586 if (aec_dump_file_ != base::kInvalidPlatformFileValue)
587 return;
588
589 audio_processor_->StartAecDump(aec_dump_file);
590 aec_dump_file_ = aec_dump_file;
Henrik Grunell 2014/03/06 10:12:20 |audio_processor_| takes ownership of |aec_dump_fi
no longer working on chromium 2014/03/06 18:57:21 Done.
591 }
592
593 void WebRtcAudioCapturer::StopAecDump() {
594 DCHECK(thread_checker_.CalledOnValidThread());
595 if (aec_dump_file_ == base::kInvalidPlatformFileValue)
596 return;
597
598 audio_processor_->StopAecDump();
599 aec_dump_file_ = base::kInvalidPlatformFileValue;
600 }
601
569 } // namespace content 602 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698