From 53fac14e41447dcd12839747e74ca044b4f606b2 Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Sun, 21 Jan 2024 11:40:19 -0500 Subject: [PATCH] app_confbridge: Don't emit warnings on valid configurations. The numeric bridge profile options `internal_sample_rate` and `maximum_sample_rate` are documented to accept the special values `auto` and `none`, respectively. While these values currently work, they also emit warnings when used which could be confusing for users. In passing, also ensure that we only accept the documented range of sample rate values between 8000 and 192000. Fixes #546 --- apps/confbridge/conf_config_parser.c | 29 +++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c index aceb3563fe..6c3582edf3 100644 --- a/apps/confbridge/conf_config_parser.c +++ b/apps/confbridge/conf_config_parser.c @@ -2220,6 +2220,30 @@ static int user_template_handler(const struct aco_option *opt, struct ast_variab return conf_find_user_profile(NULL, var->value, u_profile) ? 0 : -1; } +static int sample_rate_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) +{ + struct bridge_profile *b_profile = obj; + unsigned int *slot; + + if (!strcasecmp(var->name, "internal_sample_rate")) { + slot = &b_profile->internal_sample_rate; + if (!strcasecmp(var->value, "auto")) { + *slot = 0; + return 0; + } + } else if (!strcasecmp(var->name, "maximum_sample_rate")) { + slot = &b_profile->maximum_sample_rate; + if (!strcasecmp(var->value, "none")) { + *slot = 0; + return 0; + } + } else { + return -1; + } + + return ast_parse_arg(var->value, PARSE_UINT32 | PARSE_IN_RANGE, slot, 8000, 192000); +} + static int bridge_template_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) { struct bridge_profile *b_profile = obj; @@ -2437,10 +2461,9 @@ int conf_load_config(void) /* Bridge options */ aco_option_register(&cfg_info, "type", ACO_EXACT, bridge_types, NULL, OPT_NOOP_T, 0, 0); aco_option_register(&cfg_info, "jitterbuffer", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), USER_OPT_JITTERBUFFER); - /* "auto" will fail to parse as a uint, but we use PARSE_DEFAULT to set the value to 0 in that case, which is the value that auto resolves to */ - aco_option_register(&cfg_info, "internal_sample_rate", ACO_EXACT, bridge_types, "0", OPT_UINT_T, PARSE_DEFAULT, FLDSET(struct bridge_profile, internal_sample_rate), 0); + aco_option_register_custom(&cfg_info, "internal_sample_rate", ACO_EXACT, bridge_types, "auto", sample_rate_handler, 0); aco_option_register(&cfg_info, "binaural_active", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_BINAURAL_ACTIVE); - aco_option_register(&cfg_info, "maximum_sample_rate", ACO_EXACT, bridge_types, "0", OPT_UINT_T, PARSE_DEFAULT, FLDSET(struct bridge_profile, maximum_sample_rate), 0); + aco_option_register_custom(&cfg_info, "maximum_sample_rate", ACO_EXACT, bridge_types, "none", sample_rate_handler, 0); aco_option_register_custom(&cfg_info, "mixing_interval", ACO_EXACT, bridge_types, "20", mix_interval_handler, 0); aco_option_register(&cfg_info, "record_conference", ACO_EXACT, bridge_types, "no", OPT_BOOLFLAG_T, 1, FLDSET(struct bridge_profile, flags), BRIDGE_OPT_RECORD_CONFERENCE); aco_option_register_custom(&cfg_info, "video_mode", ACO_EXACT, bridge_types, NULL, video_mode_handler, 0);