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"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_SOURCE_MIRROR
|
||||
#include "sources/source-mirror.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRONTEND
|
||||
#include "ui/ui.hpp"
|
||||
#endif
|
||||
|
@ -152,13 +148,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Sources
|
||||
{
|
||||
#ifdef ENABLE_SOURCE_MIRROR
|
||||
streamfx::source::mirror::mirror_factory::initialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
||||
return true;
|
||||
} catch (std::exception const& ex) {
|
||||
|
@ -175,13 +164,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
|||
try {
|
||||
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
||||
|
||||
// Sources
|
||||
{
|
||||
#ifdef ENABLE_SOURCE_MIRROR
|
||||
streamfx::source::mirror::mirror_factory::finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Filters
|
||||
{
|
||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||
|
|
|
@ -381,26 +381,27 @@ bool mirror_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
|||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<mirror_factory> _source_mirror_factory_instance;
|
||||
|
||||
void streamfx::source::mirror::mirror_factory::initialize()
|
||||
std::shared_ptr<mirror_factory> mirror_factory::instance()
|
||||
{
|
||||
try {
|
||||
if (!_source_mirror_factory_instance)
|
||||
_source_mirror_factory_instance = std::make_shared<mirror_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<mirror_factory> winst;
|
||||
static std::mutex mtx;
|
||||
|
||||
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||
auto instance = winst.lock();
|
||||
if (!instance) {
|
||||
instance = std::shared_ptr<mirror_factory>(new mirror_factory());
|
||||
winst = instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void streamfx::source::mirror::mirror_factory::finalize()
|
||||
{
|
||||
_source_mirror_factory_instance.reset();
|
||||
}
|
||||
static std::shared_ptr<mirror_factory> loader_instance;
|
||||
|
||||
std::shared_ptr<mirror_factory> streamfx::source::mirror::mirror_factory::get()
|
||||
{
|
||||
return std::shared_ptr<mirror_factory>();
|
||||
}
|
||||
static auto loader = streamfx::loader(
|
||||
[]() { // Initalizer
|
||||
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 std::shared_ptr<mirror_factory> get();
|
||||
static std::shared_ptr<mirror_factory> instance();
|
||||
};
|
||||
} // namespace streamfx::source::mirror
|
||||
|
|
Loading…
Reference in a new issue