DecoderThread: use decoder_plugins_try()

.. instead of decoder_plugin_from_suffix().  This reduces overhead by
walking the array only once.
This commit is contained in:
Max Kellermann 2013-12-29 16:51:18 +01:00
parent 5bb563e3bc
commit decc4002a0

View File

@ -280,42 +280,31 @@ decoder_load_replay_gain(Decoder &decoder, const char *path_fs)
decoder_replay_gain(decoder, &info); decoder_replay_gain(decoder, &info);
} }
/**
* Try decoding a file.
*/
static bool static bool
decoder_run_file(Decoder &decoder, const char *path_fs) TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix,
const DecoderPlugin &plugin)
{ {
DecoderControl &dc = decoder.dc; if (!plugin.SupportsSuffix(suffix))
const char *suffix = uri_get_suffix(path_fs);
const struct DecoderPlugin *plugin = nullptr;
if (suffix == nullptr)
return false; return false;
dc.Unlock(); DecoderControl &dc = decoder.dc;
decoder_load_replay_gain(decoder, path_fs); if (plugin.file_decode != nullptr) {
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)) if (decoder_file_decode(plugin, decoder, path_fs))
return true; return true;
dc.Unlock(); dc.Unlock();
} else if (plugin->stream_decode != nullptr) { } else if (plugin.stream_decode != nullptr) {
InputStream *input_stream; InputStream *input_stream =
bool success; decoder_input_stream_open(dc, path_fs);
input_stream = decoder_input_stream_open(dc, path_fs);
if (input_stream == nullptr) if (input_stream == nullptr)
continue; return false;
dc.Lock(); dc.Lock();
success = decoder_stream_decode(*plugin, decoder, bool success = decoder_stream_decode(plugin, decoder,
*input_stream); *input_stream);
dc.Unlock(); dc.Unlock();
@ -327,8 +316,31 @@ decoder_run_file(Decoder &decoder, const char *path_fs)
return true; return true;
} }
} }
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;
DecoderControl &dc = decoder.dc;
dc.Unlock();
decoder_load_replay_gain(decoder, path_fs);
if (decoder_plugins_try([&decoder, path_fs, suffix](const DecoderPlugin &plugin){
return TryDecoderFile(decoder, path_fs, suffix,
plugin);
}))
return true;
dc.Lock(); dc.Lock();
return false; return false;
} }