return;
for (i = a->num_filters - 1; i >= 0; i--) {
struct filter_node *fn = s->fns + i;
- struct filter *f;
+ const struct filter *f;
if (!fn)
continue;
- f = filters + fn->filter_num;
+ f = filter_get(fn->filter_num);
if (f->close)
f->close(fn);
btr_remove_node(&fn->btrn);
parent = s->receiver_node->btrn;
for (i = 0; i < nf; i++) {
char buf[20];
- struct filter *f = filters + a->filter_nums[i];
+ const struct filter *f = filter_get(a->filter_nums[i]);
fn = s->fns + i;
fn->filter_num = a->filter_nums[i];
fn->conf = a->filter_conf[i];
a->filter_conf[nf] = cfg;
a->num_filters++;
PARA_INFO_LOG("%s filter %d: %s\n", audio_formats[format], nf,
- filters[filter_num].name);
+ filter_get(filter_num)->name);
return filter_num;
}
}
/* add "dec" to audio format name */
tmp = make_message("%sdec", audio_formats[i]);
- for (j = 0; filters[j].name; j++)
- if (!strcmp(tmp, filters[j].name))
+ for (j = 0; filter_get(j); j++)
+ if (!strcmp(tmp, filter_get(j)->name))
break;
free(tmp);
ret = -E_UNSUPPORTED_FILTER;
- if (!filters[j].name)
+ if (!filter_get(j))
goto out;
- tmp = para_strdup(filters[j].name);
+ tmp = para_strdup(filter_get(j)->name);
ret = add_filter(i, tmp);
free(tmp);
if (ret < 0)
goto out;
PARA_INFO_LOG("%s -> default filter: %s\n", audio_formats[i],
- filters[j].name);
+ filter_get(j)->name);
}
out:
return ret;
{
static struct sched s;
int i, ret;
- struct filter *f;
+ const struct filter *f;
struct btr_node *parent;
struct filter_node **fns;
goto out_cleanup;
}
fn->filter_num = ret;
- f = filters + fn->filter_num;
+ f = filter_get(fn->filter_num);
PARA_DEBUG_LOG("filter #%d: %s\n", i, f->name);
fn->btrn = btr_new_node(&(struct btr_node_description)
EMBRACE(.name = f->name, .parent = parent,
for (i--; i >= 0; i--) {
struct filter_node *fn = fns[i];
- f = filters + fn->filter_num;
+ f = filter_get(fn->filter_num);
if (f->close)
f->close(fn);
btr_remove_node(&fn->btrn);
DECLARE_FILTER_INITS
/** The filter array, one structure for each supported filter. */
-extern struct filter filters[NUM_SUPPORTED_FILTERS];
+const struct filter *filter_get(int filter_num);
#define FOR_EACH_SUPPORTED_FILTER(j) for (j = 0; j < NUM_SUPPORTED_FILTERS; j++)
/** The array of supported filters. */
-struct filter filters[NUM_SUPPORTED_FILTERS] = {FILTER_ARRAY};
+static struct filter filters[NUM_SUPPORTED_FILTERS] = {FILTER_ARRAY};
+
+const struct filter *filter_get(int filter_num)
+{
+ assert(filter_num >= 0);
+ assert(filter_num < NUM_SUPPORTED_FILTERS);
+ return filters + filter_num;
+}
/**
* Call the init function of each supported filter.
int i;
FOR_EACH_SUPPORTED_FILTER(i)
- filters[i].init(filters + i);
+ filter_get(i)->init((struct filter *)filter_get(i));
}
/*
*/
static int parse_filter_args(int filter_num, char *options, void **conf)
{
- struct filter *f = &filters[filter_num];
+ const struct filter *f = filter_get(filter_num);
int ret, argc;
char **argv;
*conf = NULL;
// PARA_DEBUG_LOG("arg: %s\n", fa);
FOR_EACH_SUPPORTED_FILTER(j) {
- const char *name = filters[j].name;
+ const char *name = filter_get(j)->name;
size_t len = strlen(name);
char c;
if (strlen(fa) < len)
c = fa[len];
if (c && c != ' ')
continue;
- if (c && !filters[j].parse_config)
+ if (c && !filter_get(j)->parse_config)
return -E_BAD_FILTER_OPTIONS;
return parse_filter_args(j, c? fa + len + 1 :
fa + strlen(fa), conf);
printf_or_die("\n ");
num = 0;
}
- num += printf_or_die("%s%s", i? " " : "", filters[i].name);
+ num += printf_or_die("%s%s", i? " " : "", filter_get(i)->name);
}
printf_or_die("\n");
FOR_EACH_SUPPORTED_FILTER(i) {
- struct filter *f = filters + i;
+ struct filter *f = (struct filter *)filter_get(i);
if (!f->help.short_help)
continue;
static int eof_cleanup(struct play_task *pt)
{
struct writer *w = writers + DEFAULT_WRITER;
- struct filter *decoder = filters + pt->fn.filter_num;
+ const struct filter *decoder = filter_get(pt->fn.filter_num);
int ret;
ret = get_playback_error(pt);
const char *af;
char *tmp, buf[20];
int ret;
- struct filter *decoder;
+ const struct filter *decoder;
btr_remove_node(&pt->rn.btrn);
if (!pt->rn.receiver || pt->next_file != pt->current_file) {
if (ret < 0)
goto fail;
pt->fn.filter_num = ret;
- decoder = filters + ret;
+ decoder = filter_get(ret);
pt->fn.btrn = btr_new_node(&(struct btr_node_description)
EMBRACE(.name = decoder->name, .parent = pt->rn.btrn,
.handler = decoder->execute, .context = &pt->fn));