From 3cc5654fec9db630eac146f8475067228efe51ae Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 30 Dec 2013 22:09:38 +0000 Subject: [PATCH] task_register() conversion: filter tasks --- aacdec_filter.c | 2 +- amp_filter.c | 2 +- audiod.c | 15 ++++++++++----- compress_filter.c | 2 +- fecdec_filter.c | 2 +- filter.c | 10 ++++++---- filter.h | 2 +- filter_common.c | 2 +- flacdec_filter.c | 4 ++-- mp3dec_filter.c | 2 +- oggdec_filter.c | 4 ++-- opusdec_filter.c | 4 ++-- play.c | 18 +++++++++++------- prebuffer_filter.c | 4 ++-- resample_filter.c | 4 ++-- spxdec_filter.c | 2 +- sync_filter.c | 4 ++-- wav_filter.c | 4 ++-- wmadec_filter.c | 2 +- 19 files changed, 50 insertions(+), 39 deletions(-) diff --git a/aacdec_filter.c b/aacdec_filter.c index d63236da..12de909c 100644 --- a/aacdec_filter.c +++ b/aacdec_filter.c @@ -82,7 +82,7 @@ static void aacdec_close(struct filter_node *fn) static int aacdec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct btr_node *btrn = fn->btrn; struct private_aacdec_data *padd = fn->private_data; int i, ret; diff --git a/amp_filter.c b/amp_filter.c index c3e55cf0..71855eb2 100644 --- a/amp_filter.c +++ b/amp_filter.c @@ -64,7 +64,7 @@ static void amp_open(struct filter_node *fn) static int amp_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_amp_data *pad = fn->private_data; struct btr_node *btrn = fn->btrn; int ret, factor = 64 + pad->amp; diff --git a/audiod.c b/audiod.c index 4b88ec5b..c5a88a9d 100644 --- a/audiod.c +++ b/audiod.c @@ -445,6 +445,7 @@ static void close_filters(struct slot_info *s) if (f->close) f->close(fn); btr_remove_node(&fn->btrn); + task_reap(&fn->task); } free(s->fns); s->fns = NULL; @@ -498,22 +499,26 @@ static void open_filters(struct slot_info *s) s->fns = para_calloc(nf * sizeof(struct filter_node)); parent = s->receiver_node->btrn; for (i = 0; i < nf; i++) { + char buf[20]; struct filter *f = filters + a->filter_nums[i]; fn = s->fns + i; fn->filter_num = a->filter_nums[i]; fn->conf = a->filter_conf[i]; - fn->task.pre_select = f->pre_select; - fn->task.post_select = f->post_select; fn->btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = f->name, .parent = parent, .handler = f->execute, .context = fn)); f->open(fn); - register_task(&sched, &fn->task); + sprintf(buf, "%s (slot %d)", f->name, (int)(s - slot)); + fn->task = task_register(&(struct task_info) { + .name = buf, + .pre_select = f->pre_select, + .post_select = f->post_select, + .context = fn, + }, &sched); parent = fn->btrn; PARA_NOTICE_LOG("%s filter %d/%d (%s) started in slot %d\n", audio_formats[s->format], i, nf, f->name, (int)(s - slot)); - sprintf(fn->task.status, "%s (slot %d)", f->name, (int)(s - slot)); } } @@ -1109,7 +1114,7 @@ static bool must_close_slot(int slot_num) if (s->receiver_node && s->receiver_node->task->error >= 0) return false; for (i = 0; i < a->num_filters; i++) - if (s->fns && s->fns[i].task.error >= 0) + if (s->fns && s->fns[i].task->error >= 0) return false; if (a->num_writers > 0) { for (i = 0; i < a->num_writers; i++) diff --git a/compress_filter.c b/compress_filter.c index b488f55c..affb3d4c 100644 --- a/compress_filter.c +++ b/compress_filter.c @@ -43,7 +43,7 @@ static void compress_close(struct filter_node *fn) static int compress_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_compress_data *pcd = fn->private_data; struct btr_node *btrn = fn->btrn; bool inplace = btr_inplace_ok(btrn); diff --git a/fecdec_filter.c b/fecdec_filter.c index b8e130d4..9d34106d 100644 --- a/fecdec_filter.c +++ b/fecdec_filter.c @@ -438,7 +438,7 @@ static void fecdec_close(struct filter_node *fn) static int fecdec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct btr_node *btrn = fn->btrn; int ret; struct fec_header h; diff --git a/filter.c b/filter.c index 7e3575fa..55afbd32 100644 --- a/filter.c +++ b/filter.c @@ -118,6 +118,7 @@ int main(int argc, char *argv[]) for (i = 0, parent = sit->btrn; i < conf.filter_given; i++) { char *fa = conf.filter_arg[i]; struct filter_node *fn; + struct task_info ti; fn = fns[i] = para_calloc(sizeof(*fn)); ret = check_filter_arg(fa, &fn->conf); @@ -127,15 +128,16 @@ int main(int argc, char *argv[]) } fn->filter_num = ret; f = filters + fn->filter_num; - sprintf(fn->task.status, "%s", f->name); PARA_DEBUG_LOG("filter #%d: %s\n", i, f->name); fn->btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = f->name, .parent = parent, .handler = f->execute, .context = fn)); - fn->task.pre_select = f->pre_select; - fn->task.post_select = f->post_select; + ti.name = f->name; + ti.pre_select = f->pre_select; + ti.post_select = f->post_select; + ti.context = fn; f->open(fn); - register_task(&s, &fn->task); + fn->task = task_register(&ti, &s); parent = fn->btrn; } sot->btrn = btr_new_node(&(struct btr_node_description) diff --git a/filter.h b/filter.h index de8ce8e8..7365f943 100644 --- a/filter.h +++ b/filter.h @@ -27,7 +27,7 @@ struct filter_node { /** The buffer tree node. */ struct btr_node *btrn; /** The task corresponding to this filter node. */ - struct task task; + struct task *task; /** The minimal input queue size, see \ref btr_node_status(). */ size_t min_iqs; }; diff --git a/filter_common.c b/filter_common.c index f2f5799f..d570e648 100644 --- a/filter_common.c +++ b/filter_common.c @@ -141,7 +141,7 @@ void print_filter_helps(unsigned flags) */ void generic_filter_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); if (btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL) != 0) sched_min_delay(s); diff --git a/flacdec_filter.c b/flacdec_filter.c index 2a58044c..16b44121 100644 --- a/flacdec_filter.c +++ b/flacdec_filter.c @@ -212,7 +212,7 @@ static bool output_queue_full(struct btr_node *btrn) static void flacdec_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_flacdec_data *pfd = fn->private_data; struct btr_node *btrn = fn->btrn; int ret; @@ -228,7 +228,7 @@ static void flacdec_pre_select(struct sched *s, struct task *t) static int flacdec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_flacdec_data *pfd = fn->private_data; struct btr_node *btrn = fn->btrn; int ret; diff --git a/mp3dec_filter.c b/mp3dec_filter.c index feaa1d1f..997cb984 100644 --- a/mp3dec_filter.c +++ b/mp3dec_filter.c @@ -79,7 +79,7 @@ static void mp3dec_close(struct filter_node *fn) static int mp3dec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); int i, ret; struct private_mp3dec_data *pmd = fn->private_data; struct btr_node *btrn = fn->btrn; diff --git a/oggdec_filter.c b/oggdec_filter.c index 3222b4aa..ad3ef60f 100644 --- a/oggdec_filter.c +++ b/oggdec_filter.c @@ -183,7 +183,7 @@ out: static void ogg_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_oggdec_data *pod = fn->private_data; struct btr_node *btrn = fn->btrn; int ret; @@ -200,7 +200,7 @@ static void ogg_pre_select(struct sched *s, struct task *t) static int ogg_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_oggdec_data *pod = fn->private_data; struct btr_node *btrn = fn->btrn; int ret, have; diff --git a/opusdec_filter.c b/opusdec_filter.c index 9022fbab..292d83c9 100644 --- a/opusdec_filter.c +++ b/opusdec_filter.c @@ -209,7 +209,7 @@ static int decode_packet(struct opusdec_context *ctx, ogg_packet *op, static int opusdec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct opusdec_context *ctx = fn->private_data; struct btr_node *btrn = fn->btrn; int ret; @@ -271,7 +271,7 @@ out: static void opusdec_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct opusdec_context *ctx = fn->private_data; int ret = btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL); diff --git a/play.c b/play.c index 2dcc37ea..045f2603 100644 --- a/play.c +++ b/play.c @@ -247,7 +247,7 @@ static int get_playback_error(struct play_task *pt) if (err >= 0) return 0; - if (pt->fn.task.error >= 0) + if (pt->fn.task->error >= 0) return 0; if (pt->rn.task->error >= 0) return 0; @@ -272,6 +272,7 @@ static int eof_cleanup(struct play_task *pt) w->free_config(pt->wn.conf); memset(&pt->wn, 0, sizeof(struct writer_node)); + task_reap(&pt->fn.task); decoder->close(&pt->fn); btr_remove_node(&pt->fn.btrn); free(pt->fn.conf); @@ -361,7 +362,7 @@ fail: static int load_file(struct play_task *pt) { const char *af; - char *tmp; + char *tmp, buf[20]; int ret; struct filter *decoder; @@ -371,7 +372,6 @@ static int load_file(struct play_task *pt) if (ret < 0) return ret; } else { - char buf[20]; pt->rn.btrn = new_recv_btrn(&pt->rn); sprintf(buf, "repos %lu", pt->start_chunk); ret = btr_exec_up(pt->rn.btrn, buf, &tmp); @@ -390,9 +390,6 @@ static int load_file(struct play_task *pt) goto fail; pt->fn.filter_num = ret; decoder = filters + ret; - pt->fn.task.pre_select = decoder->pre_select; - pt->fn.task.post_select = decoder->post_select; - sprintf(pt->fn.task.status, "%s decoder", af); pt->fn.btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = decoder->name, .parent = pt->rn.btrn, .handler = decoder->execute, .context = &pt->fn)); @@ -410,7 +407,14 @@ static int load_file(struct play_task *pt) .post_select = afh_recv->post_select, .context = &pt->rn }, &sched); - register_task(&sched, &pt->fn.task); + sprintf(buf, "%s decoder", af); + pt->fn.task = task_register( + &(struct task_info) { + .name = buf, + .pre_select = decoder->pre_select, + .post_select = decoder->post_select, + .context = &pt->fn + }, &sched); register_writer_node(&pt->wn, pt->fn.btrn, &sched); return 1; fail: diff --git a/prebuffer_filter.c b/prebuffer_filter.c index 6fac4cb3..160781a1 100644 --- a/prebuffer_filter.c +++ b/prebuffer_filter.c @@ -30,7 +30,7 @@ struct private_prebuffer_data { static void prebuffer_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct btr_node *btrn = fn->btrn; size_t iqs = btr_get_input_queue_size(btrn); struct private_prebuffer_data *ppd = fn->private_data; @@ -58,7 +58,7 @@ static void prebuffer_close(struct filter_node *fn) static int prebuffer_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct btr_node *btrn = fn->btrn; size_t iqs = btr_get_input_queue_size(btrn); struct private_prebuffer_data *ppd = fn->private_data; diff --git a/resample_filter.c b/resample_filter.c index 2caa1e21..e34af839 100644 --- a/resample_filter.c +++ b/resample_filter.c @@ -67,7 +67,7 @@ static void resample_open(struct filter_node *fn) static void resample_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct resample_context *ctx = fn->private_data; int ret = btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL); @@ -205,7 +205,7 @@ static int resample_frames(int16_t *in, size_t num_frames, bool have_more, static int resample_post_select(__a_unused struct sched *s, struct task *t) { int ret; - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct resample_context *ctx = fn->private_data; struct resample_filter_args_info *conf = fn->conf; struct btr_node *btrn = fn->btrn; diff --git a/spxdec_filter.c b/spxdec_filter.c index 72ecd62a..a1ff3ddb 100644 --- a/spxdec_filter.c +++ b/spxdec_filter.c @@ -240,7 +240,7 @@ static int compute_skip_samples(ogg_page *og, struct private_spxdec_data *psd) static int speexdec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct private_spxdec_data *psd = fn->private_data; struct btr_node *btrn = fn->btrn; int ret, ns; diff --git a/sync_filter.c b/sync_filter.c index 379b54b1..203451f2 100644 --- a/sync_filter.c +++ b/sync_filter.c @@ -261,7 +261,7 @@ static void sync_set_timeout(struct sync_filter_context *ctx, static void sync_pre_select(struct sched *s, struct task *t) { int ret; - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct sync_filter_context *ctx = fn->private_data; struct sync_filter_config *sfc = fn->conf; @@ -298,7 +298,7 @@ static struct sync_buddy *sync_find_buddy(struct sockaddr *addr, static int sync_post_select(__a_unused struct sched *s, struct task *t) { int ret; - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct sync_filter_context *ctx = fn->private_data; struct sync_filter_config *sfc = fn->conf; struct sync_buddy *buddy, *tmp; diff --git a/wav_filter.c b/wav_filter.c index bd676958..b5b0df80 100644 --- a/wav_filter.c +++ b/wav_filter.c @@ -65,7 +65,7 @@ static void wav_open(struct filter_node *fn) static void wav_pre_select(struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); size_t iqs = btr_get_input_queue_size(fn->btrn); if (iqs == 0) @@ -75,7 +75,7 @@ static void wav_pre_select(struct sched *s, struct task *t) static int wav_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); struct btr_node *btrn = fn->btrn; size_t iqs = btr_get_input_queue_size(btrn); int ret; diff --git a/wmadec_filter.c b/wmadec_filter.c index 0071337f..e4afbb56 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -1215,7 +1215,7 @@ static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result) static int wmadec_post_select(__a_unused struct sched *s, struct task *t) { - struct filter_node *fn = container_of(t, struct filter_node, task); + struct filter_node *fn = task_context(t); int ret, converted, out_size; struct private_wmadec_data *pwd = fn->private_data; struct btr_node *btrn = fn->btrn; -- 2.39.5