decoder_list: pass previous plugin pointer to lookup functions
Remove the static integer hack, that's not thread safe and sucks.
This commit is contained in:
parent
e3da174fca
commit
5d55b45654
@ -107,23 +107,38 @@ enum {
|
||||
/** which plugins have been initialized successfully? */
|
||||
static bool decoder_plugins_enabled[num_decoder_plugins];
|
||||
|
||||
const struct decoder_plugin *
|
||||
decoder_plugin_from_suffix(const char *suffix, unsigned int next)
|
||||
static unsigned
|
||||
decoder_plugin_index(const struct decoder_plugin *plugin)
|
||||
{
|
||||
static unsigned i = num_decoder_plugins;
|
||||
unsigned i = 0;
|
||||
|
||||
while (decoder_plugins[i] != plugin)
|
||||
++i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
decoder_plugin_next_index(const struct decoder_plugin *plugin)
|
||||
{
|
||||
return plugin == 0
|
||||
? 0 /* start with first plugin */
|
||||
: decoder_plugin_index(plugin) + 1;
|
||||
}
|
||||
|
||||
const struct decoder_plugin *
|
||||
decoder_plugin_from_suffix(const char *suffix,
|
||||
const struct decoder_plugin *plugin)
|
||||
{
|
||||
if (suffix == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!next)
|
||||
i = 0;
|
||||
for (; decoder_plugins[i] != NULL; ++i) {
|
||||
const struct decoder_plugin *plugin = decoder_plugins[i];
|
||||
for (unsigned i = decoder_plugin_next_index(plugin);
|
||||
decoder_plugins[i] != NULL; ++i) {
|
||||
plugin = decoder_plugins[i];
|
||||
if (decoder_plugins_enabled[i] &&
|
||||
decoder_plugin_supports_suffix(plugin, suffix)) {
|
||||
++i;
|
||||
decoder_plugin_supports_suffix(plugin, suffix))
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
@ -26,8 +26,16 @@ struct decoder_plugin;
|
||||
|
||||
/* interface for using plugins */
|
||||
|
||||
/**
|
||||
* Find the next enabled decoder plugin which supports the specified suffix.
|
||||
*
|
||||
* @param suffix the file name suffix
|
||||
* @param plugin the previous plugin, or NULL to find the first plugin
|
||||
* @return a plugin, or NULL if none matches
|
||||
*/
|
||||
const struct decoder_plugin *
|
||||
decoder_plugin_from_suffix(const char *suffix, unsigned int next);
|
||||
decoder_plugin_from_suffix(const char *suffix,
|
||||
const struct decoder_plugin *plugin);
|
||||
|
||||
const struct decoder_plugin *
|
||||
decoder_plugin_from_mime_type(const char *mimeType, unsigned int next);
|
||||
|
@ -118,13 +118,12 @@ decoder_run_stream_suffix(struct decoder *decoder, struct input_stream *is,
|
||||
const char *uri)
|
||||
{
|
||||
const char *suffix = uri_get_suffix(uri);
|
||||
const struct decoder_plugin *plugin;
|
||||
unsigned int next = 0;
|
||||
const struct decoder_plugin *plugin = NULL;
|
||||
|
||||
if (suffix == NULL)
|
||||
return false;
|
||||
|
||||
while ((plugin = decoder_plugin_from_suffix(suffix, next++)))
|
||||
while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != NULL)
|
||||
if (plugin->stream_decode != NULL &&
|
||||
decoder_stream_decode(plugin, decoder, is))
|
||||
return true;
|
||||
@ -212,15 +211,14 @@ static bool
|
||||
decoder_run_file(struct decoder *decoder, const char *path_fs)
|
||||
{
|
||||
const char *suffix = uri_get_suffix(path_fs);
|
||||
const struct decoder_plugin *plugin;
|
||||
unsigned int next = 0;
|
||||
const struct decoder_plugin *plugin = NULL;
|
||||
|
||||
if (suffix == NULL)
|
||||
return false;
|
||||
|
||||
decoder_unlock(decoder->dc);
|
||||
|
||||
while ((plugin = decoder_plugin_from_suffix(suffix, next++))) {
|
||||
while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != NULL) {
|
||||
if (plugin->file_decode != NULL) {
|
||||
decoder_lock(decoder->dc);
|
||||
|
||||
|
@ -107,7 +107,7 @@ song_file_update(struct song *song)
|
||||
if (suffix == NULL)
|
||||
return false;
|
||||
|
||||
plugin = decoder_plugin_from_suffix(suffix, false);
|
||||
plugin = decoder_plugin_from_suffix(suffix, NULL);
|
||||
if (plugin == NULL)
|
||||
return false;
|
||||
|
||||
@ -132,7 +132,7 @@ song_file_update(struct song *song)
|
||||
if (song->tag != NULL)
|
||||
break;
|
||||
|
||||
plugin = decoder_plugin_from_suffix(suffix, true);
|
||||
plugin = decoder_plugin_from_suffix(suffix, plugin);
|
||||
} while (plugin != NULL);
|
||||
|
||||
if (song->tag != NULL && tag_is_empty(song->tag))
|
||||
|
Loading…
Reference in New Issue
Block a user