Skip to content

Commit

Permalink
project: Update to new classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaymar committed May 28, 2022
1 parent 892e20e commit db309e1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 51 deletions.
8 changes: 4 additions & 4 deletions source/filters/filter-dynamic-mask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,10 @@ 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<obs::tools::visible_source>(_input.lock().get());
_input_vs = ::streamfx::obs::source_showing_reference::add_showing_reference(_input.lock());
}

void streamfx::filter::dynamic_mask::dynamic_mask_instance::hide()
Expand All @@ -389,10 +389,10 @@ 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<obs::tools::active_source>(_input.lock().get());
_input_ac = ::streamfx::obs::source_active_reference::add_active_reference(_input.lock());
}

void streamfx::filter::dynamic_mask::dynamic_mask_instance::deactivate()
Expand Down
14 changes: 8 additions & 6 deletions source/filters/filter-dynamic-mask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <map>
#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"
Expand All @@ -40,12 +42,12 @@ namespace streamfx::filter::dynamic_mask {
std::shared_ptr<streamfx::obs::gs::rendertarget> _filter_rt;
std::shared_ptr<streamfx::obs::gs::texture> _filter_texture;

bool _have_input_texture;
::streamfx::obs::weak_source _input;
std::shared_ptr<streamfx::gfx::source_texture> _input_capture;
std::shared_ptr<streamfx::obs::gs::texture> _input_texture;
std::shared_ptr<obs::tools::visible_source> _input_vs;
std::shared_ptr<obs::tools::active_source> _input_ac;
bool _have_input_texture;
::streamfx::obs::weak_source _input;
std::shared_ptr<streamfx::gfx::source_texture> _input_capture;
std::shared_ptr<streamfx::obs::gs::texture> _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<streamfx::obs::gs::rendertarget> _final_rt;
Expand Down
19 changes: 9 additions & 10 deletions source/gfx/shader/gfx-shader-param-texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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_source_t>(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<streamfx::obs::tools::child_source>(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<streamfx::obs::tools::active_source> active;
std::shared_ptr<streamfx::obs::tools::visible_source> visible;
decltype(_source_active) active;
decltype(_source_visible) visible;
if (_active) {
active = std::make_shared<streamfx::obs::tools::active_source>(source.get());
active = ::streamfx::obs::source_active_reference::add_active_reference(source);
}
if (_visible) {
visible = std::make_shared<streamfx::obs::tools::visible_source>(source.get());
visible = ::streamfx::obs::source_showing_reference::add_showing_reference(source);
}

// Create the necessary render target to capture the source.
Expand Down Expand Up @@ -391,7 +390,7 @@ void streamfx::gfx::shader::texture_parameter::visible(bool visible)
_visible = visible;
if (visible) {
if (_source) {
_source_visible = std::make_shared<streamfx::obs::tools::visible_source>(_source.get());
_source_visible = ::streamfx::obs::source_showing_reference::add_showing_reference(_source);
}
} else {
_source_visible.reset();
Expand All @@ -403,7 +402,7 @@ void streamfx::gfx::shader::texture_parameter::active(bool active)
_active = active;
if (active) {
if (_source) {
_source_active = std::make_shared<streamfx::obs::tools::active_source>(_source.get());
_source_active = ::streamfx::obs::source_active_reference::add_active_reference(_source);
}
} else {
_source_active.reset();
Expand Down
16 changes: 10 additions & 6 deletions source/gfx/shader/gfx-shader-param-texture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -54,12 +58,12 @@ namespace streamfx::gfx {
std::shared_ptr<streamfx::obs::gs::texture> _file_texture;

// Data: Source
std::string _source_name;
std::shared_ptr<obs_source_t> _source;
std::shared_ptr<streamfx::obs::tools::child_source> _source_child;
std::shared_ptr<streamfx::obs::tools::active_source> _source_active;
std::shared_ptr<streamfx::obs::tools::visible_source> _source_visible;
std::shared_ptr<streamfx::obs::gs::rendertarget> _source_rendertarget;
std::string _source_name;
::streamfx::obs::source _source;
std::shared_ptr<streamfx::obs::source_active_child> _source_child;
std::shared_ptr<streamfx::obs::source_active_reference> _source_active;
std::shared_ptr<streamfx::obs::source_showing_reference> _source_visible;
std::shared_ptr<streamfx::obs::gs::rendertarget> _source_rendertarget;

public:
texture_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
Expand Down
25 changes: 7 additions & 18 deletions source/sources/source-mirror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,22 +188,16 @@ try {
release();

// Find source by name if possible.
std::shared_ptr<obs_source_t> source =
std::shared_ptr<obs_source_t>{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<obs::tools::child_source>(_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<obs::source_signal_handler>("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) {
Expand All @@ -220,15 +214,10 @@ void mirror_instance::release()
_signal_audio.reset();
_signal_rename.reset();
_source_child.reset();
_source.reset();
}

void mirror_instance::on_rename(std::shared_ptr<obs_source_t>, calldata*)
{
obs_source_save(_self);
_source.release();
}

void mirror_instance::on_audio(std::shared_ptr<obs_source_t>, 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) {
Expand Down
14 changes: 7 additions & 7 deletions source/sources/source-mirror.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -42,11 +43,11 @@ namespace streamfx::source::mirror {

class mirror_instance : public obs::source_instance {
// Source
std::shared_ptr<obs_source_t> _source;
std::shared_ptr<obs::tools::child_source> _source_child;
std::shared_ptr<obs::source_signal_handler> _signal_rename;
std::shared_ptr<obs::audio_signal_handler> _signal_audio;
std::pair<uint32_t, uint32_t> _source_size;
::streamfx::obs::source _source;
std::shared_ptr<::streamfx::obs::source_active_child> _source_child;
std::shared_ptr<obs::source_signal_handler> _signal_rename;
std::shared_ptr<obs::audio_signal_handler> _signal_audio;
std::pair<uint32_t, uint32_t> _source_size;

// Audio
bool _audio_enabled;
Expand Down Expand Up @@ -76,8 +77,7 @@ namespace streamfx::source::mirror {
void acquire(std::string source_name);
void release();

void on_rename(std::shared_ptr<obs_source_t>, calldata*);
void on_audio(std::shared_ptr<obs_source_t>, const struct audio_data*, bool);
void on_audio(::streamfx::obs::source, const struct audio_data*, bool);

void audio_output(std::shared_ptr<void> data);
};
Expand Down

0 comments on commit db309e1

Please sign in to comment.