1 /* 2 * Copyright 2003-2021 The Music Player Daemon Project 3 * http://www.musicpd.org 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef MPD_DECODER_LIST_HXX 21 #define MPD_DECODER_LIST_HXX 22 23 #include <string_view> 24 25 struct ConfigData; 26 struct DecoderPlugin; 27 28 extern const struct DecoderPlugin *const decoder_plugins[]; 29 extern bool decoder_plugins_enabled[]; 30 31 /* interface for using plugins */ 32 33 [[gnu::pure]] 34 const struct DecoderPlugin * 35 decoder_plugin_from_name(const char *name) noexcept; 36 37 /* this is where we "load" all the "plugins" ;-) */ 38 void 39 decoder_plugin_init_all(const ConfigData &config); 40 41 /* this is where we "unload" all the "plugins" */ 42 void 43 decoder_plugin_deinit_all() noexcept; 44 45 class ScopeDecoderPluginsInit { 46 public: ScopeDecoderPluginsInit(const ConfigData & config)47 explicit ScopeDecoderPluginsInit(const ConfigData &config) { 48 decoder_plugin_init_all(config); 49 } 50 ~ScopeDecoderPluginsInit()51 ~ScopeDecoderPluginsInit() noexcept { 52 decoder_plugin_deinit_all(); 53 } 54 }; 55 56 template<typename F> 57 static inline const DecoderPlugin * decoder_plugins_find(F f)58decoder_plugins_find(F f) noexcept 59 { 60 for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) 61 if (decoder_plugins_enabled[i] && f(*decoder_plugins[i])) 62 return decoder_plugins[i]; 63 64 return nullptr; 65 } 66 67 template<typename F> 68 static inline bool decoder_plugins_try(F f)69decoder_plugins_try(F f) 70 { 71 for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) 72 if (decoder_plugins_enabled[i] && f(*decoder_plugins[i])) 73 return true; 74 75 return false; 76 } 77 78 template<typename F> 79 static inline void decoder_plugins_for_each(F f)80decoder_plugins_for_each(F f) 81 { 82 for (auto i = decoder_plugins; *i != nullptr; ++i) 83 f(**i); 84 } 85 86 template<typename F> 87 static inline void decoder_plugins_for_each_enabled(F f)88decoder_plugins_for_each_enabled(F f) 89 { 90 for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) 91 if (decoder_plugins_enabled[i]) 92 f(*decoder_plugins[i]); 93 } 94 95 /** 96 * Is there at least once #DecoderPlugin that supports the specified 97 * file name suffix? 98 */ 99 [[gnu::pure]] 100 bool 101 decoder_plugins_supports_suffix(std::string_view suffix) noexcept; 102 103 #endif 104