From 0855a5fcdbebabacebee968939cf00bf3161cfaf Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 2 May 2009 11:46:46 +0200 Subject: [PATCH] Use only a single buffer pointer for filters/receivers. This allows filters to change the output buffer size on the fly. --- alsa_write.c | 2 +- audiod.c | 8 ++++---- client.c | 2 +- file_write.c | 2 +- filter.c | 6 +++--- filter.h | 4 ++-- filter_common.c | 2 +- recv.c | 2 +- stdout.c | 4 ++-- stdout.h | 4 ++-- write.c | 2 +- write.h | 2 +- write_common.c | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index f63b7a5e..dd91cd84 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -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; diff --git a/audiod.c b/audiod.c index 6d7cce5e..77819654 100644 --- 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; } diff --git a/client.c b/client.c index 2123421e..003c1e60 100644 --- 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); diff --git a/file_write.c b/file_write.c index 0950e303..92777d7d 100644 --- a/file_write.c +++ b/file_write.c @@ -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; diff --git a/filter.c b/filter.c index 9311a20a..b8a7c5c1 100644 --- 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; diff --git a/filter.h b/filter.h index da472905..0bb51f5a 100644 --- 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. */ diff --git a/filter_common.c b/filter_common.c index b601c688..ebda1ee7 100644 --- a/filter_common.c +++ b/filter_common.c @@ -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 4f595e39..5de9c6be 100644 --- 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); diff --git a/stdout.c b/stdout.c index ce0d2209..e178fe0e 100644 --- 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); } /** diff --git a/stdout.h b/stdout.h index 4149dad3..cca12e5f 100644 --- 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 c5a26565..cc1f716f 100644 --- 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 71938a9c..365c237b 100644 --- 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. */ diff --git a/write_common.c b/write_common.c index 4e81f62d..dcf7bb16 100644 --- a/write_common.c +++ b/write_common.c @@ -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); } } -- 2.39.5