plugin: Use self-registration code everywhere

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-01-16 11:47:24 +01:00
parent cb1ae28b07
commit e9fc9e89f2
6 changed files with 45 additions and 19 deletions

View file

@ -32,18 +32,17 @@ extern "C" {
#pragma warning (pop)
}
// Initialize & Finalizer
static Filter::Blur* handler;
// Initializer & Finalizer
static Filter::Blur* filterBlurInstance;
INITIALIZER(FilterBlurInit) {
initializerFunctions.push_back([] {
handler = new Filter::Blur();
filterBlurInstance = new Filter::Blur();
});
finalizerFunctions.push_back([] {
delete handler;
delete filterBlurInstance;
});
}
enum ColorFormat : uint64_t {
RGB,
YUV, // 701

View file

@ -20,6 +20,17 @@
#include "filter-displacement.h"
#include "strings.h"
// Initializer & Finalizer
static Filter::Displacement* filterDisplacementInstance;
INITIALIZER(FilterDisplacementInit) {
initializerFunctions.push_back([] {
filterDisplacementInstance = new Filter::Displacement();
});
finalizerFunctions.push_back([] {
delete filterDisplacementInstance;
});
}
Filter::Displacement::Displacement() {
memset(&sourceInfo, 0, sizeof(obs_source_info));
sourceInfo.id = "obs-stream-effects-filter-displacement";

View file

@ -19,6 +19,10 @@
#include "filter-shape.h"
#include "strings.h"
#include <string>
#include <vector>
#include <map>
#include <memory>
extern "C" {
#pragma warning (push)
@ -29,10 +33,16 @@ extern "C" {
#pragma warning (pop)
}
#include <string>
#include <vector>
#include <map>
#include <memory>
// Initializer & Finalizer
static Filter::Shape* filterShapeInstance;
INITIALIZER(FilterShapeInit) {
initializerFunctions.push_back([] {
filterShapeInstance = new Filter::Shape();
});
finalizerFunctions.push_back([] {
delete filterShapeInstance;
});
}
typedef std::pair<uint32_t, std::string> cacheKey;
typedef std::pair<std::string, std::string> cacheValue;
@ -66,6 +76,7 @@ static void initialize() {
}
Filter::Shape::Shape() {
return; // Disabled for the time being. 3D Transform is better for this.
memset(&sourceInfo, 0, sizeof(obs_source_info));
sourceInfo.id = "obs-stream-effects-filter-shape";
sourceInfo.type = OBS_SOURCE_TYPE_FILTER;
@ -84,7 +95,6 @@ Filter::Shape::Shape() {
sourceInfo.video_tick = video_tick;
sourceInfo.video_render = video_render;
// Disabled for the time being. 3D Transform is better for this.
obs_register_source(&sourceInfo);
initialize();

View file

@ -30,6 +30,17 @@ extern "C" {
#pragma warning (pop)
}
// Initializer & Finalizer
static Filter::Transform* filterTransformInstance;
INITIALIZER(FilterTransformInit) {
initializerFunctions.push_back([] {
filterTransformInstance = new Filter::Transform();
});
finalizerFunctions.push_back([] {
delete filterTransformInstance;
});
}
#define ST "Filter.Transform"
#define ST_CAMERA "Filter.Transform.Camera"
#define ST_CAMERA_ORTHOGRAPHIC "Filter.Transform.Camera.Orthographic"

View file

@ -35,9 +35,6 @@ 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();
for (auto func : initializerFunctions) {
func();
}
@ -48,9 +45,6 @@ MODULE_EXPORT void obs_module_unload(void) {
for (auto func : finalizerFunctions) {
func();
}
delete filterTransform;
delete filterShape;
delete filterDisplacement;
}
MODULE_EXPORT const char* obs_module_name() {

View file

@ -43,13 +43,14 @@ enum class ScalingMethod : int64_t {
Lanczos,
};
Source::MirrorAddon* inst;
// Initializer & Finalizer
Source::MirrorAddon* sourceMirrorInstance;
INITIALIZER(SourceMirrorInit) {
initializerFunctions.push_back([] {
inst = new Source::MirrorAddon();
sourceMirrorInstance = new Source::MirrorAddon();
});
finalizerFunctions.push_back([] {
delete inst;
delete sourceMirrorInstance;
});
}