Chromium Code Reviews| 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/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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // Calling Terminate() multiple times in a row is OK. | 209 // Calling Terminate() multiple times in a row is OK. |
| 208 if (!initialized_) | 210 if (!initialized_) |
| 209 return 0; | 211 return 0; |
| 210 | 212 |
| 211 StopRecording(); | 213 StopRecording(); |
| 212 StopPlayout(); | 214 StopPlayout(); |
| 213 | 215 |
| 214 DCHECK(!renderer_.get() || !renderer_->IsStarted()) | 216 DCHECK(!renderer_.get() || !renderer_->IsStarted()) |
| 215 << "The shared audio renderer shouldn't be running"; | 217 << "The shared audio renderer shouldn't be running"; |
| 216 | 218 |
| 219 DisableAecDump(); | |
| 220 | |
| 217 capturers_.clear(); | 221 capturers_.clear(); |
| 218 | 222 |
| 219 initialized_ = false; | 223 initialized_ = false; |
| 220 return 0; | 224 return 0; |
| 221 } | 225 } |
| 222 | 226 |
| 223 bool WebRtcAudioDeviceImpl::Initialized() const { | 227 bool WebRtcAudioDeviceImpl::Initialized() const { |
| 224 return initialized_; | 228 return initialized_; |
| 225 } | 229 } |
| 226 | 230 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 renderer_ = renderer; | 422 renderer_ = renderer; |
| 419 return true; | 423 return true; |
| 420 } | 424 } |
| 421 | 425 |
| 422 void WebRtcAudioDeviceImpl::AddAudioCapturer( | 426 void WebRtcAudioDeviceImpl::AddAudioCapturer( |
| 423 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 427 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 424 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 428 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 425 DCHECK(thread_checker_.CalledOnValidThread()); | 429 DCHECK(thread_checker_.CalledOnValidThread()); |
| 426 DCHECK(capturer.get()); | 430 DCHECK(capturer.get()); |
| 427 DCHECK(!capturer->device_id().empty()); | 431 DCHECK(!capturer->device_id().empty()); |
| 428 base::AutoLock auto_lock(lock_); | 432 { |
| 429 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == | 433 base::AutoLock auto_lock(lock_); |
| 430 capturers_.end()); | 434 DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| 431 capturers_.push_back(capturer); | 435 capturers_.end()); |
| 436 capturers_.push_back(capturer); | |
| 437 } | |
| 438 | |
| 439 // The default capturer might have been changed, call StartAecDump() to start | |
| 440 // the Aec dump on the new default capturer in case Aec dump has been enabled. | |
| 441 StartAecDump(); | |
| 432 } | 442 } |
| 433 | 443 |
| 434 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( | 444 void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| 435 const scoped_refptr<WebRtcAudioCapturer>& capturer) { | 445 const scoped_refptr<WebRtcAudioCapturer>& capturer) { |
| 436 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; | 446 DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| 437 DCHECK(thread_checker_.CalledOnValidThread()); | 447 DCHECK(thread_checker_.CalledOnValidThread()); |
| 438 DCHECK(capturer.get()); | 448 DCHECK(capturer.get()); |
| 439 base::AutoLock auto_lock(lock_); | 449 { |
| 440 capturers_.remove(capturer); | 450 base::AutoLock auto_lock(lock_); |
| 451 capturers_.remove(capturer); | |
| 452 } | |
| 453 | |
| 454 // The default capturer might have been changed, call StartAecDump() to start | |
| 455 // the Aec dump on the new default capturer in case Aec dump has been enabled. | |
| 456 StartAecDump(); | |
|
Henrik Grunell
2014/03/06 10:12:20
Hmm, we re-use |aec_dump_file_| but that likely wo
no longer working on chromium
2014/03/06 18:57:21
Done.
| |
| 441 } | 457 } |
| 442 | 458 |
| 443 scoped_refptr<WebRtcAudioCapturer> | 459 scoped_refptr<WebRtcAudioCapturer> |
| 444 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { | 460 WebRtcAudioDeviceImpl::GetDefaultCapturer() const { |
| 445 base::AutoLock auto_lock(lock_); | 461 base::AutoLock auto_lock(lock_); |
| 446 // Use the last |capturer| which is from the latest getUserMedia call as | 462 // Use the last |capturer| which is from the latest getUserMedia call as |
| 447 // the default capture device. | 463 // the default capture device. |
| 448 for (CapturerList::const_reverse_iterator iter = capturers_.rbegin(); | 464 for (CapturerList::const_reverse_iterator iter = capturers_.rbegin(); |
| 449 iter != capturers_.rend(); ++iter) { | 465 iter != capturers_.rend(); ++iter) { |
| 450 return *iter; | 466 return *iter; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 478 DCHECK(thread_checker_.CalledOnValidThread()); | 494 DCHECK(thread_checker_.CalledOnValidThread()); |
| 479 // If there is no capturer or there are more than one open capture devices, | 495 // If there is no capturer or there are more than one open capture devices, |
| 480 // return false. | 496 // return false. |
| 481 if (capturers_.empty() || capturers_.size() > 1) | 497 if (capturers_.empty() || capturers_.size() > 1) |
| 482 return false; | 498 return false; |
| 483 | 499 |
| 484 return GetDefaultCapturer()->GetPairedOutputParameters( | 500 return GetDefaultCapturer()->GetPairedOutputParameters( |
| 485 session_id, output_sample_rate, output_frames_per_buffer); | 501 session_id, output_sample_rate, output_frames_per_buffer); |
| 486 } | 502 } |
| 487 | 503 |
| 504 void WebRtcAudioDeviceImpl::EnableAecDump( | |
| 505 IPC::PlatformFileForTransit file_handle) { | |
| 506 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 507 DCHECK_EQ(aec_dump_file_, base::kInvalidPlatformFileValue); | |
| 508 aec_dump_file_ = IPC::PlatformFileForTransitToPlatformFile(file_handle); | |
| 509 DCHECK_NE(aec_dump_file_, base::kInvalidPlatformFileValue); | |
| 510 StartAecDump(); | |
| 511 } | |
| 512 | |
| 513 void WebRtcAudioDeviceImpl::DisableAecDump() { | |
| 514 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 515 if (aec_dump_file_ == base::kInvalidPlatformFileValue) | |
| 516 return; | |
| 517 | |
| 518 StopAecDump(); | |
| 519 base::ClosePlatformFile(aec_dump_file_); | |
| 520 aec_dump_file_ = base::kInvalidPlatformFileValue; | |
| 521 } | |
| 522 | |
| 523 void WebRtcAudioDeviceImpl::StartAecDump() { | |
| 524 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 525 if (aec_dump_file_ == base::kInvalidPlatformFileValue) | |
| 526 return; | |
| 527 | |
| 528 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); | |
| 529 if (!default_capturer) | |
| 530 return; | |
| 531 | |
| 532 // We support Aec dump on only one APM. Loop through all the non-default | |
| 533 // capturers and call StopAecDump(). | |
| 534 for (CapturerList::const_iterator iter = capturers_.begin(); | |
| 535 iter != capturers_.end(); ++iter) { | |
| 536 if (*iter != default_capturer) | |
| 537 (*iter)->StopAecDump(); | |
| 538 } | |
| 539 | |
| 540 // Start the Aec dump on the default capturer. | |
| 541 default_capturer->StartAecDump(aec_dump_file_); | |
| 542 } | |
| 543 | |
| 544 void WebRtcAudioDeviceImpl::StopAecDump() { | |
| 545 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 546 // Only the default capturer can have the Aec dump. | |
| 547 scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); | |
| 548 if (default_capturer) | |
| 549 default_capturer->StopAecDump(); | |
| 550 } | |
| 551 | |
| 488 } // namespace content | 552 } // namespace content |
| OLD | NEW |