]> git.tue.mpg.de Git - paraslash.git/commitdiff
task_register() conversion: filter tasks
authorAndre Noll <maan@systemlinux.org>
Mon, 30 Dec 2013 22:09:38 +0000 (22:09 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:36:37 +0000 (15:36 +0200)
19 files changed:
aacdec_filter.c
amp_filter.c
audiod.c
compress_filter.c
fecdec_filter.c
filter.c
filter.h
filter_common.c
flacdec_filter.c
mp3dec_filter.c
oggdec_filter.c
opusdec_filter.c
play.c
prebuffer_filter.c
resample_filter.c
spxdec_filter.c
sync_filter.c
wav_filter.c
wmadec_filter.c

index d63236da5112d2ea9a9ac52d80c31abdc0ad78f4..12de909cb6cecca2a3abc4c027177bc31b91ab5d 100644 (file)
@@ -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;
index c3e55cf0477b253dfd663953613c2ed5f95daa51..71855eb2e9e5a8102d6cebf1f0c6ffd4b6180250 100644 (file)
@@ -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;
index 4b88ec5bba61c53be43e901edbae2bc8c7c84a5e..c5a88a9d5820a0d61c0b8364af0aced414a32fdb 100644 (file)
--- 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++)
index b488f55cb3ae2471201ab518ae84e3603ebcf005..affb3d4ca9a1ab30155ead26511df789eca29206 100644 (file)
@@ -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);
index b8e130d4ed124ad67fb6550073e3122be7a346be..9d34106db7562b5bc1c6ab419bf955dc15eb9572 100644 (file)
@@ -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;
index 7e3575faa36e4e04b804fc988b04c2df716e9531..55afbd3225ff84a74ad20d57b5cfc27c8c7f71cc 100644 (file)
--- 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)
index de8ce8e8b5d0ca128cbc2cb4f3bb568ec416c07e..7365f943f038583052695387ce261374d5051e63 100644 (file)
--- 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;
 };
index f2f5799f8593240f6d74d262a8bd93e0becfd191..d570e648788bf1d90253aa1d9b96aa310803d5af 100644 (file)
@@ -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);
index 2a58044c59baef2ba898e2d33b642846657e7efd..16b4412152f1b6618c8cf839b57a5237615a9d7d 100644 (file)
@@ -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;
index feaa1d1f03f9a9a4bd4b0d6f1984219b480099ad..997cb9842df365318c151ddd9d93236e78bfb449 100644 (file)
@@ -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;
index 3222b4aaaaabc046ac3983359ae58d868861c46a..ad3ef60f637fbdc3239970d4b5a0f76a42614e93 100644 (file)
@@ -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;
index 9022fbab63e0c3e2626528bcfa752ff6fde8faa3..292d83c9f960ce1332e029c4addd231a8e7f7cb1 100644 (file)
@@ -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 2dcc37ea2bf0954ccea2776c8dd410b85c9804b2..045f26038b46512f4eebfdf5bf80659c79f4fd87 100644 (file)
--- 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:
index 6fac4cb31d944db1aa603fbfdd71819a946a359c..160781a121a51f4adff74d88928144f06af4f5ee 100644 (file)
@@ -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;
index 2caa1e21395a7a77909d0284f6e44e3013640857..e34af83992526c23b73f24c03c92fde88a3a9bd0 100644 (file)
@@ -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;
index 72ecd62a8d9c11460e6962689f52446e3b43ccb7..a1ff3ddb018011eadffc3b6b0975334e33b52dab 100644 (file)
@@ -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;
index 379b54b13395b20190e69543b57ed49ed3e569fe..203451f2c23cef6cec6db8072654cbf123a30a0e 100644 (file)
@@ -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;
index bd676958e0a4be621ea29a42f51f81fd34c35d07..b5b0df80f8fe31448f991d8ba86111f6b1774ae3 100644 (file)
@@ -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;
index 0071337f38427cc98f341404a6819ee683352ecc..e4afbb56ab2d82d8d482cf27ec1eb7f96c1e5832 100644 (file)
@@ -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;