| OLD | NEW |
| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // Calling Terminate() multiple times in a row is OK. | 242 // Calling Terminate() multiple times in a row is OK. |
| 243 if (!initialized_) | 243 if (!initialized_) |
| 244 return 0; | 244 return 0; |
| 245 | 245 |
| 246 StopRecording(); | 246 StopRecording(); |
| 247 StopPlayout(); | 247 StopPlayout(); |
| 248 | 248 |
| 249 DCHECK(!renderer_.get() || !renderer_->IsStarted()) | 249 DCHECK(!renderer_.get() || !renderer_->IsStarted()) |
| 250 << "The shared audio renderer shouldn't be running"; | 250 << "The shared audio renderer shouldn't be running"; |
| 251 | 251 |
| 252 DisableAecDump(); | |
| 253 | |
| 254 // Stop all the capturers to ensure no further OnData() and | 252 // Stop all the capturers to ensure no further OnData() and |
| 255 // RemoveAudioCapturer() callback. | 253 // RemoveAudioCapturer() callback. |
| 256 // Cache the capturers in a local list since WebRtcAudioCapturer::Stop() | 254 // Cache the capturers in a local list since WebRtcAudioCapturer::Stop() |
| 257 // will trigger RemoveAudioCapturer() callback. | 255 // will trigger RemoveAudioCapturer() callback. |
| 258 CapturerList capturers; | 256 CapturerList capturers; |
| 259 capturers.swap(capturers_); | 257 capturers.swap(capturers_); |
| 260 for (CapturerList::const_iterator iter = capturers.begin(); | 258 for (CapturerList::const_iterator iter = capturers.begin(); |
| 261 iter != capturers.end(); ++iter) { | 259 iter != capturers.end(); ++iter) { |
| 262 (*iter)->Stop(); | 260 (*iter)->Stop(); |
| 263 } | 261 } |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 468 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 471 DCHECK(thread_checker_.CalledOnValidThread()); | 469 DCHECK(thread_checker_.CalledOnValidThread()); |
| 472 DCHECK(capturer.get()); | 470 DCHECK(capturer.get()); |
| 473 DCHECK(!capturer->device_id().empty()); | 471 DCHECK(!capturer->device_id().empty()); |
| 474 { | 472 { |
| 475 base::AutoLock auto_lock(lock_); | 473 base::AutoLock auto_lock(lock_); |
| 476 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == | 474 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| 477 capturers_.end()); | 475 capturers_.end()); |
| 478 capturers_.push_back(capturer); | 476 capturers_.push_back(capturer); |
| 479 } | 477 } |
| 480 | |
| 481 // Start the Aec dump if the Aec dump has been enabled and has not been | |
| 482 // started. | |
| 483 if (aec_dump_file_.IsValid()) | |
| 484 MaybeStartAecDump(); | |
| 485 } | 478 } |
| 486 | 479 |
| 487 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( | 480 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| 488 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 481 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 489 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 482 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 490 DCHECK(thread_checker_.CalledOnValidThread()); | 483 DCHECK(thread_checker_.CalledOnValidThread()); |
| 491 DCHECK(capturer.get()); | 484 DCHECK(capturer.get()); |
| 492 base::AutoLock auto_lock(lock_); | 485 base::AutoLock auto_lock(lock_); |
| 493 capturers_.remove(capturer); | 486 capturers_.remove(capturer); |
| 494 } | 487 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 DCHECK(thread_checker_.CalledOnValidThread()); | 519 DCHECK(thread_checker_.CalledOnValidThread()); |
| 527 // If there is no capturer or there are more than one open capture devices, | 520 // If there is no capturer or there are more than one open capture devices, |
| 528 // return false. | 521 // return false. |
| 529 if (capturers_.empty() || capturers_.size() > 1) | 522 if (capturers_.empty() || capturers_.size() > 1) |
| 530 return false; | 523 return false; |
| 531 | 524 |
| 532 return GetDefaultCapturer()->GetPairedOutputParameters( | 525 return GetDefaultCapturer()->GetPairedOutputParameters( |
| 533 session_id, output_sample_rate, output_frames_per_buffer); | 526 session_id, output_sample_rate, output_frames_per_buffer); |
| 534 } | 527 } |
| 535 | 528 |
| 536 void WebRtcAudioDeviceImpl::EnableAecDump(base::File aec_dump_file) { | |
| 537 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 538 DCHECK(aec_dump_file.IsValid()); | |
| 539 | |
| 540 // Close the previous AEC dump file description if it has not been consumed. | |
| 541 // This can happen if no getUserMedia has been made yet. | |
| 542 // TODO(xians): DCHECK(!aec_dump_file_.IsValid()) after the browser | |
| 543 // guarantees it won't call EnableAecDump() more than once in a row. | |
| 544 if (aec_dump_file_.IsValid()) | |
| 545 aec_dump_file_.Close(); | |
| 546 | |
| 547 aec_dump_file_ = aec_dump_file.Pass(); | |
| 548 MaybeStartAecDump(); | |
| 549 } | |
| 550 | |
| 551 void WebRtcAudioDeviceImpl::DisableAecDump() { | |
| 552 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 553 // Simply invalidate the |aec_dump_file_| if we have not pass the ownership | |
| 554 // to WebRtc. | |
| 555 if (aec_dump_file_.IsValid()) { | |
| 556 aec_dump_file_.Close(); | |
| 557 return; | |
| 558 } | |
| 559 | |
| 560 // We might have call StartAecDump() on one of the capturer. Loop | |
| 561 // through all the capturers and call StopAecDump() on each of them. | |
| 562 for (CapturerList::const_iterator iter = capturers_.begin(); | |
| 563 iter != capturers_.end(); ++iter) { | |
| 564 (*iter)->StopAecDump(); | |
| 565 } | |
| 566 } | |
| 567 | |
| 568 void WebRtcAudioDeviceImpl::MaybeStartAecDump() { | |
| 569 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 570 DCHECK(aec_dump_file_.IsValid()); | |
| 571 | |
| 572 // Start the Aec dump on the current default capturer. | |
| 573 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); | |
| 574 if (!default_capturer) | |
| 575 return; | |
| 576 | |
| 577 default_capturer->StartAecDump(aec_dump_file_.Pass()); | |
| 578 } | |
| 579 | |
| 580 } // namespace content | 529 } // namespace content |
| OLD | NEW |