mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-23 20:05:11 +00:00
code: Migrate filter::denoising to new dynamic loader
This commit is contained in:
parent
a4a18ebc3f
commit
debf976121
3 changed files with 21 additions and 29 deletions
|
@ -144,7 +144,7 @@ void denoising_instance::update(obs_data_t* data)
|
||||||
// Check if the user changed which Denoising provider we use.
|
// Check if the user changed which Denoising provider we use.
|
||||||
denoising_provider provider = static_cast<denoising_provider>(obs_data_get_int(data, ST_KEY_PROVIDER));
|
denoising_provider provider = static_cast<denoising_provider>(obs_data_get_int(data, ST_KEY_PROVIDER));
|
||||||
if (provider == denoising_provider::AUTOMATIC) {
|
if (provider == denoising_provider::AUTOMATIC) {
|
||||||
provider = denoising_factory::get()->find_ideal_provider();
|
provider = denoising_factory::instance()->find_ideal_provider();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the provider was changed, and if so switch.
|
// Check if the provider was changed, and if so switch.
|
||||||
|
@ -621,26 +621,27 @@ denoising_provider streamfx::filter::denoising::denoising_factory::find_ideal_pr
|
||||||
return denoising_provider::AUTOMATIC;
|
return denoising_provider::AUTOMATIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<denoising_factory> _video_denoising_factory_instance = nullptr;
|
std::shared_ptr<denoising_factory> denoising_factory::instance()
|
||||||
|
|
||||||
void denoising_factory::initialize()
|
|
||||||
{
|
{
|
||||||
try {
|
static std::weak_ptr<denoising_factory> winst;
|
||||||
if (!_video_denoising_factory_instance)
|
static std::mutex mtx;
|
||||||
_video_denoising_factory_instance = std::make_shared<denoising_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<denoising_factory>(new denoising_factory());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void denoising_factory::finalize()
|
static std::shared_ptr<denoising_factory> loader_instance;
|
||||||
{
|
|
||||||
_video_denoising_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<denoising_factory> denoising_factory::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return _video_denoising_factory_instance;
|
loader_instance = denoising_factory::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
@ -108,7 +108,7 @@ namespace streamfx::filter::denoising {
|
||||||
public: // Singleton
|
public: // Singleton
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static void finalize();
|
static void finalize();
|
||||||
static std::shared_ptr<::streamfx::filter::denoising::denoising_factory> get();
|
static std::shared_ptr<::streamfx::filter::denoising::denoising_factory> instance();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace streamfx::filter::denoising
|
} // namespace streamfx::filter::denoising
|
||||||
|
|
|
@ -19,9 +19,6 @@
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||||
#include "filters/filter-autoframing.hpp"
|
#include "filters/filter-autoframing.hpp"
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_FILTER_DENOISING
|
|
||||||
#include "filters/filter-denoising.hpp"
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||||
#include "filters/filter-displacement.hpp"
|
#include "filters/filter-displacement.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -128,9 +125,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||||
streamfx::filter::autoframing::autoframing_factory::initialize();
|
streamfx::filter::autoframing::autoframing_factory::initialize();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_FILTER_DENOISING
|
|
||||||
streamfx::filter::denoising::denoising_factory::initialize();
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||||
streamfx::filter::displacement::displacement_factory::initialize();
|
streamfx::filter::displacement::displacement_factory::initialize();
|
||||||
#endif
|
#endif
|
||||||
|
@ -157,9 +151,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||||
streamfx::filter::autoframing::autoframing_factory::finalize();
|
streamfx::filter::autoframing::autoframing_factory::finalize();
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_FILTER_DENOISING
|
|
||||||
streamfx::filter::denoising::denoising_factory::finalize();
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||||
streamfx::filter::displacement::displacement_factory::finalize();
|
streamfx::filter::displacement::displacement_factory::finalize();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue