]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
filter: Make ->open() optional.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 28 Jun 2015 14:18:22 +0000 (16:18 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 25 Aug 2016 15:31:21 +0000 (17:31 +0200)
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().

audiod.c
filter.c
filter.h
play.c

index fedeff7af880a009d938e73087edb7ca6c83f267..285d2762fa1093baf3e49211eab73ca631f605db 100644 (file)
--- 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));
 
                        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,
                sprintf(buf, "%s (slot %d)", f->name, (int)(s - slot));
                fn->task = task_register(&(struct task_info) {
                        .name = buf,
index 9378e4695b6b113843d7d1b34a96ded4bdebd79e..804b5e1e569a9c680e309f14738e77481161682a 100644 (file)
--- 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;
                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;
        }
                fn->task = task_register(&ti, &s);
                parent = fn->btrn;
        }
index 937bb42bc610e65d371ff8787a6e701c240c558a..0bd546903927d412fccef946cf8f43783ed8bc70 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -58,17 +58,18 @@ struct filter {
        /**
         * Open one instance of this 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.
         *
         */
        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);
        /**
         */
        void (*close)(struct filter_node *fn);
        /**
diff --git a/play.c b/play.c
index a7ce563baafae4e39e33de07867669085c648ac3..d2539ee134773614a40bca9941f35dd161007946 100644 (file)
--- 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));
        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);
 
        /* setup default writer */
        pt->wn.conf = check_writer_arg_or_die(NULL, &pt->wn.writer_num);