From e9caff38b33b06cf0bc90802539bffd13bfe07bc Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 30 Nov 2008 21:15:15 +0100 Subject: [PATCH] Create list of supported filters via autoconf. This allows to get rid of some CPP cruft in filter.h. --- aacdec.c | 2 +- amp_filter.c | 2 +- compress.c | 2 +- configure.ac | 10 +++++++++ filter.c | 2 +- filter.h | 56 ++++++-------------------------------------------- filter_chain.c | 11 +++++----- mp3dec.c | 2 +- oggdec.c | 2 +- wav.c | 2 +- 10 files changed, 29 insertions(+), 62 deletions(-) diff --git a/aacdec.c b/aacdec.c index 4c256946..38f69e88 100644 --- a/aacdec.c +++ b/aacdec.c @@ -183,7 +183,7 @@ static void aacdec_close(struct filter_node *fn) * * \sa filter::init */ -void aacdec_init(struct filter *f) +void aacdec_filter_init(struct filter *f) { f->open = aacdec_open; f->convert = aacdec; diff --git a/amp_filter.c b/amp_filter.c index 22784955..2f052601 100644 --- a/amp_filter.c +++ b/amp_filter.c @@ -90,7 +90,7 @@ static void amp_open(struct filter_node *fn) * * \param f Pointer to the struct to initialize. */ -void amp_init(struct filter *f) +void amp_filter_init(struct filter *f) { f->open = amp_open; f->close = amp_close; diff --git a/compress.c b/compress.c index 22dcfd33..d6f7520d 100644 --- a/compress.c +++ b/compress.c @@ -118,7 +118,7 @@ static void open_compress(struct filter_node *fn) * * \param f Pointer to the struct to initialize. */ -void compress_init(struct filter *f) +void compress_filter_init(struct filter *f) { f->open = open_compress; f->close = close_compress; diff --git a/configure.ac b/configure.ac index 63cbdc97..cdbdae46 100644 --- a/configure.ac +++ b/configure.ac @@ -706,6 +706,15 @@ AC_SUBST(fade_objs, add_dot_o($fade_objs)) AC_DEFINE_UNQUOTED(INIT_FADE_ERRLISTS, objlist_to_errlist($fade_errlist_objs), errors used by para_fade) + +enum="$(for i in $filters; do printf "${i}_FILTER, " | tr '[a-z]' '[A-Z]'; done)" +AC_DEFINE_UNQUOTED(FILTER_ENUM, $enum NUM_SUPPORTED_FILTERS, + enum of supported filters) +inits="$(for i in $filters; do printf 'extern void '$i'_filter_init(struct filter *f); '; done)" +AC_DEFINE_UNQUOTED(DECLARE_FILTER_INITS, $inits, init functions of the supported filters) +array="$(for i in $filters; do printf '{.name = \"'$i'\", .init = '$i'_filter_init},'; done)" +AC_DEFINE_UNQUOTED(FILTER_ARRAY, $array, array of supported filters) + enum="$(for i in $writers; do printf "${i}_WRITE, " | tr '[a-z]' '[A-Z]'; done)" AC_DEFINE_UNQUOTED(WRITER_ENUM, $enum NUM_SUPPORTED_WRITERS, enum of supported writers) @@ -716,6 +725,7 @@ inits="$(for i in $writers; do printf 'extern void '$i'_write_init(struct writer AC_DEFINE_UNQUOTED(DECLARE_WRITER_INITS, $inits, init functions of the supported writers) array="$(for i in $writers; do printf '{.init = '$i'_write_init},'; done)" AC_DEFINE_UNQUOTED(WRITER_ARRAY, $array, array of supported writers) + enum="$(for i in $audiod_audio_formats; do printf "AUDIO_FORMAT_${i}, " | tr '[a-z]' '[A-Z]'; done)" AC_DEFINE_UNQUOTED(AUDIOD_AUDIO_FORMATS_ENUM, $enum NUM_AUDIO_FORMATS, enum of audio formats supported by audiod) diff --git a/filter.c b/filter.c index adfadea7..b97bdaaa 100644 --- a/filter.c +++ b/filter.c @@ -121,7 +121,7 @@ static int parse_config(int argc, char *argv[]) if (!conf.list_filters_given) return 1; printf("available filters: "); - for (i = 0; filters[i].name; i++) + FOR_EACH_SUPPORTED_FILTER(i) printf("%s%s%s", i? " " : "", filters[i].name, filters[i].parse_config? "*": ""); printf("\nFilters marked with \"*\" have further command line options. Try\n" diff --git a/filter.h b/filter.h index 2d1c150a..2a75b186 100644 --- a/filter.h +++ b/filter.h @@ -6,6 +6,8 @@ /** \file filter.h Filter-related structures and exported symbols from filter_chain.c. */ +/** The list of supported filters. */ +enum filter_enum {FILTER_ENUM}; /** * Describes one running instance of a filter. @@ -220,55 +222,9 @@ static inline void write_int16_host_endian(char *buf, int val) #endif } +DECLARE_FILTER_INITS -/** \cond */ -extern struct filter filters[]; -#define DECLARE_EXTERN_FILTER_INIT(name) \ - extern void name ## _init(struct filter *f) - -#define FILTER_INIT(filter) { \ - .name = #filter, \ - .init = filter ## _init, \ - .parse_config = NULL, \ - .print_help = NULL \ -}, - -/* filters that are always present */ -DECLARE_EXTERN_FILTER_INIT(wav); -DECLARE_EXTERN_FILTER_INIT(compress); -DECLARE_EXTERN_FILTER_INIT(amp); - -/* next the optional filters */ -#ifdef HAVE_MAD -DECLARE_EXTERN_FILTER_INIT(mp3dec); -#define MP3DEC_FILTER FILTER_INIT(mp3dec) -#else -#define MP3DEC_FILTER -#endif - -#ifdef HAVE_FAAD -DECLARE_EXTERN_FILTER_INIT(aacdec); -#define AACDEC_FILTER FILTER_INIT(aacdec) -#else -#define AACDEC_FILTER -#endif - -#ifdef HAVE_OGGVORBIS -DECLARE_EXTERN_FILTER_INIT(oggdec); -#define OGGDEC_FILTER FILTER_INIT(oggdec) -#else -#define OGGDEC_FILTER -#endif -/** \endcond */ - -/** define an array of all available filters */ -#define DEFINE_FILTER_ARRAY(filters) struct filter filters[] = { \ - FILTER_INIT(wav) \ - FILTER_INIT(compress) \ - FILTER_INIT(amp) \ - MP3DEC_FILTER \ - AACDEC_FILTER \ - OGGDEC_FILTER \ - { .name = NULL } }; - +#define FOR_EACH_SUPPORTED_FILTER(j) for (j = 0; j < NUM_SUPPORTED_FILTERS; j++) +/** The filter array, one structure for each supported filter. */ +extern struct filter filters[NUM_SUPPORTED_FILTERS]; diff --git a/filter_chain.c b/filter_chain.c index def0a813..0da4533f 100644 --- a/filter_chain.c +++ b/filter_chain.c @@ -17,7 +17,8 @@ #include "error.h" #include "string.h" -DEFINE_FILTER_ARRAY(filters); +/** The array of supported filters. */ +struct filter filters[NUM_SUPPORTED_FILTERS] = {FILTER_ARRAY}; /** * Call the init function of each supported filter. @@ -28,10 +29,10 @@ DEFINE_FILTER_ARRAY(filters); */ void filter_init(struct filter *all_filters) { - struct filter *f; + int i; - for (f = all_filters; f->name; f++) - f->init(f); + FOR_EACH_SUPPORTED_FILTER(i) + all_filters[i].init(all_filters + i); } /** @@ -242,7 +243,7 @@ int check_filter_arg(char *fa, void **conf) *conf = NULL; // PARA_DEBUG_LOG("arg: %s\n", fa); - for (j = 0; filters[j].name; j++) { + FOR_EACH_SUPPORTED_FILTER(j) { const char *name = filters[j].name; size_t len = strlen(name); char c; diff --git a/mp3dec.c b/mp3dec.c index 0006a181..599d8a90 100644 --- a/mp3dec.c +++ b/mp3dec.c @@ -126,7 +126,7 @@ static void mp3dec_open(struct filter_node *fn) * * \sa filter::init. */ -void mp3dec_init(struct filter *f) +void mp3dec_filter_init(struct filter *f) { f->open = mp3dec_open; f->convert = mp3dec; diff --git a/oggdec.c b/oggdec.c index 46fb17ed..b4befd01 100644 --- a/oggdec.c +++ b/oggdec.c @@ -193,7 +193,7 @@ err: * * \param f Its fields are filled in by the function. */ -void oggdec_init(struct filter *f) +void oggdec_filter_init(struct filter *f) { f->open = ogg_open; f->close = ogg_close; diff --git a/wav.c b/wav.c index c03c21dc..ad3458d1 100644 --- a/wav.c +++ b/wav.c @@ -113,7 +113,7 @@ static void wav_open(struct filter_node *fn) * * \param f struct to initialize */ -void wav_init(struct filter *f) +void wav_filter_init(struct filter *f) { f->convert = wav_convert; f->close = wav_close; -- 2.39.2