X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=write.c;h=f79daf237e286dfc6821d06ad93dfdaa49bab84a;hp=def31334e5f89c0efc46055b8b28171a6107f614;hb=aa234b7afe223879a7bd7274ce05a3a315a2ec49;hpb=651d670fd60c8699ef9fd92a41e1c6dc9c84c683 diff --git a/write.c b/write.c index def31334..f79daf23 100644 --- a/write.c +++ b/write.c @@ -134,6 +134,7 @@ static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result) { struct check_wav_task_btr *cwt = btr_context(btrn); + if (!strcmp(cmd, "samplerate")) { if (cwt->state != CWS_HAVE_HEADER) return -ERRNO_TO_PARA_ERROR(ENAVAIL); @@ -143,7 +144,7 @@ static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result) if (!strcmp(cmd, "channels")) { if (cwt->state != CWS_HAVE_HEADER) return -ERRNO_TO_PARA_ERROR(ENAVAIL); - *result = make_message("%d", cwt->samplerate); + *result = make_message("%d", cwt->channels); return 1; } return -ERRNO_TO_PARA_ERROR(ENOTSUP); @@ -175,28 +176,25 @@ static void check_wav_post_select_btr(__a_unused struct sched *s, struct task *t PARA_NOTICE_LOG("wav header not found\n"); cwt->state = CWS_NO_HEADER; sprintf(t->status, "check wav: no header"); - goto consume; + goto out; } PARA_INFO_LOG("found wav header\n"); cwt->state = CWS_HAVE_HEADER; sprintf(t->status, "check wav: have header"); cwt->channels = (unsigned) a[22]; cwt->samplerate = a[24] + (a[25] << 8) + (a[26] << 16) + (a[27] << 24); -consume: PARA_INFO_LOG("channels: %d, sample rate: %d\n", cwt->channels, cwt->samplerate); btr_consume(cwt->btrn, WAV_HEADER_LEN); out: - if (sz) { + if (sz) btr_pushdown(cwt->btrn); - s->timeout.tv_sec = 0; - s->timeout.tv_usec = 1; - } else { + else { if (btr_no_parent(cwt->btrn)) t->error = -E_WRITE_EOF; } err: if (t->error < 0) - btr_del_node(cwt->btrn); + btr_remove_node(cwt->btrn); } static void initial_delay_pre_select(struct sched *s, struct task *t) @@ -298,36 +296,37 @@ static int main_btr(struct sched *s) cwt->task.error = 0; register_task(&cwt->task); - wns = para_malloc(conf.writer_given * sizeof(*wns)); + PARA_CRIT_LOG("writers:\n"); - for (i = 0; i < conf.writer_given; i++) { - struct writer_node *wn = para_calloc(sizeof(*wn)); - struct writer *w; - const char *name; - - ret = -E_WRITE_SYNTAX; - wn->conf = check_writer_arg(conf.writer_arg[i], - &wn->writer_num); - if (!wn->conf) + ret = -E_WRITE_SYNTAX; + if (!conf.writer_given) { + i = 0; + wns = para_malloc(sizeof(*wns)); + wns[0] = setup_writer_node(NULL, cwt->btrn); + if (!wns[0]) goto out; - w = writers + wn->writer_num; - name = writer_names[wn->writer_num]; - wn->btrn = btr_new_node(name, cwt->btrn, w->execute, wn); - sprintf(wn->task.status, "%s", name); - w->open(wn); - wn->task.post_select = w->post_select_btr; - wn->task.pre_select = w->pre_select_btr; - register_task(&wn->task); - wns[i] = wn; + i = 1; + } else { + wns = para_malloc(conf.writer_given * sizeof(*wns)); + for (i = 0; i < conf.writer_given; i++) { + PARA_CRIT_LOG("i: %d\n", i); + wns[i] = setup_writer_node(conf.writer_arg[i], + cwt->btrn); + if (!wns[i]) + goto out; + } } - i--; s->default_timeout.tv_sec = 10; s->default_timeout.tv_usec = 50000; ret = schedule(s); out: - for (; i >= 0; i--) { + for (i--; i >= 0; i--) { struct writer_node *wn = wns[i]; + struct writer *w = writers + wn->writer_num; + + w->close(wn); + btr_free_node(wn->btrn); free(wn->conf); free(wn); }