1 /*
2  *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 #include "api/audio/echo_canceller3_config_json.h"
11 
12 #include <stddef.h>
13 
14 #include <string>
15 #include <vector>
16 
17 #include "rtc_base/checks.h"
18 #include "rtc_base/logging.h"
19 #include "rtc_base/strings/json.h"
20 #include "rtc_base/strings/string_builder.h"
21 
22 namespace webrtc {
23 namespace {
ReadParam(const Json::Value & root,std::string param_name,bool * param)24 void ReadParam(const Json::Value& root, std::string param_name, bool* param) {
25   RTC_DCHECK(param);
26   bool v;
27   if (rtc::GetBoolFromJsonObject(root, param_name, &v)) {
28     *param = v;
29   }
30 }
31 
ReadParam(const Json::Value & root,std::string param_name,size_t * param)32 void ReadParam(const Json::Value& root, std::string param_name, size_t* param) {
33   RTC_DCHECK(param);
34   int v;
35   if (rtc::GetIntFromJsonObject(root, param_name, &v) && v >= 0) {
36     *param = v;
37   }
38 }
39 
ReadParam(const Json::Value & root,std::string param_name,int * param)40 void ReadParam(const Json::Value& root, std::string param_name, int* param) {
41   RTC_DCHECK(param);
42   int v;
43   if (rtc::GetIntFromJsonObject(root, param_name, &v)) {
44     *param = v;
45   }
46 }
47 
ReadParam(const Json::Value & root,std::string param_name,float * param)48 void ReadParam(const Json::Value& root, std::string param_name, float* param) {
49   RTC_DCHECK(param);
50   double v;
51   if (rtc::GetDoubleFromJsonObject(root, param_name, &v)) {
52     *param = static_cast<float>(v);
53   }
54 }
55 
ReadParam(const Json::Value & root,std::string param_name,EchoCanceller3Config::Filter::RefinedConfiguration * param)56 void ReadParam(const Json::Value& root,
57                std::string param_name,
58                EchoCanceller3Config::Filter::RefinedConfiguration* param) {
59   RTC_DCHECK(param);
60   Json::Value json_array;
61   if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
62     std::vector<double> v;
63     rtc::JsonArrayToDoubleVector(json_array, &v);
64     if (v.size() != 6) {
65       RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
66       return;
67     }
68     param->length_blocks = static_cast<size_t>(v[0]);
69     param->leakage_converged = static_cast<float>(v[1]);
70     param->leakage_diverged = static_cast<float>(v[2]);
71     param->error_floor = static_cast<float>(v[3]);
72     param->error_ceil = static_cast<float>(v[4]);
73     param->noise_gate = static_cast<float>(v[5]);
74   }
75 }
76 
ReadParam(const Json::Value & root,std::string param_name,EchoCanceller3Config::Filter::CoarseConfiguration * param)77 void ReadParam(const Json::Value& root,
78                std::string param_name,
79                EchoCanceller3Config::Filter::CoarseConfiguration* param) {
80   RTC_DCHECK(param);
81   Json::Value json_array;
82   if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
83     std::vector<double> v;
84     rtc::JsonArrayToDoubleVector(json_array, &v);
85     if (v.size() != 3) {
86       RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
87       return;
88     }
89     param->length_blocks = static_cast<size_t>(v[0]);
90     param->rate = static_cast<float>(v[1]);
91     param->noise_gate = static_cast<float>(v[2]);
92   }
93 }
94 
ReadParam(const Json::Value & root,std::string param_name,EchoCanceller3Config::Delay::AlignmentMixing * param)95 void ReadParam(const Json::Value& root,
96                std::string param_name,
97                EchoCanceller3Config::Delay::AlignmentMixing* param) {
98   RTC_DCHECK(param);
99 
100   Json::Value subsection;
101   if (rtc::GetValueFromJsonObject(root, param_name, &subsection)) {
102     ReadParam(subsection, "downmix", &param->downmix);
103     ReadParam(subsection, "adaptive_selection", &param->adaptive_selection);
104     ReadParam(subsection, "activity_power_threshold",
105               &param->activity_power_threshold);
106     ReadParam(subsection, "prefer_first_two_channels",
107               &param->prefer_first_two_channels);
108   }
109 }
110 
ReadParam(const Json::Value & root,std::string param_name,EchoCanceller3Config::Suppressor::SubbandNearendDetection::SubbandRegion * param)111 void ReadParam(
112     const Json::Value& root,
113     std::string param_name,
114     EchoCanceller3Config::Suppressor::SubbandNearendDetection::SubbandRegion*
115         param) {
116   RTC_DCHECK(param);
117   Json::Value json_array;
118   if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
119     std::vector<int> v;
120     rtc::JsonArrayToIntVector(json_array, &v);
121     if (v.size() != 2) {
122       RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
123       return;
124     }
125     param->low = static_cast<size_t>(v[0]);
126     param->high = static_cast<size_t>(v[1]);
127   }
128 }
129 
ReadParam(const Json::Value & root,std::string param_name,EchoCanceller3Config::Suppressor::MaskingThresholds * param)130 void ReadParam(const Json::Value& root,
131                std::string param_name,
132                EchoCanceller3Config::Suppressor::MaskingThresholds* param) {
133   RTC_DCHECK(param);
134   Json::Value json_array;
135   if (rtc::GetValueFromJsonObject(root, param_name, &json_array)) {
136     std::vector<double> v;
137     rtc::JsonArrayToDoubleVector(json_array, &v);
138     if (v.size() != 3) {
139       RTC_LOG(LS_ERROR) << "Incorrect array size for " << param_name;
140       return;
141     }
142     param->enr_transparent = static_cast<float>(v[0]);
143     param->enr_suppress = static_cast<float>(v[1]);
144     param->emr_transparent = static_cast<float>(v[2]);
145   }
146 }
147 }  // namespace
148 
Aec3ConfigFromJsonString(absl::string_view json_string,EchoCanceller3Config * config,bool * parsing_successful)149 void Aec3ConfigFromJsonString(absl::string_view json_string,
150                               EchoCanceller3Config* config,
151                               bool* parsing_successful) {
152   RTC_DCHECK(config);
153   RTC_DCHECK(parsing_successful);
154   EchoCanceller3Config& cfg = *config;
155   cfg = EchoCanceller3Config();
156   *parsing_successful = true;
157 
158   Json::Value root;
159   bool success = Json::Reader().parse(std::string(json_string), root);
160   if (!success) {
161     RTC_LOG(LS_ERROR) << "Incorrect JSON format: " << json_string;
162     *parsing_successful = false;
163     return;
164   }
165 
166   Json::Value aec3_root;
167   success = rtc::GetValueFromJsonObject(root, "aec3", &aec3_root);
168   if (!success) {
169     RTC_LOG(LS_ERROR) << "Missing AEC3 config field: " << json_string;
170     *parsing_successful = false;
171     return;
172   }
173 
174   Json::Value section;
175   if (rtc::GetValueFromJsonObject(aec3_root, "buffering", &section)) {
176     ReadParam(section, "excess_render_detection_interval_blocks",
177               &cfg.buffering.excess_render_detection_interval_blocks);
178     ReadParam(section, "max_allowed_excess_render_blocks",
179               &cfg.buffering.max_allowed_excess_render_blocks);
180   }
181 
182   if (rtc::GetValueFromJsonObject(aec3_root, "delay", &section)) {
183     ReadParam(section, "default_delay", &cfg.delay.default_delay);
184     ReadParam(section, "down_sampling_factor", &cfg.delay.down_sampling_factor);
185     ReadParam(section, "num_filters", &cfg.delay.num_filters);
186     ReadParam(section, "delay_headroom_samples",
187               &cfg.delay.delay_headroom_samples);
188     ReadParam(section, "hysteresis_limit_blocks",
189               &cfg.delay.hysteresis_limit_blocks);
190     ReadParam(section, "fixed_capture_delay_samples",
191               &cfg.delay.fixed_capture_delay_samples);
192     ReadParam(section, "delay_estimate_smoothing",
193               &cfg.delay.delay_estimate_smoothing);
194     ReadParam(section, "delay_candidate_detection_threshold",
195               &cfg.delay.delay_candidate_detection_threshold);
196 
197     Json::Value subsection;
198     if (rtc::GetValueFromJsonObject(section, "delay_selection_thresholds",
199                                     &subsection)) {
200       ReadParam(subsection, "initial",
201                 &cfg.delay.delay_selection_thresholds.initial);
202       ReadParam(subsection, "converged",
203                 &cfg.delay.delay_selection_thresholds.converged);
204     }
205 
206     ReadParam(section, "use_external_delay_estimator",
207               &cfg.delay.use_external_delay_estimator);
208     ReadParam(section, "log_warning_on_delay_changes",
209               &cfg.delay.log_warning_on_delay_changes);
210 
211     ReadParam(section, "render_alignment_mixing",
212               &cfg.delay.render_alignment_mixing);
213     ReadParam(section, "capture_alignment_mixing",
214               &cfg.delay.capture_alignment_mixing);
215   }
216 
217   if (rtc::GetValueFromJsonObject(aec3_root, "filter", &section)) {
218     ReadParam(section, "main", &cfg.filter.main);
219     ReadParam(section, "refined", &cfg.filter.refined);
220     ReadParam(section, "shadow", &cfg.filter.shadow);
221     ReadParam(section, "coarse", &cfg.filter.coarse);
222     ReadParam(section, "main_initial", &cfg.filter.main_initial);
223     ReadParam(section, "refined_initial", &cfg.filter.refined_initial);
224     ReadParam(section, "shadow_initial", &cfg.filter.shadow_initial);
225     ReadParam(section, "coarse_initial", &cfg.filter.coarse_initial);
226     ReadParam(section, "config_change_duration_blocks",
227               &cfg.filter.config_change_duration_blocks);
228     ReadParam(section, "initial_state_seconds",
229               &cfg.filter.initial_state_seconds);
230     ReadParam(section, "conservative_initial_phase",
231               &cfg.filter.conservative_initial_phase);
232     ReadParam(section, "enable_shadow_filter_output_usage",
233               &cfg.filter.enable_shadow_filter_output_usage);
234     ReadParam(section, "enable_coarse_filter_output_usage",
235               &cfg.filter.enable_coarse_filter_output_usage);
236     ReadParam(section, "use_linear_filter", &cfg.filter.use_linear_filter);
237     ReadParam(section, "export_linear_aec_output",
238               &cfg.filter.export_linear_aec_output);
239     ReadParam(section, "use_legacy_filter_naming",
240               &cfg.filter.use_legacy_filter_naming);
241   }
242 
243   if (rtc::GetValueFromJsonObject(aec3_root, "erle", &section)) {
244     ReadParam(section, "min", &cfg.erle.min);
245     ReadParam(section, "max_l", &cfg.erle.max_l);
246     ReadParam(section, "max_h", &cfg.erle.max_h);
247     ReadParam(section, "onset_detection", &cfg.erle.onset_detection);
248     ReadParam(section, "num_sections", &cfg.erle.num_sections);
249     ReadParam(section, "clamp_quality_estimate_to_zero",
250               &cfg.erle.clamp_quality_estimate_to_zero);
251     ReadParam(section, "clamp_quality_estimate_to_one",
252               &cfg.erle.clamp_quality_estimate_to_one);
253   }
254 
255   if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", &section)) {
256     ReadParam(section, "default_gain", &cfg.ep_strength.default_gain);
257     ReadParam(section, "default_len", &cfg.ep_strength.default_len);
258     ReadParam(section, "echo_can_saturate", &cfg.ep_strength.echo_can_saturate);
259     ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl);
260   }
261 
262   if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) {
263     ReadParam(section, "low_render_limit",
264               &cfg.echo_audibility.low_render_limit);
265     ReadParam(section, "normal_render_limit",
266               &cfg.echo_audibility.normal_render_limit);
267 
268     ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power);
269     ReadParam(section, "audibility_threshold_lf",
270               &cfg.echo_audibility.audibility_threshold_lf);
271     ReadParam(section, "audibility_threshold_mf",
272               &cfg.echo_audibility.audibility_threshold_mf);
273     ReadParam(section, "audibility_threshold_hf",
274               &cfg.echo_audibility.audibility_threshold_hf);
275     ReadParam(section, "use_stationarity_properties",
276               &cfg.echo_audibility.use_stationarity_properties);
277     ReadParam(section, "use_stationarity_properties_at_init",
278               &cfg.echo_audibility.use_stationarity_properties_at_init);
279   }
280 
281   if (rtc::GetValueFromJsonObject(aec3_root, "render_levels", &section)) {
282     ReadParam(section, "active_render_limit",
283               &cfg.render_levels.active_render_limit);
284     ReadParam(section, "poor_excitation_render_limit",
285               &cfg.render_levels.poor_excitation_render_limit);
286     ReadParam(section, "poor_excitation_render_limit_ds8",
287               &cfg.render_levels.poor_excitation_render_limit_ds8);
288     ReadParam(section, "render_power_gain_db",
289               &cfg.render_levels.render_power_gain_db);
290   }
291 
292   if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control",
293                                   &section)) {
294     ReadParam(section, "has_clock_drift",
295               &cfg.echo_removal_control.has_clock_drift);
296     ReadParam(section, "linear_and_stable_echo_path",
297               &cfg.echo_removal_control.linear_and_stable_echo_path);
298   }
299 
300   if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", &section)) {
301     Json::Value subsection;
302     ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
303     ReadParam(section, "min_noise_floor_power",
304               &cfg.echo_model.min_noise_floor_power);
305     ReadParam(section, "stationary_gate_slope",
306               &cfg.echo_model.stationary_gate_slope);
307     ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power);
308     ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope);
309     ReadParam(section, "render_pre_window_size",
310               &cfg.echo_model.render_pre_window_size);
311     ReadParam(section, "render_post_window_size",
312               &cfg.echo_model.render_post_window_size);
313   }
314 
315   if (rtc::GetValueFromJsonObject(aec3_root, "comfort_noise", &section)) {
316     ReadParam(section, "noise_floor_dbfs", &cfg.comfort_noise.noise_floor_dbfs);
317   }
318 
319   Json::Value subsection;
320   if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", &section)) {
321     ReadParam(section, "nearend_average_blocks",
322               &cfg.suppressor.nearend_average_blocks);
323 
324     if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
325       ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
326       ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
327       ReadParam(subsection, "max_inc_factor",
328                 &cfg.suppressor.normal_tuning.max_inc_factor);
329       ReadParam(subsection, "max_dec_factor_lf",
330                 &cfg.suppressor.normal_tuning.max_dec_factor_lf);
331     }
332 
333     if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
334       ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf);
335       ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf);
336       ReadParam(subsection, "max_inc_factor",
337                 &cfg.suppressor.nearend_tuning.max_inc_factor);
338       ReadParam(subsection, "max_dec_factor_lf",
339                 &cfg.suppressor.nearend_tuning.max_dec_factor_lf);
340     }
341 
342     if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection",
343                                     &subsection)) {
344       ReadParam(subsection, "enr_threshold",
345                 &cfg.suppressor.dominant_nearend_detection.enr_threshold);
346       ReadParam(subsection, "enr_exit_threshold",
347                 &cfg.suppressor.dominant_nearend_detection.enr_exit_threshold);
348       ReadParam(subsection, "snr_threshold",
349                 &cfg.suppressor.dominant_nearend_detection.snr_threshold);
350       ReadParam(subsection, "hold_duration",
351                 &cfg.suppressor.dominant_nearend_detection.hold_duration);
352       ReadParam(subsection, "trigger_threshold",
353                 &cfg.suppressor.dominant_nearend_detection.trigger_threshold);
354       ReadParam(
355           subsection, "use_during_initial_phase",
356           &cfg.suppressor.dominant_nearend_detection.use_during_initial_phase);
357     }
358 
359     if (rtc::GetValueFromJsonObject(section, "subband_nearend_detection",
360                                     &subsection)) {
361       ReadParam(
362           subsection, "nearend_average_blocks",
363           &cfg.suppressor.subband_nearend_detection.nearend_average_blocks);
364       ReadParam(subsection, "subband1",
365                 &cfg.suppressor.subband_nearend_detection.subband1);
366       ReadParam(subsection, "subband2",
367                 &cfg.suppressor.subband_nearend_detection.subband2);
368       ReadParam(subsection, "nearend_threshold",
369                 &cfg.suppressor.subband_nearend_detection.nearend_threshold);
370       ReadParam(subsection, "snr_threshold",
371                 &cfg.suppressor.subband_nearend_detection.snr_threshold);
372     }
373 
374     ReadParam(section, "use_subband_nearend_detection",
375               &cfg.suppressor.use_subband_nearend_detection);
376 
377     if (rtc::GetValueFromJsonObject(section, "high_bands_suppression",
378                                     &subsection)) {
379       ReadParam(subsection, "enr_threshold",
380                 &cfg.suppressor.high_bands_suppression.enr_threshold);
381       ReadParam(subsection, "max_gain_during_echo",
382                 &cfg.suppressor.high_bands_suppression.max_gain_during_echo);
383       ReadParam(subsection, "anti_howling_activation_threshold",
384                 &cfg.suppressor.high_bands_suppression
385                      .anti_howling_activation_threshold);
386       ReadParam(subsection, "anti_howling_gain",
387                 &cfg.suppressor.high_bands_suppression.anti_howling_gain);
388     }
389 
390     ReadParam(section, "floor_first_increase",
391               &cfg.suppressor.floor_first_increase);
392   }
393 }
394 
Aec3ConfigFromJsonString(absl::string_view json_string)395 EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) {
396   EchoCanceller3Config cfg;
397   bool not_used;
398   Aec3ConfigFromJsonString(json_string, &cfg, &not_used);
399   return cfg;
400 }
401 
Aec3ConfigToJsonString(const EchoCanceller3Config & config)402 std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) {
403   rtc::StringBuilder ost;
404   ost << "{";
405   ost << "\"aec3\": {";
406   ost << "\"buffering\": {";
407   ost << "\"excess_render_detection_interval_blocks\": "
408       << config.buffering.excess_render_detection_interval_blocks << ",";
409   ost << "\"max_allowed_excess_render_blocks\": "
410       << config.buffering.max_allowed_excess_render_blocks;
411   ost << "},";
412 
413   ost << "\"delay\": {";
414   ost << "\"default_delay\": " << config.delay.default_delay << ",";
415   ost << "\"down_sampling_factor\": " << config.delay.down_sampling_factor
416       << ",";
417   ost << "\"num_filters\": " << config.delay.num_filters << ",";
418   ost << "\"delay_headroom_samples\": " << config.delay.delay_headroom_samples
419       << ",";
420   ost << "\"hysteresis_limit_blocks\": " << config.delay.hysteresis_limit_blocks
421       << ",";
422   ost << "\"fixed_capture_delay_samples\": "
423       << config.delay.fixed_capture_delay_samples << ",";
424   ost << "\"delay_estimate_smoothing\": "
425       << config.delay.delay_estimate_smoothing << ",";
426   ost << "\"delay_candidate_detection_threshold\": "
427       << config.delay.delay_candidate_detection_threshold << ",";
428 
429   ost << "\"delay_selection_thresholds\": {";
430   ost << "\"initial\": " << config.delay.delay_selection_thresholds.initial
431       << ",";
432   ost << "\"converged\": " << config.delay.delay_selection_thresholds.converged;
433   ost << "},";
434 
435   ost << "\"use_external_delay_estimator\": "
436       << (config.delay.use_external_delay_estimator ? "true" : "false") << ",";
437   ost << "\"log_warning_on_delay_changes\": "
438       << (config.delay.log_warning_on_delay_changes ? "true" : "false") << ",";
439 
440   ost << "\"render_alignment_mixing\": {";
441   ost << "\"downmix\": "
442       << (config.delay.render_alignment_mixing.downmix ? "true" : "false")
443       << ",";
444   ost << "\"adaptive_selection\": "
445       << (config.delay.render_alignment_mixing.adaptive_selection ? "true"
446                                                                   : "false")
447       << ",";
448   ost << "\"activity_power_threshold\": "
449       << config.delay.render_alignment_mixing.activity_power_threshold << ",";
450   ost << "\"prefer_first_two_channels\": "
451       << (config.delay.render_alignment_mixing.prefer_first_two_channels
452               ? "true"
453               : "false");
454   ost << "},";
455 
456   ost << "\"capture_alignment_mixing\": {";
457   ost << "\"downmix\": "
458       << (config.delay.capture_alignment_mixing.downmix ? "true" : "false")
459       << ",";
460   ost << "\"adaptive_selection\": "
461       << (config.delay.capture_alignment_mixing.adaptive_selection ? "true"
462                                                                    : "false")
463       << ",";
464   ost << "\"activity_power_threshold\": "
465       << config.delay.capture_alignment_mixing.activity_power_threshold << ",";
466   ost << "\"prefer_first_two_channels\": "
467       << (config.delay.capture_alignment_mixing.prefer_first_two_channels
468               ? "true"
469               : "false");
470   ost << "}";
471   ost << "},";
472 
473   ost << "\"filter\": {";
474   ost << "\"main\": [";
475   ost << config.filter.main.length_blocks << ",";
476   ost << config.filter.main.leakage_converged << ",";
477   ost << config.filter.main.leakage_diverged << ",";
478   ost << config.filter.main.error_floor << ",";
479   ost << config.filter.main.error_ceil << ",";
480   ost << config.filter.main.noise_gate;
481   ost << "],";
482 
483   ost << "\"refined\": [";
484   ost << config.filter.refined.length_blocks << ",";
485   ost << config.filter.refined.leakage_converged << ",";
486   ost << config.filter.refined.leakage_diverged << ",";
487   ost << config.filter.refined.error_floor << ",";
488   ost << config.filter.refined.error_ceil << ",";
489   ost << config.filter.refined.noise_gate;
490   ost << "],";
491 
492   ost << "\"shadow\": [";
493   ost << config.filter.shadow.length_blocks << ",";
494   ost << config.filter.shadow.rate << ",";
495   ost << config.filter.shadow.noise_gate;
496   ost << "],";
497 
498   ost << "\"coarse\": [";
499   ost << config.filter.coarse.length_blocks << ",";
500   ost << config.filter.coarse.rate << ",";
501   ost << config.filter.coarse.noise_gate;
502   ost << "],";
503 
504   ost << "\"main_initial\": [";
505   ost << config.filter.main_initial.length_blocks << ",";
506   ost << config.filter.main_initial.leakage_converged << ",";
507   ost << config.filter.main_initial.leakage_diverged << ",";
508   ost << config.filter.main_initial.error_floor << ",";
509   ost << config.filter.main_initial.error_ceil << ",";
510   ost << config.filter.main_initial.noise_gate;
511   ost << "],";
512 
513   ost << "\"refined_initial\": [";
514   ost << config.filter.refined_initial.length_blocks << ",";
515   ost << config.filter.refined_initial.leakage_converged << ",";
516   ost << config.filter.refined_initial.leakage_diverged << ",";
517   ost << config.filter.refined_initial.error_floor << ",";
518   ost << config.filter.refined_initial.error_ceil << ",";
519   ost << config.filter.refined_initial.noise_gate;
520   ost << "],";
521 
522   ost << "\"shadow_initial\": [";
523   ost << config.filter.shadow_initial.length_blocks << ",";
524   ost << config.filter.shadow_initial.rate << ",";
525   ost << config.filter.shadow_initial.noise_gate;
526   ost << "],";
527 
528   ost << "\"coarse_initial\": [";
529   ost << config.filter.coarse_initial.length_blocks << ",";
530   ost << config.filter.coarse_initial.rate << ",";
531   ost << config.filter.coarse_initial.noise_gate;
532   ost << "],";
533 
534   ost << "\"config_change_duration_blocks\": "
535       << config.filter.config_change_duration_blocks << ",";
536   ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds
537       << ",";
538   ost << "\"conservative_initial_phase\": "
539       << (config.filter.conservative_initial_phase ? "true" : "false") << ",";
540   ost << "\"enable_shadow_filter_output_usage\": "
541       << (config.filter.enable_shadow_filter_output_usage ? "true" : "false")
542       << ",";
543   ost << "\"enable_coarse_filter_output_usage\": "
544       << (config.filter.enable_coarse_filter_output_usage ? "true" : "false")
545       << ",";
546   ost << "\"use_linear_filter\": "
547       << (config.filter.use_linear_filter ? "true" : "false") << ",";
548   ost << "\"export_linear_aec_output\": "
549       << (config.filter.export_linear_aec_output ? "true" : "false") << ",";
550   ost << "\"use_legacy_filter_naming\": "
551       << (config.filter.use_legacy_filter_naming ? "true" : "false");
552 
553   ost << "},";
554 
555   ost << "\"erle\": {";
556   ost << "\"min\": " << config.erle.min << ",";
557   ost << "\"max_l\": " << config.erle.max_l << ",";
558   ost << "\"max_h\": " << config.erle.max_h << ",";
559   ost << "\"onset_detection\": "
560       << (config.erle.onset_detection ? "true" : "false") << ",";
561   ost << "\"num_sections\": " << config.erle.num_sections << ",";
562   ost << "\"clamp_quality_estimate_to_zero\": "
563       << (config.erle.clamp_quality_estimate_to_zero ? "true" : "false") << ",";
564   ost << "\"clamp_quality_estimate_to_one\": "
565       << (config.erle.clamp_quality_estimate_to_one ? "true" : "false");
566   ost << "},";
567 
568   ost << "\"ep_strength\": {";
569   ost << "\"default_gain\": " << config.ep_strength.default_gain << ",";
570   ost << "\"default_len\": " << config.ep_strength.default_len << ",";
571   ost << "\"echo_can_saturate\": "
572       << (config.ep_strength.echo_can_saturate ? "true" : "false") << ",";
573   ost << "\"bounded_erl\": "
574       << (config.ep_strength.bounded_erl ? "true" : "false");
575 
576   ost << "},";
577 
578   ost << "\"echo_audibility\": {";
579   ost << "\"low_render_limit\": " << config.echo_audibility.low_render_limit
580       << ",";
581   ost << "\"normal_render_limit\": "
582       << config.echo_audibility.normal_render_limit << ",";
583   ost << "\"floor_power\": " << config.echo_audibility.floor_power << ",";
584   ost << "\"audibility_threshold_lf\": "
585       << config.echo_audibility.audibility_threshold_lf << ",";
586   ost << "\"audibility_threshold_mf\": "
587       << config.echo_audibility.audibility_threshold_mf << ",";
588   ost << "\"audibility_threshold_hf\": "
589       << config.echo_audibility.audibility_threshold_hf << ",";
590   ost << "\"use_stationarity_properties\": "
591       << (config.echo_audibility.use_stationarity_properties ? "true" : "false")
592       << ",";
593   ost << "\"use_stationarity_properties_at_init\": "
594       << (config.echo_audibility.use_stationarity_properties_at_init ? "true"
595                                                                      : "false");
596   ost << "},";
597 
598   ost << "\"render_levels\": {";
599   ost << "\"active_render_limit\": " << config.render_levels.active_render_limit
600       << ",";
601   ost << "\"poor_excitation_render_limit\": "
602       << config.render_levels.poor_excitation_render_limit << ",";
603   ost << "\"poor_excitation_render_limit_ds8\": "
604       << config.render_levels.poor_excitation_render_limit_ds8 << ",";
605   ost << "\"render_power_gain_db\": "
606       << config.render_levels.render_power_gain_db;
607   ost << "},";
608 
609   ost << "\"echo_removal_control\": {";
610   ost << "\"has_clock_drift\": "
611       << (config.echo_removal_control.has_clock_drift ? "true" : "false")
612       << ",";
613   ost << "\"linear_and_stable_echo_path\": "
614       << (config.echo_removal_control.linear_and_stable_echo_path ? "true"
615                                                                   : "false");
616 
617   ost << "},";
618 
619   ost << "\"echo_model\": {";
620   ost << "\"noise_floor_hold\": " << config.echo_model.noise_floor_hold << ",";
621   ost << "\"min_noise_floor_power\": "
622       << config.echo_model.min_noise_floor_power << ",";
623   ost << "\"stationary_gate_slope\": "
624       << config.echo_model.stationary_gate_slope << ",";
625   ost << "\"noise_gate_power\": " << config.echo_model.noise_gate_power << ",";
626   ost << "\"noise_gate_slope\": " << config.echo_model.noise_gate_slope << ",";
627   ost << "\"render_pre_window_size\": "
628       << config.echo_model.render_pre_window_size << ",";
629   ost << "\"render_post_window_size\": "
630       << config.echo_model.render_post_window_size;
631   ost << "},";
632 
633   ost << "\"comfort_noise\": {";
634   ost << "\"noise_floor_dbfs\": " << config.comfort_noise.noise_floor_dbfs;
635   ost << "},";
636 
637   ost << "\"suppressor\": {";
638   ost << "\"nearend_average_blocks\": "
639       << config.suppressor.nearend_average_blocks << ",";
640   ost << "\"normal_tuning\": {";
641   ost << "\"mask_lf\": [";
642   ost << config.suppressor.normal_tuning.mask_lf.enr_transparent << ",";
643   ost << config.suppressor.normal_tuning.mask_lf.enr_suppress << ",";
644   ost << config.suppressor.normal_tuning.mask_lf.emr_transparent;
645   ost << "],";
646   ost << "\"mask_hf\": [";
647   ost << config.suppressor.normal_tuning.mask_hf.enr_transparent << ",";
648   ost << config.suppressor.normal_tuning.mask_hf.enr_suppress << ",";
649   ost << config.suppressor.normal_tuning.mask_hf.emr_transparent;
650   ost << "],";
651   ost << "\"max_inc_factor\": "
652       << config.suppressor.normal_tuning.max_inc_factor << ",";
653   ost << "\"max_dec_factor_lf\": "
654       << config.suppressor.normal_tuning.max_dec_factor_lf;
655   ost << "},";
656   ost << "\"nearend_tuning\": {";
657   ost << "\"mask_lf\": [";
658   ost << config.suppressor.nearend_tuning.mask_lf.enr_transparent << ",";
659   ost << config.suppressor.nearend_tuning.mask_lf.enr_suppress << ",";
660   ost << config.suppressor.nearend_tuning.mask_lf.emr_transparent;
661   ost << "],";
662   ost << "\"mask_hf\": [";
663   ost << config.suppressor.nearend_tuning.mask_hf.enr_transparent << ",";
664   ost << config.suppressor.nearend_tuning.mask_hf.enr_suppress << ",";
665   ost << config.suppressor.nearend_tuning.mask_hf.emr_transparent;
666   ost << "],";
667   ost << "\"max_inc_factor\": "
668       << config.suppressor.nearend_tuning.max_inc_factor << ",";
669   ost << "\"max_dec_factor_lf\": "
670       << config.suppressor.nearend_tuning.max_dec_factor_lf;
671   ost << "},";
672   ost << "\"dominant_nearend_detection\": {";
673   ost << "\"enr_threshold\": "
674       << config.suppressor.dominant_nearend_detection.enr_threshold << ",";
675   ost << "\"enr_exit_threshold\": "
676       << config.suppressor.dominant_nearend_detection.enr_exit_threshold << ",";
677   ost << "\"snr_threshold\": "
678       << config.suppressor.dominant_nearend_detection.snr_threshold << ",";
679   ost << "\"hold_duration\": "
680       << config.suppressor.dominant_nearend_detection.hold_duration << ",";
681   ost << "\"trigger_threshold\": "
682       << config.suppressor.dominant_nearend_detection.trigger_threshold << ",";
683   ost << "\"use_during_initial_phase\": "
684       << config.suppressor.dominant_nearend_detection.use_during_initial_phase;
685   ost << "},";
686   ost << "\"subband_nearend_detection\": {";
687   ost << "\"nearend_average_blocks\": "
688       << config.suppressor.subband_nearend_detection.nearend_average_blocks
689       << ",";
690   ost << "\"subband1\": [";
691   ost << config.suppressor.subband_nearend_detection.subband1.low << ",";
692   ost << config.suppressor.subband_nearend_detection.subband1.high;
693   ost << "],";
694   ost << "\"subband2\": [";
695   ost << config.suppressor.subband_nearend_detection.subband2.low << ",";
696   ost << config.suppressor.subband_nearend_detection.subband2.high;
697   ost << "],";
698   ost << "\"nearend_threshold\": "
699       << config.suppressor.subband_nearend_detection.nearend_threshold << ",";
700   ost << "\"snr_threshold\": "
701       << config.suppressor.subband_nearend_detection.snr_threshold;
702   ost << "},";
703   ost << "\"use_subband_nearend_detection\": "
704       << config.suppressor.use_subband_nearend_detection << ",";
705   ost << "\"high_bands_suppression\": {";
706   ost << "\"enr_threshold\": "
707       << config.suppressor.high_bands_suppression.enr_threshold << ",";
708   ost << "\"max_gain_during_echo\": "
709       << config.suppressor.high_bands_suppression.max_gain_during_echo << ",";
710   ost << "\"anti_howling_activation_threshold\": "
711       << config.suppressor.high_bands_suppression
712              .anti_howling_activation_threshold
713       << ",";
714   ost << "\"anti_howling_gain\": "
715       << config.suppressor.high_bands_suppression.anti_howling_gain;
716   ost << "},";
717   ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase;
718   ost << "}";
719   ost << "}";
720   ost << "}";
721 
722   return ost.Release();
723 }
724 }  // namespace webrtc
725