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:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user