decoder/List: eliminate decoder_plugins_try()
Migrate callers to GetEnabledDecoderPlugins(). By not using lambdas, we can switch to enums as return value for better diagnostics.
This commit is contained in:
parent
a27fb71c4c
commit
c2470ebd9c
|
@ -68,9 +68,12 @@ ScanFileTagsNoGeneric(Path path_fs, TagHandler &handler)
|
|||
const auto suffix_utf8 = Path::FromFS(suffix).ToUTF8();
|
||||
|
||||
TagFileScan tfs(path_fs, suffix_utf8.c_str(), handler);
|
||||
return decoder_plugins_try([&](const DecoderPlugin &plugin){
|
||||
return tfs.Scan(plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (tfs.Scan(plugin))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -41,16 +41,20 @@ tag_stream_scan(InputStream &is, TagHandler &handler)
|
|||
if (full_mime != nullptr)
|
||||
mime_base = GetMimeTypeBase(full_mime);
|
||||
|
||||
return decoder_plugins_try([suffix, mime_base, &is,
|
||||
&handler](const DecoderPlugin &plugin){
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (!CheckDecoderPlugin(plugin, suffix, mime_base))
|
||||
continue;
|
||||
|
||||
try {
|
||||
is.LockRewind();
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
return CheckDecoderPlugin(plugin, suffix, mime_base) &&
|
||||
plugin.ScanStream(is, handler);
|
||||
});
|
||||
if (plugin.ScanStream(is, handler))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -152,9 +152,10 @@ GetChromaprintCommand::DecodeStream(InputStream &is)
|
|||
{
|
||||
const auto suffix = uri_get_suffix(uri);
|
||||
|
||||
decoder_plugins_try([this, &is, suffix](const DecoderPlugin &plugin){
|
||||
return DecodeStream(is, suffix, plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (DecodeStream(is, suffix, plugin))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
@ -175,9 +176,12 @@ GetChromaprintCommand::DecodeContainer(std::string_view suffix,
|
|||
inline bool
|
||||
GetChromaprintCommand::DecodeContainer(std::string_view suffix)
|
||||
{
|
||||
return decoder_plugins_try([this, suffix](const DecoderPlugin &plugin){
|
||||
return DecodeContainer(suffix, plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (DecodeContainer(suffix, plugin))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool
|
||||
|
@ -230,10 +234,10 @@ GetChromaprintCommand::DecodeFile()
|
|||
|
||||
assert(input_stream);
|
||||
|
||||
auto &is = *input_stream;
|
||||
decoder_plugins_try([this, suffix, &is](const DecoderPlugin &plugin){
|
||||
return DecodeFile(suffix, is, plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (DecodeFile(suffix, *input_stream, plugin))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "Log.hxx"
|
||||
#include "PluginUnavailable.hxx"
|
||||
|
||||
#include <algorithm> // for std::any_of()
|
||||
#include <iterator>
|
||||
|
||||
#include <string.h>
|
||||
|
@ -164,7 +165,10 @@ decoder_plugin_deinit_all() noexcept
|
|||
bool
|
||||
decoder_plugins_supports_suffix(std::string_view suffix) noexcept
|
||||
{
|
||||
return decoder_plugins_try([suffix](const DecoderPlugin &plugin){
|
||||
return plugin.SupportsSuffix(suffix);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (plugin.SupportsSuffix(suffix))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -64,17 +64,6 @@ decoder_plugins_find(F f) noexcept
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
static inline bool
|
||||
decoder_plugins_try(F f)
|
||||
{
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins())
|
||||
if (f(plugin))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there at least once #DecoderPlugin that supports the specified
|
||||
* file name suffix?
|
||||
|
|
|
@ -203,10 +203,12 @@ decoder_run_stream_locked(DecoderBridge &bridge, InputStream &is,
|
|||
{
|
||||
const auto suffix = uri_get_suffix(uri);
|
||||
|
||||
const auto f = [&,suffix](const auto &plugin)
|
||||
{ return decoder_run_stream_plugin(bridge, is, lock, suffix, plugin, tried_r); };
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (decoder_run_stream_plugin(bridge, is, lock, suffix, plugin, tried_r))
|
||||
return true;
|
||||
}
|
||||
|
||||
return decoder_plugins_try(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -268,14 +270,18 @@ MaybeLoadReplayGain(DecoderBridge &bridge, InputStream &is)
|
|||
static bool
|
||||
TryUriDecode(DecoderBridge &bridge, const char *uri)
|
||||
{
|
||||
return decoder_plugins_try([&bridge, uri](const DecoderPlugin &plugin){
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (!plugin.SupportsUri(uri))
|
||||
return false;
|
||||
continue;
|
||||
|
||||
std::unique_lock lock{bridge.dc.mutex};
|
||||
bridge.Reset();
|
||||
return DecoderUriDecode(plugin, bridge, uri);
|
||||
});
|
||||
|
||||
if (DecoderUriDecode(plugin, bridge, uri))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -367,13 +373,12 @@ static bool
|
|||
TryContainerDecoder(DecoderBridge &bridge, Path path_fs,
|
||||
std::string_view suffix)
|
||||
{
|
||||
return decoder_plugins_try([&bridge, path_fs,
|
||||
suffix](const DecoderPlugin &plugin){
|
||||
return TryContainerDecoder(bridge,
|
||||
path_fs,
|
||||
suffix,
|
||||
plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (TryContainerDecoder(bridge, path_fs, suffix, plugin))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -408,15 +413,12 @@ decoder_run_file(DecoderBridge &bridge, const char *uri_utf8, Path path_fs)
|
|||
|
||||
MaybeLoadReplayGain(bridge, *input_stream);
|
||||
|
||||
auto &is = *input_stream;
|
||||
return decoder_plugins_try([&bridge, path_fs, suffix,
|
||||
&is](const DecoderPlugin &plugin){
|
||||
return TryDecoderFile(bridge,
|
||||
path_fs,
|
||||
suffix,
|
||||
is,
|
||||
plugin);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (TryDecoderFile(bridge, path_fs, suffix, *input_stream, plugin))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,7 +65,10 @@ uri_supported_scheme(const char *uri) noexcept
|
|||
if (plugin->SupportsUri(uri))
|
||||
return true;
|
||||
|
||||
return decoder_plugins_try([uri](const auto &plugin){
|
||||
return plugin.SupportsUri(uri);
|
||||
});
|
||||
for (const auto &plugin : GetEnabledDecoderPlugins()) {
|
||||
if (plugin.SupportsUri(uri))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue