diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 5797a159..7bad5bfb 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -376,10 +376,11 @@ void dynamic_mask_instance::enum_all_sources(obs_source_enum_proc_t enum_callbac void streamfx::filter::dynamic_mask::dynamic_mask_instance::show() { - if (!_input || !obs_source_showing(obs_filter_get_parent(_self))) + if (!_input || !_self.showing() || !(_self.get_filter_parent().showing())) return; - _input_vs = std::make_shared(_input.lock().get()); + auto input = _input.lock(); + _input_vs = ::streamfx::obs::source_showing_reference::add_showing_reference(input); } void streamfx::filter::dynamic_mask::dynamic_mask_instance::hide() @@ -389,10 +390,11 @@ void streamfx::filter::dynamic_mask::dynamic_mask_instance::hide() void streamfx::filter::dynamic_mask::dynamic_mask_instance::activate() { - if (!_input || !obs_source_active(obs_filter_get_parent(_self))) + if (!_input || !_self.active() || !(_self.get_filter_parent().active())) return; - _input_ac = std::make_shared(_input.lock().get()); + auto input = _input.lock(); + _input_ac = ::streamfx::obs::source_active_reference::add_active_reference(input); } void streamfx::filter::dynamic_mask::dynamic_mask_instance::deactivate() diff --git a/source/filters/filter-dynamic-mask.hpp b/source/filters/filter-dynamic-mask.hpp index fb152d72..3b936aec 100644 --- a/source/filters/filter-dynamic-mask.hpp +++ b/source/filters/filter-dynamic-mask.hpp @@ -23,7 +23,9 @@ #include #include "gfx/gfx-source-texture.hpp" #include "obs/gs/gs-effect.hpp" +#include "obs/obs-source-active-reference.hpp" #include "obs/obs-source-factory.hpp" +#include "obs/obs-source-showing-reference.hpp" #include "obs/obs-source-tracker.hpp" #include "obs/obs-source.hpp" #include "obs/obs-tools.hpp" @@ -40,12 +42,12 @@ namespace streamfx::filter::dynamic_mask { std::shared_ptr _filter_rt; std::shared_ptr _filter_texture; - bool _have_input_texture; - ::streamfx::obs::weak_source _input; - std::shared_ptr _input_capture; - std::shared_ptr _input_texture; - std::shared_ptr _input_vs; - std::shared_ptr _input_ac; + bool _have_input_texture; + ::streamfx::obs::weak_source _input; + std::shared_ptr _input_capture; + std::shared_ptr _input_texture; + std::shared_ptr<::streamfx::obs::source_showing_reference> _input_vs; + std::shared_ptr<::streamfx::obs::source_active_reference> _input_ac; bool _have_final_texture; std::shared_ptr _final_rt; diff --git a/source/gfx/shader/gfx-shader-param-texture.cpp b/source/gfx/shader/gfx-shader-param-texture.cpp index ffdb2892..e52b169d 100644 --- a/source/gfx/shader/gfx-shader-param-texture.cpp +++ b/source/gfx/shader/gfx-shader-param-texture.cpp @@ -283,7 +283,7 @@ void streamfx::gfx::shader::texture_parameter::assign() // Reload or Reacquire everything necessary. try { // Remove now unused references. - _source.reset(); + _source.release(); _source_child.reset(); _source_active.reset(); _source_visible.reset(); @@ -298,23 +298,22 @@ void streamfx::gfx::shader::texture_parameter::assign() } } else if ((field_type() == texture_field_type::Input) && (_type == texture_type::Source)) { // Try and grab the source itself. - auto source = std::shared_ptr(obs_get_source_by_name(_source_name.c_str()), - [](obs_source_t* v) { obs_source_release(v); }); + auto source = ::streamfx::obs::source(_source_name); if (!source) { throw std::runtime_error("Specified Source does not exist."); } // Attach the child to our parent. - auto child = std::make_shared(get_parent()->get(), source); + auto child = std::make_shared<::streamfx::obs::source_active_child>(source, get_parent()->get()); // Create necessary visible and active objects. - std::shared_ptr active; - std::shared_ptr visible; + decltype(_source_active) active; + decltype(_source_visible) visible; if (_active) { - active = std::make_shared(source.get()); + active = ::streamfx::obs::source_active_reference::add_active_reference(source); } if (_visible) { - visible = std::make_shared(source.get()); + visible = ::streamfx::obs::source_showing_reference::add_showing_reference(source); } // Create the necessary render target to capture the source. @@ -391,7 +390,7 @@ void streamfx::gfx::shader::texture_parameter::visible(bool visible) _visible = visible; if (visible) { if (_source) { - _source_visible = std::make_shared(_source.get()); + _source_visible = ::streamfx::obs::source_showing_reference::add_showing_reference(_source); } } else { _source_visible.reset(); @@ -403,7 +402,7 @@ void streamfx::gfx::shader::texture_parameter::active(bool active) _active = active; if (active) { if (_source) { - _source_active = std::make_shared(_source.get()); + _source_active = ::streamfx::obs::source_active_reference::add_active_reference(_source); } } else { _source_active.reset(); diff --git a/source/gfx/shader/gfx-shader-param-texture.hpp b/source/gfx/shader/gfx-shader-param-texture.hpp index 189102a2..7491efb1 100644 --- a/source/gfx/shader/gfx-shader-param-texture.hpp +++ b/source/gfx/shader/gfx-shader-param-texture.hpp @@ -6,6 +6,10 @@ #include "gfx-shader-param.hpp" #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-texture.hpp" +#include "obs/obs-source-active-child.hpp" +#include "obs/obs-source-active-reference.hpp" +#include "obs/obs-source-showing-reference.hpp" +#include "obs/obs-source.hpp" #include "obs/obs-tools.hpp" namespace streamfx::gfx { @@ -54,12 +58,12 @@ namespace streamfx::gfx { std::shared_ptr _file_texture; // Data: Source - std::string _source_name; - std::shared_ptr _source; - std::shared_ptr _source_child; - std::shared_ptr _source_active; - std::shared_ptr _source_visible; - std::shared_ptr _source_rendertarget; + std::string _source_name; + ::streamfx::obs::source _source; + std::shared_ptr _source_child; + std::shared_ptr _source_active; + std::shared_ptr _source_visible; + std::shared_ptr _source_rendertarget; public: texture_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param, diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index 86b452cd..7c70649f 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -188,22 +188,16 @@ try { release(); // Find source by name if possible. - std::shared_ptr source = - std::shared_ptr{obs_get_source_by_name(source_name.c_str()), obs::obs_source_deleter}; - if ((!source) || (source.get() == _self)) { // If we failed, just exit early. + decltype(_source) source{source_name}; + if ((!source) || (source == _self)) { // If we failed, just exit early. return; } // Everything went well, store. - _source_child = std::make_shared(_self, source); + _source_child = std::make_shared<::streamfx::obs::source_active_child>(_self, source); _source = source; - _source_size.first = obs_source_get_width(_source.get()); - _source_size.second = obs_source_get_height(_source.get()); - - // Listen to the rename event to update our own settings. - _signal_rename = std::make_shared("rename", _source); - _signal_rename->event.add( - std::bind(&mirror_instance::on_rename, this, std::placeholders::_1, std::placeholders::_2)); + _source_size.first = obs_source_get_width(_source); + _source_size.second = obs_source_get_height(_source); // Listen to any audio the source spews out. if (_audio_enabled) { @@ -220,15 +214,10 @@ void mirror_instance::release() _signal_audio.reset(); _signal_rename.reset(); _source_child.reset(); - _source.reset(); + _source.release(); } -void mirror_instance::on_rename(std::shared_ptr, calldata*) -{ - obs_source_save(_self); -} - -void mirror_instance::on_audio(std::shared_ptr, const audio_data* audio, bool) +void mirror_instance::on_audio(::streamfx::obs::source, const audio_data* audio, bool) { // Immediately quit if there isn't any actual audio to send out. if (!_audio_enabled) { diff --git a/source/sources/source-mirror.hpp b/source/sources/source-mirror.hpp index 5ecb96dd..d0f7da0d 100644 --- a/source/sources/source-mirror.hpp +++ b/source/sources/source-mirror.hpp @@ -28,6 +28,7 @@ #include "obs/gs/gs-rendertarget.hpp" #include "obs/gs/gs-sampler.hpp" #include "obs/obs-signal-handler.hpp" +#include "obs/obs-source-active-child.hpp" #include "obs/obs-source-factory.hpp" #include "obs/obs-source.hpp" #include "obs/obs-tools.hpp" @@ -42,11 +43,11 @@ namespace streamfx::source::mirror { class mirror_instance : public obs::source_instance { // Source - std::shared_ptr _source; - std::shared_ptr _source_child; - std::shared_ptr _signal_rename; - std::shared_ptr _signal_audio; - std::pair _source_size; + ::streamfx::obs::source _source; + std::shared_ptr<::streamfx::obs::source_active_child> _source_child; + std::shared_ptr _signal_rename; + std::shared_ptr _signal_audio; + std::pair _source_size; // Audio bool _audio_enabled; @@ -76,8 +77,7 @@ namespace streamfx::source::mirror { void acquire(std::string source_name); void release(); - void on_rename(std::shared_ptr, calldata*); - void on_audio(std::shared_ptr, const struct audio_data*, bool); + void on_audio(::streamfx::obs::source, const struct audio_data*, bool); void audio_output(std::shared_ptr data); };