mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-14 15:55:07 +00:00
code: Migrate source::mirror to new dynamic loader
This commit is contained in:
parent
5ca01dc589
commit
e630ddc8a7
3 changed files with 20 additions and 37 deletions
|
@ -32,10 +32,6 @@
|
||||||
#include "filters/filter-virtual-greenscreen.hpp"
|
#include "filters/filter-virtual-greenscreen.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
|
||||||
#include "sources/source-mirror.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FRONTEND
|
#ifdef ENABLE_FRONTEND
|
||||||
#include "ui/ui.hpp"
|
#include "ui/ui.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -152,13 +148,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sources
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
|
||||||
streamfx::source::mirror::mirror_factory::initialize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
||||||
return true;
|
return true;
|
||||||
} catch (std::exception const& ex) {
|
} catch (std::exception const& ex) {
|
||||||
|
@ -175,13 +164,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
try {
|
try {
|
||||||
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
||||||
|
|
||||||
// Sources
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
|
||||||
streamfx::source::mirror::mirror_factory::finalize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||||
|
|
|
@ -381,26 +381,27 @@ bool mirror_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<mirror_factory> _source_mirror_factory_instance;
|
std::shared_ptr<mirror_factory> mirror_factory::instance()
|
||||||
|
|
||||||
void streamfx::source::mirror::mirror_factory::initialize()
|
|
||||||
{
|
{
|
||||||
try {
|
static std::weak_ptr<mirror_factory> winst;
|
||||||
if (!_source_mirror_factory_instance)
|
static std::mutex mtx;
|
||||||
_source_mirror_factory_instance = std::make_shared<mirror_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<mirror_factory>(new mirror_factory());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamfx::source::mirror::mirror_factory::finalize()
|
static std::shared_ptr<mirror_factory> loader_instance;
|
||||||
{
|
|
||||||
_source_mirror_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<mirror_factory> streamfx::source::mirror::mirror_factory::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return std::shared_ptr<mirror_factory>();
|
loader_instance = mirror_factory::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
@ -90,6 +90,6 @@ namespace streamfx::source::mirror {
|
||||||
|
|
||||||
static void finalize();
|
static void finalize();
|
||||||
|
|
||||||
static std::shared_ptr<mirror_factory> get();
|
static std::shared_ptr<mirror_factory> instance();
|
||||||
};
|
};
|
||||||
} // namespace streamfx::source::mirror
|
} // namespace streamfx::source::mirror
|
||||||
|
|
Loading…
Reference in a new issue