snd_pcm_uframes_t period_size;
int err;
+ PARA_INFO_LOG("opening %s\n", conf->device_arg);
err = snd_pcm_open(&pad->handle, conf->device_arg,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0)
{
struct private_alsa_write_data *pad = para_calloc(sizeof(*pad));
- sprintf(wn->task.status, "alsa writer");
wn->private_data = pad;
return 1;
}
if (!pad->handle)
return 1;
if (wn->btrn) {
- int ret = btr_node_status(wn->btrn, wn->min_iqs);
+ int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return 1;
if (ret < 0) {
snd_pcm_close(pad->handle);
snd_config_update_free_global();
}
- alsa_cmdline_parser_free(wn->conf);
free(pad);
}
again:
t->error = 0;
- ret = btr_node_status(btrn, wn->min_iqs);
+ ret = btr_node_status(btrn, wn->min_iqs, BTR_NT_LEAF);
if (ret == 0)
return;
btr_merge(btrn, wn->min_iqs);
bytes = btr_next_buffer(btrn, &data);
- if (bytes < pad->bytes_per_frame) { /* eof */
+ if (ret < 0 || bytes < pad->bytes_per_frame) { /* eof */
assert(btr_no_parent(btrn));
ret = -E_ALSA_EOF;
if (!pad->handle)
avail = snd_pcm_avail_update(pad->handle);
if (avail + 1000 > pad->buffer_frames)
goto err;
+ PARA_DEBUG_LOG("waiting for device to drain\n");
return;
}
if (!pad->handle) {
- char *buf;
struct alsa_write_args_info *conf = wn->conf;
if (bytes == 0) /* no data available */
return;
- PARA_CRIT_LOG("alsa init\n");
/* defaults */
pad->samplerate = conf->samplerate_arg;
pad->channels = conf->channels_arg;
if (!conf->samplerate_given) { /* config option trumps btr_exec */
- /* ask parent btr nodes */
- buf = NULL;
- ret = btr_exec_up(btrn, "samplerate", &buf);
- PARA_CRIT_LOG("ret: %d\n", ret);
- if (ret >= 0) {
- int32_t rate;
-
- ret = para_atoi32(buf, &rate);
- free(buf);
- if (ret < 0) /* should not happen */
- goto err;
- pad->samplerate = rate;
- }
+ int32_t rate;
+ ret = get_btr_samplerate(btrn, &rate);
+ if (ret < 0)
+ goto err;
+ pad->samplerate = rate;
}
if (!conf->channels_given) {
- buf = NULL;
- ret = btr_exec_up(btrn, "channels", &buf);
- if (ret >= 0) {
- int32_t ch;
-
- ret = para_atoi32(buf, &ch);
- freep(&buf);
- if (ret < 0)
- goto err;
- pad->channels = ch;
- }
+ int32_t ch;
+ ret = get_btr_channels(btrn, &ch);
+ if (ret < 0)
+ goto err;
+ pad->channels = ch;
}
PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->samplerate);
ret = 1;
return NULL;
}
+static void alsa_free_config(void *conf)
+{
+ alsa_cmdline_parser_free(conf);
+}
+
/**
- * the init function of the alsa writer
+ * The init function of the alsa writer.
*
- * \param w pointer to the writer to initialize
+ * \param w Pointer to the writer to initialize.
*
- * \sa struct writer
+ * \sa \ref struct writer.
*/
void alsa_write_init(struct writer *w)
{
w->post_select_btr = alsa_write_post_select_btr;
w->parse_config = alsa_parse_config;
w->shutdown = NULL; /* nothing to do */
+ 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