mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-23 20:05:11 +00:00
code: Migrate filter::autoframing to new dynamic loader
This commit is contained in:
parent
debf976121
commit
0227cfd7b5
3 changed files with 21 additions and 29 deletions
|
@ -345,7 +345,7 @@ void autoframing_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.
|
||||||
auto provider = static_cast<tracking_provider>(obs_data_get_int(data, ST_KEY_ADVANCED_PROVIDER));
|
auto provider = static_cast<tracking_provider>(obs_data_get_int(data, ST_KEY_ADVANCED_PROVIDER));
|
||||||
if (provider == tracking_provider::AUTOMATIC) {
|
if (provider == tracking_provider::AUTOMATIC) {
|
||||||
provider = autoframing_factory::get()->find_ideal_provider();
|
provider = autoframing_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.
|
||||||
|
@ -1255,26 +1255,27 @@ tracking_provider streamfx::filter::autoframing::autoframing_factory::find_ideal
|
||||||
return tracking_provider::INVALID;
|
return tracking_provider::INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<autoframing_factory> _filter_autoframing_factory_instance = nullptr;
|
std::shared_ptr<autoframing_factory> autoframing_factory::instance()
|
||||||
|
|
||||||
void autoframing_factory::initialize()
|
|
||||||
{
|
{
|
||||||
try {
|
static std::weak_ptr<autoframing_factory> winst;
|
||||||
if (!_filter_autoframing_factory_instance)
|
static std::mutex mtx;
|
||||||
_filter_autoframing_factory_instance = std::make_shared<autoframing_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<autoframing_factory>(new autoframing_factory());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoframing_factory::finalize()
|
static std::shared_ptr<autoframing_factory> loader_instance;
|
||||||
{
|
|
||||||
_filter_autoframing_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<autoframing_factory> autoframing_factory::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return _filter_autoframing_factory_instance;
|
loader_instance = autoframing_factory::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
@ -171,6 +171,6 @@ namespace streamfx::filter::autoframing {
|
||||||
public: // Singleton
|
public: // Singleton
|
||||||
static void initialize();
|
static void initialize();
|
||||||
static void finalize();
|
static void finalize();
|
||||||
static std::shared_ptr<autoframing_factory> get();
|
static std::shared_ptr<autoframing_factory> instance();
|
||||||
};
|
};
|
||||||
} // namespace streamfx::filter::autoframing
|
} // namespace streamfx::filter::autoframing
|
||||||
|
|
|
@ -16,9 +16,6 @@
|
||||||
#include "encoders/encoder-aom-av1.hpp"
|
#include "encoders/encoder-aom-av1.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
|
||||||
#include "filters/filter-autoframing.hpp"
|
|
||||||
#endif
|
|
||||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||||
#include "filters/filter-displacement.hpp"
|
#include "filters/filter-displacement.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -122,9 +119,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
|
||||||
streamfx::filter::autoframing::autoframing_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
|
||||||
|
@ -148,9 +142,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
|
||||||
streamfx::filter::autoframing::autoframing_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