client: Do not leak buffer tree node on exit.
[paraslash.git] / audiod.c
index 8d8c46b..6e5efd6 100644 (file)
--- 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);
@@ -806,16 +812,10 @@ static int parse_receiver_args(void)
        struct audio_format_info *a;
 
        for (i = conf.receiver_given - 1; i >= 0; i--) {
-               char *arg = conf.receiver_arg[i];
-               char *recv_arg = strchr(arg, ':');
-               int af_mask, j;
+               char *arg;
+               int j, af_mask;
 
-               ret = -E_MISSING_COLON;
-               if (!recv_arg)
-                       goto out;
-               *recv_arg = '\0';
-               recv_arg++;
-               ret = get_matching_audio_format_nums(arg);
+               ret = parse_stream_command(conf.receiver_arg[i], &arg);
                if (ret < 0)
                        goto out;
                af_mask = ret;
@@ -831,7 +831,7 @@ static int parse_receiver_args(void)
                         */
                        if (a->receiver_conf)
                                a->receiver->free_config(a->receiver_conf);
-                       a->receiver_conf = check_receiver_arg(recv_arg, &receiver_num);
+                       a->receiver_conf = check_receiver_arg(arg, &receiver_num);
                        ret = -E_RECV_SYNTAX;
                        if (!a->receiver_conf)
                                goto out;
@@ -875,8 +875,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 +909,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:
@@ -1055,7 +1048,6 @@ static void close_stat_pipe(void)
 {
        if (!stat_task->ct)
                return;
-       btr_free_node(stat_task->ct->btrn);
        client_close(stat_task->ct);
        stat_task->ct = NULL;
        clear_and_dump_items();