code: Migrate filter::dynamic_mask to new dynamic loader

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-05-14 08:49:10 +02:00 committed by Xaymar
parent 4d913c34f5
commit 1059e5c027
3 changed files with 20 additions and 28 deletions

View file

@ -822,26 +822,27 @@ bool dynamic_mask_factory::on_manual_open(obs_properties_t* props, obs_property_
}
#endif
std::shared_ptr<dynamic_mask_factory> _filter_dynamic_mask_factory_instance = nullptr;
void streamfx::filter::dynamic_mask::dynamic_mask_factory::initialize()
std::shared_ptr<dynamic_mask_factory> dynamic_mask_factory::instance()
{
try {
if (!_filter_dynamic_mask_factory_instance)
_filter_dynamic_mask_factory_instance = std::make_shared<dynamic_mask_factory>();
} catch (const std::exception& ex) {
D_LOG_ERROR("Failed to initialize due to error: %s", ex.what());
} catch (...) {
D_LOG_ERROR("Failed to initialize due to unknown error.", "");
static std::weak_ptr<dynamic_mask_factory> winst;
static std::mutex mtx;
std::unique_lock<decltype(mtx)> lock(mtx);
auto instance = winst.lock();
if (!instance) {
instance = std::shared_ptr<dynamic_mask_factory>(new dynamic_mask_factory());
winst = instance;
}
return instance;
}
void streamfx::filter::dynamic_mask::dynamic_mask_factory::finalize()
{
_filter_dynamic_mask_factory_instance.reset();
}
static std::shared_ptr<dynamic_mask_factory> loader_instance;
std::shared_ptr<dynamic_mask_factory> streamfx::filter::dynamic_mask::dynamic_mask_factory::get()
{
return _filter_dynamic_mask_factory_instance;
}
static auto loader = streamfx::loader(
[]() { // Initalizer
loader_instance = dynamic_mask_factory::instance();
},
[]() { // Finalizer
loader_instance.reset();
},
streamfx::loader_priority::NORMAL);

View file

@ -133,6 +133,6 @@ namespace streamfx::filter::dynamic_mask {
static void finalize();
static std::shared_ptr<dynamic_mask_factory> get();
static std::shared_ptr<dynamic_mask_factory> instance();
};
} // namespace streamfx::filter::dynamic_mask

View file

@ -28,9 +28,6 @@
#ifdef ENABLE_FILTER_DISPLACEMENT
#include "filters/filter-displacement.hpp"
#endif
#ifdef ENABLE_FILTER_DYNAMIC_MASK
#include "filters/filter-dynamic-mask.hpp"
#endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
#include "filters/filter-sdf-effects.hpp"
#endif
@ -156,9 +153,6 @@ MODULE_EXPORT bool obs_module_load(void)
#ifdef ENABLE_FILTER_DISPLACEMENT
streamfx::filter::displacement::displacement_factory::initialize();
#endif
#ifdef ENABLE_FILTER_DYNAMIC_MASK
streamfx::filter::dynamic_mask::dynamic_mask_factory::initialize();
#endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
streamfx::filter::sdf_effects::sdf_effects_factory::initialize();
#endif
@ -214,9 +208,6 @@ MODULE_EXPORT void obs_module_unload(void)
#ifdef ENABLE_FILTER_DISPLACEMENT
streamfx::filter::displacement::displacement_factory::finalize();
#endif
#ifdef ENABLE_FILTER_DYNAMIC_MASK
streamfx::filter::dynamic_mask::dynamic_mask_factory::finalize();
#endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
streamfx::filter::sdf_effects::sdf_effects_factory::finalize();
#endif