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

Unified 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: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
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 ef816fcc60d359c2f150be6fb5ce8cead0108686..197649a55ce6321d69961335692d26bf97e8f09a 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()";
}
@@ -214,6 +216,8 @@ int32_t WebRtcAudioDeviceImpl::Terminate() {
DCHECK(!renderer_.get() || !renderer_->IsStarted())
<< "The shared audio renderer shouldn't be running";
+ DisableAecDump();
+
capturers_.clear();
initialized_ = false;
@@ -425,10 +429,16 @@ 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);
+ }
+
+ // The default capturer might have been changed, call StartAecDump() to start
+ // the Aec dump on the new default capturer in case Aec dump has been enabled.
+ StartAecDump();
}
void WebRtcAudioDeviceImpl::RemoveAudioCapturer(
@@ -436,8 +446,14 @@ void WebRtcAudioDeviceImpl::RemoveAudioCapturer(
DVLOG(1) << "WebRtcAudioDeviceImpl::AddAudioCapturer()";
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(capturer.get());
- base::AutoLock auto_lock(lock_);
- capturers_.remove(capturer);
+ {
+ base::AutoLock auto_lock(lock_);
+ capturers_.remove(capturer);
+ }
+
+ // The default capturer might have been changed, call StartAecDump() to start
+ // the Aec dump on the new default capturer in case Aec dump has been enabled.
+ 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.
}
scoped_refptr<WebRtcAudioCapturer>
@@ -485,4 +501,52 @@ bool WebRtcAudioDeviceImpl::GetAuthorizedDeviceInfoForAudioRenderer(
session_id, output_sample_rate, output_frames_per_buffer);
}
+void WebRtcAudioDeviceImpl::EnableAecDump(
+ IPC::PlatformFileForTransit file_handle) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ DCHECK_EQ(aec_dump_file_, base::kInvalidPlatformFileValue);
+ aec_dump_file_ = IPC::PlatformFileForTransitToPlatformFile(file_handle);
+ DCHECK_NE(aec_dump_file_, base::kInvalidPlatformFileValue);
+ StartAecDump();
+}
+
+void WebRtcAudioDeviceImpl::DisableAecDump() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (aec_dump_file_ == base::kInvalidPlatformFileValue)
+ return;
+
+ StopAecDump();
+ base::ClosePlatformFile(aec_dump_file_);
+ aec_dump_file_ = base::kInvalidPlatformFileValue;
+}
+
+void WebRtcAudioDeviceImpl::StartAecDump() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ if (aec_dump_file_ == base::kInvalidPlatformFileValue)
+ return;
+
+ scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer());
+ if (!default_capturer)
+ return;
+
+ // We support Aec dump on only one APM. Loop through all the non-default
+ // capturers and call StopAecDump().
+ for (CapturerList::const_iterator iter = capturers_.begin();
+ iter != capturers_.end(); ++iter) {
+ if (*iter != default_capturer)
+ (*iter)->StopAecDump();
+ }
+
+ // Start the Aec dump on the default capturer.
+ default_capturer->StartAecDump(aec_dump_file_);
+}
+
+void WebRtcAudioDeviceImpl::StopAecDump() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // Only the default capturer can have the Aec dump.
+ scoped_refptr<WebRtcAudioCapturer> default_capturer(GetDefaultCapturer());
+ if (default_capturer)
+ default_capturer->StopAecDump();
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698