code: Migrate filter::sdf_effects to new dynamic loader

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-05-14 08:51:35 +02:00 committed by Xaymar
parent 17d25f1ef0
commit 5ca01dc589
3 changed files with 20 additions and 28 deletions

View file

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

View file

@ -100,7 +100,7 @@ namespace streamfx::filter::sdf_effects {
static void finalize(); static void finalize();
static std::shared_ptr<sdf_effects_factory> get(); static std::shared_ptr<sdf_effects_factory> instance();
}; };
} // namespace streamfx::filter::sdf_effects } // namespace streamfx::filter::sdf_effects

View file

@ -25,9 +25,6 @@
#ifdef ENABLE_FILTER_DISPLACEMENT #ifdef ENABLE_FILTER_DISPLACEMENT
#include "filters/filter-displacement.hpp" #include "filters/filter-displacement.hpp"
#endif #endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
#include "filters/filter-sdf-effects.hpp"
#endif
#ifdef ENABLE_FILTER_UPSCALING #ifdef ENABLE_FILTER_UPSCALING
#include "filters/filter-upscaling.hpp" #include "filters/filter-upscaling.hpp"
#endif #endif
@ -147,9 +144,6 @@ MODULE_EXPORT bool obs_module_load(void)
#ifdef ENABLE_FILTER_DISPLACEMENT #ifdef ENABLE_FILTER_DISPLACEMENT
streamfx::filter::displacement::displacement_factory::initialize(); streamfx::filter::displacement::displacement_factory::initialize();
#endif #endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
streamfx::filter::sdf_effects::sdf_effects_factory::initialize();
#endif
#ifdef ENABLE_FILTER_UPSCALING #ifdef ENABLE_FILTER_UPSCALING
streamfx::filter::upscaling::upscaling_factory::initialize(); streamfx::filter::upscaling::upscaling_factory::initialize();
#endif #endif
@ -199,9 +193,6 @@ MODULE_EXPORT void obs_module_unload(void)
#ifdef ENABLE_FILTER_DISPLACEMENT #ifdef ENABLE_FILTER_DISPLACEMENT
streamfx::filter::displacement::displacement_factory::finalize(); streamfx::filter::displacement::displacement_factory::finalize();
#endif #endif
#ifdef ENABLE_FILTER_SDF_EFFECTS
streamfx::filter::sdf_effects::sdf_effects_factory::finalize();
#endif
#ifdef ENABLE_FILTER_UPSCALING #ifdef ENABLE_FILTER_UPSCALING
streamfx::filter::upscaling::upscaling_factory::finalize(); streamfx::filter::upscaling::upscaling_factory::finalize();
#endif #endif