X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=write.c;h=d2169f26c9ed499c300c03ca01a81b0c9f1963db;hp=103f2acc97c1cb781226c9192dacf42899c060c8;hb=009e80ae25df7a247a263b5b8e2259c9bdfe20ce;hpb=f1401e9c2d74154a81d16e2d1a2413e7125abb15 diff --git a/write.c b/write.c index 103f2acc..d2169f26 100644 --- a/write.c +++ b/write.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2009 Andre Noll + * Copyright (C) 2005-2010 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -37,7 +37,7 @@ struct check_wav_task { /** Number of channels specified in wav header given by \a buf. */ unsigned channels; /** Sample rate specified in wav header given by \a buf. */ - unsigned samplerate; + unsigned sample_rate; /** The task structure used by the scheduler. */ struct task task; struct btr_node *btrn; @@ -67,23 +67,22 @@ static void check_wav_pre_select(struct sched *s, struct task *t) sched_min_delay(s); } +#define HANDLE_EXEC(_cmd) \ + if (!strcmp(cmd, #_cmd)) { \ + if (!conf._cmd ## _given && cwt->state == CWS_NEED_HEADER) \ + return -E_BTR_NAVAIL; \ + *result = make_message("%d", cwt->state == CWS_NO_HEADER? \ + conf._cmd ## _arg : cwt->_cmd); \ + return 1; \ + } \ + + static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result) { struct check_wav_task *cwt = btr_context(btrn); - - if (!strcmp(cmd, "samplerate")) { - if (cwt->state != CWS_HAVE_HEADER) - return -ERRNO_TO_PARA_ERROR(ENAVAIL); - *result = make_message("%d", cwt->samplerate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (cwt->state != CWS_HAVE_HEADER) - return -ERRNO_TO_PARA_ERROR(ENAVAIL); - *result = make_message("%d", cwt->channels); - return 1; - } + HANDLE_EXEC(sample_rate); + HANDLE_EXEC(channels); return -ERRNO_TO_PARA_ERROR(ENOTSUP); } @@ -107,7 +106,7 @@ static void check_wav_post_select(__a_unused struct sched *s, struct task *t) goto pushdown; cwt->min_iqs = 0; cwt->channels = 2; - cwt->samplerate = 44100; + cwt->sample_rate = 44100; if (a[0] != 'R' || a[1] != 'I' || a[2] != 'F' || a[3] != 'F') { PARA_NOTICE_LOG("wav header not found\n"); cwt->state = CWS_NO_HEADER; @@ -118,8 +117,8 @@ static void check_wav_post_select(__a_unused struct sched *s, struct task *t) 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); - PARA_INFO_LOG("channels: %d, sample rate: %d\n", cwt->channels, cwt->samplerate); + cwt->sample_rate = a[24] + (a[25] << 8) + (a[26] << 16) + (a[27] << 24); + PARA_INFO_LOG("channels: %d, sample rate: %d\n", cwt->channels, cwt->sample_rate); btr_consume(btrn, WAV_HEADER_LEN); pushdown: btr_pushdown(btrn); @@ -154,14 +153,17 @@ static int main_btr(struct sched *s) struct writer_node *wns; loglevel = get_loglevel_by_name(conf.loglevel_arg); - sit.btrn = btr_new_node("stdin", NULL /* stdin has no parent */, NULL, NULL); + sit.btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = "stdin")); stdin_set_defaults(&sit); register_task(&sit.task); cwt->state = CWS_NEED_HEADER; cwt->min_iqs = WAV_HEADER_LEN; - cwt->btrn = btr_new_node("check wav", sit.btrn, check_wav_exec, cwt); - sprintf(cwt->task.status, "check wav"); + cwt->btrn = btr_new_node(&(struct btr_node_description) + EMBRACE(.name = "check_wav", .parent = sit.btrn, + .handler = check_wav_exec, .context = cwt)); + sprintf(cwt->task.status, "check_wav"); cwt->task.pre_select = check_wav_pre_select; cwt->task.post_select = check_wav_post_select; cwt->task.error = 0;