From: Andre Noll Date: Sun, 28 Jun 2015 14:18:22 +0000 (+0200) Subject: filter: Make ->open() optional. X-Git-Tag: v0.5.7~27 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=5ff39998bf0ce71bd8fc8d0f002ceb81b711992f;ds=sidebyside filter: Make ->open() optional. There is no need to force each filter to supply this method, so teach the three callers of ->open() to check for NULL pointers. The commit also fixes some trivial language issues in the documentation of ->open() and ->close(). --- diff --git a/audiod.c b/audiod.c index fedeff7a..285d2762 100644 --- a/audiod.c +++ b/audiod.c @@ -596,7 +596,8 @@ static void open_filters(struct slot_info *s) EMBRACE(.name = f->name, .parent = parent, .handler = f->execute, .context = fn)); - f->open(fn); + if (f->open) + f->open(fn); sprintf(buf, "%s (slot %d)", f->name, (int)(s - slot)); fn->task = task_register(&(struct task_info) { .name = buf, diff --git a/filter.c b/filter.c index 9378e469..804b5e1e 100644 --- a/filter.c +++ b/filter.c @@ -142,7 +142,8 @@ int main(int argc, char *argv[]) ti.pre_select = f->pre_select; ti.post_select = f->post_select; ti.context = fn; - f->open(fn); + if (f->open) + f->open(fn); fn->task = task_register(&ti, &s); parent = fn->btrn; } diff --git a/filter.h b/filter.h index 937bb42b..0bd54690 100644 --- a/filter.h +++ b/filter.h @@ -58,17 +58,18 @@ struct filter { /** * Open one instance of this filter. * - * This should allocate the output buffer of the given filter node and do any - * other filter-specific preparations like initializing the private_data member - * of \a fn suitably. The open function is assumed to succeed. + * This should allocate the output buffer of the given filter node and + * do any other filter-specific preparations like initializing the + * private_data member of \a fn suitably. The open function is + * optional, If it is provided, it is assumed to succeed. */ void (*open)(struct filter_node *fn); /** * Close one instance of this filter. * - * Free all resources of associated with \a fn that were previously allocated - * by the open() function. It's OK to leave this alone if the filter does not - * need any cleanups. + * Free all resources associated with \a fn that were previously + * allocated by the open() function. It's OK to set this to NULL if the + * filter does not need to perform any cleanup operation. */ void (*close)(struct filter_node *fn); /** diff --git a/play.c b/play.c index a7ce563b..d2539ee1 100644 --- a/play.c +++ b/play.c @@ -397,7 +397,8 @@ static int load_file(struct play_task *pt) pt->fn.btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = decoder->name, .parent = pt->rn.btrn, .handler = decoder->execute, .context = &pt->fn)); - decoder->open(&pt->fn); + if (decoder->open) + decoder->open(&pt->fn); /* setup default writer */ pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num);