mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-27 13:53:01 +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.
|
||||
auto provider = static_cast<tracking_provider>(obs_data_get_int(data, ST_KEY_ADVANCED_PROVIDER));
|
||||
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.
|
||||
|
@ -1255,26 +1255,27 @@ tracking_provider streamfx::filter::autoframing::autoframing_factory::find_ideal
|
|||
return tracking_provider::INVALID;
|
||||
}
|
||||
|
||||
std::shared_ptr<autoframing_factory> _filter_autoframing_factory_instance = nullptr;
|
||||
|
||||
void autoframing_factory::initialize()
|
||||
std::shared_ptr<autoframing_factory> autoframing_factory::instance()
|
||||
{
|
||||
try {
|
||||
if (!_filter_autoframing_factory_instance)
|
||||
_filter_autoframing_factory_instance = std::make_shared<autoframing_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<autoframing_factory> winst;
|
||||
static std::mutex mtx;
|
||||
|
||||
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||
auto instance = winst.lock();
|
||||
if (!instance) {
|
||||
instance = std::shared_ptr<autoframing_factory>(new autoframing_factory());
|
||||
winst = instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void autoframing_factory::finalize()
|
||||
{
|
||||
_filter_autoframing_factory_instance.reset();
|
||||
}
|
||||
static std::shared_ptr<autoframing_factory> loader_instance;
|
||||
|
||||
std::shared_ptr<autoframing_factory> autoframing_factory::get()
|
||||
{
|
||||
return _filter_autoframing_factory_instance;
|
||||
}
|
||||
static auto loader = streamfx::loader(
|
||||
[]() { // Initalizer
|
||||
loader_instance = autoframing_factory::instance();
|
||||
},
|
||||
[]() { // Finalizer
|
||||
loader_instance.reset();
|
||||
},
|
||||
streamfx::loader_priority::NORMAL);
|
||||
|
|
|
@ -171,6 +171,6 @@ namespace streamfx::filter::autoframing {
|
|||
public: // Singleton
|
||||
static void initialize();
|
||||
static void finalize();
|
||||
static std::shared_ptr<autoframing_factory> get();
|
||||
static std::shared_ptr<autoframing_factory> instance();
|
||||
};
|
||||
} // namespace streamfx::filter::autoframing
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
#include "encoders/encoder-aom-av1.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||
#include "filters/filter-autoframing.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||
#include "filters/filter-displacement.hpp"
|
||||
#endif
|
||||
|
@ -122,9 +119,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
|||
|
||||
// Filters
|
||||
{
|
||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||
streamfx::filter::autoframing::autoframing_factory::initialize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||
streamfx::filter::displacement::displacement_factory::initialize();
|
||||
#endif
|
||||
|
@ -148,9 +142,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
|||
|
||||
// Filters
|
||||
{
|
||||
#ifdef ENABLE_FILTER_AUTOFRAMING
|
||||
streamfx::filter::autoframing::autoframing_factory::finalize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_DISPLACEMENT
|
||||
streamfx::filter::displacement::displacement_factory::finalize();
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue