From dbed4189f2731469321f9df5b02d41774adb02b7 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 19 Apr 2011 20:58:11 +0200 Subject: [PATCH] audiod: Allow regular expressions in writer config. --- audiod.c | 61 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/audiod.c b/audiod.c index 1f1f1aa6..8d8c46b0 100644 --- a/audiod.c +++ b/audiod.c @@ -732,19 +732,19 @@ static int update_item(int itemnum, char *buf) static int parse_stream_command(const char *txt, char **cmd) { - char *p = strchr(txt, ':'); - int i; + int ret, len; + char *re, *p = strchr(txt, ':'); if (!p) return -E_MISSING_COLON; - p++; - FOR_EACH_AUDIO_FORMAT(i) { - if (strncmp(txt, audio_formats[i], strlen(audio_formats[i]))) - continue; - *cmd = p; - return i; - } - return -E_UNSUPPORTED_AUDIO_FORMAT; + *cmd = p + 1; + len = p - txt; + re = malloc(len + 1); + strncpy(re, txt, len); + re[len] = '\0'; + ret = get_matching_audio_format_nums(re); + free(re); + return ret; } static int add_filter(int format, char *cmdline) @@ -764,36 +764,35 @@ static int add_filter(int format, char *cmdline) static int parse_writer_args(void) { - int i, ret, nw; + int i, ret; char *cmd; struct audio_format_info *a; - nw = PARA_MAX(1U, conf.writer_given); - PARA_INFO_LOG("maximal number of writers: %d\n", nw); - FOR_EACH_AUDIO_FORMAT(i) { - a = &afi[i]; - a->writer_conf = para_malloc(nw * sizeof(void *)); - a->writer_nums = para_malloc(nw * sizeof(int)); - a->num_writers = 0; - } for (i = 0; i < conf.writer_given; i++) { void *wconf; - int writer_num; + int j, nw, writer_num, af_mask; + ret = parse_stream_command(conf.writer_arg[i], &cmd); if (ret < 0) goto out; - a = &afi[ret]; - nw = a->num_writers; - wconf = check_writer_arg(cmd, &writer_num); - if (!wconf) { - ret = writer_num; - goto out; + af_mask = ret; + FOR_EACH_AUDIO_FORMAT(j) { + a = afi + j; + if ((af_mask & (1 << j)) == 0) /* no match */ + continue; + ret = -E_WRITE_COMMON_SYNTAX; + wconf = check_writer_arg(cmd, &writer_num); + if (!wconf) + goto out; + nw = a->num_writers; + a->writer_nums = para_realloc(a->writer_nums, (nw + 1) * sizeof(int)); + a->writer_conf = para_realloc(a->writer_conf, (nw + 1) * sizeof(void *)); + a->writer_nums[nw] = writer_num; + a->writer_conf[nw] = wconf; + PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[writer_num], + nw, writer_names[writer_num]); + a->num_writers++; } - a->writer_nums[nw] = writer_num; - a->writer_conf[nw] = wconf; - PARA_INFO_LOG("%s writer #%d: %s\n", audio_formats[ret], - nw, writer_names[writer_num]); - a->num_writers++; } ret = 1; out: -- 2.39.2