diff --git a/source/obs/obs-tools.cpp b/source/obs/obs-tools.cpp index 6fc72301..0e27fea7 100644 --- a/source/obs/obs-tools.cpp +++ b/source/obs/obs-tools.cpp @@ -179,3 +179,19 @@ bool obs::tools::obs_properties_remove_by_name(obs_properties_t* props, const ch return false; } + +obs::tools::child_source::child_source(obs_source_t* parent, std::shared_ptr child) + : _parent(parent), _child(child) +{ + obs_source_add_active_child(_parent, _child.get()); +} + +obs::tools::child_source::~child_source() +{ + obs_source_remove_active_child(_parent, _child.get()); +} + +std::shared_ptr obs::tools::child_source::get() +{ + return _child; +} diff --git a/source/obs/obs-tools.hpp b/source/obs/obs-tools.hpp index 56bd1572..efda77bd 100644 --- a/source/obs/obs-tools.hpp +++ b/source/obs/obs-tools.hpp @@ -22,6 +22,7 @@ #pragma once #include +#include #include // OBS @@ -39,6 +40,17 @@ namespace obs { bool scene_contains_source(obs_scene_t* scene, obs_source_t* source); bool obs_properties_remove_by_name(obs_properties_t* props, const char* name); + + class child_source { + obs_source_t* _parent; + std::shared_ptr _child; + + public: + child_source(obs_source_t* parent, std::shared_ptr child); + virtual ~child_source(); + + std::shared_ptr get(); + }; } // namespace tools static void obs_source_deleter(obs_source_t* v)