From 009e80ae25df7a247a263b5b8e2259c9bdfe20ce Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 1 Jul 2010 11:44:16 +0200 Subject: [PATCH] write: Make get_btr_value() return void. 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 | 8 ++------ oss_write.c | 8 ++------ osx_write.c | 8 ++------ write_common.c | 18 +++++++++--------- write_common.h | 6 +++--- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/alsa_write.c b/alsa_write.c index f24e117b..09cca93f 100644 --- a/alsa_write.c +++ b/alsa_write.c @@ -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); diff --git a/oss_write.c b/oss_write.c index 7acde1da..ea31fc81 100644 --- a/oss_write.c +++ b/oss_write.c @@ -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; diff --git a/osx_write.c b/osx_write.c index 209721cf..65a5adc7 100644 --- a/osx_write.c +++ b/osx_write.c @@ -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 diff --git a/write_common.c b/write_common.c index 0d30eb80..b73ba9a1 100644 --- a/write_common.c +++ b/write_common.c @@ -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); } diff --git a/write_common.h b/write_common.h index 785161ef..74f8e1c4 100644 --- a/write_common.h +++ b/write_common.h @@ -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); -- 2.30.2