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