aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder_list.c35
-rw-r--r--src/decoder_list.h10
-rw-r--r--src/decoder_thread.c10
3 files changed, 38 insertions, 17 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);