From 8a8ebd94b01def6a6182645976e063465c04446b Mon Sep 17 00:00:00 2001 From: peah Date: Mon, 22 May 2017 15:48:47 -0700 Subject: [PATCH] Field trial support to whenever possible turn off the AGC and HPF When operating on mobile devices, where hardware support is available for the AEC and NS functionality, it is desirable to be able to operate without hardcoded behaviors for the WebRTC AGC and HPF. This CL adds support to allow a field trial to turn these off whenever that is possible. BUG=webrtc:6220, webrtc:6183, webrtc:6181 Review-Url: https://codereview.webrtc.org/2876133002 Cr-Commit-Position: refs/heads/master@{#18226} --- webrtc/media/engine/webrtcvoiceengine.cc | 52 +++++++++++++++---- .../objc/Framework/Classes/RTCFieldTrials.mm | 2 + .../Framework/Headers/WebRTC/RTCFieldTrials.h | 1 + 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/webrtc/media/engine/webrtcvoiceengine.cc b/webrtc/media/engine/webrtcvoiceengine.cc index 2b0f72aef1..2103138960 100644 --- a/webrtc/media/engine/webrtcvoiceengine.cc +++ b/webrtc/media/engine/webrtcvoiceengine.cc @@ -336,6 +336,7 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { LOG(LS_INFO) << "WebRtcVoiceEngine::ApplyOptions: " << options_in.ToString(); AudioOptions options = options_in; // The options are modified below. + // Set and adjust echo canceller options. // kEcConference is AEC with high suppression. webrtc::EcModes ec_mode = webrtc::kEcConference; if (options.aecm_generate_comfort_noise) { @@ -345,21 +346,13 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { } #if defined(WEBRTC_IOS) - // On iOS, VPIO provides built-in EC, NS and AGC. + // On iOS, VPIO provides built-in EC. options.echo_cancellation = rtc::Optional(false); - options.auto_gain_control = rtc::Optional(false); - options.noise_suppression = rtc::Optional(false); - LOG(LS_INFO) - << "Always disable AEC, NS and AGC on iOS. Use built-in instead."; + options.extended_filter_aec = rtc::Optional(false); + LOG(LS_INFO) << "Always disable AEC on iOS. Use built-in instead."; #elif defined(ANDROID) ec_mode = webrtc::kEcAecm; -#endif - -#if defined(WEBRTC_IOS) || defined(ANDROID) - options.typing_detection = rtc::Optional(false); - options.experimental_agc = rtc::Optional(false); options.extended_filter_aec = rtc::Optional(false); - options.experimental_ns = rtc::Optional(false); #endif // Delay Agnostic AEC automatically turns on EC if not set except on iOS @@ -376,6 +369,43 @@ bool WebRtcVoiceEngine::ApplyOptions(const AudioOptions& options_in) { } #endif +// Set and adjust noise suppressor options. +#if defined(WEBRTC_IOS) + // On iOS, VPIO provides built-in NS. + options.noise_suppression = rtc::Optional(false); + options.typing_detection = rtc::Optional(false); + options.experimental_ns = rtc::Optional(false); + LOG(LS_INFO) << "Always disable NS on iOS. Use built-in instead."; +#elif defined(ANDROID) + options.typing_detection = rtc::Optional(false); + options.experimental_ns = rtc::Optional(false); +#endif + +// Set and adjust gain control options. +#if defined(WEBRTC_IOS) + // On iOS, VPIO provides built-in AGC. + options.auto_gain_control = rtc::Optional(false); + options.experimental_agc = rtc::Optional(false); + LOG(LS_INFO) << "Always disable AGC on iOS. Use built-in instead."; +#elif defined(ANDROID) + options.experimental_agc = rtc::Optional(false); +#endif + +#if defined(WEBRTC_IOS) || defined(WEBRTC_ANDROID) + // Turn off the gain control if specified by the field trial. The purpose of the field trial is to reduce the amount of resampling performed inside the audio processing module on mobile platforms by whenever possible turning off the fixed AGC mode and the high-pass filter. (https://bugs.chromium.org/p/webrtc/issues/detail?id=6181). + if (webrtc::field_trial::IsEnabled( + "WebRTC-Audio-MinimizeResamplingOnMobile")) { + options.auto_gain_control = rtc::Optional(false); + LOG(LS_INFO) << "Disable AGC according to field trial."; + if (!(options.noise_suppression.value_or(false) or + options.echo_cancellation.value_or(false))) { + // If possible, turn off the high-pass filter. + LOG(LS_INFO) << "Disable high-pass filter in response to field trial."; + options.highpass_filter = rtc::Optional(false); + } + } +#endif + #if (WEBRTC_INTELLIGIBILITY_ENHANCER == 0) // Hardcode the intelligibility enhancer to be off. options.intelligibility_enhancer = rtc::Optional(false); diff --git a/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm b/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm index 28ce5414bd..854bc7caaf 100644 --- a/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm +++ b/webrtc/sdk/objc/Framework/Classes/RTCFieldTrials.mm @@ -27,6 +27,8 @@ NSString * const kRTCFieldTrialImprovedBitrateEstimateKey = @"WebRTC-ImprovedBit NSString * const kRTCFieldTrialMedianSlopeFilterKey = @"WebRTC-BweMedianSlopeFilter"; NSString * const kRTCFieldTrialTrendlineFilterKey = @"WebRTC-BweTrendlineFilter"; NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile"; +NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey = + @"WebRTC-Audio-MinimizeResamplingOnMobile"; NSString * const kRTCFieldTrialEnabledValue = @"Enabled"; static std::unique_ptr gFieldTrialInitString; diff --git a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h index a9d68066b5..78d69610d8 100644 --- a/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h +++ b/webrtc/sdk/objc/Framework/Headers/WebRTC/RTCFieldTrials.h @@ -19,6 +19,7 @@ RTC_EXTERN NSString * const kRTCFieldTrialFlexFec03AdvertisedKey; RTC_EXTERN NSString * const kRTCFieldTrialFlexFec03Key; RTC_EXTERN NSString * const kRTCFieldTrialImprovedBitrateEstimateKey; RTC_EXTERN NSString * const kRTCFieldTrialH264HighProfileKey; +RTC_EXTERN NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey; /** The valid value for field trials above. */ RTC_EXTERN NSString * const kRTCFieldTrialEnabledValue;