write: Make get_btr_value() return void.
authorAndre Noll <maan@systemlinux.org>
Thu, 1 Jul 2010 09:44:16 +0000 (11:44 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 13 Jul 2010 12:39:16 +0000 (14:39 +0200)
Asking upper buffer tree nodes for the sample rate and the channels
count should never fail, because the writer only asks if there is
already some output data to process.

So, replace the tests by assertions, change the return value
of get_btr_value() to void and fix up all callers accordingly.
This simplifies the code a bit.

alsa_write.c
oss_write.c
osx_write.c
write_common.c
write_common.h

index f24e117..09cca93 100644 (file)
@@ -231,13 +231,9 @@ again:
                int32_t val;
                if (bytes == 0) /* no data available */
                        return;
-               ret = get_btr_sample_rate(btrn, &val);
-               if (ret < 0)
-                       goto err;
+               get_btr_sample_rate(btrn, &val);
                pad->sample_rate = val;
-               ret = get_btr_channels(btrn, &val);
-               if (ret < 0)
-                       goto err;
+               get_btr_channels(btrn, &val);
                pad->channels = val;
                PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels,
                        pad->sample_rate);
index 7acde1d..ea31fc8 100644 (file)
@@ -158,12 +158,8 @@ static void oss_post_select(__a_unused struct sched *s,
                return;
        if (powd->fd < 0) {
                int32_t rate, ch;
-               ret = get_btr_sample_rate(btrn, &rate);
-               if (ret < 0)
-                       goto out;
-               ret = get_btr_channels(btrn, &ch);
-               if (ret < 0)
-                       goto out;
+               get_btr_sample_rate(btrn, &rate);
+               get_btr_channels(btrn, &ch);
                ret = oss_init(wn, rate, ch);
                if (ret < 0)
                        goto out;
index 209721c..65a5adc 100644 (file)
@@ -193,13 +193,9 @@ static int osx_write_open(struct writer_node *wn)
        if (AudioUnitInitialize(powd->audio_unit))
                goto e1;
        powd->play = 0;
-       ret = get_btr_sample_rate(btrn, &val);
-       if (ret < 0)
-               goto e1;
+       get_btr_sample_rate(btrn, &val);
        powd->sample_rate = val;
-       ret = get_btr_channels(btrn, &val);
-       if (ret < 0)
-               goto e1;
+       get_btr_channels(btrn, &val);
        powd->channels = val;
        /*
         * Choose PCM format. We tell the Output Unit what format we're going
index 0d30eb8..b73ba9a 100644 (file)
@@ -147,30 +147,30 @@ void print_writer_helps(int detailed)
        }
 }
 
-static int get_btr_value(struct btr_node *btrn, const char *key, int32_t *result)
+static void get_btr_value(struct btr_node *btrn, const char *cmd,
+               int32_t *result)
 {
        char *buf = NULL;
-       int ret = btr_exec_up(btrn, key, &buf);
+       int ret = btr_exec_up(btrn, cmd, &buf);
 
-       if (ret < 0)
-               return ret;
+       assert(ret >= 0);
        ret = para_atoi32(buf, result);
+       assert(ret >= 0);
        free(buf);
-       return ret;
 }
 
 /*
  * Ask parent btr nodes for the sample rate of the current stream.
  */
-int get_btr_sample_rate(struct btr_node *btrn, int32_t *result)
+void get_btr_sample_rate(struct btr_node *btrn, int32_t *result)
 {
-       return get_btr_value(btrn, "sample_rate", result);
+       get_btr_value(btrn, "sample_rate", result);
 }
 
 /*
  * Ask parent btr nodes for the channel count of the current stream.
  */
-int get_btr_channels(struct btr_node *btrn, int32_t *result)
+void get_btr_channels(struct btr_node *btrn, int32_t *result)
 {
-       return get_btr_value(btrn, "channels", result);
+       get_btr_value(btrn, "channels", result);
 }
index 785161e..74f8e1c 100644 (file)
@@ -4,7 +4,7 @@
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
 
-/** \file write_common.h Exported symbols from write_common.c */
+/** \file write_common.h Exported symbols from write_common.c. */
 
 void writer_init(void);
 void *check_writer_arg(const char *wa, int *writer_num);
@@ -12,5 +12,5 @@ void print_writer_helps(int detailed);
 void register_writer_node(struct writer_node *wn, struct btr_node *parent);
 int setup_writer_node(const char *arg, struct btr_node *parent,
                struct writer_node *wn);
-int get_btr_sample_rate(struct btr_node *btrn, int32_t *result);
-int get_btr_channels(struct btr_node *btrn, int32_t *result);
+void get_btr_sample_rate(struct btr_node *btrn, int32_t *result);
+void get_btr_channels(struct btr_node *btrn, int32_t *result);