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

Side by Side Diff: content/renderer/media/webrtc_audio_device_impl.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: minor fix to one comment. 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
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_device_impl.h" 5 #include "content/renderer/media/webrtc_audio_device_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/platform_file.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/win/windows_version.h" 11 #include "base/win/windows_version.h"
11 #include "content/renderer/media/webrtc_audio_capturer.h" 12 #include "content/renderer/media/webrtc_audio_capturer.h"
12 #include "content/renderer/media/webrtc_audio_renderer.h" 13 #include "content/renderer/media/webrtc_audio_renderer.h"
13 #include "content/renderer/render_thread_impl.h" 14 #include "content/renderer/render_thread_impl.h"
14 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
15 #include "media/audio/sample_rates.h" 16 #include "media/audio/sample_rates.h"
16 17
17 using media::AudioParameters; 18 using media::AudioParameters;
18 using media::ChannelLayout; 19 using media::ChannelLayout;
19 20
20 namespace content { 21 namespace content {
21 22
22 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() 23 WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()
23 : ref_count_(0), 24 : ref_count_(0),
24 audio_transport_callback_(NULL), 25 audio_transport_callback_(NULL),
25 input_delay_ms_(0), 26 input_delay_ms_(0),
26 output_delay_ms_(0), 27 output_delay_ms_(0),
27 initialized_(false), 28 initialized_(false),
28 playing_(false), 29 playing_(false),
29 recording_(false), 30 recording_(false),
30 microphone_volume_(0) { 31 microphone_volume_(0),
32 aec_dump_file_(base::kInvalidPlatformFileValue) {
31 DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()"; 33 DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()";
32 } 34 }
33 35
34 WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl() { 36 WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl() {
35 DVLOG(1) << "WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl()"; 37 DVLOG(1) << "WebRtcAudioDeviceImpl::~WebRtcAudioDeviceImpl()";
36 DCHECK(thread_checker_.CalledOnValidThread()); 38 DCHECK(thread_checker_.CalledOnValidThread());
37 Terminate(); 39 Terminate();
38 } 40 }
39 41
40 int32_t WebRtcAudioDeviceImpl::AddRef() { 42 int32_t WebRtcAudioDeviceImpl::AddRef() {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // Calling Terminate() multiple times in a row is OK. 215 // Calling Terminate() multiple times in a row is OK.
214 if (!initialized_) 216 if (!initialized_)
215 return 0; 217 return 0;
216 218
217 StopRecording(); 219 StopRecording();
218 StopPlayout(); 220 StopPlayout();
219 221
220 DCHECK(!renderer_.get() || !renderer_->IsStarted()) 222 DCHECK(!renderer_.get() || !renderer_->IsStarted())
221 << "The shared audio renderer shouldn't be running"; 223 << "The shared audio renderer shouldn't be running";
222 224
225 DisableAecDump();
226
223 capturers_.clear(); 227 capturers_.clear();
224 228
225 initialized_ = false; 229 initialized_ = false;
226 return 0; 230 return 0;
227 } 231 }
228 232
229 bool WebRtcAudioDeviceImpl::Initialized() const { 233 bool WebRtcAudioDeviceImpl::Initialized() const {
230 return initialized_; 234 return initialized_;
231 } 235 }
232 236
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 renderer_ = renderer; 428 renderer_ = renderer;
425 return true; 429 return true;
426 } 430 }
427 431
428 void WebRtcAudioDeviceImpl::AddAudioCapturer( 432 void WebRtcAudioDeviceImpl::AddAudioCapturer(
429 const scoped_refptr<WebRtcAudioCapturer>& capturer) { 433 const scoped_refptr<WebRtcAudioCapturer>& capturer) {
430 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; 434 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()";
431 DCHECK(thread_checker_.CalledOnValidThread()); 435 DCHECK(thread_checker_.CalledOnValidThread());
432 DCHECK(capturer.get()); 436 DCHECK(capturer.get());
433 DCHECK(!capturer->device_id().empty()); 437 DCHECK(!capturer->device_id().empty());
434 base::AutoLock auto_lock(lock_); 438 {
435 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == 439 base::AutoLock auto_lock(lock_);
436 capturers_.end()); 440 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) ==
437 capturers_.push_back(capturer); 441 capturers_.end());
442 capturers_.push_back(capturer);
443 }
444
445 // Start the Aec dump if the Aec dump has been enabled and has not been
446 // started.
447 if (aec_dump_file_ != base::kInvalidPlatformFileValue)
448 MaybeStartAecDump();
438 } 449 }
439 450
440 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( 451 void WebRtcAudioDeviceImpl::RemoveAudioCapturer(
441 const scoped_refptr<WebRtcAudioCapturer>& capturer) { 452 const scoped_refptr<WebRtcAudioCapturer>& capturer) {
442 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; 453 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()";
443 DCHECK(thread_checker_.CalledOnValidThread()); 454 DCHECK(thread_checker_.CalledOnValidThread());
444 DCHECK(capturer.get()); 455 DCHECK(capturer.get());
445 base::AutoLock auto_lock(lock_); 456 base::AutoLock auto_lock(lock_);
446 capturers_.remove(capturer); 457 capturers_.remove(capturer);
447 } 458 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 DCHECK(thread_checker_.CalledOnValidThread()); 495 DCHECK(thread_checker_.CalledOnValidThread());
485 // If there is no capturer or there are more than one open capture devices, 496 // If there is no capturer or there are more than one open capture devices,
486 // return false. 497 // return false.
487 if (capturers_.empty() || capturers_.size() > 1) 498 if (capturers_.empty() || capturers_.size() > 1)
488 return false; 499 return false;
489 500
490 return GetDefaultCapturer()->GetPairedOutputParameters( 501 return GetDefaultCapturer()->GetPairedOutputParameters(
491 session_id, output_sample_rate, output_frames_per_buffer); 502 session_id, output_sample_rate, output_frames_per_buffer);
492 } 503 }
493 504
505 void WebRtcAudioDeviceImpl::EnableAecDump(
506 const base::PlatformFile& aec_dump_file) {
507 DCHECK(thread_checker_.CalledOnValidThread());
508 DCHECK_NE(aec_dump_file, base::kInvalidPlatformFileValue);
509 DCHECK_EQ(aec_dump_file_, base::kInvalidPlatformFileValue);
510 aec_dump_file_ = aec_dump_file;
511 MaybeStartAecDump();
512 }
513
514 void WebRtcAudioDeviceImpl::DisableAecDump() {
515 DCHECK(thread_checker_.CalledOnValidThread());
516 // Simply invalidate the |aec_dump_file_| if we have not pass the ownership
517 // to WebRtc.
518 if (aec_dump_file_ != base::kInvalidPlatformFileValue) {
519 base::ClosePlatformFile(aec_dump_file_);
520 aec_dump_file_ = base::kInvalidPlatformFileValue;
521 return;
522 }
523
524 // We might have call StartAecDump() on one of the capturer. Loop
525 // through all the capturers and call StopAecDump() on each of them.
526 for (CapturerList::const_iterator iter = capturers_.begin();
527 iter != capturers_.end(); ++iter) {
528 (*iter)->StopAecDump();
529 }
530 }
531
532 void WebRtcAudioDeviceImpl::MaybeStartAecDump() {
533 DCHECK(thread_checker_.CalledOnValidThread());
534 DCHECK_NE(aec_dump_file_, base::kInvalidPlatformFileValue);
535
536 // Start the Aec dump on the current default capturer.
537 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer());
538 if (!default_capturer)
539 return;
540
541 default_capturer->StartAecDump(aec_dump_file_);
542
543 // Invalidate the |aec_dump_file_| since the ownership of the file has been
544 // passed to WebRtc.
545 aec_dump_file_ = base::kInvalidPlatformFileValue;
546 }
547
494 } // namespace content 548 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_device_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698