From e9fc9e89f237d77ffa3316610b093d56fc3fbbf5 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 16 Jan 2018 11:47:24 +0100 Subject: [PATCH] plugin: Use self-registration code everywhere --- source/filter-blur.cpp | 9 ++++----- source/filter-displacement.cpp | 11 +++++++++++ source/filter-shape.cpp | 20 +++++++++++++++----- source/filter-transform.cpp | 11 +++++++++++ source/plugin.cpp | 6 ------ source/source-mirror.cpp | 7 ++++--- 6 files changed, 45 insertions(+), 19 deletions(-) diff --git a/source/filter-blur.cpp b/source/filter-blur.cpp index 5d58c67d..b8d949a8 100644 --- a/source/filter-blur.cpp +++ b/source/filter-blur.cpp @@ -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 diff --git a/source/filter-displacement.cpp b/source/filter-displacement.cpp index f4180184..245b8e65 100644 --- a/source/filter-displacement.cpp +++ b/source/filter-displacement.cpp @@ -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"; diff --git a/source/filter-shape.cpp b/source/filter-shape.cpp index bd6e67ef..f46cd7f3 100644 --- a/source/filter-shape.cpp +++ b/source/filter-shape.cpp @@ -19,6 +19,10 @@ #include "filter-shape.h" #include "strings.h" +#include +#include +#include +#include extern "C" { #pragma warning (push) @@ -29,10 +33,16 @@ extern "C" { #pragma warning (pop) } -#include -#include -#include -#include +// Initializer & Finalizer +static Filter::Shape* filterShapeInstance; +INITIALIZER(FilterShapeInit) { + initializerFunctions.push_back([] { + filterShapeInstance = new Filter::Shape(); + }); + finalizerFunctions.push_back([] { + delete filterShapeInstance; + }); +} typedef std::pair cacheKey; typedef std::pair 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(); diff --git a/source/filter-transform.cpp b/source/filter-transform.cpp index ace14cc4..01af8fe4 100644 --- a/source/filter-transform.cpp +++ b/source/filter-transform.cpp @@ -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" diff --git a/source/plugin.cpp b/source/plugin.cpp index aa64ee90..08484020 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -35,9 +35,6 @@ std::list> initializerFunctions; std::list> 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() { diff --git a/source/source-mirror.cpp b/source/source-mirror.cpp index 07ae415d..5f908407 100644 --- a/source/source-mirror.cpp +++ b/source/source-mirror.cpp @@ -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; }); }