X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=alsa_write.c;h=e75fa23067380244cd451eedc1c523fae3fb004f;hp=c99f26e413c9bce1b67386fee7d4eba29d8b518e;hb=393c52c9e726570a2ee287e9f7e103b619a28f73;hpb=3b3049ea42b0c754a0e1343a74591ce020cf1488 diff --git a/alsa_write.c b/alsa_write.c index c99f26e4..e75fa230 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -34,16 +34,21 @@ struct private_alsa_write_data { snd_pcm_t *handle; /** Determined and set by alsa_init(). */ int bytes_per_frame; - /** - * The sample rate given by command line option or the decoder - * of the writer node group. + /* + * If the sample rate is not given at the command line and no wav + * header was detected, the btr exec mechanism is employed to query the + * ancestor buffer tree nodes for this information. In a typical setup + * the decoder passes the sample rate back to the alsa writer. + * + * \sa \ref btr_exec_up(). */ unsigned sample_rate; - snd_pcm_format_t sample_format; - /** - * The number of channels, given by command line option or the - * decoder of the writer node group. + /* + * The sample format (8/16 bit, signed/unsigned, little/big endian) is + * determined in the same way as the \a sample_rate. */ + snd_pcm_format_t sample_format; + /* The number of channels, again determined like \a sample_rate. */ unsigned channels; struct timeval drain_barrier; /* File descriptor for select(). */ @@ -75,6 +80,7 @@ static int alsa_init(struct private_alsa_write_data *pad, unsigned buffer_time; int ret; const char *msg; + unsigned period_time; PARA_INFO_LOG("opening %s\n", conf->device_arg); msg = "unable to open pcm"; @@ -119,6 +125,13 @@ static int alsa_init(struct private_alsa_write_data *pad, &buffer_time, NULL); if (ret < 0) goto fail; + period_time = buffer_time / 4; + msg = "could not set period time"; + ret = snd_pcm_hw_params_set_period_time_near(pad->handle, hwparams, + &period_time, 0); + if (ret < 0) + goto fail; + msg = "unable to install hw params"; ret = snd_pcm_hw_params(pad->handle, hwparams); if (ret < 0) @@ -164,17 +177,19 @@ static int alsa_init(struct private_alsa_write_data *pad, goto fail; ret = snd_output_buffer_open(&output_log); if (ret == 0) { - char *buf; - PARA_INFO_LOG("dumping alsa configuration\n"); + char *buf, *p; + size_t sz; + PARA_DEBUG_LOG("dumping alsa configuration\n"); snd_pcm_dump(pad->handle, output_log); - snd_output_buffer_string(output_log, &buf); - for (;;) { - char *p = strchr(buf, '\n'); - if (!p) /* omit last output line, it's empty */ + snd_pcm_hw_params_dump(hwparams, output_log); + sz = snd_output_buffer_string(output_log, &buf); + for (p = buf; p < buf + sz;) { + char *q = memchr(p, '\n', buf + sz - p); + if (!q) break; - *p = '\0'; - PARA_INFO_LOG("%s\n", buf); - buf = p + 1; + *q = '\0'; + PARA_DEBUG_LOG("%s\n", p); + p = q + 1; } snd_output_close(output_log); } @@ -210,7 +225,6 @@ static void alsa_write_pre_select(struct sched *s, struct task *t) if (ret < 0) { PARA_ERROR_LOG("could not get alsa poll fd: %s\n", snd_strerror(-ret)); - t->error = -E_ALSA; return; } pad->poll_fd = pfd.fd; @@ -357,13 +371,9 @@ void alsa_write_init(struct writer *w) alsa_write_cmdline_parser_init(&dummy); w->close = alsa_close; w->pre_select = alsa_write_pre_select; - w->new_post_select = alsa_write_post_select; - w->post_select = NULL; + w->post_select = alsa_write_post_select; w->parse_config_or_die = alsa_parse_config_or_die; w->free_config = alsa_free_config; - w->help = (struct ggo_help) { - .short_help = alsa_write_args_info_help, - .detailed_help = alsa_write_args_info_detailed_help - }; + w->help = (struct ggo_help)DEFINE_GGO_HELP(alsa_write); alsa_write_cmdline_parser_free(&dummy); }