]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Deduplicate --channels and --sample-rate.
authorAndre Noll <maan@systemlinux.org>
Wed, 30 Jun 2010 16:40:47 +0000 (18:40 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 13 Jul 2010 12:39:16 +0000 (14:39 +0200)
These options are identical for all writers. Moreover, they only
make sense for para_write but are ignored for para_audiod.

So move these options from the writer-specific ggo file to write.m4,
the config file for para_write. The writers obtain the sample rate
and the channels count as before via the buffer tree exec mechanism,
but it is now the check_wav node rather than the btr node of the writer
that computes this information from the given option, the wav header
or the builtin default.

The new HANDLE_EXEC macro contains the logic for determining the
source of both the sample rate and the channels count.

alsa_write.c
ggo/alsa_write.m4
ggo/oss_write.ggo
ggo/osx_write.ggo
ggo/write.m4
oss_write.c
osx_write.c
write.c

index 240d51230fc2533e98de8cb6bbfc73ede69004bf..f24e117be072a757af58f57349e9f26e0e689ef4 100644 (file)
@@ -228,23 +228,19 @@ again:
                return;
        }
        if (!pad->handle) {
-               struct alsa_write_args_info *conf = wn->conf;
+               int32_t val;
                if (bytes == 0) /* no data available */
                        return;
-               /* defaults */
-               pad->sample_rate = conf->sample_rate_arg;
-               pad->channels = conf->channels_arg;
-               if (!conf->sample_rate_given) { /* config option trumps btr_exec */
-                       int32_t rate;
-                       if (get_btr_sample_rate(btrn, &rate) >= 0)
-                               pad->sample_rate = rate;
-               }
-               if (!conf->channels_given) {
-                       int32_t ch;
-                       if (get_btr_channels(btrn, &ch) >= 0)
-                               pad->channels = ch;
-               }
-               PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->sample_rate);
+               ret = get_btr_sample_rate(btrn, &val);
+               if (ret < 0)
+                       goto err;
+               pad->sample_rate = val;
+               ret = get_btr_channels(btrn, &val);
+               if (ret < 0)
+                       goto err;
+               pad->channels = val;
+               PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels,
+                       pad->sample_rate);
                ret = alsa_init(pad, wn->conf);
                if (ret < 0)
                        goto err;
index 54d0f72fdfe8de2930054d5adb755a8449c50041..d0cd4071cdcf44346c982976f324547cabcafe19 100644 (file)
@@ -11,28 +11,4 @@ details="
        On systems with dmix, a better choice than the default
        value might be to use \"plug:swmix\".
 "
-
-option "channels" c
-#~~~~~~~~~~~~~~~~~~
-"specify number of channels"
-int typestr="num"
-default="2"
-optional
-details="
-       This option is only necessary for playing raw audio with
-       para_write.  In all other cases (plaing wav files with
-       para_write or using this writer with para_audiod), the number
-       of channels will be obtained from other resources.
-"
-
-option "sample_rate" s
-#~~~~~~~~~~~~~~~~~~~~~
-"force given sample rate"
-int typestr="num"
-default="44100"
-optional
-details="
-       Again, it is only necessary to specify this when playing raw
-       audio with para_write.
-"
 </qu>
index 1f6f582595b2ff3d2dbfb138e3e85b346032e9e1..351561cd00c5daf9f8a00722a42a793d5bf49b6e 100644 (file)
@@ -4,27 +4,4 @@ option "device" d
 string typestr="device"
 default="/dev/dsp"
 optional
-
-option "channels" c
-#~~~~~~~~~~~~~~~~~~
-"specify number of channels"
-int typestr="num"
-default="2"
-optional
-details="
-       This option is only necessary for playing raw audio with
-       para_write.  In all other cases (plaing wav files with
-       para_write or using this writer with para_audiod), the number
-       of channels will be obtained from other resources.
-"
-
-option "sample_rate" s
-#~~~~~~~~~~~~~~~~~~~~~
-"force given sample rate"
-int typestr="num"
-default="44100"
-optional
-details="
-       Again, it is only necessary to specify this when playing raw
-       audio with para_write.
-"
+details = ""
index 8dca821245422fcb5aba2b963566cc9d8cdb9187..bee16d9e629c16acb8414407fefa8af2c1b7a992 100644 (file)
@@ -1,28 +1,6 @@
 section "osx options"
 #####################
 
-option "channels" c
-#~~~~~~~~~~~~~~~~~~
-"channel count"
-
-details = "
-       Specify the number of channels. This is only neccessary for raw audio.
-"
-
-       int typestr="num"
-       default="2"
-       optional
-
-option "sample_rate" s
-#~~~~~~~~~~~~~~~~~~~~~
-
-"force given sample rate (only neccessary for
-raw audio)"
-
-       int typestr="num"
-       default="44100"
-       optional
-
 option "numbuffers" n
 #~~~~~~~~~~~~~~~~~~~~~
 
@@ -32,3 +10,4 @@ you get buffer underruns)"
        int typestr="num"
        default="20"
        optional
+       details = ""
index d954316a40d1fe62ad9846b1dd803a83fb4cf2c0..847bd2054bb060332961a68749c665acfd9aa2bf 100644 (file)
@@ -12,3 +12,23 @@ details="
        May be give multiple times. The same writer may be specified
        more than once.
 "
+
+text "
+       The following options are only necessary for raw audio. When
+       playing wav files this information is obtained from the
+       wave header.
+"
+
+option "channels" c
+#~~~~~~~~~~~~~~~~~~
+"specify number of channels"
+int typestr = "num"
+default = "2"
+optional
+
+option "sample-rate" s
+#~~~~~~~~~~~~~~~~~~~~~
+"force given sample rate"
+int typestr = "num"
+default = "44100"
+optional
index 6ca1e16eaf62d33a54d58456d43779fb055c3bec..7acde1dacc42bcef0af94380109fc14f6ea55287 100644 (file)
@@ -146,7 +146,6 @@ static void oss_post_select(__a_unused struct sched *s,
                struct task *t)
 {
        struct writer_node *wn = container_of(t, struct writer_node, task);
-       struct oss_write_args_info *conf = wn->conf;
        struct private_oss_write_data *powd = wn->private_data;
        struct btr_node *btrn = wn->btrn;
        size_t frames, bytes;
@@ -159,16 +158,12 @@ static void oss_post_select(__a_unused struct sched *s,
                return;
        if (powd->fd < 0) {
                int32_t rate, ch;
-               ret = -1;
-               if (!conf->sample_rate_given) /* config option trumps btr_exec */
-                       ret = get_btr_sample_rate(wn->btrn, &rate);
+               ret = get_btr_sample_rate(btrn, &rate);
                if (ret < 0)
-                       rate = conf->sample_rate_arg;
-               ret = -1;
-               if (!conf->channels_given)
-                       ret = get_btr_channels(wn->btrn, &ch);
+                       goto out;
+               ret = get_btr_channels(btrn, &ch);
                if (ret < 0)
-                       ch = conf->channels_arg;
+                       goto out;
                ret = oss_init(wn, rate, ch);
                if (ret < 0)
                        goto out;
index cde7fcea867ef4bb35b9799f2c0b59dce455085e..209721cfd2a9bd4475fdab2d1211be14b15e9d84 100644 (file)
@@ -172,7 +172,7 @@ static int osx_write_open(struct writer_node *wn)
        AudioStreamBasicDescription format;
        int ret;
        struct btr_node *btrn = wn->btrn;
-       struct osx_write_args_info *conf = wn->conf;
+       int32_t val;
 
        wn->private_data = powd;
        /* where did that default audio output go? */
@@ -193,18 +193,14 @@ static int osx_write_open(struct writer_node *wn)
        if (AudioUnitInitialize(powd->audio_unit))
                goto e1;
        powd->play = 0;
-       powd->sample_rate = conf->sample_rate_arg;
-       powd->channels = conf->channels_arg;
-       if (!conf->sample_rate_given) {
-               int32_t rate;
-               get_btr_sample_rate(btrn, &rate);
-               powd->sample_rate = rate;
-       }
-       if (!conf->channels_given) {
-               int32_t ch;
-               get_btr_channels(btrn, &ch);
-               powd->channels = ch;
-       }
+       ret = get_btr_sample_rate(btrn, &val);
+       if (ret < 0)
+               goto e1;
+       powd->sample_rate = val;
+       ret = get_btr_channels(btrn, &val);
+       if (ret < 0)
+               goto e1;
+       powd->channels = val;
        /*
         * Choose PCM format. We tell the Output Unit what format we're going
         * to supply data to it. This is necessary if you're providing data
diff --git a/write.c b/write.c
index 7dc9f85ce3223b24678214b526dd76e35c1d2dcf..d2169f26c9ed499c300c03ca01a81b0c9f1963db 100644 (file)
--- a/write.c
+++ b/write.c
@@ -67,23 +67,22 @@ static void check_wav_pre_select(struct sched *s, struct task *t)
                sched_min_delay(s);
 }
 
+#define HANDLE_EXEC(_cmd) \
+       if (!strcmp(cmd, #_cmd)) { \
+               if (!conf._cmd ## _given && cwt->state == CWS_NEED_HEADER) \
+                       return -E_BTR_NAVAIL; \
+               *result = make_message("%d", cwt->state == CWS_NO_HEADER? \
+                       conf._cmd ## _arg : cwt->_cmd); \
+               return 1; \
+       } \
+
+
 static int check_wav_exec(struct btr_node *btrn, const char *cmd, char **result)
 {
        struct check_wav_task *cwt = btr_context(btrn);
 
-
-       if (!strcmp(cmd, "sample_rate")) {
-               if (cwt->state != CWS_HAVE_HEADER)
-                       return -E_BTR_NAVAIL;
-               *result = make_message("%d", cwt->sample_rate);
-               return 1;
-       }
-       if (!strcmp(cmd, "channels")) {
-               if (cwt->state != CWS_HAVE_HEADER)
-                       return -E_BTR_NAVAIL;
-               *result = make_message("%d", cwt->channels);
-               return 1;
-       }
+       HANDLE_EXEC(sample_rate);
+       HANDLE_EXEC(channels);
        return -ERRNO_TO_PARA_ERROR(ENOTSUP);
 }