decoder/List: add RAII class
This commit is contained in:
parent
e85b24bee0
commit
7a23c123c8
|
@ -534,7 +534,7 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
|
|||
|
||||
pcm_convert_global_init(raw_config);
|
||||
|
||||
decoder_plugin_init_all(raw_config);
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init(raw_config);
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
const bool create_db = InitDatabaseAndStorage(raw_config);
|
||||
|
@ -669,7 +669,6 @@ mpd_main_after_fork(const ConfigData &raw_config, const Config &config)
|
|||
|
||||
instance->FinishShutdownPartitions();
|
||||
command_finish();
|
||||
decoder_plugin_deinit_all();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,17 @@ decoder_plugin_init_all(const ConfigData &config);
|
|||
void
|
||||
decoder_plugin_deinit_all() noexcept;
|
||||
|
||||
class ScopeDecoderPluginsInit {
|
||||
public:
|
||||
explicit ScopeDecoderPluginsInit(const ConfigData &config) {
|
||||
decoder_plugin_init_all(config);
|
||||
}
|
||||
|
||||
~ScopeDecoderPluginsInit() noexcept {
|
||||
decoder_plugin_deinit_all();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename F>
|
||||
static inline const DecoderPlugin *
|
||||
decoder_plugins_find(F f) noexcept
|
||||
|
|
|
@ -65,7 +65,7 @@ try {
|
|||
|
||||
const Path path = Path::FromFS(argv[1]);
|
||||
|
||||
decoder_plugin_init_all(ConfigData());
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init({});
|
||||
|
||||
const auto *plugin = FindContainerDecoderPlugin(path);
|
||||
if (plugin == nullptr) {
|
||||
|
@ -87,8 +87,6 @@ try {
|
|||
|
||||
bos.Flush();
|
||||
|
||||
decoder_plugin_deinit_all();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
} catch (...) {
|
||||
PrintException(std::current_exception());
|
||||
|
|
|
@ -91,22 +91,18 @@ class GlobalInit {
|
|||
const ConfigData config;
|
||||
EventThread io_thread;
|
||||
const ScopeInputPluginsInit input_plugins_init;
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init;
|
||||
|
||||
public:
|
||||
explicit GlobalInit(Path config_path)
|
||||
:config(AutoLoadConfigFile(config_path)),
|
||||
input_plugins_init(config, io_thread.GetEventLoop())
|
||||
input_plugins_init(config, io_thread.GetEventLoop()),
|
||||
decoder_plugins_init(config)
|
||||
{
|
||||
io_thread.Start();
|
||||
|
||||
decoder_plugin_init_all(config);
|
||||
|
||||
pcm_convert_global_init(config);
|
||||
}
|
||||
|
||||
~GlobalInit() {
|
||||
decoder_plugin_deinit_all();
|
||||
}
|
||||
};
|
||||
|
||||
class ChromaprintDecoderClient final : public DecoderClient {
|
||||
|
|
|
@ -66,7 +66,7 @@ try {
|
|||
|
||||
const ScopeInputPluginsInit input_plugins_init(config, io_thread.GetEventLoop());
|
||||
playlist_list_global_init(config);
|
||||
decoder_plugin_init_all(config);
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init(config);
|
||||
|
||||
/* open the playlist */
|
||||
|
||||
|
@ -116,7 +116,6 @@ try {
|
|||
playlist.reset();
|
||||
is.reset();
|
||||
|
||||
decoder_plugin_deinit_all();
|
||||
playlist_list_global_finish();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
|
|
@ -96,8 +96,7 @@ try {
|
|||
const ScopeInputPluginsInit input_plugins_init(ConfigData(),
|
||||
io_thread.GetEventLoop());
|
||||
|
||||
decoder_plugin_init_all(ConfigData());
|
||||
AtScopeExit() { decoder_plugin_deinit_all(); };
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init({});
|
||||
|
||||
plugin = decoder_plugin_from_name(decoder_name);
|
||||
if (plugin == NULL) {
|
||||
|
|
|
@ -89,19 +89,15 @@ class GlobalInit {
|
|||
const ConfigData config;
|
||||
EventThread io_thread;
|
||||
const ScopeInputPluginsInit input_plugins_init;
|
||||
const ScopeDecoderPluginsInit decoder_plugins_init;
|
||||
|
||||
public:
|
||||
explicit GlobalInit(Path config_path)
|
||||
:config(AutoLoadConfigFile(config_path)),
|
||||
input_plugins_init(config, io_thread.GetEventLoop())
|
||||
input_plugins_init(config, io_thread.GetEventLoop()),
|
||||
decoder_plugins_init(config)
|
||||
{
|
||||
io_thread.Start();
|
||||
|
||||
decoder_plugin_init_all(config);
|
||||
}
|
||||
|
||||
~GlobalInit() {
|
||||
decoder_plugin_deinit_all();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue