- if (snd_pcm_sw_params_set_start_threshold(pad->handle, swparams,
- start_threshold) < 0)
- return -E_START_THRESHOLD;
- stop_threshold = pad->buffer_frames;
- if (snd_pcm_sw_params_set_stop_threshold(pad->handle, swparams,
- stop_threshold) < 0)
- return -E_STOP_THRESHOLD;
- if (snd_pcm_sw_params(pad->handle, swparams) < 0)
- PARA_WARNING_LOG("unable to install sw params\n");
- pad->bytes_per_frame = snd_pcm_format_physical_width(pad->sample_format)
- * pad->channels / 8;
- if (pad->bytes_per_frame <= 0)
- return -E_PHYSICAL_WIDTH;
- PARA_INFO_LOG("bytes per frame: %d\n", pad->bytes_per_frame);
- if (snd_pcm_nonblock(pad->handle, 1))
- PARA_ERROR_LOG("failed to set nonblock mode\n");
- return 1;
-}
-
-/* Open an instance of the alsa writer. */
-static int alsa_open(struct writer_node *wn)
-{
- wn->private_data = para_calloc(sizeof(struct private_alsa_write_data));
- return 1;
+ msg = "could not set start threshold";
+ ret = snd_pcm_sw_params_set_start_threshold(pad->handle, swparams,
+ start_threshold);
+ if (ret < 0)
+ goto fail;
+ stop_threshold = buffer_size;
+ msg = "could not set stop threshold";
+ ret = snd_pcm_sw_params_set_stop_threshold(pad->handle, swparams,
+ stop_threshold);
+ if (ret < 0)
+ goto fail;
+ msg = "unable to install sw params";
+ ret = snd_pcm_sw_params(pad->handle, swparams);
+ if (ret < 0)
+ goto fail;
+ msg = "unable to determine bytes per frame";
+ ret = snd_pcm_format_physical_width(pad->sample_format);
+ if (ret <= 0)
+ goto fail;
+ pad->bytes_per_frame = ret * pad->channels / 8;
+ msg = "failed to set alsa handle to nonblock mode";
+ ret = snd_pcm_nonblock(pad->handle, 1);
+ if (ret < 0)
+ goto fail;
+ ret = snd_output_buffer_open(&output_log);
+ if (ret == 0) {
+ char *buf, *p;
+ size_t sz;
+ PARA_DEBUG_LOG("dumping alsa configuration\n");
+ snd_pcm_dump(pad->handle, output_log);
+ 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;
+ *q = '\0';
+ PARA_DEBUG_LOG("%s\n", p);
+ p = q + 1;
+ }
+ snd_output_close(output_log);
+ }
+ ret = 1;
+ goto out;
+fail:
+ if (ret < 0)
+ PARA_ERROR_LOG("%s: %s\n", msg, snd_strerror(-ret));
+ else
+ PARA_ERROR_LOG("%s\n", msg);
+ ret = -E_ALSA;
+out:
+ snd_pcm_hw_params_free(hwparams);
+ snd_pcm_sw_params_free(swparams);
+ return ret;