decoder/plugin: add "suffixes" function
For decoder plugins like FFmpeg where the supported codecs cannot be determined at compile time.
This commit is contained in:
parent
8b77da545d
commit
78a9c17bc6
@ -147,6 +147,10 @@ static void version()
|
||||
for (; *suffixes != nullptr; ++suffixes)
|
||||
fmt::print(" {}", *suffixes);
|
||||
|
||||
if (plugin.suffixes_function != nullptr)
|
||||
for (const auto &i : plugin.suffixes_function())
|
||||
printf(" %s", i.c_str());
|
||||
|
||||
if (plugin.protocols != nullptr)
|
||||
for (const auto &i : plugin.protocols())
|
||||
fmt::print(" {}", i);
|
||||
|
@ -23,8 +23,10 @@ DecoderPlugin::SupportsUri(const char *uri) const noexcept
|
||||
bool
|
||||
DecoderPlugin::SupportsSuffix(std::string_view suffix) const noexcept
|
||||
{
|
||||
return suffixes != nullptr &&
|
||||
StringArrayContainsCase(suffixes, suffix);
|
||||
return (suffixes != nullptr &&
|
||||
StringArrayContainsCase(suffixes, suffix)) ||
|
||||
(suffixes_function != nullptr &&
|
||||
suffixes_function().contains(suffix));
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -35,6 +35,13 @@ struct DecoderPlugin {
|
||||
*/
|
||||
void (*finish)() noexcept = nullptr;
|
||||
|
||||
/**
|
||||
* Return a set of supported filename suffixes. Use this
|
||||
* instead of #suffixes if the supported suffixes can only be
|
||||
* determined at runtime.
|
||||
*/
|
||||
std::set<std::string, std::less<>> (*suffixes_function)() noexcept = nullptr;
|
||||
|
||||
/**
|
||||
* Return a set of supported protocols.
|
||||
*/
|
||||
@ -152,6 +159,12 @@ struct DecoderPlugin {
|
||||
return copy;
|
||||
}
|
||||
|
||||
constexpr auto WithSuffixes(std::set<std::string, std::less<>> (*_suffixes)() noexcept) const noexcept {
|
||||
auto copy = *this;
|
||||
copy.suffixes_function = _suffixes;
|
||||
return copy;
|
||||
}
|
||||
|
||||
constexpr auto WithMimeTypes(const char *const*_mime_types) const noexcept {
|
||||
auto copy = *this;
|
||||
copy.mime_types = _mime_types;
|
||||
|
@ -25,6 +25,10 @@ decoder_plugin_print(Response &r,
|
||||
for (p = plugin.suffixes; *p != nullptr; ++p)
|
||||
r.Fmt(FMT_STRING("suffix: {}\n"), *p);
|
||||
|
||||
if (plugin.suffixes_function != nullptr)
|
||||
for (const auto &i : plugin.suffixes_function())
|
||||
r.Fmt(FMT_STRING("suffix: {}\n"), i);
|
||||
|
||||
if (plugin.mime_types != nullptr)
|
||||
for (p = plugin.mime_types; *p != nullptr; ++p)
|
||||
r.Fmt(FMT_STRING("mime_type: {}\n"), *p);
|
||||
|
Loading…
Reference in New Issue
Block a user