diff --git a/api/audio/echo_canceller3_config_json.cc b/api/audio/echo_canceller3_config_json.cc index 784f928f9c..d039c8b616 100644 --- a/api/audio/echo_canceller3_config_json.cc +++ b/api/audio/echo_canceller3_config_json.cc @@ -109,21 +109,29 @@ void ReadParam(const Json::Value& root, } } // namespace -EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) { - EchoCanceller3Config cfg; +void Aec3ConfigFromJsonString(absl::string_view json_string, + EchoCanceller3Config* config, + bool* parsing_successful) { + RTC_DCHECK(config); + RTC_DCHECK(parsing_successful); + EchoCanceller3Config& cfg = *config; + cfg = EchoCanceller3Config(); + *parsing_successful = true; Json::Value root; bool success = Json::Reader().parse(std::string(json_string), root); if (!success) { RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string; - return EchoCanceller3Config(); + *parsing_successful = false; + return; } Json::Value aec3_root; success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root); if (!success) { RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string; - return EchoCanceller3Config(); + *parsing_successful = false; + return; } Json::Value section; @@ -325,6 +333,12 @@ EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) { ReadParam(section, "enforce_empty_higher_bands", &cfg.suppressor.enforce_empty_higher_bands); } +} + +EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) { + EchoCanceller3Config cfg; + bool not_used; + Aec3ConfigFromJsonString(json_string, &cfg, ¬_used); return cfg; } diff --git a/api/audio/echo_canceller3_config_json.h b/api/audio/echo_canceller3_config_json.h index 3c8b97589f..8973650f85 100644 --- a/api/audio/echo_canceller3_config_json.h +++ b/api/audio/echo_canceller3_config_json.h @@ -20,6 +20,16 @@ namespace webrtc { // Parses a JSON-encoded string into an Aec3 config. Fields corresponds to // substruct names, with the addition that there must be a top-level node +// "aec3". Produces default config values for anything that cannot be parsed +// from the string. If any error was found in the parsing, parsing_successful is +// set to false. +RTC_EXPORT void Aec3ConfigFromJsonString(absl::string_view json_string, + EchoCanceller3Config* config, + bool* parsing_successful); + +// To be deprecated. +// Parses a JSON-encoded string into an Aec3 config. Fields corresponds to +// substruct names, with the addition that there must be a top-level node // "aec3". Returns default config values for anything that cannot be parsed from // the string. RTC_EXPORT EchoCanceller3Config diff --git a/modules/audio_processing/test/audio_processing_simulator.cc b/modules/audio_processing/test/audio_processing_simulator.cc index e4ac57b069..aae936389b 100644 --- a/modules/audio_processing/test/audio_processing_simulator.cc +++ b/modules/audio_processing/test/audio_processing_simulator.cc @@ -48,7 +48,17 @@ EchoCanceller3Config ReadAec3ConfigFromJsonFile(const std::string& filename) { while (std::getline(f, s)) { json_string += s; } - return Aec3ConfigFromJsonString(json_string); + + bool parsing_successful; + EchoCanceller3Config cfg; + Aec3ConfigFromJsonString(json_string, &cfg, &parsing_successful); + if (!parsing_successful) { + std::cout << "Parsing of json string failed: " << std::endl + << json_string << std::endl; + RTC_CHECK(false); + } + + return cfg; } void CopyFromAudioFrame(const AudioFrame& src, ChannelBuffer* dest) {