Use only a single buffer pointer for filters/receivers.
authorAndre Noll <maan@systemlinux.org>
Sat, 2 May 2009 09:46:46 +0000 (11:46 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 2 May 2009 09:46:46 +0000 (11:46 +0200)
This allows filters to change the output buffer size on the fly.

13 files changed:
alsa_write.c
audiod.c
client.c
file_write.c
filter.c
filter.h
filter_common.c
recv.c
stdout.c
stdout.h
write.c
write.h
write_common.c

index f63b7a5..dd91cd8 100644 (file)
@@ -164,7 +164,7 @@ static int alsa_write_post_select(__a_unused struct sched *s,
        struct private_alsa_write_data *pad = wn->private_data;
        struct writer_node_group *wng = wn->wng;
        size_t frames, bytes = *wng->loaded - wn->written;
-       unsigned char *data = (unsigned char*)wng->buf + wn->written;
+       unsigned char *data = (unsigned char*)*wng->bufp + wn->written;
        struct timeval tv;
        snd_pcm_sframes_t ret;
 
index 6d7cce5..7781965 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -382,7 +382,7 @@ static void open_filters(int slot_num)
        PARA_INFO_LOG("opening %s filters\n", audio_formats[s->format]);
        s->fc = para_calloc(sizeof(struct filter_chain));
        s->fc->filter_nodes = para_malloc(nf * sizeof(struct filter_node));
-       s->fc->inbuf = s->receiver_node->buf;
+       s->fc->inbufp = &s->receiver_node->buf;
        s->fc->in_loaded = &s->receiver_node->loaded;
        s->fc->input_error = &s->receiver_node->task.error;
        s->fc->task.pre_select = filter_pre_select;
@@ -402,7 +402,7 @@ static void open_filters(int slot_num)
                f->open(fn);
                PARA_NOTICE_LOG("%s filter %d/%d (%s) started in slot %d\n",
                        audio_formats[s->format], i,  nf, f->name, slot_num);
-               s->fc->outbuf = fn->buf;
+               s->fc->outbufp = &fn->buf;
                s->fc->out_loaded = &fn->loaded;
        }
        register_task(&s->fc->task);
@@ -420,7 +420,7 @@ static void open_writers(int slot_num)
        else
                s->wng = wng_new(a->num_writers);
        if (s->fc) {
-               s->wng->buf = s->fc->outbuf;
+               s->wng->bufp = s->fc->outbufp;
                s->wng->loaded = s->fc->out_loaded;
                s->wng->input_error = &s->fc->task.error;
                s->wng->channels = &s->fc->channels;
@@ -428,7 +428,7 @@ static void open_writers(int slot_num)
                s->fc->output_error = &s->wng->task.error;
                PARA_INFO_LOG("samplerate: %d\n", *s->wng->samplerate);
        } else {
-               s->wng->buf = s->receiver_node->buf;
+               s->wng->bufp = &s->receiver_node->buf;
                s->wng->loaded = &s->receiver_node->loaded;
                s->wng->input_error = &s->receiver_node->task.error;
        }
index 2123421..003c1e6 100644 (file)
--- a/client.c
+++ b/client.c
@@ -40,7 +40,7 @@ static void supervisor_post_select(__a_unused struct sched *s, struct task *t)
        }
        if (ct->status == CL_RECEIVING) {
                stdout_set_defaults(&sot);
-               sot.buf = ct->buf;
+               sot.bufp = &ct->buf;
                sot.loaded = &ct->loaded;
                sot.input_error = &ct->task.error;
                register_task(&sot.task);
index 0950e30..92777d7 100644 (file)
@@ -79,7 +79,7 @@ static int file_write_post_select(struct sched *s, struct writer_node *wn)
        if (!FD_ISSET(pfwd->fd, &s->wfds))
                return 1;
 //     PARA_INFO_LOG("writing %zd\n", *wng->loaded);
-       ret = write(pfwd->fd, wng->buf + wn->written,
+       ret = write(pfwd->fd, *wng->bufp + wn->written,
                *wng->loaded - wn->written);
        if (ret < 0)
                return -E_FW_WRITE;
index 9311a20..b8a7c5c 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -56,7 +56,7 @@ static void open_filters(void)
                struct filter *f = filters + fn->filter_num;
                f->open(fn);
                PARA_INFO_LOG("opened %s filter\n", f->name);
-               fc->outbuf = fn->buf;
+               fc->outbufp = &fn->buf;
                fc->out_loaded = &fn->loaded;
        }
 }
@@ -70,7 +70,7 @@ static int init_filter_chain(void)
                return -E_NO_FILTERS;
        fc->num_filters = conf.filter_given;
        fc->filter_nodes = para_malloc(fc->num_filters * sizeof(struct filter_node));
-       fc->inbuf = sit->buf;
+       fc->inbufp = &sit->buf;
        fc->in_loaded = &sit->loaded;
        fc->input_error = &sit->task.error;
        fc->task.error = 0;
@@ -170,7 +170,7 @@ int main(int argc, char *argv[])
        sit->output_error = &fc->task.error;
 
        stdout_set_defaults(sot);
-       sot->buf = fc->outbuf;
+       sot->bufp = fc->outbufp;
        sot->loaded = fc->out_loaded;
        sot->input_error = &fc->task.error;
 
index da47290..0bb51f5 100644 (file)
--- a/filter.h
+++ b/filter.h
@@ -59,13 +59,13 @@ struct filter_chain {
         * buffer used to read from stdin for para_filter; the output buffer of the
         * current receiver for para_audiod).
         */
-       char *inbuf;
+       char **inbufp;
        /**
         * The output buffer of the filter chain.
         *
         * Points to the output buffer of the last filter in the filter chain.
         */
-       char *outbuf;
+       char **outbufp;
        /** Contains the number of bytes loaded in the input buffer. */
        size_t *in_loaded;
        /** Contains the number of bytes loaded in the output buffer. */
index b601c68..ebda1ee 100644 (file)
@@ -118,7 +118,7 @@ void filter_pre_select(__a_unused struct sched *s, struct task *t)
                return;
        }
 again:
-       ib = fc->inbuf;
+       ib = *fc->inbufp;
        loaded = fc->in_loaded;
        conv = 0;
        FOR_EACH_FILTER_NODE(fn, fc, i) {
diff --git a/recv.c b/recv.c
index 4f595e3..5de9c6b 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
        r_opened = 1;
 
        stdout_set_defaults(&sot);
-       sot.buf = rn.buf;
+       sot.bufp = &rn.buf;
        sot.loaded = &rn.loaded;
        sot.input_error = &rn.task.error;
        register_task(&sot.task);
index ce0d220..e178fe0 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -68,14 +68,14 @@ static void stdout_post_select(struct sched *s, struct task *t)
        }
        if (!FD_ISSET(STDOUT_FILENO, &s->wfds))
                return;
-       ret = write(STDOUT_FILENO, sot->buf, *sot->loaded);
+       ret = write(STDOUT_FILENO, *sot->bufp, *sot->loaded);
        if (ret < 0) {
                t->error = -ERRNO_TO_PARA_ERROR(errno);
                return;
        }
        *sot->loaded -= ret;
        if (*sot->loaded)
-               memmove(sot->buf, sot->buf + ret, *sot->loaded);
+               memmove(*sot->bufp, *sot->bufp + ret, *sot->loaded);
 }
 
 /**
index 4149dad..cca12e5 100644 (file)
--- a/stdout.h
+++ b/stdout.h
@@ -10,8 +10,8 @@
  * The task structure used for writing to stdout.
  */
 struct stdout_task {
-       /** Pointer to the data buffer. */
-       char *buf;
+       /** Pointer to the data buffer pointer. */
+       char **bufp;
        /** Number of bytes loaded in \a buf. */
        size_t *loaded;
        /** Pointer to the error variable of the feeding task. */
diff --git a/write.c b/write.c
index c5a2656..cc1f716 100644 (file)
--- a/write.c
+++ b/write.c
@@ -214,7 +214,7 @@ int main(int argc, char *argv[])
        sit.bufsize = conf.bufsize_arg * 1024;
        sit.buf = para_malloc(sit.bufsize);
 
-       wng->buf = sit.buf;
+       wng->bufp = &sit.buf;
        wng->loaded = &sit.loaded;
        wng->input_error = &sit.task.error;
 
diff --git a/write.h b/write.h
index 71938a9..365c237 100644 (file)
--- a/write.h
+++ b/write.h
@@ -96,7 +96,7 @@ struct writer_node_group {
        /** Non-zero if an error or end of file was encountered by the feeding task. */
        int *input_error;
        /** Current output buffer. */
-       char *buf;
+       char **bufp;
        /** Number of bytes loaded in the output buffer. */
        size_t *loaded;
        /** Number of audio channels of the current stream. */
index 4e81f62..dcf7bb1 100644 (file)
@@ -61,7 +61,7 @@ static void wng_post_select(struct sched *s, struct task *t)
        }
        if (*g->loaded && min_written) {
 //             PARA_INFO_LOG("moving %zd bytes\n", *g->loaded);
-               memmove(g->buf, g->buf + min_written, *g->loaded);
+               memmove(*g->bufp, *g->bufp + min_written, *g->loaded);
        }
 }