• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, "refined", &cfg.filter.refined);
219     ReadParam(section, "coarse", &cfg.filter.coarse);
220     ReadParam(section, "refined_initial", &cfg.filter.refined_initial);
221     ReadParam(section, "coarse_initial", &cfg.filter.coarse_initial);
222     ReadParam(section, "config_change_duration_blocks",
223               &cfg.filter.config_change_duration_blocks);
224     ReadParam(section, "initial_state_seconds",
225               &cfg.filter.initial_state_seconds);
226     ReadParam(section, "conservative_initial_phase",
227               &cfg.filter.conservative_initial_phase);
228     ReadParam(section, "enable_coarse_filter_output_usage",
229               &cfg.filter.enable_coarse_filter_output_usage);
230     ReadParam(section, "use_linear_filter", &cfg.filter.use_linear_filter);
231     ReadParam(section, "export_linear_aec_output",
232               &cfg.filter.export_linear_aec_output);
233   }
234 
235   if (rtc::GetValueFromJsonObject(aec3_root, "erle", &section)) {
236     ReadParam(section, "min", &cfg.erle.min);
237     ReadParam(section, "max_l", &cfg.erle.max_l);
238     ReadParam(section, "max_h", &cfg.erle.max_h);
239     ReadParam(section, "onset_detection", &cfg.erle.onset_detection);
240     ReadParam(section, "num_sections", &cfg.erle.num_sections);
241     ReadParam(section, "clamp_quality_estimate_to_zero",
242               &cfg.erle.clamp_quality_estimate_to_zero);
243     ReadParam(section, "clamp_quality_estimate_to_one",
244               &cfg.erle.clamp_quality_estimate_to_one);
245   }
246 
247   if (rtc::GetValueFromJsonObject(aec3_root, "ep_strength", &section)) {
248     ReadParam(section, "default_gain", &cfg.ep_strength.default_gain);
249     ReadParam(section, "default_len", &cfg.ep_strength.default_len);
250     ReadParam(section, "echo_can_saturate", &cfg.ep_strength.echo_can_saturate);
251     ReadParam(section, "bounded_erl", &cfg.ep_strength.bounded_erl);
252   }
253 
254   if (rtc::GetValueFromJsonObject(aec3_root, "echo_audibility", &section)) {
255     ReadParam(section, "low_render_limit",
256               &cfg.echo_audibility.low_render_limit);
257     ReadParam(section, "normal_render_limit",
258               &cfg.echo_audibility.normal_render_limit);
259 
260     ReadParam(section, "floor_power", &cfg.echo_audibility.floor_power);
261     ReadParam(section, "audibility_threshold_lf",
262               &cfg.echo_audibility.audibility_threshold_lf);
263     ReadParam(section, "audibility_threshold_mf",
264               &cfg.echo_audibility.audibility_threshold_mf);
265     ReadParam(section, "audibility_threshold_hf",
266               &cfg.echo_audibility.audibility_threshold_hf);
267     ReadParam(section, "use_stationarity_properties",
268               &cfg.echo_audibility.use_stationarity_properties);
269     ReadParam(section, "use_stationarity_properties_at_init",
270               &cfg.echo_audibility.use_stationarity_properties_at_init);
271   }
272 
273   if (rtc::GetValueFromJsonObject(aec3_root, "render_levels", &section)) {
274     ReadParam(section, "active_render_limit",
275               &cfg.render_levels.active_render_limit);
276     ReadParam(section, "poor_excitation_render_limit",
277               &cfg.render_levels.poor_excitation_render_limit);
278     ReadParam(section, "poor_excitation_render_limit_ds8",
279               &cfg.render_levels.poor_excitation_render_limit_ds8);
280     ReadParam(section, "render_power_gain_db",
281               &cfg.render_levels.render_power_gain_db);
282   }
283 
284   if (rtc::GetValueFromJsonObject(aec3_root, "echo_removal_control",
285                                   &section)) {
286     ReadParam(section, "has_clock_drift",
287               &cfg.echo_removal_control.has_clock_drift);
288     ReadParam(section, "linear_and_stable_echo_path",
289               &cfg.echo_removal_control.linear_and_stable_echo_path);
290   }
291 
292   if (rtc::GetValueFromJsonObject(aec3_root, "echo_model", &section)) {
293     Json::Value subsection;
294     ReadParam(section, "noise_floor_hold", &cfg.echo_model.noise_floor_hold);
295     ReadParam(section, "min_noise_floor_power",
296               &cfg.echo_model.min_noise_floor_power);
297     ReadParam(section, "stationary_gate_slope",
298               &cfg.echo_model.stationary_gate_slope);
299     ReadParam(section, "noise_gate_power", &cfg.echo_model.noise_gate_power);
300     ReadParam(section, "noise_gate_slope", &cfg.echo_model.noise_gate_slope);
301     ReadParam(section, "render_pre_window_size",
302               &cfg.echo_model.render_pre_window_size);
303     ReadParam(section, "render_post_window_size",
304               &cfg.echo_model.render_post_window_size);
305   }
306 
307   if (rtc::GetValueFromJsonObject(aec3_root, "comfort_noise", &section)) {
308     ReadParam(section, "noise_floor_dbfs", &cfg.comfort_noise.noise_floor_dbfs);
309   }
310 
311   Json::Value subsection;
312   if (rtc::GetValueFromJsonObject(aec3_root, "suppressor", &section)) {
313     ReadParam(section, "nearend_average_blocks",
314               &cfg.suppressor.nearend_average_blocks);
315 
316     if (rtc::GetValueFromJsonObject(section, "normal_tuning", &subsection)) {
317       ReadParam(subsection, "mask_lf", &cfg.suppressor.normal_tuning.mask_lf);
318       ReadParam(subsection, "mask_hf", &cfg.suppressor.normal_tuning.mask_hf);
319       ReadParam(subsection, "max_inc_factor",
320                 &cfg.suppressor.normal_tuning.max_inc_factor);
321       ReadParam(subsection, "max_dec_factor_lf",
322                 &cfg.suppressor.normal_tuning.max_dec_factor_lf);
323     }
324 
325     if (rtc::GetValueFromJsonObject(section, "nearend_tuning", &subsection)) {
326       ReadParam(subsection, "mask_lf", &cfg.suppressor.nearend_tuning.mask_lf);
327       ReadParam(subsection, "mask_hf", &cfg.suppressor.nearend_tuning.mask_hf);
328       ReadParam(subsection, "max_inc_factor",
329                 &cfg.suppressor.nearend_tuning.max_inc_factor);
330       ReadParam(subsection, "max_dec_factor_lf",
331                 &cfg.suppressor.nearend_tuning.max_dec_factor_lf);
332     }
333 
334     if (rtc::GetValueFromJsonObject(section, "dominant_nearend_detection",
335                                     &subsection)) {
336       ReadParam(subsection, "enr_threshold",
337                 &cfg.suppressor.dominant_nearend_detection.enr_threshold);
338       ReadParam(subsection, "enr_exit_threshold",
339                 &cfg.suppressor.dominant_nearend_detection.enr_exit_threshold);
340       ReadParam(subsection, "snr_threshold",
341                 &cfg.suppressor.dominant_nearend_detection.snr_threshold);
342       ReadParam(subsection, "hold_duration",
343                 &cfg.suppressor.dominant_nearend_detection.hold_duration);
344       ReadParam(subsection, "trigger_threshold",
345                 &cfg.suppressor.dominant_nearend_detection.trigger_threshold);
346       ReadParam(
347           subsection, "use_during_initial_phase",
348           &cfg.suppressor.dominant_nearend_detection.use_during_initial_phase);
349     }
350 
351     if (rtc::GetValueFromJsonObject(section, "subband_nearend_detection",
352                                     &subsection)) {
353       ReadParam(
354           subsection, "nearend_average_blocks",
355           &cfg.suppressor.subband_nearend_detection.nearend_average_blocks);
356       ReadParam(subsection, "subband1",
357                 &cfg.suppressor.subband_nearend_detection.subband1);
358       ReadParam(subsection, "subband2",
359                 &cfg.suppressor.subband_nearend_detection.subband2);
360       ReadParam(subsection, "nearend_threshold",
361                 &cfg.suppressor.subband_nearend_detection.nearend_threshold);
362       ReadParam(subsection, "snr_threshold",
363                 &cfg.suppressor.subband_nearend_detection.snr_threshold);
364     }
365 
366     ReadParam(section, "use_subband_nearend_detection",
367               &cfg.suppressor.use_subband_nearend_detection);
368 
369     if (rtc::GetValueFromJsonObject(section, "high_bands_suppression",
370                                     &subsection)) {
371       ReadParam(subsection, "enr_threshold",
372                 &cfg.suppressor.high_bands_suppression.enr_threshold);
373       ReadParam(subsection, "max_gain_during_echo",
374                 &cfg.suppressor.high_bands_suppression.max_gain_during_echo);
375       ReadParam(subsection, "anti_howling_activation_threshold",
376                 &cfg.suppressor.high_bands_suppression
377                      .anti_howling_activation_threshold);
378       ReadParam(subsection, "anti_howling_gain",
379                 &cfg.suppressor.high_bands_suppression.anti_howling_gain);
380     }
381 
382     ReadParam(section, "floor_first_increase",
383               &cfg.suppressor.floor_first_increase);
384   }
385 }
386 
Aec3ConfigFromJsonString(absl::string_view json_string)387 EchoCanceller3Config Aec3ConfigFromJsonString(absl::string_view json_string) {
388   EchoCanceller3Config cfg;
389   bool not_used;
390   Aec3ConfigFromJsonString(json_string, &cfg, &not_used);
391   return cfg;
392 }
393 
Aec3ConfigToJsonString(const EchoCanceller3Config & config)394 std::string Aec3ConfigToJsonString(const EchoCanceller3Config& config) {
395   rtc::StringBuilder ost;
396   ost << "{";
397   ost << "\"aec3\": {";
398   ost << "\"buffering\": {";
399   ost << "\"excess_render_detection_interval_blocks\": "
400       << config.buffering.excess_render_detection_interval_blocks << ",";
401   ost << "\"max_allowed_excess_render_blocks\": "
402       << config.buffering.max_allowed_excess_render_blocks;
403   ost << "},";
404 
405   ost << "\"delay\": {";
406   ost << "\"default_delay\": " << config.delay.default_delay << ",";
407   ost << "\"down_sampling_factor\": " << config.delay.down_sampling_factor
408       << ",";
409   ost << "\"num_filters\": " << config.delay.num_filters << ",";
410   ost << "\"delay_headroom_samples\": " << config.delay.delay_headroom_samples
411       << ",";
412   ost << "\"hysteresis_limit_blocks\": " << config.delay.hysteresis_limit_blocks
413       << ",";
414   ost << "\"fixed_capture_delay_samples\": "
415       << config.delay.fixed_capture_delay_samples << ",";
416   ost << "\"delay_estimate_smoothing\": "
417       << config.delay.delay_estimate_smoothing << ",";
418   ost << "\"delay_candidate_detection_threshold\": "
419       << config.delay.delay_candidate_detection_threshold << ",";
420 
421   ost << "\"delay_selection_thresholds\": {";
422   ost << "\"initial\": " << config.delay.delay_selection_thresholds.initial
423       << ",";
424   ost << "\"converged\": " << config.delay.delay_selection_thresholds.converged;
425   ost << "},";
426 
427   ost << "\"use_external_delay_estimator\": "
428       << (config.delay.use_external_delay_estimator ? "true" : "false") << ",";
429   ost << "\"log_warning_on_delay_changes\": "
430       << (config.delay.log_warning_on_delay_changes ? "true" : "false") << ",";
431 
432   ost << "\"render_alignment_mixing\": {";
433   ost << "\"downmix\": "
434       << (config.delay.render_alignment_mixing.downmix ? "true" : "false")
435       << ",";
436   ost << "\"adaptive_selection\": "
437       << (config.delay.render_alignment_mixing.adaptive_selection ? "true"
438                                                                   : "false")
439       << ",";
440   ost << "\"activity_power_threshold\": "
441       << config.delay.render_alignment_mixing.activity_power_threshold << ",";
442   ost << "\"prefer_first_two_channels\": "
443       << (config.delay.render_alignment_mixing.prefer_first_two_channels
444               ? "true"
445               : "false");
446   ost << "},";
447 
448   ost << "\"capture_alignment_mixing\": {";
449   ost << "\"downmix\": "
450       << (config.delay.capture_alignment_mixing.downmix ? "true" : "false")
451       << ",";
452   ost << "\"adaptive_selection\": "
453       << (config.delay.capture_alignment_mixing.adaptive_selection ? "true"
454                                                                    : "false")
455       << ",";
456   ost << "\"activity_power_threshold\": "
457       << config.delay.capture_alignment_mixing.activity_power_threshold << ",";
458   ost << "\"prefer_first_two_channels\": "
459       << (config.delay.capture_alignment_mixing.prefer_first_two_channels
460               ? "true"
461               : "false");
462   ost << "}";
463   ost << "},";
464 
465   ost << "\"filter\": {";
466 
467   ost << "\"refined\": [";
468   ost << config.filter.refined.length_blocks << ",";
469   ost << config.filter.refined.leakage_converged << ",";
470   ost << config.filter.refined.leakage_diverged << ",";
471   ost << config.filter.refined.error_floor << ",";
472   ost << config.filter.refined.error_ceil << ",";
473   ost << config.filter.refined.noise_gate;
474   ost << "],";
475 
476   ost << "\"coarse\": [";
477   ost << config.filter.coarse.length_blocks << ",";
478   ost << config.filter.coarse.rate << ",";
479   ost << config.filter.coarse.noise_gate;
480   ost << "],";
481 
482   ost << "\"refined_initial\": [";
483   ost << config.filter.refined_initial.length_blocks << ",";
484   ost << config.filter.refined_initial.leakage_converged << ",";
485   ost << config.filter.refined_initial.leakage_diverged << ",";
486   ost << config.filter.refined_initial.error_floor << ",";
487   ost << config.filter.refined_initial.error_ceil << ",";
488   ost << config.filter.refined_initial.noise_gate;
489   ost << "],";
490 
491   ost << "\"coarse_initial\": [";
492   ost << config.filter.coarse_initial.length_blocks << ",";
493   ost << config.filter.coarse_initial.rate << ",";
494   ost << config.filter.coarse_initial.noise_gate;
495   ost << "],";
496 
497   ost << "\"config_change_duration_blocks\": "
498       << config.filter.config_change_duration_blocks << ",";
499   ost << "\"initial_state_seconds\": " << config.filter.initial_state_seconds
500       << ",";
501   ost << "\"conservative_initial_phase\": "
502       << (config.filter.conservative_initial_phase ? "true" : "false") << ",";
503   ost << "\"enable_coarse_filter_output_usage\": "
504       << (config.filter.enable_coarse_filter_output_usage ? "true" : "false")
505       << ",";
506   ost << "\"use_linear_filter\": "
507       << (config.filter.use_linear_filter ? "true" : "false") << ",";
508   ost << "\"export_linear_aec_output\": "
509       << (config.filter.export_linear_aec_output ? "true" : "false");
510 
511   ost << "},";
512 
513   ost << "\"erle\": {";
514   ost << "\"min\": " << config.erle.min << ",";
515   ost << "\"max_l\": " << config.erle.max_l << ",";
516   ost << "\"max_h\": " << config.erle.max_h << ",";
517   ost << "\"onset_detection\": "
518       << (config.erle.onset_detection ? "true" : "false") << ",";
519   ost << "\"num_sections\": " << config.erle.num_sections << ",";
520   ost << "\"clamp_quality_estimate_to_zero\": "
521       << (config.erle.clamp_quality_estimate_to_zero ? "true" : "false") << ",";
522   ost << "\"clamp_quality_estimate_to_one\": "
523       << (config.erle.clamp_quality_estimate_to_one ? "true" : "false");
524   ost << "},";
525 
526   ost << "\"ep_strength\": {";
527   ost << "\"default_gain\": " << config.ep_strength.default_gain << ",";
528   ost << "\"default_len\": " << config.ep_strength.default_len << ",";
529   ost << "\"echo_can_saturate\": "
530       << (config.ep_strength.echo_can_saturate ? "true" : "false") << ",";
531   ost << "\"bounded_erl\": "
532       << (config.ep_strength.bounded_erl ? "true" : "false");
533 
534   ost << "},";
535 
536   ost << "\"echo_audibility\": {";
537   ost << "\"low_render_limit\": " << config.echo_audibility.low_render_limit
538       << ",";
539   ost << "\"normal_render_limit\": "
540       << config.echo_audibility.normal_render_limit << ",";
541   ost << "\"floor_power\": " << config.echo_audibility.floor_power << ",";
542   ost << "\"audibility_threshold_lf\": "
543       << config.echo_audibility.audibility_threshold_lf << ",";
544   ost << "\"audibility_threshold_mf\": "
545       << config.echo_audibility.audibility_threshold_mf << ",";
546   ost << "\"audibility_threshold_hf\": "
547       << config.echo_audibility.audibility_threshold_hf << ",";
548   ost << "\"use_stationarity_properties\": "
549       << (config.echo_audibility.use_stationarity_properties ? "true" : "false")
550       << ",";
551   ost << "\"use_stationarity_properties_at_init\": "
552       << (config.echo_audibility.use_stationarity_properties_at_init ? "true"
553                                                                      : "false");
554   ost << "},";
555 
556   ost << "\"render_levels\": {";
557   ost << "\"active_render_limit\": " << config.render_levels.active_render_limit
558       << ",";
559   ost << "\"poor_excitation_render_limit\": "
560       << config.render_levels.poor_excitation_render_limit << ",";
561   ost << "\"poor_excitation_render_limit_ds8\": "
562       << config.render_levels.poor_excitation_render_limit_ds8 << ",";
563   ost << "\"render_power_gain_db\": "
564       << config.render_levels.render_power_gain_db;
565   ost << "},";
566 
567   ost << "\"echo_removal_control\": {";
568   ost << "\"has_clock_drift\": "
569       << (config.echo_removal_control.has_clock_drift ? "true" : "false")
570       << ",";
571   ost << "\"linear_and_stable_echo_path\": "
572       << (config.echo_removal_control.linear_and_stable_echo_path ? "true"
573                                                                   : "false");
574 
575   ost << "},";
576 
577   ost << "\"echo_model\": {";
578   ost << "\"noise_floor_hold\": " << config.echo_model.noise_floor_hold << ",";
579   ost << "\"min_noise_floor_power\": "
580       << config.echo_model.min_noise_floor_power << ",";
581   ost << "\"stationary_gate_slope\": "
582       << config.echo_model.stationary_gate_slope << ",";
583   ost << "\"noise_gate_power\": " << config.echo_model.noise_gate_power << ",";
584   ost << "\"noise_gate_slope\": " << config.echo_model.noise_gate_slope << ",";
585   ost << "\"render_pre_window_size\": "
586       << config.echo_model.render_pre_window_size << ",";
587   ost << "\"render_post_window_size\": "
588       << config.echo_model.render_post_window_size;
589   ost << "},";
590 
591   ost << "\"comfort_noise\": {";
592   ost << "\"noise_floor_dbfs\": " << config.comfort_noise.noise_floor_dbfs;
593   ost << "},";
594 
595   ost << "\"suppressor\": {";
596   ost << "\"nearend_average_blocks\": "
597       << config.suppressor.nearend_average_blocks << ",";
598   ost << "\"normal_tuning\": {";
599   ost << "\"mask_lf\": [";
600   ost << config.suppressor.normal_tuning.mask_lf.enr_transparent << ",";
601   ost << config.suppressor.normal_tuning.mask_lf.enr_suppress << ",";
602   ost << config.suppressor.normal_tuning.mask_lf.emr_transparent;
603   ost << "],";
604   ost << "\"mask_hf\": [";
605   ost << config.suppressor.normal_tuning.mask_hf.enr_transparent << ",";
606   ost << config.suppressor.normal_tuning.mask_hf.enr_suppress << ",";
607   ost << config.suppressor.normal_tuning.mask_hf.emr_transparent;
608   ost << "],";
609   ost << "\"max_inc_factor\": "
610       << config.suppressor.normal_tuning.max_inc_factor << ",";
611   ost << "\"max_dec_factor_lf\": "
612       << config.suppressor.normal_tuning.max_dec_factor_lf;
613   ost << "},";
614   ost << "\"nearend_tuning\": {";
615   ost << "\"mask_lf\": [";
616   ost << config.suppressor.nearend_tuning.mask_lf.enr_transparent << ",";
617   ost << config.suppressor.nearend_tuning.mask_lf.enr_suppress << ",";
618   ost << config.suppressor.nearend_tuning.mask_lf.emr_transparent;
619   ost << "],";
620   ost << "\"mask_hf\": [";
621   ost << config.suppressor.nearend_tuning.mask_hf.enr_transparent << ",";
622   ost << config.suppressor.nearend_tuning.mask_hf.enr_suppress << ",";
623   ost << config.suppressor.nearend_tuning.mask_hf.emr_transparent;
624   ost << "],";
625   ost << "\"max_inc_factor\": "
626       << config.suppressor.nearend_tuning.max_inc_factor << ",";
627   ost << "\"max_dec_factor_lf\": "
628       << config.suppressor.nearend_tuning.max_dec_factor_lf;
629   ost << "},";
630   ost << "\"dominant_nearend_detection\": {";
631   ost << "\"enr_threshold\": "
632       << config.suppressor.dominant_nearend_detection.enr_threshold << ",";
633   ost << "\"enr_exit_threshold\": "
634       << config.suppressor.dominant_nearend_detection.enr_exit_threshold << ",";
635   ost << "\"snr_threshold\": "
636       << config.suppressor.dominant_nearend_detection.snr_threshold << ",";
637   ost << "\"hold_duration\": "
638       << config.suppressor.dominant_nearend_detection.hold_duration << ",";
639   ost << "\"trigger_threshold\": "
640       << config.suppressor.dominant_nearend_detection.trigger_threshold << ",";
641   ost << "\"use_during_initial_phase\": "
642       << config.suppressor.dominant_nearend_detection.use_during_initial_phase;
643   ost << "},";
644   ost << "\"subband_nearend_detection\": {";
645   ost << "\"nearend_average_blocks\": "
646       << config.suppressor.subband_nearend_detection.nearend_average_blocks
647       << ",";
648   ost << "\"subband1\": [";
649   ost << config.suppressor.subband_nearend_detection.subband1.low << ",";
650   ost << config.suppressor.subband_nearend_detection.subband1.high;
651   ost << "],";
652   ost << "\"subband2\": [";
653   ost << config.suppressor.subband_nearend_detection.subband2.low << ",";
654   ost << config.suppressor.subband_nearend_detection.subband2.high;
655   ost << "],";
656   ost << "\"nearend_threshold\": "
657       << config.suppressor.subband_nearend_detection.nearend_threshold << ",";
658   ost << "\"snr_threshold\": "
659       << config.suppressor.subband_nearend_detection.snr_threshold;
660   ost << "},";
661   ost << "\"use_subband_nearend_detection\": "
662       << config.suppressor.use_subband_nearend_detection << ",";
663   ost << "\"high_bands_suppression\": {";
664   ost << "\"enr_threshold\": "
665       << config.suppressor.high_bands_suppression.enr_threshold << ",";
666   ost << "\"max_gain_during_echo\": "
667       << config.suppressor.high_bands_suppression.max_gain_during_echo << ",";
668   ost << "\"anti_howling_activation_threshold\": "
669       << config.suppressor.high_bands_suppression
670              .anti_howling_activation_threshold
671       << ",";
672   ost << "\"anti_howling_gain\": "
673       << config.suppressor.high_bands_suppression.anti_howling_gain;
674   ost << "},";
675   ost << "\"floor_first_increase\": " << config.suppressor.floor_first_increase;
676   ost << "}";
677   ost << "}";
678   ost << "}";
679 
680   return ost.Release();
681 }
682 }  // namespace webrtc
683