]> git.tue.mpg.de Git - paraslash.git/commitdiff
struct writer_node: Store the number of the writer rather than a pointer.
authorAndre Noll <maan@systemlinux.org>
Thu, 14 May 2009 06:34:06 +0000 (08:34 +0200)
committerAndre Noll <maan@systemlinux.org>
Thu, 14 May 2009 06:34:06 +0000 (08:34 +0200)
This makes it easier to get the name of the writer from the writer_node
struct.

audiod.c
write.c
write.h
write_common.c

index ce5bc551f8767349a41fe0974f52fa1975d2a1f8..eb3b200ae6e5969be231c8be3e169d52e4430873 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -49,8 +49,8 @@ struct audio_format_info {
        void **filter_conf;
        /** the number of filters that should be activated for this audio format */
        unsigned int num_writers;
-       /** pointer to the array of writers to be activated */
-       struct writer **writers;
+       /** Array of writer numbers to be activated. */
+       int *writer_nums;
        /** pointer to the array of writer configurations */
        void **writer_conf;
        /** do not start receiver/filters/writer before this time */
@@ -434,7 +434,7 @@ static void open_writers(int slot_num)
        }
        for (i = 0; i < a->num_writers; i++) {
                s->wng->writer_nodes[i].conf = a->writer_conf[i];
-               s->wng->writer_nodes[i].writer = a->writers[i];
+               s->wng->writer_nodes[i].writer_num = a->writer_nums[i];
        }
        ret = wng_open(s->wng);
        if (ret < 0)
@@ -689,7 +689,7 @@ static int parse_writer_args(void)
        FOR_EACH_AUDIO_FORMAT(i) {
                a = &afi[i];
                a->writer_conf = para_malloc(nw * sizeof(void *));
-               a->writers = para_malloc(nw * sizeof(struct writer *));
+               a->writer_nums = para_malloc(nw * sizeof(int));
                a->num_writers = 0;
        }
        for (i = 0; i < conf.writer_given; i++) {
@@ -705,7 +705,7 @@ static int parse_writer_args(void)
                        ret = writer_num;
                        goto out;
                }
-               a->writers[nw] = &writers[writer_num];
+               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]);
diff --git a/write.c b/write.c
index cc1f716f8a962de165f93d0f090d21e591a43b11..c12736a66bfb81c9dcf85c412b1a581a2cade0ce 100644 (file)
--- a/write.c
+++ b/write.c
@@ -153,7 +153,7 @@ static struct writer_node_group *check_args(void)
                        conf.writer_arg[i], &writer_num);
                if (!g->writer_nodes[i].conf)
                        goto out;
-               g->writer_nodes[i].writer = &writers[writer_num];
+               g->writer_nodes[i].writer_num = writer_num;
        }
        ret = 1;
 out:
diff --git a/write.h b/write.h
index 365c237bf2b41e92e7ae14129d460d95396576ca..1f316fc0ece5d029e21ef5d49d9853ae9d2c8900 100644 (file)
--- a/write.h
+++ b/write.h
@@ -13,8 +13,8 @@ enum writer_enum {WRITER_ENUM};
  * Describes one running instance of a writer.
  */
 struct writer_node {
-       /** Points to the writer structure associated with this node. */
-       struct writer *writer; /* FIXME: Should better be only the number. */
+       /** The number of this writer. */
+       int writer_num;
        /** Writer-specific data. */
        void *private_data;
        /** Pointer to the group this node belongs to. */
index 316c87ef1f818469c061cf9dc12635d1613fd4ad..476df8f0ec7b4f6ea7c3388795f9272d1e02fd8b 100644 (file)
@@ -27,9 +27,10 @@ static void wng_pre_select(__a_unused struct sched *s, struct task *t)
 
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               if (!wn->writer->pre_select)
+               struct writer *w = writers + wn->writer_num;
+               if (!w->pre_select)
                        continue;
-               t->error = wn->writer->pre_select(s, wn);
+               t->error = w->pre_select(s, wn);
                if (t->error < 0)
                        return;
        }
@@ -43,7 +44,8 @@ static void wng_post_select(struct sched *s, struct task *t)
 
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               t->error = wn->writer->post_select(s, wn);
+               struct writer *w = writers + wn->writer_num;
+               t->error = w->post_select(s, wn);
                if (t->error < 0)
                        return;
                if (!i)
@@ -84,8 +86,9 @@ int wng_open(struct writer_node_group *g)
        PARA_NOTICE_LOG("opening wng %p with %d writer(s)\n", g, g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
+               struct writer *w = writers + wn->writer_num;
                wn->wng = g;
-               ret = wn->writer->open(wn);
+               ret = w->open(wn);
                if (ret < 0)
                        goto err_out;
        }
@@ -97,7 +100,8 @@ err_out:
        PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        while (i > 0) {
                struct writer_node *wn = &g->writer_nodes[--i];
-               wn->writer->close(wn);
+               struct writer *w = writers + wn->writer_num;
+               w->close(wn);
        }
        free(g->writer_nodes);
        g->num_writers = 0;
@@ -121,7 +125,8 @@ void wng_close(struct writer_node_group *g)
        PARA_NOTICE_LOG("closing wng with %d writer(s)\n", g->num_writers);
        FOR_EACH_WRITER_NODE(i, g) {
                struct writer_node *wn = &g->writer_nodes[i];
-               wn->writer->close(wn);
+               struct writer *w = writers + wn->writer_num;
+               w->close(wn);
        }
        free(g->writer_nodes);
        free(g);
@@ -207,7 +212,7 @@ void *check_writer_arg(const char *wa, int *writer_num)
 struct writer_node_group *setup_default_wng(void)
 {
        struct writer_node_group *wng = wng_new(1);
-       wng->writer_nodes[0].writer = &writers[DEFAULT_WRITER];
+       wng->writer_nodes[0].writer_num = DEFAULT_WRITER;
        PARA_INFO_LOG("using default writer: %s %p\n",
                writer_names[DEFAULT_WRITER], writers[DEFAULT_WRITER].parse_config);
        wng->writer_nodes[0].conf = writers[DEFAULT_WRITER].parse_config("");