From 203581f30ce9385287c1f69b0fa548d101bc24d7 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 7 Jun 2020 21:56:45 +0200 Subject: [PATCH] obs/source-factory: Add function to register proxy objects Proxies allow for older configurations to work fine on newer versions, without having to manually adjust the scene collection to match the new ids at all. Thanks to the migration system we can freely support any number of old versions, as long as we write migration code. --- source/common.hpp | 3 +++ source/obs/obs-source-factory.hpp | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/common.hpp b/source/common.hpp index 79f98b99..8d4197e5 100644 --- a/source/common.hpp +++ b/source/common.hpp @@ -33,12 +33,15 @@ // Common C++ includes #include #include +#include #include +#include #include #include #include #include #include +#include // Common Plugin includes #include "strings.hpp" diff --git a/source/obs/obs-source-factory.hpp b/source/obs/obs-source-factory.hpp index d9595f04..cfa5f704 100644 --- a/source/obs/obs-source-factory.hpp +++ b/source/obs/obs-source-factory.hpp @@ -25,7 +25,9 @@ namespace obs { template class source_factory { protected: - obs_source_info _info = {}; + obs_source_info _info = {}; + std::map> _proxies; + std::set _proxy_names; public: source_factory() @@ -166,6 +168,20 @@ namespace obs { obs_register_source(&_info); } + void register_proxy(std::string_view name) + { + auto iter = _proxy_names.emplace(name); + + // Create proxy. + std::shared_ptr proxy = std::make_shared(); + memcpy(proxy.get(), &_info, sizeof(obs_source_info)); + proxy->id = iter.first->c_str(); + proxy->output_flags |= OBS_SOURCE_DEPRECATED; + obs_register_source(proxy.get()); + + _proxies.emplace(name, proxy); + } + private /* Factory */: static const char* _get_name(void* type_data) noexcept try { @@ -509,7 +525,7 @@ namespace obs { public: virtual const char* get_name() { - return "Not Implemented Yet"; + return "Not Yet Implemented"; } virtual void* create(obs_data_t* settings, obs_source_t* source)