diff options
author | Max Kellermann <max@duempel.org> | 2008-11-01 14:53:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-01 14:53:30 +0100 |
commit | 1a4a3e1f1f09ade38095757952bbf732ec275fe8 (patch) | |
tree | 465860e3457d06639aea949175ba8776f585dec7 /src | |
parent | 5036368f540af93372b750fe80e1c191b409a7a9 (diff) | |
download | mpd-1a4a3e1f1f09ade38095757952bbf732ec275fe8.tar.gz mpd-1a4a3e1f1f09ade38095757952bbf732ec275fe8.tar.xz mpd-1a4a3e1f1f09ade38095757952bbf732ec275fe8.zip |
decoder: manage decoder list in a static array
Currently, there is no way to dynamically load decoder plugins, thus
we don't need a dynamic list to manage them.
Diffstat (limited to 'src')
-rw-r--r-- | src/decoder_api.c | 11 | ||||
-rw-r--r-- | src/decoder_api.h | 4 | ||||
-rw-r--r-- | src/decoder_list.c | 168 | ||||
-rw-r--r-- | src/decoder_list.h | 4 |
4 files changed, 78 insertions, 109 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c index d9ac186e3..77f5b0215 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -18,7 +18,6 @@ */ #include "decoder_internal.h" -#include "decoder_list.h" #include "decoder_control.h" #include "player_control.h" #include "audio.h" @@ -31,16 +30,6 @@ #include <assert.h> -void decoder_plugin_register(struct decoder_plugin *plugin) -{ - decoder_plugin_load(plugin); -} - -void decoder_plugin_unregister(struct decoder_plugin *plugin) -{ - decoder_plugin_unload(plugin); -} - void decoder_initialized(struct decoder * decoder, const struct audio_format *audio_format, float total_time) diff --git a/src/decoder_api.h b/src/decoder_api.h index 1400f52c2..911a4e3eb 100644 --- a/src/decoder_api.h +++ b/src/decoder_api.h @@ -103,10 +103,6 @@ struct decoder_plugin { }; -void decoder_plugin_register(struct decoder_plugin *plugin); - -void decoder_plugin_unregister(struct decoder_plugin *plugin); - /** * Opaque handle which the decoder plugin passes to the functions in * this header. diff --git a/src/decoder_list.c b/src/decoder_list.c index e99f6a5fd..99d490777 100644 --- a/src/decoder_list.c +++ b/src/decoder_list.c @@ -18,7 +18,8 @@ #include "decoder_list.h" #include "decoder_api.h" -#include "list.h" + +#include <glib.h> extern struct decoder_plugin mp3Plugin; extern struct decoder_plugin oggvorbisPlugin; @@ -32,27 +33,46 @@ extern struct decoder_plugin wavpackPlugin; extern struct decoder_plugin modPlugin; extern struct decoder_plugin ffmpegPlugin; -static List *inputPlugin_list; - -void decoder_plugin_load(struct decoder_plugin * inputPlugin) -{ - if (!inputPlugin) - return; - if (!inputPlugin->name) - return; - - if (inputPlugin->init != NULL && !inputPlugin->init()) - return; +static const struct decoder_plugin *const decoder_plugins[] = { +#ifdef HAVE_MAD + &mp3Plugin, +#endif +#ifdef HAVE_OGGVORBIS + &oggvorbisPlugin, +#endif +#ifdef HAVE_FLAC_COMMON + &oggflacPlugin, +#endif +#ifdef HAVE_FLAC + &flacPlugin, +#endif +#ifdef HAVE_AUDIOFILE + &audiofilePlugin, +#endif +#ifdef HAVE_FAAD + &mp4Plugin, + &aacPlugin, +#endif +#ifdef HAVE_MPCDEC + &mpcPlugin, +#endif +#ifdef HAVE_WAVPACK + &wavpackPlugin, +#endif +#ifdef HAVE_MIKMOD + &modPlugin, +#endif +#ifdef HAVE_FFMPEG + &ffmpegPlugin, +#endif +}; - insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin); -} +enum { + num_decoder_plugins = G_N_ELEMENTS(decoder_plugins), +}; -void decoder_plugin_unload(struct decoder_plugin * inputPlugin) -{ - if (inputPlugin->finish != NULL) - inputPlugin->finish(); - deleteFromList(inputPlugin_list, inputPlugin->name); -} +/** which plugins have been initialized successfully? */ +static bool decoder_plugins_enabled[num_decoder_plugins]; static int stringFoundInStringArray(const char *const*array, const char *suffix) { @@ -68,28 +88,20 @@ static int stringFoundInStringArray(const char *const*array, const char *suffix) const struct decoder_plugin * decoder_plugin_from_suffix(const char *suffix, unsigned int next) { - static ListNode *pos; - ListNode *node; - const struct decoder_plugin *plugin; + static unsigned i = num_decoder_plugins; if (suffix == NULL) return NULL; - if (next) { - if (pos) - node = pos; - else - return NULL; - } else - node = inputPlugin_list->firstNode; - - while (node != NULL) { - plugin = node->data; - if (stringFoundInStringArray(plugin->suffixes, suffix)) { - pos = node->nextNode; + if (!next) + i = 0; + for (; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (decoder_plugins_enabled[i] && + stringFoundInStringArray(plugin->suffixes, suffix)) { + ++i; return plugin; } - node = node->nextNode; } return NULL; @@ -98,22 +110,20 @@ decoder_plugin_from_suffix(const char *suffix, unsigned int next) const struct decoder_plugin * decoder_plugin_from_mime_type(const char *mimeType, unsigned int next) { - static ListNode *pos; - ListNode *node; - struct decoder_plugin *plugin; + static unsigned i = num_decoder_plugins; if (mimeType == NULL) return NULL; - node = (next && pos) ? pos : inputPlugin_list->firstNode; - - while (node != NULL) { - plugin = node->data; - if (stringFoundInStringArray(plugin->mime_types, mimeType)) { - pos = node->nextNode; + if (!next) + i = 0; + for (; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (decoder_plugins_enabled[i] && + stringFoundInStringArray(plugin->mime_types, mimeType)) { + ++i; return plugin; } - node = node->nextNode; } return NULL; @@ -122,27 +132,30 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next) const struct decoder_plugin * decoder_plugin_from_name(const char *name) { - void *plugin = NULL; - - findInList(inputPlugin_list, name, &plugin); + for (unsigned i = 0; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (decoder_plugins_enabled[i] && + strcmp(plugin->name, name) == 0) + return plugin; + } - return (const struct decoder_plugin *) plugin; + return NULL; } void decoder_plugin_print_all_suffixes(FILE * fp) { - ListNode *node = inputPlugin_list->firstNode; - struct decoder_plugin *plugin; const char *const*suffixes; - while (node) { - plugin = (struct decoder_plugin *) node->data; + for (unsigned i = 0; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (!decoder_plugins_enabled[i]) + continue; + suffixes = plugin->suffixes; while (suffixes && *suffixes) { fprintf(fp, "%s ", *suffixes); suffixes++; } - node = node->nextNode; } fprintf(fp, "\n"); fflush(fp); @@ -150,43 +163,18 @@ void decoder_plugin_print_all_suffixes(FILE * fp) void decoder_plugin_init_all(void) { - inputPlugin_list = makeList(NULL, 1); - - /* load plugins here */ -#ifdef HAVE_MAD - decoder_plugin_load(&mp3Plugin); -#endif -#ifdef HAVE_OGGVORBIS - decoder_plugin_load(&oggvorbisPlugin); -#endif -#ifdef HAVE_FLAC_COMMON - decoder_plugin_load(&oggflacPlugin); -#endif -#ifdef HAVE_FLAC - decoder_plugin_load(&flacPlugin); -#endif -#ifdef HAVE_AUDIOFILE - decoder_plugin_load(&audiofilePlugin); -#endif -#ifdef HAVE_FAAD - decoder_plugin_load(&mp4Plugin); - decoder_plugin_load(&aacPlugin); -#endif -#ifdef HAVE_MPCDEC - decoder_plugin_load(&mpcPlugin); -#endif -#ifdef HAVE_WAVPACK - decoder_plugin_load(&wavpackPlugin); -#endif -#ifdef HAVE_MIKMOD - decoder_plugin_load(&modPlugin); -#endif -#ifdef HAVE_FFMPEG - decoder_plugin_load(&ffmpegPlugin); -#endif + for (unsigned i = 0; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (plugin->init != NULL && decoder_plugins[i]->init()) + decoder_plugins_enabled[i] = true; + } } void decoder_plugin_deinit_all(void) { - freeList(inputPlugin_list); + for (unsigned i = 0; i < num_decoder_plugins; ++i) { + const struct decoder_plugin *plugin = decoder_plugins[i]; + if (decoder_plugins_enabled[i] && plugin->finish != NULL) + decoder_plugins[i]->finish(); + } } diff --git a/src/decoder_list.h b/src/decoder_list.h index 2e18438fb..80ade3312 100644 --- a/src/decoder_list.h +++ b/src/decoder_list.h @@ -23,10 +23,6 @@ struct decoder_plugin; -/* individual functions to load/unload plugins */ -void decoder_plugin_load(struct decoder_plugin *inputPlugin); -void decoder_plugin_unload(struct decoder_plugin *inputPlugin); - /* interface for using plugins */ const struct decoder_plugin * |