Commit 13e9f184 authored by Max Kellermann's avatar Max Kellermann

DecoderPlugin: move functions into the struct

parent 875821f2
......@@ -148,7 +148,7 @@ decoder_plugin_from_suffix(const char *suffix,
decoder_plugins[i] != nullptr; ++i) {
plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
decoder_plugin_supports_suffix(*plugin, suffix))
plugin->SupportsSuffix(suffix))
return plugin;
}
......@@ -168,7 +168,7 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
for (; decoder_plugins[i] != nullptr; ++i) {
const struct DecoderPlugin *plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
decoder_plugin_supports_mime_type(*plugin, mimeType)) {
plugin->SupportsMimeType(mimeType)) {
++i;
return plugin;
}
......@@ -226,7 +226,7 @@ void decoder_plugin_init_all(void)
/* the plugin is disabled in mpd.conf */
continue;
if (decoder_plugin_init(plugin, *param))
if (plugin.Init(*param))
decoder_plugins_enabled[i] = true;
}
}
......@@ -234,5 +234,5 @@ void decoder_plugin_init_all(void)
void decoder_plugin_deinit_all(void)
{
decoder_plugins_for_each_enabled(plugin)
decoder_plugin_finish(*plugin);
plugin->Finish();
}
......@@ -24,22 +24,19 @@
#include <assert.h>
bool
decoder_plugin_supports_suffix(const DecoderPlugin &plugin,
const char *suffix)
DecoderPlugin::SupportsSuffix(const char *suffix) const
{
assert(suffix != nullptr);
return plugin.suffixes != nullptr &&
string_array_contains(plugin.suffixes, suffix);
return suffixes != nullptr && string_array_contains(suffixes, suffix);
}
bool
decoder_plugin_supports_mime_type(const DecoderPlugin &plugin,
const char *mime_type)
DecoderPlugin::SupportsMimeType(const char *mime_type) const
{
assert(mime_type != nullptr);
return plugin.mime_types != nullptr &&
string_array_contains(plugin.mime_types, mime_type);
return mime_types != nullptr &&
string_array_contains(mime_types, mime_type);
}
......@@ -20,6 +20,8 @@
#ifndef MPD_DECODER_PLUGIN_HXX
#define MPD_DECODER_PLUGIN_HXX
#include "Compiler.h"
struct config_param;
struct input_stream;
struct Tag;
......@@ -100,105 +102,81 @@ struct DecoderPlugin {
/* last element in these arrays must always be a nullptr: */
const char *const*suffixes;
const char *const*mime_types;
};
/**
* Initialize a decoder plugin.
*
* @param param a configuration block for this plugin, or nullptr if none
* is configured
* @return true if the plugin was initialized successfully, false if
* the plugin is not available
*/
static inline bool
decoder_plugin_init(const DecoderPlugin &plugin,
const config_param &param)
{
return plugin.init != nullptr
? plugin.init(param)
: true;
}
/**
* Initialize a decoder plugin.
*
* @param param a configuration block for this plugin, or nullptr if none
* is configured
* @return true if the plugin was initialized successfully, false if
* the plugin is not available
*/
bool Init(const config_param &param) const {
return init != nullptr
? init(param)
: true;
}
/**
* Deinitialize a decoder plugin which was initialized successfully.
*/
static inline void
decoder_plugin_finish(const DecoderPlugin &plugin)
{
if (plugin.finish != nullptr)
plugin.finish();
}
/**
* Deinitialize a decoder plugin which was initialized successfully.
*/
void Finish() const {
if (finish != nullptr)
finish();
}
/**
* Decode a stream.
*/
static inline void
decoder_plugin_stream_decode(const DecoderPlugin &plugin,
struct decoder *decoder, struct input_stream *is)
{
plugin.stream_decode(decoder, is);
}
/**
* Decode a stream.
*/
void StreamDecode(decoder &decoder, input_stream &is) const {
stream_decode(&decoder, &is);
}
/**
* Decode a file.
*/
static inline void
decoder_plugin_file_decode(const DecoderPlugin &plugin,
struct decoder *decoder, const char *path_fs)
{
plugin.file_decode(decoder, path_fs);
}
/**
* Decode a file.
*/
void FileDecode(decoder &decoder, const char *path_fs) const {
file_decode(&decoder, path_fs);
}
/**
* Read the tag of a file.
*/
static inline bool
decoder_plugin_scan_file(const DecoderPlugin &plugin,
const char *path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
return plugin.scan_file != nullptr
? plugin.scan_file(path_fs, handler, handler_ctx)
: false;
}
/**
* Read the tag of a file.
*/
bool ScanFile(const char *path_fs,
const tag_handler &handler, void *handler_ctx) const {
return scan_file != nullptr
? scan_file(path_fs, &handler, handler_ctx)
: false;
}
/**
* Read the tag of a stream.
*/
static inline bool
decoder_plugin_scan_stream(const DecoderPlugin &plugin,
struct input_stream *is,
const struct tag_handler *handler,
void *handler_ctx)
{
return plugin.scan_stream != nullptr
? plugin.scan_stream(is, handler, handler_ctx)
: false;
}
/**
* Read the tag of a stream.
*/
bool ScanStream(input_stream &is,
const tag_handler &handler, void *handler_ctx) const {
return scan_stream != nullptr
? scan_stream(&is, &handler, handler_ctx)
: false;
}
/**
* return "virtual" tracks in a container
*/
static inline char *
decoder_plugin_container_scan( const DecoderPlugin &plugin,
const char* pathname,
const unsigned int tnum)
{
return plugin.container_scan(pathname, tnum);
}
/**
* return "virtual" tracks in a container
*/
char *ContainerScan(const char *path, const unsigned int tnum) const {
return container_scan(path, tnum);
}
/**
* Does the plugin announce the specified file name suffix?
*/
bool
decoder_plugin_supports_suffix(const DecoderPlugin &plugin,
const char *suffix);
/**
* Does the plugin announce the specified file name suffix?
*/
gcc_pure gcc_nonnull_all
bool SupportsSuffix(const char *suffix) const;
/**
* Does the plugin announce the specified MIME type?
*/
bool
decoder_plugin_supports_mime_type(const DecoderPlugin &plugin,
const char *mime_type);
/**
* Does the plugin announce the specified MIME type?
*/
gcc_pure gcc_nonnull_all
bool SupportsMimeType(const char *mime_type) const;
};
#endif
......@@ -133,7 +133,7 @@ decoder_stream_decode(const DecoderPlugin &plugin,
decoder->dc.Unlock();
decoder_plugin_stream_decode(plugin, decoder, input_stream);
plugin.StreamDecode(*decoder, *input_stream);
decoder->dc.Lock();
......@@ -162,7 +162,7 @@ decoder_file_decode(const DecoderPlugin &plugin,
decoder->dc.Unlock();
decoder_plugin_file_decode(plugin, decoder, path);
plugin.FileDecode(*decoder, path);
decoder->dc.Lock();
......
......@@ -53,8 +53,8 @@ tag_file_scan(const char *path_fs,
do {
/* load file tag */
if (decoder_plugin_scan_file(*plugin, path_fs,
handler, handler_ctx))
if (plugin->ScanFile(path_fs,
*handler, handler_ctx))
break;
/* fall back to stream tag */
......@@ -67,9 +67,8 @@ tag_file_scan(const char *path_fs,
/* now try the stream_tag() method */
if (is != nullptr) {
if (decoder_plugin_scan_stream(*plugin, is,
handler,
handler_ctx))
if (plugin->ScanStream(*is,
*handler, handler_ctx))
break;
is->LockSeek(0, SEEK_SET, IgnoreError());
......
......@@ -98,8 +98,8 @@ update_container_file(Directory &directory,
const auto child_path_fs =
map_directory_child_fs(*contdir, vtrack);
decoder_plugin_scan_file(plugin, child_path_fs.c_str(),
&add_tag_handler, &tag_builder);
plugin.ScanFile(child_path_fs.c_str(),
add_tag_handler, &tag_builder);
if (tag_builder.IsDefined())
song->tag = tag_builder.Commit();
......
......@@ -181,8 +181,7 @@ int main(int argc, char **argv)
return 1;
}
bool success = decoder_plugin_scan_file(*plugin, path,
&print_handler, NULL);
bool success = plugin->ScanFile(path, print_handler, nullptr);
if (!success && plugin->scan_stream != NULL) {
Mutex mutex;
Cond cond;
......@@ -209,8 +208,7 @@ int main(int argc, char **argv)
mutex.unlock();
success = decoder_plugin_scan_stream(*plugin, is,
&print_handler, NULL);
success = plugin->ScanStream(*is, print_handler, nullptr);
is->Close();
}
......
......@@ -184,8 +184,7 @@ int main(int argc, char **argv)
decoder.initialized = false;
if (decoder.plugin->file_decode != NULL) {
decoder_plugin_file_decode(*decoder.plugin, &decoder,
decoder.uri);
decoder.plugin->FileDecode(decoder, decoder.uri);
} else if (decoder.plugin->stream_decode != NULL) {
Mutex mutex;
Cond cond;
......@@ -201,7 +200,7 @@ int main(int argc, char **argv)
return 1;
}
decoder_plugin_stream_decode(*decoder.plugin, &decoder, is);
decoder.plugin->StreamDecode(decoder, *is);
is->Close();
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment