From c51443d1b33680e6eb6bf0bf0e4f639b30219c5f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 19 Apr 2011 21:34:24 +0200 Subject: [PATCH] audiod: Allow regular expressions in filter config. --- audiod.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/audiod.c b/audiod.c index 8d8c46b0..ff3ba8c2 100644 --- a/audiod.c +++ b/audiod.c @@ -751,11 +751,17 @@ static int add_filter(int format, char *cmdline) { struct audio_format_info *a = &afi[format]; int filter_num, nf = a->num_filters; + void *cfg; - filter_num = check_filter_arg(cmdline, &a->filter_conf[nf]); + filter_num = check_filter_arg(cmdline, &cfg); if (filter_num < 0) return filter_num; + a->filter_conf = para_realloc(a->filter_conf, + (nf + 1) * sizeof(void *)); + a->filter_nums = para_realloc(a->filter_nums, + (nf + 1) * sizeof(unsigned)); a->filter_nums[nf] = filter_num; + a->filter_conf[nf] = cfg; a->num_filters++; PARA_INFO_LOG("%s filter %d: %s\n", audio_formats[format], nf, filters[filter_num].name); @@ -875,8 +881,8 @@ static int init_default_filters(void) if (a->num_filters) continue; /* no default -- nothing to to */ /* - * If udp is used to receive this audiod format, add fecdec as - * the first filter. + * udp and dccp streams are fec-encoded, so add fecdec as the + * first filter. */ if (strcmp(afi[i].receiver->name, "udp") == 0 || strcmp(afi[i].receiver->name, "dccp") == 0) { @@ -909,30 +915,23 @@ out: static int parse_filter_args(void) { - int i, ret, nf; + int i, j, ret, af_mask; - nf = PARA_MAX(2U, conf.filter_given); - PARA_INFO_LOG("maximal number of filters: %d\n", nf); - FOR_EACH_AUDIO_FORMAT(i) { - afi[i].filter_conf = para_malloc(nf * sizeof(void *)); - afi[i].filter_nums = para_malloc(nf * sizeof(unsigned)); - } if (!conf.no_default_filters_given) return init_default_filters(); for (i = 0; i < conf.filter_given; i++) { - char *arg = conf.filter_arg[i]; - char *filter_name = strchr(arg, ':'); - ret = -E_MISSING_COLON; - if (!filter_name) - goto out; - *filter_name = '\0'; - filter_name++; - ret = get_audio_format_num(arg); - if (ret < 0) - goto out; - ret = add_filter(ret, filter_name); + char *arg; + ret = parse_stream_command(conf.filter_arg[i], &arg); if (ret < 0) goto out; + af_mask = ret; + FOR_EACH_AUDIO_FORMAT(j) { + if ((af_mask & (1 << j)) == 0) /* no match */ + continue; + ret = add_filter(j, arg); + if (ret < 0) + goto out; + } } ret = init_default_filters(); /* use default values for the rest */ out: -- 2.39.5