X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=write.c;h=c425c7cb72235ae2d8f620e04a633524fd917ea8;hp=ec27f3d35ac078824e03f33c3ba38572177ef38d;hb=c73d23911d78ed10179c12ef8f79a3fcf3bbcdaf;hpb=9b3b5e8babdf1fd13e2e5c18572f33d9a701cb4f diff --git a/write.c b/write.c index ec27f3d3..c425c7cb 100644 --- a/write.c +++ b/write.c @@ -1,22 +1,13 @@ /* - * Copyright (C) 2005-2006 Andre Noll + * Copyright (C) 2005-2007 Andre Noll * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Licensed under the GPL v2. For licencing details see COPYING. */ -/** \file write.c Paraslash's standalone wav/raw player */ +/** \file write.c Paraslash's standalone wav/raw player. */ + +#include +#include #include "para.h" #include "string.h" @@ -31,31 +22,27 @@ INIT_WRITE_ERRLISTS; -/** - * check if given buffer contains a valid wave header - */ +/** Check if given buffer contains a valid wave header. */ struct check_wav_task { - /** the buffer to check */ + /** The buffer to check. */ char *buf; - /** number of bytes loaded in \a buf */ + /** Number of bytes loaded in \a buf. */ size_t *loaded; - /** non-zero if end of file was reached */ - int *eof; - /** number of channels specified in wav header given by \a buf */ + /** Non-zero if an error occurred or end of file was reached. */ + int *error; + /** Number of channels specified in wav header given by \a buf. */ unsigned channels; - /** samplerate specified in wav header given by \a buf */ + /** Sample rate specified in wav header given by \a buf. */ unsigned samplerate; - /** the task structure for this task */ + /** The task structure for this task. */ struct task task; }; -/** - * delay writing until given time - */ +/** Delay writing until given time. */ struct initial_delay_task { - /** the time the first data should be written out */ + /** The time the first data should be written out. */ struct timeval start_time; - /** the task structure for this task */ + /** The task structure for this task. */ struct task task; }; @@ -65,14 +52,14 @@ static struct check_wav_task cwt; static struct initial_delay_task idt; static struct writer_node_group *wng; -/** length of a standard wav header */ +/** Length of a standard wav header. */ #define WAV_HEADER_LEN 44 /** - * test if audio buffer contains a valid wave header + * Test if audio buffer contains a valid wave header. * * \return If not, return -E_NO_WAV_HEADER, otherwise, return zero. If - * there is less than WAV_HEADER_LEN bytes awailable, return one. + * there is less than WAV_HEADER_LEN bytes available, return one. */ static void check_wav_pre_select(__a_unused struct sched *s, struct task *t) { @@ -80,7 +67,7 @@ static void check_wav_pre_select(__a_unused struct sched *s, struct task *t) unsigned char *a; if (*wt->loaded < WAV_HEADER_LEN) { - t->ret = *wt->eof? -E_PREMATURE_END : 1; + t->ret = *wt->error? -E_PREMATURE_END : 1; return; } wt->channels = 2; @@ -113,22 +100,7 @@ static void initial_delay_pre_select(struct sched *s, struct task *t) s->timeout = diff; } -/** - * all log messages are written to stderr - * - * \param ll: loglevel - * \param fmt: format string - */ -void para_log(int ll, const char* fmt,...) -{ - va_list argp; - - if (ll < conf.loglevel_arg) - return; - va_start(argp, fmt); - vfprintf(stderr, fmt, argp); - va_end(argp); -} +INIT_STDERR_LOGGING(conf.loglevel_arg) static struct writer_node_group *check_args(void) { @@ -184,7 +156,7 @@ static void wng_event_handler(struct task *t) { struct writer_node_group *g = t->private_data; - PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); + PARA_INFO_LOG("%s\n", para_strerror(-t->ret)); unregister_task(t); wng_close(g); } @@ -194,17 +166,17 @@ static void idt_event_handler(struct task *t) { int ret; - PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); + PARA_INFO_LOG("%s\n", para_strerror(-t->ret)); unregister_task(t); wng->buf = sit.buf; wng->loaded = &sit.loaded; - wng->input_eof = &sit.eof; + wng->input_error = &sit.error; wng->task.event_handler = wng_event_handler; wng->channels = &cwt.channels; wng->samplerate = &cwt.samplerate; ret = wng_open(wng); if (ret < 0) { - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + PARA_ERROR_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); } } @@ -212,10 +184,10 @@ static void idt_event_handler(struct task *t) static void cwt_event_handler(struct task *t) { if (t->ret != -E_NO_WAV_HEADER && t->ret != -E_WAV_HEADER_SUCCESS) { - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret)); + PARA_ERROR_LOG("%s\n", para_strerror(-t->ret)); exit(EXIT_FAILURE); } - PARA_INFO_LOG("%s\n", PARA_STRERROR(-t->ret)); + PARA_INFO_LOG("%s\n", para_strerror(-t->ret)); unregister_task(t); // if (t->ret == -E_WAV_HEADER_SUCCESS) { // conf.channels_arg = cwt.channels; @@ -229,11 +201,15 @@ static void cwt_event_handler(struct task *t) } /** - * para_write's main function + * Para_write's main function. + * + * \param argc The usual argument counter. + * \param argv The usual argument vector. * * It registers the stdin task, the check_wav_task, the task for initial delay * and all tasks for actually writing out the stream. * + * \return \p EXIT_SUCCESS or EXIT_FAILURE */ int main(int argc, char *argv[]) { @@ -241,6 +217,7 @@ int main(int argc, char *argv[]) struct sched s; write_cmdline_parser(argc, argv, &conf); + HANDLE_VERSION_FLAG("write", conf); init_supported_writers(); wng = check_args(); @@ -257,17 +234,17 @@ int main(int argc, char *argv[]) cwt.task.event_handler = cwt_event_handler; cwt.buf = sit.buf; cwt.loaded = &sit.loaded; - cwt.eof = &sit.eof; + cwt.error = &sit.error; sprintf(cwt.task.status, "check wav"); register_task(&cwt.task); s.default_timeout.tv_sec = 1; s.default_timeout.tv_usec = 0; - ret = sched(&s); + ret = schedule(&s); out: if (ret < 0) { - PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + PARA_ERROR_LOG("%s\n", para_strerror(-ret)); ret = EXIT_FAILURE; } else ret = EXIT_SUCCESS;