aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-29 16:51:18 +0100
committerMax Kellermann <max@duempel.org>2013-12-29 16:51:18 +0100
commitdecc4002a02d07c12b360929dc62b5ffcae37582 (patch)
tree1a4ffb312b516e33b194f52367e8b963e421ff7d
parent5bb563e3bc72b7aaea4e2df3280f38085bb515ba (diff)
downloadmpd-decc4002a02d07c12b360929dc62b5ffcae37582.tar.gz
mpd-decc4002a02d07c12b360929dc62b5ffcae37582.tar.xz
mpd-decc4002a02d07c12b360929dc62b5ffcae37582.zip
DecoderThread: use decoder_plugins_try()
.. instead of decoder_plugin_from_suffix(). This reduces overhead by walking the array only once.
-rw-r--r--src/DecoderThread.cxx76
1 files changed, 44 insertions, 32 deletions
diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx
index 3ccbd1082..ef6655484 100644
--- a/src/DecoderThread.cxx
+++ b/src/DecoderThread.cxx
@@ -280,54 +280,66 @@ decoder_load_replay_gain(Decoder &decoder, const char *path_fs)
decoder_replay_gain(decoder, &info);
}
-/**
- * Try decoding a file.
- */
static bool
-decoder_run_file(Decoder &decoder, const char *path_fs)
+TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix,
+ const DecoderPlugin &plugin)
{
+ if (!plugin.SupportsSuffix(suffix))
+ return false;
+
DecoderControl &dc = decoder.dc;
- const char *suffix = uri_get_suffix(path_fs);
- const struct DecoderPlugin *plugin = nullptr;
- if (suffix == nullptr)
- return false;
+ if (plugin.file_decode != nullptr) {
+ dc.Lock();
- dc.Unlock();
+ if (decoder_file_decode(plugin, decoder, path_fs))
+ return true;
- decoder_load_replay_gain(decoder, path_fs);
+ dc.Unlock();
+ } else if (plugin.stream_decode != nullptr) {
+ InputStream *input_stream =
+ decoder_input_stream_open(dc, path_fs);
+ if (input_stream == nullptr)
+ return false;
- while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != nullptr) {
- if (plugin->file_decode != nullptr) {
- dc.Lock();
+ dc.Lock();
- if (decoder_file_decode(*plugin, decoder, path_fs))
- return true;
+ bool success = decoder_stream_decode(plugin, decoder,
+ *input_stream);
- dc.Unlock();
- } else if (plugin->stream_decode != nullptr) {
- InputStream *input_stream;
- bool success;
+ dc.Unlock();
- input_stream = decoder_input_stream_open(dc, path_fs);
- if (input_stream == nullptr)
- continue;
+ input_stream->Close();
+ if (success) {
dc.Lock();
+ return true;
+ }
+ }
- success = decoder_stream_decode(*plugin, decoder,
- *input_stream);
+ return false;
+}
+
+/**
+ * Try decoding a file.
+ */
+static bool
+decoder_run_file(Decoder &decoder, const char *path_fs)
+{
+ const char *suffix = uri_get_suffix(path_fs);
+ if (suffix == nullptr)
+ return false;
- dc.Unlock();
+ DecoderControl &dc = decoder.dc;
+ dc.Unlock();
- input_stream->Close();
+ decoder_load_replay_gain(decoder, path_fs);
- if (success) {
- dc.Lock();
- return true;
- }
- }
- }
+ if (decoder_plugins_try([&decoder, path_fs, suffix](const DecoderPlugin &plugin){
+ return TryDecoderFile(decoder, path_fs, suffix,
+ plugin);
+ }))
+ return true;
dc.Lock();
return false;