alsa: Dump the configuration on startup.
authorAndre Noll <maan@systemlinux.org>
Tue, 26 Jul 2011 20:47:20 +0000 (22:47 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 18 Oct 2011 17:29:33 +0000 (19:29 +0200)
Currently we log selected alsa parameters, but it is sometimes
useful to see the full configuration. This patch adds a call to
snd_pcm_dump() to alsa_init() which obtains the alsa hardware and
software configuration. It is printed for loglevels info and debug.

alsa_write.c

index b89c8c3..a7539ba 100644 (file)
@@ -77,6 +77,7 @@ static int alsa_init(struct private_alsa_write_data *pad,
        snd_pcm_sw_params_t *swparams;
        snd_pcm_uframes_t start_threshold, stop_threshold;
        snd_pcm_uframes_t period_size;
+       snd_output_t *log;
        int err;
 
        PARA_INFO_LOG("opening %s\n", conf->device_arg);
@@ -105,7 +106,6 @@ static int alsa_init(struct private_alsa_write_data *pad,
                &pad->buffer_time, NULL);
        if (err < 0 || !pad->buffer_time)
                return -E_GET_BUFFER_TIME;
-       PARA_INFO_LOG("buffer time: %d\n", pad->buffer_time);
        if (snd_pcm_hw_params_set_buffer_time_near(pad->handle, hwparams,
                        &pad->buffer_time, NULL) < 0)
                return -E_SET_BUFFER_TIME;
@@ -113,8 +113,6 @@ static int alsa_init(struct private_alsa_write_data *pad,
                return -E_HW_PARAMS;
        snd_pcm_hw_params_get_period_size(hwparams, &period_size, NULL);
        snd_pcm_hw_params_get_buffer_size(hwparams, &pad->buffer_frames);
-       PARA_INFO_LOG("buffer size: %lu, period_size: %lu\n", pad->buffer_frames,
-               period_size);
        if (period_size == pad->buffer_frames)
                return -E_BAD_PERIOD;
        snd_pcm_sw_params_current(pad->handle, swparams);
@@ -137,9 +135,24 @@ static int alsa_init(struct private_alsa_write_data *pad,
                * 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");
+       err = snd_output_buffer_open(&log);
+       if (err == 0) {
+               char *buf;
+               PARA_INFO_LOG("dumping alsa configuration\n");
+               snd_pcm_dump(pad->handle, log);
+               snd_output_buffer_string(log, &buf);
+               for (;;) {
+                       char *p = strchr(buf, '\n');
+                       if (!p) /* omit last output line, it's empty */
+                               break;
+                       *p = '\0';
+                       PARA_INFO_LOG("%s\n", buf);
+                       buf = p + 1;
+               }
+               snd_output_close(log);
+       }
        return 1;
 }