diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DecoderList.cxx | 8 | ||||
-rw-r--r-- | src/DecoderPlugin.cxx | 13 | ||||
-rw-r--r-- | src/DecoderPlugin.hxx | 160 | ||||
-rw-r--r-- | src/DecoderThread.cxx | 4 | ||||
-rw-r--r-- | src/TagFile.cxx | 9 | ||||
-rw-r--r-- | src/UpdateContainer.cxx | 4 |
6 files changed, 86 insertions, 112 deletions
diff --git a/src/DecoderList.cxx b/src/DecoderList.cxx index a9a4b5432..8fa821f58 100644 --- a/src/DecoderList.cxx +++ b/src/DecoderList.cxx @@ -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(); } diff --git a/src/DecoderPlugin.cxx b/src/DecoderPlugin.cxx index eb83d542d..77ed90882 100644 --- a/src/DecoderPlugin.cxx +++ b/src/DecoderPlugin.cxx @@ -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); } diff --git a/src/DecoderPlugin.hxx b/src/DecoderPlugin.hxx index aaf7e5152..7aa508c53 100644 --- a/src/DecoderPlugin.hxx +++ b/src/DecoderPlugin.hxx @@ -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 ¶m) -{ - 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 ¶m) 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 diff --git a/src/DecoderThread.cxx b/src/DecoderThread.cxx index 83de64670..6fe1ff746 100644 --- a/src/DecoderThread.cxx +++ b/src/DecoderThread.cxx @@ -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(); diff --git a/src/TagFile.cxx b/src/TagFile.cxx index 70e92e73f..c26bdecde 100644 --- a/src/TagFile.cxx +++ b/src/TagFile.cxx @@ -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()); diff --git a/src/UpdateContainer.cxx b/src/UpdateContainer.cxx index 94a004f12..3f658cbcc 100644 --- a/src/UpdateContainer.cxx +++ b/src/UpdateContainer.cxx @@ -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(); |