diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index 64b9f117..6570c78e 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -807,13 +807,13 @@ obs_properties_t* blur_factory::get_properties2(blur_instance* data) /// Source p = obs_properties_add_list(pr, ST_KEY_MASK_SOURCE, D_TRANSLATE(ST_I18N_MASK_SOURCE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); obs_property_list_add_string(p, "", ""); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { obs_property_list_add_string(p, std::string(name + " (Source)").c_str(), name.c_str()); return false; }, obs::source_tracker::filter_video_sources); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { obs_property_list_add_string(p, std::string(name + " (Scene)").c_str(), name.c_str()); return false; diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 7ec9c02b..ec71e006 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -730,7 +730,7 @@ obs_properties_t* dynamic_mask_factory::get_properties2(dynamic_mask_instance* d { // Input p = obs_properties_add_list(props, ST_KEY_INPUT, D_TRANSLATE(ST_I18N_INPUT), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); obs_property_list_add_string(p, "", ""); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SOURCE) << ")"; @@ -738,7 +738,7 @@ obs_properties_t* dynamic_mask_factory::get_properties2(dynamic_mask_instance* d return false; }, obs::source_tracker::filter_video_sources); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SCENE) << ")"; diff --git a/source/gfx/shader/gfx-shader-param-texture.cpp b/source/gfx/shader/gfx-shader-param-texture.cpp index 4be81497..cf9a3eb6 100644 --- a/source/gfx/shader/gfx-shader-param-texture.cpp +++ b/source/gfx/shader/gfx-shader-param-texture.cpp @@ -188,7 +188,7 @@ void streamfx::gfx::shader::texture_parameter::properties(obs_properties_t* prop { auto p = obs_properties_add_list(pr, _keys[2].c_str(), D_TRANSLATE(ST_I18N_SOURCE), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING); obs_property_list_add_string(p, "", ""); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SOURCE) << ")"; @@ -196,7 +196,7 @@ void streamfx::gfx::shader::texture_parameter::properties(obs_properties_t* prop return false; }, obs::source_tracker::filter_video_sources); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SCENE) << ")"; diff --git a/source/obs/obs-source-tracker.cpp b/source/obs/obs-source-tracker.cpp index 278327f6..4a010b71 100644 --- a/source/obs/obs-source-tracker.cpp +++ b/source/obs/obs-source-tracker.cpp @@ -4,6 +4,7 @@ #include "obs-source-tracker.hpp" #include "obs/obs-tools.hpp" +#include "plugin.hpp" #include "util/util-logging.hpp" #include "warning-disable.hpp" @@ -235,17 +236,27 @@ void streamfx::obs::source_tracker::source_rename_handler(void* ptr, calldata_t* } } -std::shared_ptr streamfx::obs::source_tracker::get() +std::shared_ptr streamfx::obs::source_tracker::instance() { - static std::mutex inst_mtx; - static std::weak_ptr inst_weak; + static std::weak_ptr winst; + static std::mutex mtx; - std::unique_lock lock(inst_mtx); - if (inst_weak.expired()) { - auto instance = std::shared_ptr(new streamfx::obs::source_tracker()); - inst_weak = instance; - return instance; - } else { - return inst_weak.lock(); + std::unique_lock lock(mtx); + auto instance = winst.lock(); + if (!instance) { + instance = std::shared_ptr(new streamfx::obs::source_tracker()); + winst = instance; } + return instance; } + +static std::shared_ptr loader_instance; + +static auto loader = streamfx::loader( + []() { // Initalizer + loader_instance = streamfx::obs::source_tracker::instance(); + }, + []() { // Finalizer + loader_instance.reset(); + }, + streamfx::loader_priority::HIGHEST); // Does not rely on other critical functionality. diff --git a/source/obs/obs-source-tracker.hpp b/source/obs/obs-source-tracker.hpp index 24cd1de8..fb7a0a61 100644 --- a/source/obs/obs-source-tracker.hpp +++ b/source/obs/obs-source-tracker.hpp @@ -32,7 +32,7 @@ namespace streamfx::obs { // @return true to skip, false to pass along. typedef std::function filter_cb_t; - protected: + private: source_tracker(); public: @@ -62,6 +62,6 @@ namespace streamfx::obs { static void source_rename_handler(void* ptr, calldata_t* data) noexcept; public: // Singleton - static std::shared_ptr get(); + static std::shared_ptr instance(); }; } // namespace streamfx::obs diff --git a/source/plugin.cpp b/source/plugin.cpp index cc1d2997..3be4f2e0 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -7,7 +7,6 @@ #include "gfx/gfx-opengl.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-vertexbuffer.hpp" -#include "obs/obs-source-tracker.hpp" #ifdef ENABLE_NVIDIA_CUDA #include "nvidia/cuda/nvidia-cuda-obs.hpp" @@ -81,8 +80,7 @@ #include #include "warning-enable.hpp" -static std::shared_ptr _streamfx_gfx_opengl; -static std::shared_ptr _source_tracker; +static std::shared_ptr _streamfx_gfx_opengl; namespace streamfx { typedef std::list loader_list_t; @@ -138,9 +136,6 @@ MODULE_EXPORT bool obs_module_load(void) } } - // Initialize Source Tracker - _source_tracker = streamfx::obs::source_tracker::get(); - // Initialize GLAD (OpenGL) { streamfx::obs::gs::context gctx{}; @@ -320,9 +315,6 @@ MODULE_EXPORT void obs_module_unload(void) _streamfx_gfx_opengl.reset(); } - // Finalize Source Tracker - _source_tracker.reset(); - // // Auto-Updater //#ifdef ENABLE_UPDATER // _updater.reset(); diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index bbf49d9a..e955b81a 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -327,7 +327,7 @@ obs_properties_t* mirror_factory::get_properties2(mirror_instance* data) obs_property_set_modified_callback(p, modified_properties); obs_property_list_add_string(p, "", ""); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SOURCE) << ")"; @@ -335,7 +335,7 @@ obs_properties_t* mirror_factory::get_properties2(mirror_instance* data) return false; }, obs::source_tracker::filter_sources); - obs::source_tracker::get()->enumerate( + obs::source_tracker::instance()->enumerate( [&p](std::string name, ::streamfx::obs::source) { std::stringstream sstr; sstr << name << " (" << D_TRANSLATE(S_SOURCETYPE_SCENE) << ")";