X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=alsa_writer.c;h=617173a8f89c003158e724a51eae1beb23c3b39f;hp=ad65c92fb6df70db22ca569d140514beba0f13a0;hb=633f7c0f0194cd8ec3a478d820f55dd6a752d915;hpb=0610638110061ff05670a6c497b371bf2e1d4d0f diff --git a/alsa_writer.c b/alsa_writer.c index ad65c92f..617173a8 100644 --- a/alsa_writer.c +++ b/alsa_writer.c @@ -33,20 +33,20 @@ #include -#include "write.cmdline.h" +#include "alsa_write.cmdline.h" #include "error.h" -extern struct gengetopt_args_info conf; #define FORMAT SND_PCM_FORMAT_S16_LE /** data specific to the alsa writer */ struct private_alsa_data { -/** the alsa handle */ -snd_pcm_t *handle; -/** determined and set by alsa_open() */ -size_t bytes_per_frame; -struct timeval next_chunk; + /** the alsa handle */ + snd_pcm_t *handle; + /** determined and set by alsa_open() */ + size_t bytes_per_frame; + /** don't write anything until this time */ + struct timeval next_chunk; }; /* @@ -65,10 +65,11 @@ static int alsa_open(struct writer_node *w) snd_pcm_info_t *info; snd_pcm_uframes_t period_size; struct private_alsa_data *pad = para_calloc(sizeof(struct private_alsa_data)); - w->private_data = pad; + struct alsa_write_args_info *conf = w->conf; + w->private_data = pad; snd_pcm_info_alloca(&info); - err = snd_pcm_open(&pad->handle, conf.device_arg, + err = snd_pcm_open(&pad->handle, conf->device_arg, SND_PCM_STREAM_PLAYBACK, 0); if (err < 0) return -E_PCM_OPEN; @@ -85,10 +86,10 @@ static int alsa_open(struct writer_node *w) if (snd_pcm_hw_params_set_format(pad->handle, hwparams, FORMAT) < 0) return -E_SAMPLE_FORMAT; if (snd_pcm_hw_params_set_channels(pad->handle, hwparams, - conf.channels_arg) < 0) + conf->channels_arg) < 0) return -E_CHANNEL_COUNT; if (snd_pcm_hw_params_set_rate_near(pad->handle, hwparams, - (unsigned int*) &conf.sample_rate_arg, 0) < 0) + (unsigned int*) &conf->sample_rate_arg, 0) < 0) return -E_SET_RATE; err = snd_pcm_hw_params_get_buffer_time_max(hwparams, &buffer_time, 0); if (err < 0 || !buffer_time) @@ -127,7 +128,7 @@ static int alsa_open(struct writer_node *w) if (snd_pcm_sw_params(pad->handle, swparams) < 0) return -E_SW_PARAMS; pad->bytes_per_frame = snd_pcm_format_physical_width(FORMAT) - * conf.channels_arg / 8; + * conf->channels_arg / 8; // if (snd_pcm_nonblock(pad->handle, 1)) // PARA_ERROR_LOG("%s\n", "failed to set nonblock mode"); return period_size * pad->bytes_per_frame; @@ -140,7 +141,7 @@ static void alsa_write_pre_select(struct sched *s, struct task *t) struct timeval diff; t->ret = 0; - if (*wng->eof && *wng->loaded < pad->bytes_per_frame) + if (*wng->input_eof && *wng->loaded < pad->bytes_per_frame) return; t->ret = 1; if (*wng->loaded < pad->bytes_per_frame) @@ -165,7 +166,7 @@ static void alsa_write_post_select(struct sched *s, struct task *t) t->ret = 0; if (!frames) { - if (*wng->eof) + if (*wng->input_eof) t->ret = *wng->loaded; return; } @@ -208,6 +209,21 @@ static void alsa_close(struct writer_node *wn) free(pad); } +__malloc void *alsa_parse_config(char *options) +{ + struct alsa_write_args_info *conf + = para_calloc(sizeof(struct alsa_write_args_info)); + PARA_INFO_LOG("options: %s, %d\n", options, strcspn(options, " \t")); + int ret = alsa_cmdline_parser_string(options, conf, "alsa_write"); + if (ret) + goto err_out; + PARA_INFO_LOG("help given: %d\n", conf->help_given); + return conf; +err_out: + free(conf); + return NULL; +} + /** the init function of the alsa writer */ void alsa_writer_init(struct writer *w) { @@ -215,5 +231,6 @@ void alsa_writer_init(struct writer *w) w->close = alsa_close; w->pre_select = alsa_write_pre_select; w->post_select = alsa_write_post_select; + w->parse_config = alsa_parse_config; w->shutdown = NULL; /* nothing to do */ }