From 4d425382c007b200121b4be5120db1acd30d292f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 30 Jun 2010 19:04:30 +0200 Subject: [PATCH] Introduce decoder_execute(). All four decoders support the same two commands: "sample_rate" and "channels". This patch adds a public function to filter_common.c which implements these two commands and is called by all decoders. This allows to kill four copies of code with identical functionality. --- aacdec_filter.c | 14 +------------- filter.h | 2 ++ filter_common.c | 30 ++++++++++++++++++++++++++++++ mp3dec_filter.c | 14 +------------- oggdec_filter.c | 14 +------------- wmadec_filter.c | 15 ++------------- 6 files changed, 37 insertions(+), 52 deletions(-) diff --git a/aacdec_filter.c b/aacdec_filter.c index 79c8bb66..2dd68448 100644 --- a/aacdec_filter.c +++ b/aacdec_filter.c @@ -60,19 +60,7 @@ static int aacdec_execute(struct btr_node *btrn, const char *cmd, char **result) struct filter_node *fn = btr_context(btrn); struct private_aacdec_data *padd = fn->private_data; - if (!strcmp(cmd, "sample_rate")) { - if (padd->sample_rate == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", padd->sample_rate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (padd->channels == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", padd->channels); - return 1; - } - return -ERRNO_TO_PARA_ERROR(ENOTSUP); + return decoder_execute(cmd, padd->sample_rate, padd->channels, result); } static void aacdec_open(struct filter_node *fn) diff --git a/filter.h b/filter.h index c34acca8..692020c4 100644 --- a/filter.h +++ b/filter.h @@ -120,6 +120,8 @@ void filter_init(void); int check_filter_arg(char *filter_arg, void **conf); void print_filter_helps(int detailed); void generic_filter_pre_select(struct sched *s, struct task *t); +int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels, + char **result); static inline void write_int16_host_endian(char *buf, int val) { diff --git a/filter_common.c b/filter_common.c index 06a1f52b..8e657f5a 100644 --- a/filter_common.c +++ b/filter_common.c @@ -136,3 +136,33 @@ void generic_filter_pre_select(struct sched *s, struct task *t) if (btr_node_status(fn->btrn, fn->min_iqs, BTR_NT_INTERNAL) != 0) sched_min_delay(s); } + +/** + * Execute a btr command for a decoder. + * + * The buffer tree nodes of the writers ask the parent nodes about sample_rate + * and the channels count. This function is called by all decoders to answer + * these queries. + * + * \param cmd The command to be executed by the child node. + * \param sample_rate Known to the decoder. + * \param channels Known to the decoder. + * \param result Ascii representation on the answer is stored here. + */ +int decoder_execute(const char *cmd, unsigned sample_rate, unsigned channels, + char **result) +{ + if (!strcmp(cmd, "sample_rate")) { + if (sample_rate == 0) + return -E_BTR_NAVAIL; + *result = make_message("%u", sample_rate); + return 1; + } + if (!strcmp(cmd, "channels")) { + if (channels == 0) + return -E_BTR_NAVAIL; + *result = make_message("%u", channels); + return 1; + } + return -ERRNO_TO_PARA_ERROR(ENOTSUP); +} diff --git a/mp3dec_filter.c b/mp3dec_filter.c index f03fbb76..c2c15a3a 100644 --- a/mp3dec_filter.c +++ b/mp3dec_filter.c @@ -236,19 +236,7 @@ static int mp3dec_execute(struct btr_node *btrn, const char *cmd, char **result) struct filter_node *fn = btr_context(btrn); struct private_mp3dec_data *pmd = fn->private_data; - if (!strcmp(cmd, "sample_rate")) { - if (pmd->sample_rate == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pmd->sample_rate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (pmd->channels == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pmd->channels); - return 1; - } - return -ERRNO_TO_PARA_ERROR(ENOTSUP); + return decoder_execute(cmd, pmd->sample_rate, pmd->channels, result); } static void mp3dec_free_config(void *conf) diff --git a/oggdec_filter.c b/oggdec_filter.c index 8a40ce0c..68b4db16 100644 --- a/oggdec_filter.c +++ b/oggdec_filter.c @@ -121,19 +121,7 @@ static int oggdec_execute(struct btr_node *btrn, const char *cmd, char **result) struct filter_node *fn = btr_context(btrn); struct private_oggdec_data *pod = fn->private_data; - if (!strcmp(cmd, "sample_rate")) { - if (pod->sample_rate == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pod->sample_rate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (pod->channels == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pod->channels); - return 1; - } - return -ERRNO_TO_PARA_ERROR(ENOTSUP); + return decoder_execute(cmd, pod->sample_rate, pod->channels, result); } static int ogg_init(struct filter_node *fn) diff --git a/wmadec_filter.c b/wmadec_filter.c index 88165b9a..aab7cf94 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -1208,19 +1208,8 @@ static int wmadec_execute(struct btr_node *btrn, const char *cmd, char **result) struct filter_node *fn = btr_context(btrn); struct private_wmadec_data *pwd = fn->private_data; - if (!strcmp(cmd, "sample_rate")) { - if (pwd->ahi.sample_rate == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pwd->ahi.sample_rate); - return 1; - } - if (!strcmp(cmd, "channels")) { - if (pwd->ahi.channels == 0) - return -E_BTR_NAVAIL; - *result = make_message("%u", pwd->ahi.channels); - return 1; - } - return -ERRNO_TO_PARA_ERROR(ENOTSUP); + return decoder_execute(cmd, pwd->ahi.sample_rate, pwd->ahi.channels, + result); } #define WMA_OUTPUT_BUFFER_SIZE (128 * 1024) -- 2.30.2