]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - alsa_write.c
alsa: Defer asking for samplerate/channels until alsa init time.
[paraslash.git] / alsa_write.c
index c7b09f3b06f65d73b79724b8fc04f970279efa3c..5959545f81e706ad3ebaa34ffb83104d139ca5fb 100644 (file)
 #include "list.h"
 #include "sched.h"
 #include "ggo.h"
+#include "buffer_tree.h"
 #include "write.h"
 #include "alsa_write.cmdline.h"
 #include "error.h"
-#include "buffer_tree.h"
 
 /** always use 16 bit little endian */
 #define FORMAT SND_PCM_FORMAT_S16_LE
@@ -151,49 +151,11 @@ static int alsa_open_nobtr(struct writer_node *wn)
 
 static int alsa_open_btr(struct writer_node *wn)
 {
-       struct alsa_write_args_info *conf = wn->conf;
        struct private_alsa_write_data *pad = para_calloc(sizeof(*pad));
-       int ret;
-       char *buf = NULL;
 
        sprintf(wn->task.status, "alsa writer");
        wn->private_data = pad;
-
-       /* defaults */
-       pad->samplerate = conf->samplerate_arg;
-       pad->channels = conf->channels_arg;
-
-       if (!conf->samplerate_given) { /* config option trumps btr_exec */
-               /* ask parent btr nodes */
-               ret = btr_exec_up(wn->btrn, "samplerate", &buf);
-               if (ret >= 0) {
-                       int32_t rate;
-                       ret = para_atoi32(buf, &rate);
-                       if (ret < 0) /* should not happen */
-                               goto out;
-                       pad->samplerate = rate;
-               }
-               freep(&buf);
-       }
-
-       if (!conf->channels_given) {
-               ret = btr_exec_up(wn->btrn, "channels", &buf);
-               if (ret >= 0) {
-                       int32_t ch;
-                       ret = para_atoi32(buf, &ch);
-                       if (ret < 0)
-                               goto out;
-                       pad->channels = ch;
-               }
-               freep(&buf);
-       }
-       PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->samplerate);
-       ret = 1;
-out:
-       freep(&buf);
-       if (ret < 0)
-               free(pad);
-       return ret;
+       return 1;
 }
 static int alsa_open(struct writer_node *wn)
 {
@@ -346,9 +308,44 @@ again:
        if (btr_no_parent(wn->btrn) && (!pad->handle || bytes < pad->bytes_per_frame))
                goto err;
        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(wn->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;
+                       }
+               }
+               if (!conf->channels_given) {
+                       buf = NULL;
+                       ret = btr_exec_up(wn->btrn, "channels", &buf);
+                       if (ret >= 0) {
+                               int32_t ch;
+
+                               ret = para_atoi32(buf, &ch);
+                               freep(&buf);
+                               if (ret < 0)
+                                       goto err;
+                               pad->channels = ch;
+                       }
+               }
+               PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->samplerate);
+               ret = 1;
                ret = alsa_init(pad, wn->conf);
                if (ret < 0)
                        goto err;