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:
parent
5bb563e3bc
commit
decc4002a0
@ -280,54 +280,66 @@ decoder_load_replay_gain(Decoder &decoder, const char *path_fs)
|
|||||||
decoder_replay_gain(decoder, &info);
|
decoder_replay_gain(decoder, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
TryDecoderFile(Decoder &decoder, const char *path_fs, const char *suffix,
|
||||||
|
const DecoderPlugin &plugin)
|
||||||
|
{
|
||||||
|
if (!plugin.SupportsSuffix(suffix))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
DecoderControl &dc = decoder.dc;
|
||||||
|
|
||||||
|
if (plugin.file_decode != nullptr) {
|
||||||
|
dc.Lock();
|
||||||
|
|
||||||
|
if (decoder_file_decode(plugin, decoder, path_fs))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
dc.Unlock();
|
||||||
|
} else if (plugin.stream_decode != nullptr) {
|
||||||
|
InputStream *input_stream =
|
||||||
|
decoder_input_stream_open(dc, path_fs);
|
||||||
|
if (input_stream == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dc.Lock();
|
||||||
|
|
||||||
|
bool success = decoder_stream_decode(plugin, decoder,
|
||||||
|
*input_stream);
|
||||||
|
|
||||||
|
dc.Unlock();
|
||||||
|
|
||||||
|
input_stream->Close();
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
dc.Lock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try decoding a file.
|
* Try decoding a file.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
decoder_run_file(Decoder &decoder, const char *path_fs)
|
decoder_run_file(Decoder &decoder, const char *path_fs)
|
||||||
{
|
{
|
||||||
DecoderControl &dc = decoder.dc;
|
|
||||||
const char *suffix = uri_get_suffix(path_fs);
|
const char *suffix = uri_get_suffix(path_fs);
|
||||||
const struct DecoderPlugin *plugin = nullptr;
|
|
||||||
|
|
||||||
if (suffix == nullptr)
|
if (suffix == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
DecoderControl &dc = decoder.dc;
|
||||||
dc.Unlock();
|
dc.Unlock();
|
||||||
|
|
||||||
decoder_load_replay_gain(decoder, path_fs);
|
decoder_load_replay_gain(decoder, path_fs);
|
||||||
|
|
||||||
while ((plugin = decoder_plugin_from_suffix(suffix, plugin)) != nullptr) {
|
if (decoder_plugins_try([&decoder, path_fs, suffix](const DecoderPlugin &plugin){
|
||||||
if (plugin->file_decode != nullptr) {
|
return TryDecoderFile(decoder, path_fs, suffix,
|
||||||
dc.Lock();
|
plugin);
|
||||||
|
}))
|
||||||
if (decoder_file_decode(*plugin, decoder, path_fs))
|
return true;
|
||||||
return true;
|
|
||||||
|
|
||||||
dc.Unlock();
|
|
||||||
} else if (plugin->stream_decode != nullptr) {
|
|
||||||
InputStream *input_stream;
|
|
||||||
bool success;
|
|
||||||
|
|
||||||
input_stream = decoder_input_stream_open(dc, path_fs);
|
|
||||||
if (input_stream == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
dc.Lock();
|
|
||||||
|
|
||||||
success = decoder_stream_decode(*plugin, decoder,
|
|
||||||
*input_stream);
|
|
||||||
|
|
||||||
dc.Unlock();
|
|
||||||
|
|
||||||
input_stream->Close();
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
dc.Lock();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dc.Lock();
|
dc.Lock();
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user