aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-07 15:14:16 +0100
committerMax Kellermann <max@duempel.org>2009-11-07 15:14:16 +0100
commit5d55b45654eacd479a93673f9ec9ad3627952a96 (patch)
tree4602220efc2da432bc1aac9a828f3694064a9af5
parente3da174fca30c493ec311e41ad3dc6795053757d (diff)
downloadmpd-5d55b45654eacd479a93673f9ec9ad3627952a96.tar.gz
mpd-5d55b45654eacd479a93673f9ec9ad3627952a96.tar.xz
mpd-5d55b45654eacd479a93673f9ec9ad3627952a96.zip
decoder_list: pass previous plugin pointer to lookup functions
Remove the static integer hack, that's not thread safe and sucks.
-rw-r--r--src/decoder_list.c35
-rw-r--r--src/decoder_list.h10
-rw-r--r--src/decoder_thread.c10
-rw-r--r--src/song_update.c4
4 files changed, 40 insertions, 19 deletions
diff --git a/src/decoder_list.c b/src/decoder_list.c
index 837c5ca7b..53c882161 100644
--- a/src/decoder_list.c
+++ b/src/decoder_list.c
@@ -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;
diff --git a/src/decoder_list.h b/src/decoder_list.h
index 23788189c..3b3cfd040 100644
--- a/src/decoder_list.h
+++ b/src/decoder_list.h
@@ -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);
diff --git a/src/decoder_thread.c b/src/decoder_thread.c
index e39c7f98e..1e850a037 100644
--- a/src/decoder_thread.c
+++ b/src/decoder_thread.c
@@ -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);
diff --git a/src/song_update.c b/src/song_update.c
index cfef5861f..2239f9aa6 100644
--- a/src/song_update.c
+++ b/src/song_update.c
@@ -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))