]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Introduce decoder_execute().
authorAndre Noll <maan@systemlinux.org>
Wed, 30 Jun 2010 17:04:30 +0000 (19:04 +0200)
committerAndre Noll <maan@systemlinux.org>
Tue, 13 Jul 2010 12:39:16 +0000 (14:39 +0200)
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
filter.h
filter_common.c
mp3dec_filter.c
oggdec_filter.c
wmadec_filter.c

index 79c8bb660a9a94708b1d540d00d35b4795e0ba24..2dd68448b3b130172ba3417cb20eedcfc1fff262 100644 (file)
@@ -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)
index c34acca8e96063804fd0d4cf788ac27658ca94b7..692020c40ca80fcd7dd008d59095d7df469d9399 100644 (file)
--- 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)
 {
index 06a1f52bf15012c556b7b3443e8a5e51b5ac4f16..8e657f5a4e880ea3968991974a8c07e1e75d96db 100644 (file)
@@ -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);
+}
index f03fbb76d4c004f1b439bb26bbfbe6414d7b07cf..c2c15a3aeacd1e2b9b6d613efacd99345f30eb61 100644 (file)
@@ -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)
index 8a40ce0c56192041bac5edcc9e00a76dd82dcaa8..68b4db160662b5952136b015b33b17d8419f4907 100644 (file)
@@ -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)
index 88165b9a073222e8779e15965caba59023c1520b..aab7cf94f76adc0311aa6cd925da00ad5d8323a4 100644 (file)
@@ -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)