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? */
|
/** which plugins have been initialized successfully? */
|
||||||
static bool decoder_plugins_enabled[num_decoder_plugins];
|
static bool decoder_plugins_enabled[num_decoder_plugins];
|
||||||
|
|
||||||
const struct decoder_plugin *
|
static unsigned
|
||||||
decoder_plugin_from_suffix(const char *suffix, unsigned int next)
|
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)
|
if (suffix == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!next)
|
for (unsigned i = decoder_plugin_next_index(plugin);
|
||||||
i = 0;
|
decoder_plugins[i] != NULL; ++i) {
|
||||||
for (; decoder_plugins[i] != NULL; ++i) {
|
plugin = decoder_plugins[i];
|
||||||
const struct decoder_plugin *plugin = decoder_plugins[i];
|
|
||||||
if (decoder_plugins_enabled[i] &&
|
if (decoder_plugins_enabled[i] &&
|
||||||
decoder_plugin_supports_suffix(plugin, suffix)) {
|
decoder_plugin_supports_suffix(plugin, suffix))
|
||||||
++i;
|
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -26,8 +26,16 @@ struct decoder_plugin;
|
|||||||
|
|
||||||
/* interface for using plugins */
|
/* 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 *
|
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 *
|
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);
|
||||||
|
@ -118,13 +118,12 @@ decoder_run_stream_suffix(struct decoder *decoder, struct input_stream *is,
|
|||||||
const char *uri)
|
const char *uri)
|
||||||
{
|
{
|
||||||
const char *suffix = uri_get_suffix(uri);
|
const char *suffix = uri_get_suffix(uri);
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin = NULL;
|
||||||
unsigned int next = 0;
|
|
||||||
|
|
||||||
if (suffix == NULL)
|
if (suffix == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
while ((plugin = decoder_plugin_from_suffix(suffix, next++)))
|
while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != NULL)
|
||||||
if (plugin->stream_decode != NULL &&
|
if (plugin->stream_decode != NULL &&
|
||||||
decoder_stream_decode(plugin, decoder, is))
|
decoder_stream_decode(plugin, decoder, is))
|
||||||
return true;
|
return true;
|
||||||
@ -212,15 +211,14 @@ static bool
|
|||||||
decoder_run_file(struct decoder *decoder, const char *path_fs)
|
decoder_run_file(struct decoder *decoder, const char *path_fs)
|
||||||
{
|
{
|
||||||
const char *suffix = uri_get_suffix(path_fs);
|
const char *suffix = uri_get_suffix(path_fs);
|
||||||
const struct decoder_plugin *plugin;
|
const struct decoder_plugin *plugin = NULL;
|
||||||
unsigned int next = 0;
|
|
||||||
|
|
||||||
if (suffix == NULL)
|
if (suffix == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
decoder_unlock(decoder->dc);
|
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) {
|
if (plugin->file_decode != NULL) {
|
||||||
decoder_lock(decoder->dc);
|
decoder_lock(decoder->dc);
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ song_file_update(struct song *song)
|
|||||||
if (suffix == NULL)
|
if (suffix == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
plugin = decoder_plugin_from_suffix(suffix, false);
|
plugin = decoder_plugin_from_suffix(suffix, NULL);
|
||||||
if (plugin == NULL)
|
if (plugin == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ song_file_update(struct song *song)
|
|||||||
if (song->tag != NULL)
|
if (song->tag != NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
plugin = decoder_plugin_from_suffix(suffix, true);
|
plugin = decoder_plugin_from_suffix(suffix, plugin);
|
||||||
} while (plugin != NULL);
|
} while (plugin != NULL);
|
||||||
|
|
||||||
if (song->tag != NULL && tag_is_empty(song->tag))
|
if (song->tag != NULL && tag_is_empty(song->tag))
|
||||||
|
Loading…
Reference in New Issue
Block a user