plugin: Allow new filters and transitions to self-register

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2017-11-05 20:05:48 +01:00
parent 3baecb4f2f
commit fc02f3fdad
2 changed files with 38 additions and 0 deletions

View file

@ -32,15 +32,24 @@ Filter::Displacement *filterDisplacement;
Filter::Shape *filterShape;
Filter::Transform *filterTransform;
std::list<std::function<void()>> initializerFunctions;
std::list<std::function<void()>> finalizerFunctions;
MODULE_EXPORT bool obs_module_load(void) {
filterDisplacement = new Filter::Displacement();
filterShape = new Filter::Shape();
filterTransform = new Filter::Transform();
filterBlur = new Filter::Blur();
for (auto func : initializerFunctions) {
func();
}
return true;
}
MODULE_EXPORT void obs_module_unload(void) {
for (auto func : finalizerFunctions) {
func();
}
delete filterTransform;
delete filterShape;
delete filterDisplacement;

View file

@ -19,6 +19,8 @@
#pragma once
#include <inttypes.h>
#include <list>
#include <functional>
#pragma warning (push)
#pragma warning (disable: 4201)
@ -57,3 +59,30 @@
#define __FUNCTION_NAME__ __func__
#endif
#endif
#ifdef __cplusplus
#define INITIALIZER(f) \
static void f(void); \
struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \
static void f(void)
#elif defined(_MSC_VER)
#pragma section(".CRT$XCU",read)
#define INITIALIZER2_(f,p) \
static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker,"/include:" p #f "_")) \
static void f(void)
#ifdef _WIN64
#define INITIALIZER(f) INITIALIZER2_(f,"")
#else
#define INITIALIZER(f) INITIALIZER2_(f,"_")
#endif
#else
#define INITIALIZER(f) \
static void f(void) __attribute__((constructor)); \
static void f(void)
#endif
// Initializer & Finalizer
extern std::list<std::function<void()>> initializerFunctions;
extern std::list<std::function<void()>> finalizerFunctions;