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