Chromium Code Reviews| Index: content/renderer/media/webrtc_audio_device_impl.cc |
| diff --git a/content/renderer/media/webrtc_audio_device_impl.cc b/content/renderer/media/webrtc_audio_device_impl.cc |
| index 7e27af1a08cfac518300914d164e73cac44da714..2491f1700aaab2fa189993804b4273a4c1b12d2d 100644 |
| --- a/content/renderer/media/webrtc_audio_device_impl.cc |
| +++ b/content/renderer/media/webrtc_audio_device_impl.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/bind.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/platform_file.h" |
| #include "base/strings/string_util.h" |
| #include "base/win/windows_version.h" |
| #include "content/renderer/media/webrtc_audio_capturer.h" |
| @@ -27,7 +28,8 @@ WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl() |
| initialized_(false), |
| playing_(false), |
| recording_(false), |
| - microphone_volume_(0) { |
| + microphone_volume_(0), |
| + aec_dump_file_(base::kInvalidPlatformFileValue) { |
| DVLOG(1) << "WebRtcAudioDeviceImpl::WebRtcAudioDeviceImpl()"; |
| } |
| @@ -220,6 +222,8 @@ int32_t WebRtcAudioDeviceImpl::Terminate() { |
| DCHECK(!renderer_.get() || !renderer_->IsStarted()) |
| << "The shared audio renderer shouldn't be running"; |
| + DisableAecDump(); |
| + |
| capturers_.clear(); |
| initialized_ = false; |
| @@ -431,10 +435,17 @@ void WebRtcAudioDeviceImpl::AddAudioCapturer( |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(capturer.get()); |
| DCHECK(!capturer->device_id().empty()); |
| - base::AutoLock auto_lock(lock_); |
| - DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| - capturers_.end()); |
| - capturers_.push_back(capturer); |
| + { |
| + base::AutoLock auto_lock(lock_); |
| + DCHECK(std::find(capturers_.begin(), capturers_.end(), capturer) == |
| + capturers_.end()); |
| + capturers_.push_back(capturer); |
| + } |
| + |
| + // Start the Aec dump if the Aec dump has been enabled and has not been |
| + // started. |
| + if (aec_dump_file_ != base::kInvalidPlatformFileValue) |
| + StartAecDump(); |
| } |
| void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| @@ -442,8 +453,10 @@ void WebRtcAudioDeviceImpl::RemoveAudioCapturer( |
| DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()"; |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| DCHECK(capturer.get()); |
| - base::AutoLock auto_lock(lock_); |
| - capturers_.remove(capturer); |
| + { |
|
Henrik Grunell
2014/03/07 09:14:57
Nit: don't need {}
no longer working on chromium
2014/03/07 10:14:54
Done.
|
| + base::AutoLock auto_lock(lock_); |
| + capturers_.remove(capturer); |
| + } |
| } |
| scoped_refptr<WebRtcAudioCapturer> |
| @@ -491,4 +504,46 @@ bool WebRtcAudioDeviceImpl::GetAuthorizedDeviceInfoForAudioRenderer( |
| session_id, output_sample_rate, output_frames_per_buffer); |
| } |
| +void WebRtcAudioDeviceImpl::EnableAecDump( |
| + const base::PlatformFile& aec_dump_file) { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK_NE(aec_dump_file, base::kInvalidPlatformFileValue); |
| + DCHECK_EQ(aec_dump_file_, base::kInvalidPlatformFileValue); |
| + aec_dump_file_ = aec_dump_file; |
| + StartAecDump(); |
|
Henrik Grunell
2014/03/07 09:14:57
Have StartAecDump() take the file as an argument,
no longer working on chromium
2014/03/07 10:14:54
Discussed offline, keep the way how it is.
|
| +} |
| + |
| +void WebRtcAudioDeviceImpl::DisableAecDump() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + // Simply invalidate the |aec_dump_file_| if we have not pass the ownership |
| + // to WebRtc. |
| + if (aec_dump_file_ != base::kInvalidPlatformFileValue) { |
| + aec_dump_file_ = base::kInvalidPlatformFileValue; |
|
Henrik Grunell
2014/03/07 09:14:57
Close the file before setting to invalid.
|
| + return; |
| + } |
| + |
| + // We might have call StartAecDump() on one of the capturer. Loop through all |
| + // the capturers and call StopAecDump() on each of them to stop Aec dump. |
| + for (CapturerList::const_iterator iter = capturers_.begin(); |
| + iter != capturers_.end(); ++iter) { |
| + (*iter)->StopAecDump(); |
| + } |
| +} |
| + |
| +void WebRtcAudioDeviceImpl::StartAecDump() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + DCHECK_NE(aec_dump_file_, base::kInvalidPlatformFileValue); |
| + |
| + // Start the Aec dump on the current default capturer. |
| + scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer()); |
| + if (!default_capturer) |
| + return; |
| + |
| + default_capturer->StartAecDump(aec_dump_file_); |
| + |
| + // Invalidate the |aec_dump_file_| since the ownership of the file has been |
| + // passed to WebRtc. |
| + aec_dump_file_ = base::kInvalidPlatformFileValue; |
| +} |
| + |
| } // namespace content |