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.
This commit is contained in:
Max Kellermann 2008-11-01 14:53:30 +01:00
parent 5036368f54
commit 1a4a3e1f1f
4 changed files with 78 additions and 109 deletions

View File

@ -18,7 +18,6 @@
*/ */
#include "decoder_internal.h" #include "decoder_internal.h"
#include "decoder_list.h"
#include "decoder_control.h" #include "decoder_control.h"
#include "player_control.h" #include "player_control.h"
#include "audio.h" #include "audio.h"
@ -31,16 +30,6 @@
#include <assert.h> #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, void decoder_initialized(struct decoder * decoder,
const struct audio_format *audio_format, const struct audio_format *audio_format,
float total_time) float total_time)

View File

@ -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 * Opaque handle which the decoder plugin passes to the functions in
* this header. * this header.

View File

@ -18,7 +18,8 @@
#include "decoder_list.h" #include "decoder_list.h"
#include "decoder_api.h" #include "decoder_api.h"
#include "list.h"
#include <glib.h>
extern struct decoder_plugin mp3Plugin; extern struct decoder_plugin mp3Plugin;
extern struct decoder_plugin oggvorbisPlugin; extern struct decoder_plugin oggvorbisPlugin;
@ -32,27 +33,46 @@ extern struct decoder_plugin wavpackPlugin;
extern struct decoder_plugin modPlugin; extern struct decoder_plugin modPlugin;
extern struct decoder_plugin ffmpegPlugin; extern struct decoder_plugin ffmpegPlugin;
static List *inputPlugin_list; 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
};
void decoder_plugin_load(struct decoder_plugin * inputPlugin) enum {
{ num_decoder_plugins = G_N_ELEMENTS(decoder_plugins),
if (!inputPlugin) };
return;
if (!inputPlugin->name)
return;
if (inputPlugin->init != NULL && !inputPlugin->init()) /** which plugins have been initialized successfully? */
return; static bool decoder_plugins_enabled[num_decoder_plugins];
insertInList(inputPlugin_list, inputPlugin->name, (void *)inputPlugin);
}
void decoder_plugin_unload(struct decoder_plugin * inputPlugin)
{
if (inputPlugin->finish != NULL)
inputPlugin->finish();
deleteFromList(inputPlugin_list, inputPlugin->name);
}
static int stringFoundInStringArray(const char *const*array, const char *suffix) 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 * const struct decoder_plugin *
decoder_plugin_from_suffix(const char *suffix, unsigned int next) decoder_plugin_from_suffix(const char *suffix, unsigned int next)
{ {
static ListNode *pos; static unsigned i = num_decoder_plugins;
ListNode *node;
const struct decoder_plugin *plugin;
if (suffix == NULL) if (suffix == NULL)
return NULL; return NULL;
if (next) { if (!next)
if (pos) i = 0;
node = pos; for (; i < num_decoder_plugins; ++i) {
else const struct decoder_plugin *plugin = decoder_plugins[i];
return NULL; if (decoder_plugins_enabled[i] &&
} else stringFoundInStringArray(plugin->suffixes, suffix)) {
node = inputPlugin_list->firstNode; ++i;
while (node != NULL) {
plugin = node->data;
if (stringFoundInStringArray(plugin->suffixes, suffix)) {
pos = node->nextNode;
return plugin; return plugin;
} }
node = node->nextNode;
} }
return NULL; return NULL;
@ -98,22 +110,20 @@ decoder_plugin_from_suffix(const char *suffix, unsigned int next)
const struct decoder_plugin * const struct decoder_plugin *
decoder_plugin_from_mime_type(const char *mimeType, unsigned int next) decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
{ {
static ListNode *pos; static unsigned i = num_decoder_plugins;
ListNode *node;
struct decoder_plugin *plugin;
if (mimeType == NULL) if (mimeType == NULL)
return NULL; return NULL;
node = (next && pos) ? pos : inputPlugin_list->firstNode; if (!next)
i = 0;
while (node != NULL) { for (; i < num_decoder_plugins; ++i) {
plugin = node->data; const struct decoder_plugin *plugin = decoder_plugins[i];
if (stringFoundInStringArray(plugin->mime_types, mimeType)) { if (decoder_plugins_enabled[i] &&
pos = node->nextNode; stringFoundInStringArray(plugin->mime_types, mimeType)) {
++i;
return plugin; return plugin;
} }
node = node->nextNode;
} }
return NULL; return NULL;
@ -122,27 +132,30 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
const struct decoder_plugin * const struct decoder_plugin *
decoder_plugin_from_name(const char *name) decoder_plugin_from_name(const char *name)
{ {
void *plugin = NULL; 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;
}
findInList(inputPlugin_list, name, &plugin); return NULL;
return (const struct decoder_plugin *) plugin;
} }
void decoder_plugin_print_all_suffixes(FILE * fp) void decoder_plugin_print_all_suffixes(FILE * fp)
{ {
ListNode *node = inputPlugin_list->firstNode;
struct decoder_plugin *plugin;
const char *const*suffixes; const char *const*suffixes;
while (node) { for (unsigned i = 0; i < num_decoder_plugins; ++i) {
plugin = (struct decoder_plugin *) node->data; const struct decoder_plugin *plugin = decoder_plugins[i];
if (!decoder_plugins_enabled[i])
continue;
suffixes = plugin->suffixes; suffixes = plugin->suffixes;
while (suffixes && *suffixes) { while (suffixes && *suffixes) {
fprintf(fp, "%s ", *suffixes); fprintf(fp, "%s ", *suffixes);
suffixes++; suffixes++;
} }
node = node->nextNode;
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
fflush(fp); fflush(fp);
@ -150,43 +163,18 @@ void decoder_plugin_print_all_suffixes(FILE * fp)
void decoder_plugin_init_all(void) void decoder_plugin_init_all(void)
{ {
inputPlugin_list = makeList(NULL, 1); for (unsigned i = 0; i < num_decoder_plugins; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
/* load plugins here */ if (plugin->init != NULL && decoder_plugins[i]->init())
#ifdef HAVE_MAD decoder_plugins_enabled[i] = true;
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
} }
void decoder_plugin_deinit_all(void) 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();
}
} }

View File

@ -23,10 +23,6 @@
struct decoder_plugin; 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 */ /* interface for using plugins */
const struct decoder_plugin * const struct decoder_plugin *