]> git.tue.mpg.de Git - paraslash.git/commitdiff
alsa: Defer asking for samplerate/channels until alsa init time.
authorAndre Noll <maan@systemlinux.org>
Thu, 31 Dec 2009 17:37:20 +0000 (18:37 +0100)
committerAndre Noll <maan@systemlinux.org>
Thu, 31 Dec 2009 17:37:20 +0000 (18:37 +0100)
alsa_write.c

index e1c5ce312e6ce8f6af6d81c9070b5899e40f1398..5959545f81e706ad3ebaa34ffb83104d139ca5fb 100644 (file)
@@ -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;