Commit 1fd5b379 authored by Kehuang Li's avatar Kehuang Li Committed by Commit Bot

Make noise suppression level configurable

It was hard coded to level kHigh. This cl is to add the configure to the
json configure string used in MediaStreamAudioProcessor.

Bug: internal: 131692686
Test: Passed unit tests that check configuration.
Change-Id: I690b65bcf9d0cffafc42b564546f51a3296ffb37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1650300Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Kehuang Li <kehuangli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#668514}
parent b2fa1529
...@@ -32,11 +32,8 @@ namespace { ...@@ -32,11 +32,8 @@ namespace {
using NoiseSuppression = webrtc::AudioProcessing::Config::NoiseSuppression; using NoiseSuppression = webrtc::AudioProcessing::Config::NoiseSuppression;
base::Optional<double> GetGainControlCompressionGain( base::Optional<double> GetGainControlCompressionGain(
const base::Optional<base::Value>& config) { const base::Value& config) {
if (!config) const base::Value* found = config.FindKey("gain_control_compression_gain_db");
return base::nullopt;
const base::Value* found =
config->FindKey("gain_control_compression_gain_db");
if (!found) if (!found)
return base::nullopt; return base::nullopt;
double gain = found->GetDouble(); double gain = found->GetDouble();
...@@ -44,11 +41,8 @@ base::Optional<double> GetGainControlCompressionGain( ...@@ -44,11 +41,8 @@ base::Optional<double> GetGainControlCompressionGain(
return gain; return gain;
} }
base::Optional<double> GetPreAmplifierGainFactor( base::Optional<double> GetPreAmplifierGainFactor(const base::Value& config) {
const base::Optional<base::Value>& config) { const base::Value* found = config.FindKey("pre_amplifier_fixed_gain_factor");
if (!config)
return base::nullopt;
const base::Value* found = config->FindKey("pre_amplifier_fixed_gain_factor");
if (!found) if (!found)
return base::nullopt; return base::nullopt;
double factor = found->GetDouble(); double factor = found->GetDouble();
...@@ -56,17 +50,30 @@ base::Optional<double> GetPreAmplifierGainFactor( ...@@ -56,17 +50,30 @@ base::Optional<double> GetPreAmplifierGainFactor(
return factor; return factor;
} }
void GetExtraGainConfig( base::Optional<NoiseSuppression::Level> GetNoiseSuppressionLevel(
const base::Value& config) {
const base::Value* found = config.FindKey("noise_suppression_level");
if (!found)
return base::nullopt;
int level = found->GetInt();
DCHECK_GE(level, static_cast<int>(NoiseSuppression::kLow));
DCHECK_LE(level, static_cast<int>(NoiseSuppression::kVeryHigh));
return static_cast<NoiseSuppression::Level>(level);
}
void GetExtraConfigFromJson(
const std::string& audio_processing_platform_config_json, const std::string& audio_processing_platform_config_json,
base::Optional<double>* gain_control_compression_gain_db, base::Optional<double>* gain_control_compression_gain_db,
base::Optional<double>* pre_amplifier_fixed_gain_factor) { base::Optional<double>* pre_amplifier_fixed_gain_factor,
base::Optional<NoiseSuppression::Level>* noise_suppression_level) {
auto config = base::JSONReader::Read(audio_processing_platform_config_json); auto config = base::JSONReader::Read(audio_processing_platform_config_json);
if (!config) { if (!config) {
LOG(ERROR) << "Failed to parse platform config JSON."; LOG(ERROR) << "Failed to parse platform config JSON.";
return; return;
} }
*gain_control_compression_gain_db = GetGainControlCompressionGain(config); *gain_control_compression_gain_db = GetGainControlCompressionGain(*config);
*pre_amplifier_fixed_gain_factor = GetPreAmplifierGainFactor(config); *pre_amplifier_fixed_gain_factor = GetPreAmplifierGainFactor(*config);
*noise_suppression_level = GetNoiseSuppressionLevel(*config);
} }
} // namespace } // namespace
...@@ -224,10 +231,12 @@ void PopulateApmConfig( ...@@ -224,10 +231,12 @@ void PopulateApmConfig(
// TODO(saza): When Chrome uses AGC2, handle all JSON config via the // TODO(saza): When Chrome uses AGC2, handle all JSON config via the
// webrtc::AudioProcessing::Config, crbug.com/895814. // webrtc::AudioProcessing::Config, crbug.com/895814.
base::Optional<double> pre_amplifier_fixed_gain_factor; base::Optional<double> pre_amplifier_fixed_gain_factor;
base::Optional<NoiseSuppression::Level> noise_suppression_level;
if (audio_processing_platform_config_json.has_value()) { if (audio_processing_platform_config_json.has_value()) {
GetExtraGainConfig(audio_processing_platform_config_json.value(), GetExtraConfigFromJson(audio_processing_platform_config_json.value(),
gain_control_compression_gain_db, gain_control_compression_gain_db,
&pre_amplifier_fixed_gain_factor); &pre_amplifier_fixed_gain_factor,
&noise_suppression_level);
} }
apm_config->high_pass_filter.enabled = properties.goog_highpass_filter; apm_config->high_pass_filter.enabled = properties.goog_highpass_filter;
...@@ -240,7 +249,8 @@ void PopulateApmConfig( ...@@ -240,7 +249,8 @@ void PopulateApmConfig(
if (properties.goog_noise_suppression) { if (properties.goog_noise_suppression) {
apm_config->noise_suppression.enabled = true; apm_config->noise_suppression.enabled = true;
apm_config->noise_suppression.level = NoiseSuppression::kHigh; apm_config->noise_suppression.level =
noise_suppression_level.value_or(NoiseSuppression::kHigh);
} }
if (properties.EchoCancellationIsWebRtcProvided()) { if (properties.EchoCancellationIsWebRtcProvided()) {
......
...@@ -71,6 +71,29 @@ TEST(ConfigAutomaticGainControlTest, EnableHybridAGC) { ...@@ -71,6 +71,29 @@ TEST(ConfigAutomaticGainControlTest, EnableHybridAGC) {
saturation_margin); saturation_margin);
} }
TEST(PopulateApmConfigTest, DefaultWithoutConfigJson) {
webrtc::AudioProcessing::Config apm_config;
AudioProcessingProperties properties;
base::Optional<double> gain_control_compression_gain_db;
PopulateApmConfig(&apm_config, properties,
base::nullopt, // |audio_processing_platform_config_json|.
&gain_control_compression_gain_db);
EXPECT_FALSE(gain_control_compression_gain_db.has_value());
EXPECT_TRUE(apm_config.high_pass_filter.enabled);
EXPECT_FALSE(apm_config.pre_amplifier.enabled);
EXPECT_TRUE(apm_config.noise_suppression.enabled);
EXPECT_EQ(apm_config.noise_suppression.level,
webrtc::AudioProcessing::Config::NoiseSuppression::kHigh);
EXPECT_TRUE(apm_config.echo_canceller.enabled);
#if defined(OS_ANDROID)
EXPECT_TRUE(
#else
EXPECT_FALSE(
#endif
apm_config.echo_canceller.mobile_mode);
}
TEST(PopulateApmConfigTest, SetGainsInConfigJson) { TEST(PopulateApmConfigTest, SetGainsInConfigJson) {
webrtc::AudioProcessing::Config apm_config; webrtc::AudioProcessing::Config apm_config;
AudioProcessingProperties properties; AudioProcessingProperties properties;
...@@ -99,4 +122,29 @@ TEST(PopulateApmConfigTest, SetGainsInConfigJson) { ...@@ -99,4 +122,29 @@ TEST(PopulateApmConfigTest, SetGainsInConfigJson) {
apm_config.echo_canceller.mobile_mode); apm_config.echo_canceller.mobile_mode);
} }
TEST(PopulateApmConfigTest, SetNoiseSuppressionLevelInConfigJson) {
webrtc::AudioProcessing::Config apm_config;
AudioProcessingProperties properties;
base::Optional<std::string> audio_processing_platform_config_json =
"{\"noise_suppression_level\": 3}";
base::Optional<double> gain_control_compression_gain_db;
PopulateApmConfig(&apm_config, properties,
audio_processing_platform_config_json,
&gain_control_compression_gain_db);
EXPECT_FALSE(gain_control_compression_gain_db.has_value());
EXPECT_TRUE(apm_config.high_pass_filter.enabled);
EXPECT_FALSE(apm_config.pre_amplifier.enabled);
EXPECT_TRUE(apm_config.noise_suppression.enabled);
EXPECT_EQ(apm_config.noise_suppression.level,
webrtc::AudioProcessing::Config::NoiseSuppression::kVeryHigh);
EXPECT_TRUE(apm_config.echo_canceller.enabled);
#if defined(OS_ANDROID)
EXPECT_TRUE(
#else
EXPECT_FALSE(
#endif
apm_config.echo_canceller.mobile_mode);
}
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment