X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=audiod.c;h=27eba9e3e584cd06294bef568cc4eb19d1ce1f88;hp=2819091b80a2c27991df0ae0f3a95290e7423916;hb=6793399f34237840fbf48220971966bc9a3d5a18;hpb=c057c50d3d6e4c8d61e9c6db3e120270793e270e diff --git a/audiod.c b/audiod.c index 2819091b..27eba9e3 100644 --- a/audiod.c +++ b/audiod.c @@ -110,6 +110,8 @@ struct status_task { struct timeval clock_diff_barrier; /** Number of the audio format as announced by para_server. */ int current_audio_format_num; + /* The status task btrn is the child of the client task. */ + struct btr_node *btrn; }; /** The array of status items sent by para_server. */ @@ -357,6 +359,7 @@ static void close_writers(struct slot_info *s) if (s->format < 0) return; + assert(s->wns); a = afi + s->format; if (a->num_writers == 0) writer_cleanup(s->wns); @@ -479,7 +482,11 @@ static void open_filters(struct slot_info *s) 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(f->name, parent, f->execute, fn); + + 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(&fn->task); parent = fn->btrn; @@ -532,7 +539,8 @@ static int open_receiver(int format) rn = s->receiver_node; rn->receiver = r; rn->conf = a->receiver_conf; - rn->btrn = btr_new_node(r->name, NULL, NULL, rn); + rn->btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = r->name, .context = rn)); ret = r->open(rn); if (ret < 0) { btr_free_node(rn->btrn); @@ -1026,6 +1034,7 @@ static void close_stat_pipe(void) { if (!stat_task->ct) return; + btr_free_node(stat_task->ct->btrn); client_close(stat_task->ct); stat_task->ct = NULL; clear_and_dump_items(); @@ -1122,8 +1131,17 @@ static void start_stop_decoders(struct sched *s) sched_min_delay(s); } -/* restart the client task if necessary */ static void status_pre_select(struct sched *s, struct task *t) +{ + struct status_task *st = container_of(t, struct status_task, task); + int ret; + + ret = btr_node_status(st->btrn, 0, BTR_NT_LEAF); + sched_request_barrier(&st->restart_barrier, s); +} + +/* restart the client task if necessary */ +static void status_post_select(struct sched *s, struct task *t) { struct status_task *st = container_of(t, struct status_task, task); @@ -1131,7 +1149,7 @@ static void status_pre_select(struct sched *s, struct task *t) if (!st->ct) goto out; if (st->ct->task.error >= 0) { - st->ct->task.error = -E_AUDIOD_OFF; + kill_btrn(st->ct->btrn, &st->ct->task, -E_AUDIOD_OFF); goto out; } if (st->ct->task.error != -E_TASK_UNREGISTERED) @@ -1141,6 +1159,8 @@ static void status_pre_select(struct sched *s, struct task *t) goto out; } if (st->ct) { + char *buf; + size_t sz; int ret; if (st->ct->task.error < 0) { if (st->ct->task.error != -E_TASK_UNREGISTERED) @@ -1150,21 +1170,25 @@ static void status_pre_select(struct sched *s, struct task *t) } if (st->ct->status != CL_RECEIVING) goto out; - ret = for_each_stat_item(st->ct->buf, st->ct->loaded, - update_item); + ret = btr_node_status(st->btrn, 0, BTR_NT_LEAF); + if (ret <= 0) + goto out; + sz = btr_next_buffer(st->btrn, &buf); + ret = for_each_stat_item(buf, sz, update_item); if (ret < 0) { - st->ct->task.error = ret; + kill_btrn(st->ct->btrn, &st->ct->task, ret); goto out; } - if (st->ct->loaded != ret) { + if (sz != ret) st->last_status_read = *now; - st->ct->loaded = ret; - } else { + else { struct timeval diff; tv_diff(now, &st->last_status_read, &diff); if (diff.tv_sec > 61) - st->ct->task.error = -E_STATUS_TIMEOUT; + kill_btrn(st->ct->btrn, &st->ct->task, + -E_STATUS_TIMEOUT); } + btr_consume(st->btrn, sz - ret); goto out; } if (tv_diff(now, &st->restart_barrier, NULL) < 0) @@ -1174,14 +1198,14 @@ static void status_pre_select(struct sched *s, struct task *t) int argc = 5; PARA_INFO_LOG("clock diff count: %d\n", st->clock_diff_count); st->clock_diff_count--; - client_open(argc, argv, &st->ct, NULL); + client_open(argc, argv, &st->ct, NULL, NULL, st->btrn); set_stat_task_restart_barrier(2); sched_min_delay(s); } else { char *argv[] = {"audiod", "--", "stat", "-p", NULL}; int argc = 4; - client_open(argc, argv, &st->ct, NULL); + client_open(argc, argv, &st->ct, NULL, NULL, st->btrn); set_stat_task_restart_barrier(5); sched_min_delay(s); } @@ -1198,10 +1222,13 @@ static void init_status_task(struct status_task *st) { memset(st, 0, sizeof(struct status_task)); st->task.pre_select = status_pre_select; + st->task.post_select = status_post_select; st->sa_time_diff_sign = 1; st->clock_diff_count = conf.clock_diff_count_arg; st->current_audio_format_num = -1; - sprintf(st->task.status, "status task"); + sprintf(st->task.status, "stat"); + st->btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = "stat")); } static void set_initial_status(void)