From 46b05602ec44a2b5299c469e6b01874eb822e93c Mon Sep 17 00:00:00 2001 From: "Paul Kerr [:pkerr]" Date: Tue, 24 Nov 2015 08:32:11 -0800 Subject: [PATCH] Bug 1226347 - Part 2: Allow control of AEC via prefs. r=rjesup --- .../src/media-conduit/AudioConduit.cpp | 20 ++++++++++++++++++- .../signaling/test/mediapipeline_unittest.cpp | 7 +------ .../echo_cancellation_impl.cc | 4 ++-- .../include/audio_processing.h | 12 +++++++++++ .../trunk/webrtc/voice_engine/channel.cc | 4 ++++ .../webrtc/voice_engine/channel_manager.cc | 7 ++++--- .../webrtc/voice_engine/channel_manager.h | 3 +-- .../webrtc/voice_engine/voe_base_impl.cc | 2 +- modules/libpref/init/all.js | 6 ++++++ 9 files changed, 50 insertions(+), 15 deletions(-) diff --git a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp index 4a5d12a47107..2948a490800e 100755 --- a/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp +++ b/media/webrtc/signaling/src/media-conduit/AudioConduit.cpp @@ -23,6 +23,8 @@ #include "mozilla/Telemetry.h" #endif +#include "webrtc/common.h" +#include "webrtc/modules/audio_processing/include/audio_processing.h" #include "webrtc/voice_engine/include/voe_errors.h" #include "webrtc/system_wrappers/interface/clock.h" #include "browser_logging/WebRtcLog.h" @@ -231,9 +233,25 @@ MediaConduitErrorCode WebrtcAudioConduit::Init() return kMediaConduitSessionNotInited; } #endif + webrtc::Config config; + bool aec_extended_filter = true; // Always default to the extended filter length + bool aec_delay_agnostic = false; +#if !defined(MOZILLA_EXTERNAL_LINKAGE) + nsresult rv; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + prefs->GetBoolPref("media.getusermedia.aec_extended_filter", &aec_extended_filter); + rv = prefs->GetBoolPref("media.getusermedia.aec_delay_agnostic", &aec_delay_agnostic); + if (NS_SUCCEEDED(rv)) { + // Only override platform setting if pref is defined. + config.Set(new webrtc::DelayAgnostic(aec_delay_agnostic)); + } + } +#endif + config.Set(new webrtc::ExtendedFilter(aec_extended_filter)); // Per WebRTC APIs below function calls return nullptr on failure - if(!(mVoiceEngine = webrtc::VoiceEngine::Create())) + if(!(mVoiceEngine = webrtc::VoiceEngine::Create(config))) { CSFLogError(logTag, "%s Unable to create voice engine", __FUNCTION__); return kMediaConduitSessionNotInited; diff --git a/media/webrtc/signaling/test/mediapipeline_unittest.cpp b/media/webrtc/signaling/test/mediapipeline_unittest.cpp index 85557de045bb..06febf8c9faa 100644 --- a/media/webrtc/signaling/test/mediapipeline_unittest.cpp +++ b/media/webrtc/signaling/test/mediapipeline_unittest.cpp @@ -396,15 +396,10 @@ class MediaPipelineTest : public ::testing::Test { // Setup transport flows InitTransports(aIsRtcpMux); -#if 0 //DEBUG(pkerr) - mozilla::SyncRunnable::DispatchToThread( - test_utils->sts_target(), - WrapRunnable(&p1_, &TestAgent::CreatePipelines_s, aIsRtcpMux)); -#else NS_DispatchToMainThread( WrapRunnable(&p1_, &TestAgent::CreatePipelines_s, aIsRtcpMux), NS_DISPATCH_SYNC); -#endif + mozilla::SyncRunnable::DispatchToThread( test_utils->sts_target(), WrapRunnable(&p2_, &TestAgent::CreatePipelines_s, aIsRtcpMux)); diff --git a/media/webrtc/trunk/webrtc/modules/audio_processing/echo_cancellation_impl.cc b/media/webrtc/trunk/webrtc/modules/audio_processing/echo_cancellation_impl.cc index 1915c579aabf..c6a35f1b6806 100644 --- a/media/webrtc/trunk/webrtc/modules/audio_processing/echo_cancellation_impl.cc +++ b/media/webrtc/trunk/webrtc/modules/audio_processing/echo_cancellation_impl.cc @@ -336,8 +336,8 @@ int EchoCancellationImpl::Initialize() { } void EchoCancellationImpl::SetExtraOptions(const Config& config) { - extended_filter_enabled_ = true; // XXX config.Get().enabled; - delay_agnostic_enabled_ = true; // XXX config.Get().enabled; + extended_filter_enabled_ = config.Get().enabled; + delay_agnostic_enabled_ = config.Get().enabled; Configure(); } diff --git a/media/webrtc/trunk/webrtc/modules/audio_processing/include/audio_processing.h b/media/webrtc/trunk/webrtc/modules/audio_processing/include/audio_processing.h index 72553ffa6e7d..97b14b0d9ccc 100644 --- a/media/webrtc/trunk/webrtc/modules/audio_processing/include/audio_processing.h +++ b/media/webrtc/trunk/webrtc/modules/audio_processing/include/audio_processing.h @@ -37,6 +37,18 @@ class LevelEstimator; class NoiseSuppression; class VoiceDetection; +struct ExtendedFilter { + ExtendedFilter() : enabled(false) {} + explicit ExtendedFilter(bool enabled) : enabled(enabled) {} + bool enabled; +}; + +struct DelayAgnostic { + DelayAgnostic() : enabled(false) {} + explicit DelayAgnostic(bool enabled) : enabled(enabled) {} + bool enabled; +}; + // Use to enable the delay correction feature. This now engages an extended // filter mode in the AEC, along with robustness measures around the reported // system delays. It comes with a significant increase in AEC complexity, but is diff --git a/media/webrtc/trunk/webrtc/voice_engine/channel.cc b/media/webrtc/trunk/webrtc/voice_engine/channel.cc index ed250bd7747c..c4ddd2fe94db 100644 --- a/media/webrtc/trunk/webrtc/voice_engine/channel.cc +++ b/media/webrtc/trunk/webrtc/voice_engine/channel.cc @@ -849,6 +849,10 @@ Channel::Channel(int32_t channelId, Config audioproc_config; audioproc_config.Set(new ExperimentalAgc(false)); + audioproc_config.Set( + new ExtendedFilter(config.Get().enabled)); + audioproc_config.Set( + new DelayAgnostic(config.Get().enabled)); rx_audioproc_.reset(AudioProcessing::Create(audioproc_config)); } diff --git a/media/webrtc/trunk/webrtc/voice_engine/channel_manager.cc b/media/webrtc/trunk/webrtc/voice_engine/channel_manager.cc index 938625747616..78c484f3dc6a 100644 --- a/media/webrtc/trunk/webrtc/voice_engine/channel_manager.cc +++ b/media/webrtc/trunk/webrtc/voice_engine/channel_manager.cc @@ -46,10 +46,11 @@ ChannelOwner::ChannelRef::ChannelRef(class Channel* channel) : channel(channel), ref_count(1) {} ChannelManager::ChannelManager(uint32_t instance_id, const Config& config) - : instance_id_(instance_id), + : config_(config), + instance_id_(instance_id), last_channel_id_(-1), - lock_(CriticalSectionWrapper::CreateCriticalSection()), - config_(config) {} + lock_(CriticalSectionWrapper::CreateCriticalSection()) + {} ChannelOwner ChannelManager::CreateChannel() { return CreateChannelInternal(config_); diff --git a/media/webrtc/trunk/webrtc/voice_engine/channel_manager.h b/media/webrtc/trunk/webrtc/voice_engine/channel_manager.h index eae014ed09c4..27e2865bafef 100644 --- a/media/webrtc/trunk/webrtc/voice_engine/channel_manager.h +++ b/media/webrtc/trunk/webrtc/voice_engine/channel_manager.h @@ -109,6 +109,7 @@ class ChannelManager { void DestroyAllChannels(); size_t NumOfChannels() const; + const Config& config_; private: // Create a channel given a configuration, |config|. @@ -121,8 +122,6 @@ class ChannelManager { rtc::scoped_ptr lock_; std::vector channels_; - const Config& config_; - DISALLOW_COPY_AND_ASSIGN(ChannelManager); }; } // namespace voe diff --git a/media/webrtc/trunk/webrtc/voice_engine/voe_base_impl.cc b/media/webrtc/trunk/webrtc/voice_engine/voe_base_impl.cc index ce22311e3272..430ee40c6755 100644 --- a/media/webrtc/trunk/webrtc/voice_engine/voe_base_impl.cc +++ b/media/webrtc/trunk/webrtc/voice_engine/voe_base_impl.cc @@ -424,7 +424,7 @@ int VoEBaseImpl::Init(AudioDeviceModule* external_adm, } if (!audioproc) { - audioproc = AudioProcessing::Create(); + audioproc = AudioProcessing::Create(_shared->channel_manager().config_); if (!audioproc) { LOG(LS_ERROR) << "Failed to create AudioProcessing."; _shared->SetLastError(VE_NO_MEMORY); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index c3b286311065..d96b07dc7ab5 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -439,6 +439,12 @@ pref("media.getusermedia.noise_enabled", false); pref("media.getusermedia.aec_enabled", true); pref("media.getusermedia.noise_enabled", true); #endif +pref("media.getusermedia.aec_extended_filter", true); +#if defined(ANDROID) +pref("media.getusermedia.aec_delay_agnostic", true); +#else +pref("media.getusermedia.aec_delay_agnostic", false); +#endif pref("media.getusermedia.noise", 1); pref("media.getusermedia.agc_enabled", false); pref("media.getusermedia.agc", 1);