project: Refactoring Part 2

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-01-27 23:33:12 +01:00
parent 39b0600aa3
commit 10c0081f32
10 changed files with 304 additions and 304 deletions

View file

@ -85,28 +85,28 @@ static uint8_t const max_kernel_size = 25;
// Initializer & Finalizer
INITIALIZER(filterBlurFactoryInitializer)
{
initializerFunctions.push_back([] { filter::blur::factory::initialize(); });
finalizerFunctions.push_back([] { filter::blur::factory::finalize(); });
initializerFunctions.push_back([] { filter::blur::blur_factory::initialize(); });
finalizerFunctions.push_back([] { filter::blur::blur_factory::finalize(); });
}
static std::shared_ptr<filter::blur::factory> factory_instance = nullptr;
static std::shared_ptr<filter::blur::blur_factory> factory_instance = nullptr;
void filter::blur::factory::initialize()
void filter::blur::blur_factory::initialize()
{
factory_instance = std::make_shared<filter::blur::factory>();
factory_instance = std::make_shared<filter::blur::blur_factory>();
}
void filter::blur::factory::finalize()
void filter::blur::blur_factory::finalize()
{
factory_instance.reset();
}
std::shared_ptr<filter::blur::factory> filter::blur::factory::get()
std::shared_ptr<filter::blur::blur_factory> filter::blur::blur_factory::get()
{
return factory_instance;
}
filter::blur::factory::factory()
filter::blur::blur_factory::blur_factory()
{
memset(&source_info, 0, sizeof(obs_source_info));
source_info.id = "obs-stream-effects-filter-blur";
@ -128,9 +128,9 @@ filter::blur::factory::factory()
obs_register_source(&source_info);
}
filter::blur::factory::~factory() {}
filter::blur::blur_factory::~blur_factory() {}
void filter::blur::factory::on_list_fill()
void filter::blur::blur_factory::on_list_fill()
{
obs_enter_graphics();
@ -166,7 +166,7 @@ void filter::blur::factory::on_list_fill()
obs_leave_graphics();
}
void filter::blur::factory::on_list_empty()
void filter::blur::blur_factory::on_list_empty()
{
obs_enter_graphics();
blur_effect.reset();
@ -176,7 +176,7 @@ void filter::blur::factory::on_list_empty()
obs_leave_graphics();
}
void filter::blur::factory::generate_gaussian_kernels()
void filter::blur::blur_factory::generate_gaussian_kernels()
{
// 2D texture, horizontal is value, vertical is kernel size.
size_t size_power_of_two = size_t(pow(2, util::math::get_power_of_two_exponent_ceil(max_kernel_size)));
@ -219,24 +219,24 @@ void filter::blur::factory::generate_gaussian_kernels()
}
}
void filter::blur::factory::generate_kernel_textures()
void filter::blur::blur_factory::generate_kernel_textures()
{
generate_gaussian_kernels();
}
void* filter::blur::factory::create(obs_data_t* data, obs_source_t* parent)
void* filter::blur::blur_factory::create(obs_data_t* data, obs_source_t* parent)
{
if (get()->sources.empty()) {
get()->on_list_fill();
}
filter::blur::instance* ptr = new filter::blur::instance(data, parent);
filter::blur::blur_instance* ptr = new filter::blur::blur_instance(data, parent);
get()->sources.push_back(ptr);
return ptr;
}
void filter::blur::factory::destroy(void* inptr)
void filter::blur::blur_factory::destroy(void* inptr)
{
filter::blur::instance* ptr = reinterpret_cast<filter::blur::instance*>(inptr);
filter::blur::blur_instance* ptr = reinterpret_cast<filter::blur::blur_instance*>(inptr);
get()->sources.remove(ptr);
if (get()->sources.empty()) {
get()->on_list_empty();
@ -244,7 +244,7 @@ void filter::blur::factory::destroy(void* inptr)
delete ptr;
}
void filter::blur::factory::get_defaults(obs_data_t* data)
void filter::blur::blur_factory::get_defaults(obs_data_t* data)
{
obs_data_set_default_int(data, P_TYPE, filter::blur::type::Box);
obs_data_set_default_int(data, P_SIZE, 5);
@ -284,62 +284,62 @@ void filter::blur::factory::get_defaults(obs_data_t* data)
obs_data_set_default_int(data, P_COLORFORMAT, ColorFormat::RGB);
}
obs_properties_t* filter::blur::factory::get_properties(void* inptr)
obs_properties_t* filter::blur::blur_factory::get_properties(void* inptr)
{
return reinterpret_cast<filter::blur::instance*>(inptr)->get_properties();
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_properties();
}
void filter::blur::factory::update(void* inptr, obs_data_t* settings)
void filter::blur::blur_factory::update(void* inptr, obs_data_t* settings)
{
reinterpret_cast<filter::blur::instance*>(inptr)->update(settings);
reinterpret_cast<filter::blur::blur_instance*>(inptr)->update(settings);
}
void filter::blur::factory::load(void* inptr, obs_data_t* settings)
void filter::blur::blur_factory::load(void* inptr, obs_data_t* settings)
{
reinterpret_cast<filter::blur::instance*>(inptr)->update(settings);
reinterpret_cast<filter::blur::blur_instance*>(inptr)->update(settings);
}
const char* filter::blur::factory::get_name(void*)
const char* filter::blur::blur_factory::get_name(void*)
{
return P_TRANSLATE(SOURCE_NAME);
}
uint32_t filter::blur::factory::get_width(void* inptr)
uint32_t filter::blur::blur_factory::get_width(void* inptr)
{
return reinterpret_cast<filter::blur::instance*>(inptr)->get_width();
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_width();
}
uint32_t filter::blur::factory::get_height(void* inptr)
uint32_t filter::blur::blur_factory::get_height(void* inptr)
{
return reinterpret_cast<filter::blur::instance*>(inptr)->get_height();
return reinterpret_cast<filter::blur::blur_instance*>(inptr)->get_height();
}
void filter::blur::factory::activate(void* inptr)
void filter::blur::blur_factory::activate(void* inptr)
{
reinterpret_cast<filter::blur::instance*>(inptr)->activate();
reinterpret_cast<filter::blur::blur_instance*>(inptr)->activate();
}
void filter::blur::factory::deactivate(void* inptr)
void filter::blur::blur_factory::deactivate(void* inptr)
{
reinterpret_cast<filter::blur::instance*>(inptr)->deactivate();
reinterpret_cast<filter::blur::blur_instance*>(inptr)->deactivate();
}
void filter::blur::factory::video_tick(void* inptr, float delta)
void filter::blur::blur_factory::video_tick(void* inptr, float delta)
{
reinterpret_cast<filter::blur::instance*>(inptr)->video_tick(delta);
reinterpret_cast<filter::blur::blur_instance*>(inptr)->video_tick(delta);
}
void filter::blur::factory::video_render(void* inptr, gs_effect_t* effect)
void filter::blur::blur_factory::video_render(void* inptr, gs_effect_t* effect)
{
reinterpret_cast<filter::blur::instance*>(inptr)->video_render(effect);
reinterpret_cast<filter::blur::blur_instance*>(inptr)->video_render(effect);
}
std::shared_ptr<gs::effect> filter::blur::factory::get_effect(filter::blur::type)
std::shared_ptr<gs::effect> filter::blur::blur_factory::get_effect(filter::blur::type)
{
return blur_effect;
}
std::string filter::blur::factory::get_technique(filter::blur::type type)
std::string filter::blur::blur_factory::get_technique(filter::blur::type type)
{
switch (type) {
case type::Box:
@ -356,27 +356,27 @@ std::string filter::blur::factory::get_technique(filter::blur::type type)
return "";
}
std::shared_ptr<gs::effect> filter::blur::factory::get_color_converter_effect()
std::shared_ptr<gs::effect> filter::blur::blur_factory::get_color_converter_effect()
{
return color_converter_effect;
}
std::shared_ptr<gs::effect> filter::blur::factory::get_mask_effect()
std::shared_ptr<gs::effect> filter::blur::blur_factory::get_mask_effect()
{
return mask_effect;
}
std::shared_ptr<gs::texture> filter::blur::factory::get_kernel(filter::blur::type type)
std::shared_ptr<gs::texture> filter::blur::blur_factory::get_kernel(filter::blur::type type)
{
return kernels.at(type);
}
std::shared_ptr<std::vector<float_t>> filter::blur::factory::get_gaussian_kernel(uint8_t size)
std::shared_ptr<std::vector<float_t>> filter::blur::blur_factory::get_gaussian_kernel(uint8_t size)
{
return gaussian_kernels.at(size);
}
bool filter::blur::instance::apply_shared_param(gs_texture_t* input, float texelX, float texelY)
bool filter::blur::blur_instance::apply_shared_param(gs_texture_t* input, float texelX, float texelY)
{
bool result = true;
@ -401,7 +401,7 @@ bool filter::blur::instance::apply_shared_param(gs_texture_t* input, float texel
return result;
}
bool filter::blur::instance::apply_bilateral_param()
bool filter::blur::blur_instance::apply_bilateral_param()
{
if (type != type::Bilateral)
return false;
@ -417,9 +417,9 @@ bool filter::blur::instance::apply_bilateral_param()
return true;
}
bool filter::blur::instance::apply_gaussian_param(uint8_t width)
bool filter::blur::blur_instance::apply_gaussian_param(uint8_t width)
{
auto kernel = filter::blur::factory::get()->get_gaussian_kernel(width);
auto kernel = filter::blur::blur_factory::get()->get_gaussian_kernel(width);
if (blur_effect->has_parameter("kernel")) {
blur_effect->get_parameter("kernel").set_float_array(&(kernel->front()), kernel->size());
@ -428,7 +428,7 @@ bool filter::blur::instance::apply_gaussian_param(uint8_t width)
return true;
}
bool filter::blur::instance::apply_mask_parameters(std::shared_ptr<gs::effect> effect,
bool filter::blur::blur_instance::apply_mask_parameters(std::shared_ptr<gs::effect> effect,
gs_texture_t* original_texture, gs_texture_t* blurred_texture)
{
if (effect->has_parameter("image_orig")) {
@ -493,7 +493,7 @@ bool filter::blur::instance::apply_mask_parameters(std::shared_ptr<gs::effect> e
return true;
}
bool filter::blur::instance::modified_properties(void*, obs_properties_t* props, obs_property*,
bool filter::blur::blur_instance::modified_properties(void*, obs_properties_t* props, obs_property*,
obs_data_t* settings)
{
// bilateral blur
@ -537,7 +537,7 @@ bool filter::blur::instance::modified_properties(void*, obs_properties_t* props,
return true;
}
bool filter::blur::instance::can_log()
bool filter::blur::blur_instance::can_log()
{
// Only allow logging errors every 200ms.
auto now = std::chrono::high_resolution_clock::now();
@ -546,7 +546,7 @@ bool filter::blur::instance::can_log()
return std::chrono::duration_cast<std::chrono::milliseconds>(delta) > std::chrono::milliseconds(200);
}
filter::blur::instance::instance(obs_data_t* settings, obs_source_t* parent)
filter::blur::blur_instance::blur_instance(obs_data_t* settings, obs_source_t* parent)
{
m_source = parent;
@ -561,19 +561,19 @@ filter::blur::instance::instance(obs_data_t* settings, obs_source_t* parent)
}
// Get initial Blur effect.
blur_effect = filter::blur::factory::get()->get_effect(filter::blur::type::Box);
blur_effect = filter::blur::blur_factory::get()->get_effect(filter::blur::type::Box);
update(settings);
}
filter::blur::instance::~instance()
filter::blur::blur_instance::~blur_instance()
{
this->mask.source.source_texture.reset();
this->rt_primary.reset();
this->rt_secondary.reset();
}
obs_properties_t* filter::blur::instance::get_properties()
obs_properties_t* filter::blur::blur_instance::get_properties()
{
obs_properties_t* pr = obs_properties_create();
obs_property_t* p = NULL;
@ -681,11 +681,11 @@ obs_properties_t* filter::blur::instance::get_properties()
return pr;
}
void filter::blur::instance::update(obs_data_t* settings)
void filter::blur::blur_instance::update(obs_data_t* settings)
{
type = (blur::type)obs_data_get_int(settings, P_TYPE);
blur_effect = factory::get()->get_effect(type);
blur_technique = factory::get()->get_technique(type);
blur_effect = blur_factory::get()->get_effect(type);
blur_technique = blur_factory::get()->get_technique(type);
size = (uint64_t)obs_data_get_int(settings, P_SIZE);
// bilateral blur
@ -764,28 +764,28 @@ void filter::blur::instance::update(obs_data_t* settings)
}
}
void filter::blur::instance::load(obs_data_t* settings)
void filter::blur::blur_instance::load(obs_data_t* settings)
{
update(settings);
}
uint32_t filter::blur::instance::get_width()
uint32_t filter::blur::blur_instance::get_width()
{
return uint32_t(0);
}
uint32_t filter::blur::instance::get_height()
uint32_t filter::blur::blur_instance::get_height()
{
return uint32_t(0);
}
void filter::blur::instance::activate() {}
void filter::blur::blur_instance::activate() {}
void filter::blur::instance::deactivate() {}
void filter::blur::blur_instance::deactivate() {}
void filter::blur::instance::video_tick(float) {}
void filter::blur::blur_instance::video_tick(float) {}
void filter::blur::instance::video_render(gs_effect_t* effect)
void filter::blur::blur_instance::video_render(gs_effect_t* effect)
{
obs_source_t* parent = obs_filter_get_parent(this->m_source);
obs_source_t* target = obs_filter_get_target(this->m_source);
@ -796,7 +796,7 @@ void filter::blur::instance::video_render(gs_effect_t* effect)
bool failed = false;
std::shared_ptr<gs::effect> colorConversionEffect = factory::get()->get_color_converter_effect();
std::shared_ptr<gs::effect> colorConversionEffect = blur_factory::get()->get_color_converter_effect();
// Verify that we can actually run first.
if (!target || !parent || !this->m_source) {
@ -1084,7 +1084,7 @@ void filter::blur::instance::video_render(gs_effect_t* effect)
this->mask.source.texture = this->mask.source.source_texture->render(source_width, source_height);
}
std::shared_ptr<gs::effect> mask_effect = factory::get()->get_mask_effect();
std::shared_ptr<gs::effect> mask_effect = blur_factory::get()->get_mask_effect();
apply_mask_parameters(mask_effect, tex_source->get_object(), tex_intermediate->get_object());
try {

View file

@ -42,7 +42,7 @@
namespace filter {
namespace blur {
class instance;
class blur_instance;
enum type : int64_t {
Box,
@ -58,11 +58,11 @@ namespace filter {
Source,
};
class factory {
friend class std::_Ptr_base<filter::blur::factory>;
class blur_factory {
friend class std::_Ptr_base<filter::blur::blur_factory>;
obs_source_info source_info;
std::list<instance*> sources;
std::list<blur_instance*> sources;
std::shared_ptr<gs::effect> color_converter_effect;
std::shared_ptr<gs::effect> mask_effect;
@ -73,11 +73,11 @@ namespace filter {
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<factory> get();
static std::shared_ptr<blur_factory> get();
public:
factory();
~factory();
blur_factory();
~blur_factory();
void on_list_fill();
void on_list_empty();
@ -117,7 +117,7 @@ namespace filter {
std::shared_ptr<std::vector<float_t>> get_gaussian_kernel(uint8_t size);
};
class instance {
class blur_instance {
obs_source_t* m_source;
std::shared_ptr<gs::rendertarget> rt_source;
std::shared_ptr<gs::rendertarget> rt_primary;
@ -192,8 +192,8 @@ namespace filter {
bool can_log();
public:
instance(obs_data_t* settings, obs_source_t* self);
~instance();
blur_instance(obs_data_t* settings, obs_source_t* self);
~blur_instance();
obs_properties_t* get_properties();
void update(obs_data_t*);

View file

@ -24,28 +24,28 @@
// Initializer & Finalizer
INITIALIZER(FilterDisplacementInit)
{
initializerFunctions.push_back([] { filter::displacement::factory::initialize(); });
finalizerFunctions.push_back([] { filter::displacement::factory::finalize(); });
initializerFunctions.push_back([] { filter::displacement::displacement_factory::initialize(); });
finalizerFunctions.push_back([] { filter::displacement::displacement_factory::finalize(); });
}
static std::shared_ptr<filter::displacement::factory> factory_instance = nullptr;
static std::shared_ptr<filter::displacement::displacement_factory> factory_instance = nullptr;
void filter::displacement::factory::initialize()
void filter::displacement::displacement_factory::initialize()
{
factory_instance = std::make_shared<filter::displacement::factory>();
factory_instance = std::make_shared<filter::displacement::displacement_factory>();
}
void filter::displacement::factory::finalize()
void filter::displacement::displacement_factory::finalize()
{
factory_instance.reset();
}
std::shared_ptr<filter::displacement::factory> filter::displacement::factory::get()
std::shared_ptr<filter::displacement::displacement_factory> filter::displacement::displacement_factory::get()
{
return factory_instance;
}
filter::displacement::factory::factory()
filter::displacement::displacement_factory::displacement_factory()
{
memset(&sourceInfo, 0, sizeof(obs_source_info));
sourceInfo.id = "obs-stream-effects-filter-displacement";
@ -68,34 +68,34 @@ filter::displacement::factory::factory()
obs_register_source(&sourceInfo);
}
filter::displacement::factory::~factory() {}
filter::displacement::displacement_factory::~displacement_factory() {}
const char* filter::displacement::factory::get_name(void*)
const char* filter::displacement::displacement_factory::get_name(void*)
{
return P_TRANSLATE(S_FILTER_DISPLACEMENT);
}
void* filter::displacement::factory::create(obs_data_t* data, obs_source_t* source)
void* filter::displacement::displacement_factory::create(obs_data_t* data, obs_source_t* source)
{
return new instance(data, source);
return new displacement_instance(data, source);
}
void filter::displacement::factory::destroy(void* ptr)
void filter::displacement::displacement_factory::destroy(void* ptr)
{
delete reinterpret_cast<instance*>(ptr);
delete reinterpret_cast<displacement_instance*>(ptr);
}
uint32_t filter::displacement::factory::get_width(void* ptr)
uint32_t filter::displacement::displacement_factory::get_width(void* ptr)
{
return reinterpret_cast<instance*>(ptr)->get_width();
return reinterpret_cast<displacement_instance*>(ptr)->get_width();
}
uint32_t filter::displacement::factory::get_height(void* ptr)
uint32_t filter::displacement::displacement_factory::get_height(void* ptr)
{
return reinterpret_cast<instance*>(ptr)->get_height();
return reinterpret_cast<displacement_instance*>(ptr)->get_height();
}
void filter::displacement::factory::get_defaults(obs_data_t* data)
void filter::displacement::displacement_factory::get_defaults(obs_data_t* data)
{
char* disp = obs_module_file("filter-displacement/neutral.png");
obs_data_set_default_string(data, S_FILTER_DISPLACEMENT_FILE, disp);
@ -104,13 +104,13 @@ void filter::displacement::factory::get_defaults(obs_data_t* data)
bfree(disp);
}
obs_properties_t* filter::displacement::factory::get_properties(void* ptr)
obs_properties_t* filter::displacement::displacement_factory::get_properties(void* ptr)
{
obs_properties_t* pr = obs_properties_create();
std::string path = "";
if (ptr)
path = reinterpret_cast<instance*>(ptr)->get_file();
path = reinterpret_cast<displacement_instance*>(ptr)->get_file();
obs_properties_add_path(pr, S_FILTER_DISPLACEMENT_FILE, P_TRANSLATE(S_FILTER_DISPLACEMENT_FILE),
obs_path_type::OBS_PATH_FILE, P_TRANSLATE(S_FILTER_DISPLACEMENT_FILE_TYPES), path.c_str());
@ -121,42 +121,42 @@ obs_properties_t* filter::displacement::factory::get_properties(void* ptr)
return pr;
}
void filter::displacement::factory::update(void* ptr, obs_data_t* data)
void filter::displacement::displacement_factory::update(void* ptr, obs_data_t* data)
{
reinterpret_cast<instance*>(ptr)->update(data);
reinterpret_cast<displacement_instance*>(ptr)->update(data);
}
void filter::displacement::factory::activate(void* ptr)
void filter::displacement::displacement_factory::activate(void* ptr)
{
reinterpret_cast<instance*>(ptr)->activate();
reinterpret_cast<displacement_instance*>(ptr)->activate();
}
void filter::displacement::factory::deactivate(void* ptr)
void filter::displacement::displacement_factory::deactivate(void* ptr)
{
reinterpret_cast<instance*>(ptr)->deactivate();
reinterpret_cast<displacement_instance*>(ptr)->deactivate();
}
void filter::displacement::factory::show(void* ptr)
void filter::displacement::displacement_factory::show(void* ptr)
{
reinterpret_cast<instance*>(ptr)->show();
reinterpret_cast<displacement_instance*>(ptr)->show();
}
void filter::displacement::factory::hide(void* ptr)
void filter::displacement::displacement_factory::hide(void* ptr)
{
reinterpret_cast<instance*>(ptr)->hide();
reinterpret_cast<displacement_instance*>(ptr)->hide();
}
void filter::displacement::factory::video_tick(void* ptr, float time)
void filter::displacement::displacement_factory::video_tick(void* ptr, float time)
{
reinterpret_cast<instance*>(ptr)->video_tick(time);
reinterpret_cast<displacement_instance*>(ptr)->video_tick(time);
}
void filter::displacement::factory::video_render(void* ptr, gs_effect_t* effect)
void filter::displacement::displacement_factory::video_render(void* ptr, gs_effect_t* effect)
{
reinterpret_cast<instance*>(ptr)->video_render(effect);
reinterpret_cast<displacement_instance*>(ptr)->video_render(effect);
}
void filter::displacement::instance::validate_file_texture(std::string file)
void filter::displacement::displacement_instance::validate_file_texture(std::string file)
{
bool do_update = false;
@ -184,7 +184,7 @@ void filter::displacement::instance::validate_file_texture(std::string file)
}
}
filter::displacement::instance::instance(obs_data_t* data, obs_source_t* context)
filter::displacement::displacement_instance::displacement_instance(obs_data_t* data, obs_source_t* context)
: m_self(context), m_active(true), m_timer(0), m_effect(nullptr), m_distance(0), m_file_create_time(0),
m_file_modified_time(0), m_file_size(0)
{
@ -199,13 +199,13 @@ filter::displacement::instance::instance(obs_data_t* data, obs_source_t* context
update(data);
}
filter::displacement::instance::~instance()
filter::displacement::displacement_instance::~displacement_instance()
{
m_effect.reset();
m_file_texture.reset();
}
void filter::displacement::instance::update(obs_data_t* data)
void filter::displacement::displacement_instance::update(obs_data_t* data)
{
validate_file_texture(obs_data_get_string(data, S_FILTER_DISPLACEMENT_FILE));
@ -214,25 +214,25 @@ void filter::displacement::instance::update(obs_data_t* data)
float_t(obs_data_get_double(data, S_FILTER_DISPLACEMENT_SCALE)));
}
uint32_t filter::displacement::instance::get_width()
uint32_t filter::displacement::displacement_instance::get_width()
{
return 0;
}
uint32_t filter::displacement::instance::get_height()
uint32_t filter::displacement::displacement_instance::get_height()
{
return 0;
}
void filter::displacement::instance::activate() {}
void filter::displacement::displacement_instance::activate() {}
void filter::displacement::instance::deactivate() {}
void filter::displacement::displacement_instance::deactivate() {}
void filter::displacement::instance::show() {}
void filter::displacement::displacement_instance::show() {}
void filter::displacement::instance::hide() {}
void filter::displacement::displacement_instance::hide() {}
void filter::displacement::instance::video_tick(float time)
void filter::displacement::displacement_instance::video_tick(float time)
{
m_timer += time;
if (m_timer >= 1.0) {
@ -246,7 +246,7 @@ float interp(float a, float b, float v)
return (a * (1.0f - v)) + (b * v);
}
void filter::displacement::instance::video_render(gs_effect_t*)
void filter::displacement::displacement_instance::video_render(gs_effect_t*)
{
obs_source_t* parent = obs_filter_get_parent(m_self);
obs_source_t* target = obs_filter_get_target(m_self);
@ -277,7 +277,7 @@ void filter::displacement::instance::video_render(gs_effect_t*)
obs_source_process_filter_end(m_self, m_effect->get_object(), baseW, baseH);
}
std::string filter::displacement::instance::get_file()
std::string filter::displacement::displacement_instance::get_file()
{
return m_file_name;
}

View file

@ -42,19 +42,19 @@
namespace filter {
namespace displacement {
class factory {
friend class std::_Ptr_base<filter::displacement::factory>;
class displacement_factory {
friend class std::_Ptr_base<filter::displacement::displacement_factory>;
obs_source_info sourceInfo;
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<factory> get();
static std::shared_ptr<displacement_factory> get();
public:
factory();
~factory();
displacement_factory();
~displacement_factory();
static const char* get_name(void*);
@ -73,7 +73,7 @@ namespace filter {
static void video_render(void*, gs_effect_t*);
};
class instance {
class displacement_instance {
obs_source_t* m_self;
bool m_active;
float_t m_timer;
@ -93,8 +93,8 @@ namespace filter {
void validate_file_texture(std::string file);
public:
instance(obs_data_t*, obs_source_t*);
~instance();
displacement_instance(obs_data_t*, obs_source_t*);
~displacement_instance();
void update(obs_data_t*);
uint32_t get_width();

View file

@ -41,28 +41,28 @@
// Initializer & Finalizer
INITIALIZER(filterShadowFactoryInitializer)
{
initializerFunctions.push_back([] { filter::shadow_sdf::factory::initialize(); });
finalizerFunctions.push_back([] { filter::shadow_sdf::factory::finalize(); });
initializerFunctions.push_back([] { filter::shadow_sdf::shadow_sdf_factory::initialize(); });
finalizerFunctions.push_back([] { filter::shadow_sdf::shadow_sdf_factory::finalize(); });
}
static std::shared_ptr<filter::shadow_sdf::factory> factory_instance = nullptr;
static std::shared_ptr<filter::shadow_sdf::shadow_sdf_factory> factory_instance = nullptr;
void filter::shadow_sdf::factory::initialize()
void filter::shadow_sdf::shadow_sdf_factory::initialize()
{
factory_instance = std::make_shared<filter::shadow_sdf::factory>();
factory_instance = std::make_shared<filter::shadow_sdf::shadow_sdf_factory>();
}
void filter::shadow_sdf::factory::finalize()
void filter::shadow_sdf::shadow_sdf_factory::finalize()
{
factory_instance.reset();
}
std::shared_ptr<filter::shadow_sdf::factory> filter::shadow_sdf::factory::get()
std::shared_ptr<filter::shadow_sdf::shadow_sdf_factory> filter::shadow_sdf::shadow_sdf_factory::get()
{
return factory_instance;
}
bool filter::shadow_sdf::instance::cb_modified_inside(void*, obs_properties_t* props, obs_property*,
bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_inside(void*, obs_properties_t* props, obs_property*,
obs_data_t* settings)
{
bool v = obs_data_get_bool(settings, P_INNER);
@ -75,7 +75,7 @@ bool filter::shadow_sdf::instance::cb_modified_inside(void*, obs_properties_t* p
return true;
}
bool filter::shadow_sdf::instance::cb_modified_outside(void*, obs_properties_t* props, obs_property*,
bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_outside(void*, obs_properties_t* props, obs_property*,
obs_data_t* settings)
{
bool v = obs_data_get_bool(settings, P_OUTER);
@ -88,7 +88,7 @@ bool filter::shadow_sdf::instance::cb_modified_outside(void*, obs_properties_t*
return true;
}
filter::shadow_sdf::instance::instance(obs_data_t* settings, obs_source_t* self)
filter::shadow_sdf::shadow_sdf_instance::shadow_sdf_instance(obs_data_t* settings, obs_source_t* self)
: m_self(self), m_source_rendered(false)
{
this->m_source_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
@ -103,9 +103,9 @@ filter::shadow_sdf::instance::instance(obs_data_t* settings, obs_source_t* self)
this->update(settings);
}
filter::shadow_sdf::instance::~instance() {}
filter::shadow_sdf::shadow_sdf_instance::~shadow_sdf_instance() {}
obs_properties_t* filter::shadow_sdf::instance::get_properties()
obs_properties_t* filter::shadow_sdf::shadow_sdf_instance::get_properties()
{
obs_properties_t* props = obs_properties_create();
obs_property_t* p = nullptr;
@ -161,7 +161,7 @@ obs_properties_t* filter::shadow_sdf::instance::get_properties()
return props;
}
void filter::shadow_sdf::instance::update(obs_data_t* data)
void filter::shadow_sdf::shadow_sdf_instance::update(obs_data_t* data)
{
this->m_inner_shadow = obs_data_get_bool(data, P_INNER);
this->m_inner_range_min = float_t(obs_data_get_double(data, P_INNER_RANGE_MINIMUM));
@ -186,27 +186,27 @@ void filter::shadow_sdf::instance::update(obs_data_t* data)
| (int32_t(obs_data_get_double(data, P_OUTER_ALPHA) * 2.55) << 24);
}
uint32_t filter::shadow_sdf::instance::get_width()
uint32_t filter::shadow_sdf::shadow_sdf_instance::get_width()
{
return uint32_t(0);
}
uint32_t filter::shadow_sdf::instance::get_height()
uint32_t filter::shadow_sdf::shadow_sdf_instance::get_height()
{
return uint32_t(0);
}
void filter::shadow_sdf::instance::activate() {}
void filter::shadow_sdf::shadow_sdf_instance::activate() {}
void filter::shadow_sdf::instance::deactivate() {}
void filter::shadow_sdf::shadow_sdf_instance::deactivate() {}
void filter::shadow_sdf::instance::video_tick(float time)
void filter::shadow_sdf::shadow_sdf_instance::video_tick(float time)
{
this->m_tick += time;
m_source_rendered = false;
}
void filter::shadow_sdf::instance::video_render(gs_effect_t*)
void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*)
{
obs_source_t* parent = obs_filter_get_parent(this->m_self);
obs_source_t* target = obs_filter_get_target(this->m_self);
@ -256,7 +256,7 @@ void filter::shadow_sdf::instance::video_render(gs_effect_t*)
}
std::shared_ptr<gs::effect> sdf_effect =
filter::shadow_sdf::factory::get()->get_sdf_generator_effect();
filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_generator_effect();
if (!sdf_effect) {
throw std::runtime_error("SDF Effect no loaded");
}
@ -292,7 +292,7 @@ void filter::shadow_sdf::instance::video_render(gs_effect_t*)
{
std::shared_ptr<gs::effect> shadow_effect =
filter::shadow_sdf::factory::get()->get_sdf_shadow_effect();
filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_shadow_effect();
if (!shadow_effect) {
throw std::runtime_error("Shadow Effect no loaded");
}
@ -356,7 +356,7 @@ void filter::shadow_sdf::instance::video_render(gs_effect_t*)
gs_enable_depth_test(false);
}
filter::shadow_sdf::factory::factory()
filter::shadow_sdf::shadow_sdf_factory::shadow_sdf_factory()
{
memset(&source_info, 0, sizeof(obs_source_info));
source_info.id = "obs-stream-effects-filter-shadow-sdf";
@ -377,9 +377,9 @@ filter::shadow_sdf::factory::factory()
obs_register_source(&source_info);
}
filter::shadow_sdf::factory::~factory() {}
filter::shadow_sdf::shadow_sdf_factory::~shadow_sdf_factory() {}
void filter::shadow_sdf::factory::on_list_fill()
void filter::shadow_sdf::shadow_sdf_factory::on_list_fill()
{
{
char* file = obs_module_file("effects/sdf-generator.effect");
@ -401,25 +401,25 @@ void filter::shadow_sdf::factory::on_list_fill()
}
}
void filter::shadow_sdf::factory::on_list_empty()
void filter::shadow_sdf::shadow_sdf_factory::on_list_empty()
{
sdf_generator_effect.reset();
sdf_shadow_effect.reset();
}
void* filter::shadow_sdf::factory::create(obs_data_t* data, obs_source_t* parent)
void* filter::shadow_sdf::shadow_sdf_factory::create(obs_data_t* data, obs_source_t* parent)
{
if (get()->sources.empty()) {
get()->on_list_fill();
}
filter::shadow_sdf::instance* ptr = new filter::shadow_sdf::instance(data, parent);
filter::shadow_sdf::shadow_sdf_instance* ptr = new filter::shadow_sdf::shadow_sdf_instance(data, parent);
get()->sources.push_back(ptr);
return ptr;
}
void filter::shadow_sdf::factory::destroy(void* inptr)
void filter::shadow_sdf::shadow_sdf_factory::destroy(void* inptr)
{
filter::shadow_sdf::instance* ptr = reinterpret_cast<filter::shadow_sdf::instance*>(inptr);
filter::shadow_sdf::shadow_sdf_instance* ptr = reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr);
get()->sources.remove(ptr);
if (get()->sources.empty()) {
get()->on_list_empty();
@ -427,7 +427,7 @@ void filter::shadow_sdf::factory::destroy(void* inptr)
delete ptr;
}
void filter::shadow_sdf::factory::get_defaults(obs_data_t* data)
void filter::shadow_sdf::shadow_sdf_factory::get_defaults(obs_data_t* data)
{
obs_data_set_bool(data, P_INNER, false);
obs_data_set_double(data, P_INNER_RANGE_MINIMUM, 0.0);
@ -446,57 +446,57 @@ void filter::shadow_sdf::factory::get_defaults(obs_data_t* data)
obs_data_set_double(data, P_OUTER_ALPHA, 100.0);
}
obs_properties_t* filter::shadow_sdf::factory::get_properties(void* inptr)
obs_properties_t* filter::shadow_sdf::shadow_sdf_factory::get_properties(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->get_properties();
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_properties();
}
void filter::shadow_sdf::factory::update(void* inptr, obs_data_t* settings)
void filter::shadow_sdf::shadow_sdf_factory::update(void* inptr, obs_data_t* settings)
{
reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->update(settings);
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->update(settings);
}
const char* filter::shadow_sdf::factory::get_name(void*)
const char* filter::shadow_sdf::shadow_sdf_factory::get_name(void*)
{
return P_TRANSLATE(SOURCE_NAME);
}
uint32_t filter::shadow_sdf::factory::get_width(void* inptr)
uint32_t filter::shadow_sdf::shadow_sdf_factory::get_width(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->get_width();
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_width();
}
uint32_t filter::shadow_sdf::factory::get_height(void* inptr)
uint32_t filter::shadow_sdf::shadow_sdf_factory::get_height(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->get_height();
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_height();
}
void filter::shadow_sdf::factory::activate(void* inptr)
void filter::shadow_sdf::shadow_sdf_factory::activate(void* inptr)
{
reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->activate();
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->activate();
}
void filter::shadow_sdf::factory::deactivate(void* inptr)
void filter::shadow_sdf::shadow_sdf_factory::deactivate(void* inptr)
{
reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->deactivate();
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->deactivate();
}
void filter::shadow_sdf::factory::video_tick(void* inptr, float delta)
void filter::shadow_sdf::shadow_sdf_factory::video_tick(void* inptr, float delta)
{
reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->video_tick(delta);
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->video_tick(delta);
}
void filter::shadow_sdf::factory::video_render(void* inptr, gs_effect_t* effect)
void filter::shadow_sdf::shadow_sdf_factory::video_render(void* inptr, gs_effect_t* effect)
{
reinterpret_cast<filter::shadow_sdf::instance*>(inptr)->video_render(effect);
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->video_render(effect);
}
std::shared_ptr<gs::effect> filter::shadow_sdf::factory::get_sdf_generator_effect()
std::shared_ptr<gs::effect> filter::shadow_sdf::shadow_sdf_factory::get_sdf_generator_effect()
{
return sdf_generator_effect;
}
std::shared_ptr<gs::effect> filter::shadow_sdf::factory::get_sdf_shadow_effect()
std::shared_ptr<gs::effect> filter::shadow_sdf::shadow_sdf_factory::get_sdf_shadow_effect()
{
return sdf_shadow_effect;
}

View file

@ -41,13 +41,13 @@
namespace filter {
namespace shadow_sdf {
class instance;
class shadow_sdf_instance;
class factory {
friend class std::_Ptr_base<filter::shadow_sdf::factory>;
class shadow_sdf_factory {
friend class std::_Ptr_base<filter::shadow_sdf::shadow_sdf_factory>;
obs_source_info source_info;
std::list<instance*> sources;
std::list<shadow_sdf_instance*> sources;
std::shared_ptr<gs::effect> sdf_generator_effect;
std::shared_ptr<gs::effect> sdf_shadow_effect;
@ -55,11 +55,11 @@ namespace filter {
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<factory> get();
static std::shared_ptr<shadow_sdf_factory> get();
public:
factory();
~factory();
shadow_sdf_factory();
~shadow_sdf_factory();
void on_list_fill();
void on_list_empty();
@ -86,7 +86,7 @@ namespace filter {
std::shared_ptr<gs::effect> get_sdf_shadow_effect();
};
class instance {
class shadow_sdf_instance {
obs_source_t* m_self;
// Input
@ -120,8 +120,8 @@ namespace filter {
obs_data_t* settings);
public:
instance(obs_data_t* settings, obs_source_t* self);
~instance();
shadow_sdf_instance(obs_data_t* settings, obs_source_t* self);
~shadow_sdf_instance();
obs_properties_t* get_properties();
void update(obs_data_t*);

View file

@ -78,28 +78,28 @@ enum RotationOrder : int64_t {
// Initializer & Finalizer
INITIALIZER(FilterTransformInit)
{
initializerFunctions.push_back([] { filter::transform::factory::initialize(); });
finalizerFunctions.push_back([] { filter::transform::factory::finalize(); });
initializerFunctions.push_back([] { filter::transform::transform_factory::initialize(); });
finalizerFunctions.push_back([] { filter::transform::transform_factory::finalize(); });
}
static std::shared_ptr<filter::transform::factory> factory_instance = nullptr;
static std::shared_ptr<filter::transform::transform_factory> factory_instance = nullptr;
void filter::transform::factory::initialize()
void filter::transform::transform_factory::initialize()
{
factory_instance = std::make_shared<filter::transform::factory>();
factory_instance = std::make_shared<filter::transform::transform_factory>();
}
void filter::transform::factory::finalize()
void filter::transform::transform_factory::finalize()
{
factory_instance.reset();
}
std::shared_ptr<filter::transform::factory> filter::transform::factory::get()
std::shared_ptr<filter::transform::transform_factory> filter::transform::transform_factory::get()
{
return factory_instance;
}
filter::transform::factory::factory()
filter::transform::transform_factory::transform_factory()
{
memset(&sourceInfo, 0, sizeof(obs_source_info));
sourceInfo.id = "obs-stream-effects-filter-transform";
@ -120,14 +120,14 @@ filter::transform::factory::factory()
obs_register_source(&sourceInfo);
}
filter::transform::factory::~factory() {}
filter::transform::transform_factory::~transform_factory() {}
const char* filter::transform::factory::get_name(void*)
const char* filter::transform::transform_factory::get_name(void*)
{
return P_TRANSLATE(ST);
}
void filter::transform::factory::get_defaults(obs_data_t* data)
void filter::transform::transform_factory::get_defaults(obs_data_t* data)
{
obs_data_set_default_int(data, ST_CAMERA, (int64_t)CameraMode::Orthographic);
obs_data_set_default_double(data, ST_CAMERA_FIELDOFVIEW, 90.0);
@ -145,7 +145,7 @@ void filter::transform::factory::get_defaults(obs_data_t* data)
obs_data_set_default_int(data, ST_ROTATION_ORDER, RotationOrder::ZXY);
}
obs_properties_t* filter::transform::factory::get_properties(void*)
obs_properties_t* filter::transform::transform_factory::get_properties(void*)
{
obs_properties_t* pr = obs_properties_create();
obs_property_t* p = NULL;
@ -245,7 +245,7 @@ obs_properties_t* filter::transform::factory::get_properties(void*)
return pr;
}
bool filter::transform::factory::modified_properties(obs_properties_t* pr, obs_property_t*, obs_data_t* d)
bool filter::transform::transform_factory::modified_properties(obs_properties_t* pr, obs_property_t*, obs_data_t* d)
{
switch ((CameraMode)obs_data_get_int(d, ST_CAMERA)) {
case CameraMode::Orthographic:
@ -269,52 +269,52 @@ bool filter::transform::factory::modified_properties(obs_properties_t* pr, obs_p
return true;
}
void* filter::transform::factory::create(obs_data_t* data, obs_source_t* source)
void* filter::transform::transform_factory::create(obs_data_t* data, obs_source_t* source)
{
return new instance(data, source);
return new transform_instance(data, source);
}
void filter::transform::factory::destroy(void* ptr)
void filter::transform::transform_factory::destroy(void* ptr)
{
delete reinterpret_cast<instance*>(ptr);
delete reinterpret_cast<transform_instance*>(ptr);
}
uint32_t filter::transform::factory::get_width(void* ptr)
uint32_t filter::transform::transform_factory::get_width(void* ptr)
{
return reinterpret_cast<instance*>(ptr)->get_width();
return reinterpret_cast<transform_instance*>(ptr)->get_width();
}
uint32_t filter::transform::factory::get_height(void* ptr)
uint32_t filter::transform::transform_factory::get_height(void* ptr)
{
return reinterpret_cast<instance*>(ptr)->get_height();
return reinterpret_cast<transform_instance*>(ptr)->get_height();
}
void filter::transform::factory::update(void* ptr, obs_data_t* data)
void filter::transform::transform_factory::update(void* ptr, obs_data_t* data)
{
reinterpret_cast<instance*>(ptr)->update(data);
reinterpret_cast<transform_instance*>(ptr)->update(data);
}
void filter::transform::factory::activate(void* ptr)
void filter::transform::transform_factory::activate(void* ptr)
{
reinterpret_cast<instance*>(ptr)->activate();
reinterpret_cast<transform_instance*>(ptr)->activate();
}
void filter::transform::factory::deactivate(void* ptr)
void filter::transform::transform_factory::deactivate(void* ptr)
{
reinterpret_cast<instance*>(ptr)->deactivate();
reinterpret_cast<transform_instance*>(ptr)->deactivate();
}
void filter::transform::factory::video_tick(void* ptr, float time)
void filter::transform::transform_factory::video_tick(void* ptr, float time)
{
reinterpret_cast<instance*>(ptr)->video_tick(time);
reinterpret_cast<transform_instance*>(ptr)->video_tick(time);
}
void filter::transform::factory::video_render(void* ptr, gs_effect_t* effect)
void filter::transform::transform_factory::video_render(void* ptr, gs_effect_t* effect)
{
reinterpret_cast<instance*>(ptr)->video_render(effect);
reinterpret_cast<transform_instance*>(ptr)->video_render(effect);
}
filter::transform::instance::~instance()
filter::transform::transform_instance::~transform_instance()
{
m_shear.reset();
m_scale.reset();
@ -327,7 +327,7 @@ filter::transform::instance::~instance()
m_source_rendertarget.reset();
}
filter::transform::instance::instance(obs_data_t* data, obs_source_t* context)
filter::transform::transform_instance::transform_instance(obs_data_t* data, obs_source_t* context)
: m_active(true), m_self(context), m_source_rendered(false), m_mipmap_enabled(false), m_mipmap_strength(50.0),
m_mipmap_generator(gs::mipmapper::generator::Linear), m_update_mesh(false), m_rotation_order(RotationOrder::ZXY),
m_camera_orthographic(true), m_camera_fov(90.0)
@ -348,17 +348,17 @@ filter::transform::instance::instance(obs_data_t* data, obs_source_t* context)
update(data);
}
uint32_t filter::transform::instance::get_width()
uint32_t filter::transform::transform_instance::get_width()
{
return 0;
}
uint32_t filter::transform::instance::get_height()
uint32_t filter::transform::transform_instance::get_height()
{
return 0;
}
void filter::transform::instance::update(obs_data_t* data)
void filter::transform::transform_instance::update(obs_data_t* data)
{
// Camera
m_camera_orthographic = obs_data_get_int(data, ST_CAMERA) == 0;
@ -387,17 +387,17 @@ void filter::transform::instance::update(obs_data_t* data)
m_update_mesh = true;
}
void filter::transform::instance::activate()
void filter::transform::transform_instance::activate()
{
m_active = true;
}
void filter::transform::instance::deactivate()
void filter::transform::transform_instance::deactivate()
{
m_active = false;
}
void filter::transform::instance::video_tick(float)
void filter::transform::transform_instance::video_tick(float)
{
// Update Mesh
if (m_update_mesh) {
@ -501,7 +501,7 @@ void filter::transform::instance::video_tick(float)
this->m_source_rendered = false;
}
void filter::transform::instance::video_render(gs_effect_t* paramEffect)
void filter::transform::transform_instance::video_render(gs_effect_t* paramEffect)
{
if (!m_active) {
obs_source_skip_video_filter(m_self);

View file

@ -28,19 +28,19 @@
namespace filter {
namespace transform {
class factory {
friend class std::_Ptr_base<filter::transform::factory>;
class transform_factory {
friend class std::_Ptr_base<filter::transform::transform_factory>;
obs_source_info sourceInfo;
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<factory> get();
static std::shared_ptr<transform_factory> get();
public:
factory();
~factory();
transform_factory();
~transform_factory();
static const char* get_name(void*);
static void get_defaults(obs_data_t*);
@ -60,7 +60,7 @@ namespace filter {
static void video_render(void*, gs_effect_t*);
};
class instance {
class transform_instance {
bool m_active;
obs_source_t* m_self;
@ -93,8 +93,8 @@ namespace filter {
float_t m_camera_fov;
public:
~instance();
instance(obs_data_t*, obs_source_t*);
~transform_instance();
transform_instance(obs_data_t*, obs_source_t*);
uint32_t get_width();
uint32_t get_height();

View file

@ -59,28 +59,28 @@
// Initializer & Finalizer
INITIALIZER(SourceMirrorInit)
{
initializerFunctions.push_back([] { source::mirror::factory::initialize(); });
finalizerFunctions.push_back([] { source::mirror::factory::finalize(); });
initializerFunctions.push_back([] { source::mirror::mirror_factory::initialize(); });
finalizerFunctions.push_back([] { source::mirror::mirror_factory::finalize(); });
}
static std::shared_ptr<source::mirror::factory> factory_instance = nullptr;
static std::shared_ptr<source::mirror::mirror_factory> factory_instance = nullptr;
void source::mirror::factory::initialize()
void source::mirror::mirror_factory::initialize()
{
factory_instance = std::make_shared<source::mirror::factory>();
factory_instance = std::make_shared<source::mirror::mirror_factory>();
}
void source::mirror::factory::finalize()
void source::mirror::mirror_factory::finalize()
{
factory_instance.reset();
}
std::shared_ptr<source::mirror::factory> source::mirror::factory::get()
std::shared_ptr<source::mirror::mirror_factory> source::mirror::mirror_factory::get()
{
return factory_instance;
}
source::mirror::factory::factory()
source::mirror::mirror_factory::mirror_factory()
{
memset(&osi, 0, sizeof(obs_source_info));
osi.id = "obs-stream-effects-source-mirror";
@ -106,14 +106,14 @@ source::mirror::factory::factory()
obs_register_source(&osi);
}
source::mirror::factory::~factory() {}
source::mirror::mirror_factory::~mirror_factory() {}
const char* source::mirror::factory::get_name(void*)
const char* source::mirror::mirror_factory::get_name(void*)
{
return P_TRANSLATE(S_SOURCE_MIRROR);
}
void source::mirror::factory::get_defaults(obs_data_t* data)
void source::mirror::mirror_factory::get_defaults(obs_data_t* data)
{
obs_data_set_default_string(data, P_SOURCE, "");
obs_data_set_default_bool(data, P_SOURCE_AUDIO, false);
@ -124,7 +124,7 @@ void source::mirror::factory::get_defaults(obs_data_t* data)
obs_data_set_default_int(data, P_SCALING_BOUNDS, (int64_t)obs_bounds_type::OBS_BOUNDS_STRETCH);
}
bool source::mirror::factory::modified_properties(obs_properties_t* pr, obs_property_t* p, obs_data_t* data)
bool source::mirror::mirror_factory::modified_properties(obs_properties_t* pr, obs_property_t* p, obs_data_t* data)
{
if (obs_properties_get(pr, P_SOURCE) == p) {
obs_source_t* target = obs_get_source_by_name(obs_data_get_string(data, P_SOURCE));
@ -167,7 +167,7 @@ static void UpdateSourceList(obs_property_t* p)
#endif
}
obs_properties_t* source::mirror::factory::get_properties(void*)
obs_properties_t* source::mirror::mirror_factory::get_properties(void*)
{
obs_properties_t* pr = obs_properties_create();
obs_property_t* p = nullptr;
@ -216,91 +216,91 @@ obs_properties_t* source::mirror::factory::get_properties(void*)
return pr;
}
void* source::mirror::factory::create(obs_data_t* data, obs_source_t* source)
void* source::mirror::mirror_factory::create(obs_data_t* data, obs_source_t* source)
{
return new source::mirror::instance(data, source);
return new source::mirror::mirror_instance(data, source);
}
void source::mirror::factory::destroy(void* p)
void source::mirror::mirror_factory::destroy(void* p)
{
if (p) {
delete static_cast<source::mirror::instance*>(p);
delete static_cast<source::mirror::mirror_instance*>(p);
}
}
uint32_t source::mirror::factory::get_width(void* p)
uint32_t source::mirror::mirror_factory::get_width(void* p)
{
if (p) {
return static_cast<source::mirror::instance*>(p)->get_width();
return static_cast<source::mirror::mirror_instance*>(p)->get_width();
}
return 0;
}
uint32_t source::mirror::factory::get_height(void* p)
uint32_t source::mirror::mirror_factory::get_height(void* p)
{
if (p) {
return static_cast<source::mirror::instance*>(p)->get_height();
return static_cast<source::mirror::mirror_instance*>(p)->get_height();
}
return 0;
}
void source::mirror::factory::update(void* p, obs_data_t* data)
void source::mirror::mirror_factory::update(void* p, obs_data_t* data)
{
if (p) {
static_cast<source::mirror::instance*>(p)->update(data);
static_cast<source::mirror::mirror_instance*>(p)->update(data);
}
}
void source::mirror::factory::activate(void* p)
void source::mirror::mirror_factory::activate(void* p)
{
if (p) {
static_cast<source::mirror::instance*>(p)->activate();
static_cast<source::mirror::mirror_instance*>(p)->activate();
}
}
void source::mirror::factory::deactivate(void* p)
void source::mirror::mirror_factory::deactivate(void* p)
{
if (p) {
static_cast<source::mirror::instance*>(p)->deactivate();
static_cast<source::mirror::mirror_instance*>(p)->deactivate();
}
}
void source::mirror::factory::video_tick(void* p, float t)
void source::mirror::mirror_factory::video_tick(void* p, float t)
{
if (p) {
static_cast<source::mirror::instance*>(p)->video_tick(t);
static_cast<source::mirror::mirror_instance*>(p)->video_tick(t);
}
}
void source::mirror::factory::video_render(void* p, gs_effect_t* ef)
void source::mirror::mirror_factory::video_render(void* p, gs_effect_t* ef)
{
if (p) {
static_cast<source::mirror::instance*>(p)->video_render(ef);
static_cast<source::mirror::mirror_instance*>(p)->video_render(ef);
}
}
void source::mirror::factory::enum_active_sources(void* p, obs_source_enum_proc_t enum_callback, void* param)
void source::mirror::mirror_factory::enum_active_sources(void* p, obs_source_enum_proc_t enum_callback, void* param)
{
if (p) {
static_cast<source::mirror::instance*>(p)->enum_active_sources(enum_callback, param);
static_cast<source::mirror::mirror_instance*>(p)->enum_active_sources(enum_callback, param);
}
}
void source::mirror::factory::load(void* p, obs_data_t* d)
void source::mirror::mirror_factory::load(void* p, obs_data_t* d)
{
if (p) {
static_cast<source::mirror::instance*>(p)->load(d);
static_cast<source::mirror::mirror_instance*>(p)->load(d);
}
}
void source::mirror::factory::save(void* p, obs_data_t* d)
void source::mirror::mirror_factory::save(void* p, obs_data_t* d)
{
if (p) {
static_cast<source::mirror::instance*>(p)->save(d);
static_cast<source::mirror::mirror_instance*>(p)->save(d);
}
}
void source::mirror::instance::release_input()
void source::mirror::mirror_instance::release_input()
{
// Clear any references to the previous source.
if (this->m_source_item) {
@ -314,7 +314,7 @@ void source::mirror::instance::release_input()
this->m_source.reset();
}
void source::mirror::instance::acquire_input(std::string source_name)
void source::mirror::mirror_instance::acquire_input(std::string source_name)
{
// Acquire new reference to current source.
obs_source_t* ref_source = obs_get_source_by_name(source_name.c_str());
@ -349,12 +349,12 @@ void source::mirror::instance::acquire_input(std::string source_name)
// If everything worked fine, we now set everything up.
this->m_source = std::move(new_source);
this->m_source->events.rename += std::bind(&source::mirror::instance::on_source_rename, this, std::placeholders::_1,
this->m_source->events.rename += std::bind(&source::mirror::mirror_instance::on_source_rename, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
try {
// Audio
this->m_source_audio = std::make_shared<obs::audio_capture>(this->m_source);
this->m_source_audio->on.data += std::bind(&source::mirror::instance::audio_capture_cb, this, std::placeholders::_1,
this->m_source_audio->on.data += std::bind(&source::mirror::mirror_instance::audio_capture_cb, this, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3);
} catch (...) {
P_LOG_ERROR("<Source Mirror:%s> Unexpected error during registering audio callback for '%s'.",
@ -362,7 +362,7 @@ void source::mirror::instance::acquire_input(std::string source_name)
}
}
source::mirror::instance::instance(obs_data_t* data, obs_source_t* src)
source::mirror::mirror_instance::mirror_instance(obs_data_t* data, obs_source_t* src)
: m_self(src), m_active(true), m_tick(0), m_scene_rendered(false), m_rescale_enabled(false),
m_rescale_keep_orig_size(false), m_rescale_width(1), m_rescale_height(1),
m_rescale_type(obs_scale_type::OBS_SCALE_BICUBIC), m_rescale_bounds(obs_bounds_type::OBS_BOUNDS_STRETCH),
@ -379,10 +379,10 @@ source::mirror::instance::instance(obs_data_t* data, obs_source_t* src)
for (size_t idx = 0; idx < this->m_audio_data.size(); idx++) {
this->m_audio_data[idx].resize(AUDIO_OUTPUT_FRAMES);
}
this->m_audio_thread = std::thread(std::bind(&source::mirror::instance::audio_output_cb, this));
this->m_audio_thread = std::thread(std::bind(&source::mirror::mirror_instance::audio_output_cb, this));
}
source::mirror::instance::~instance()
source::mirror::mirror_instance::~mirror_instance()
{
release_input();
@ -398,7 +398,7 @@ source::mirror::instance::~instance()
this->m_scene.reset();
}
uint32_t source::mirror::instance::get_width()
uint32_t source::mirror::mirror_instance::get_width()
{
if (this->m_rescale_enabled && this->m_rescale_width > 0 && !this->m_rescale_keep_orig_size) {
return this->m_rescale_width;
@ -410,7 +410,7 @@ uint32_t source::mirror::instance::get_width()
return 1;
}
uint32_t source::mirror::instance::get_height()
uint32_t source::mirror::mirror_instance::get_height()
{
if (this->m_rescale_enabled && this->m_rescale_height > 0 && !this->m_rescale_keep_orig_size)
return this->m_rescale_height;
@ -421,7 +421,7 @@ uint32_t source::mirror::instance::get_height()
return 1;
}
void source::mirror::instance::update(obs_data_t* data)
void source::mirror::mirror_instance::update(obs_data_t* data)
{
{ // User changed the source we are tracking.
release_input();
@ -471,7 +471,7 @@ void source::mirror::instance::update(obs_data_t* data)
}
}
void source::mirror::instance::activate()
void source::mirror::mirror_instance::activate()
{
this->m_active = true;
@ -481,7 +481,7 @@ void source::mirror::instance::activate()
}
}
void source::mirror::instance::deactivate()
void source::mirror::mirror_instance::deactivate()
{
this->m_active = false;
}
@ -496,7 +496,7 @@ static inline void mix_audio(float* p_out, float* p_in, size_t pos, size_t count
*(out++) += *(in++);
}
void source::mirror::instance::video_tick(float time)
void source::mirror::mirror_instance::video_tick(float time)
{
this->m_tick += time;
if (this->m_tick > 0.1f) {
@ -537,7 +537,7 @@ void source::mirror::instance::video_tick(float time)
m_scene_rendered = false;
}
void source::mirror::instance::video_render(gs_effect_t* effect)
void source::mirror::mirror_instance::video_render(gs_effect_t* effect)
{
if ((this->m_rescale_width == 0) || (this->m_rescale_height == 0) || !this->m_source_item
|| !this->m_scene_texture_renderer) {
@ -570,7 +570,7 @@ void source::mirror::instance::video_render(gs_effect_t* effect)
}
}
void source::mirror::instance::audio_capture_cb(std::shared_ptr<obs::source> source, audio_data const* const audio, bool)
void source::mirror::mirror_instance::audio_capture_cb(std::shared_ptr<obs::source> source, audio_data const* const audio, bool)
{
std::unique_lock<std::mutex> ulock(this->m_audio_lock);
if (!this->m_audio_enabled) {
@ -608,7 +608,7 @@ void source::mirror::instance::audio_capture_cb(std::shared_ptr<obs::source> sou
this->m_audio_notify.notify_all();
}
void source::mirror::instance::audio_output_cb()
void source::mirror::mirror_instance::audio_output_cb()
{
std::unique_lock<std::mutex> ulock(this->m_audio_lock);
@ -622,26 +622,26 @@ void source::mirror::instance::audio_output_cb()
}
}
void source::mirror::instance::enum_active_sources(obs_source_enum_proc_t enum_callback, void* param)
void source::mirror::mirror_instance::enum_active_sources(obs_source_enum_proc_t enum_callback, void* param)
{
if (this->m_scene) {
enum_callback(this->m_self, this->m_scene->get(), param);
}
}
void source::mirror::instance::load(obs_data_t* data)
void source::mirror::mirror_instance::load(obs_data_t* data)
{
this->update(data);
}
void source::mirror::instance::save(obs_data_t* data)
void source::mirror::mirror_instance::save(obs_data_t* data)
{
if (this->m_source_item) {
obs_data_set_string(data, P_SOURCE, obs_source_get_name(m_source->get()));
}
}
void source::mirror::instance::on_source_rename(obs::source* source, std::string, std::string)
void source::mirror::mirror_instance::on_source_rename(obs::source* source, std::string, std::string)
{
obs_data_t* ref = obs_source_get_settings(this->m_self);
obs_data_set_string(ref, P_SOURCE, obs_source_get_name(source->get()));

View file

@ -42,19 +42,19 @@
namespace source {
namespace mirror {
class factory {
friend class std::_Ptr_base<source::mirror::factory>;
class mirror_factory {
friend class std::_Ptr_base<source::mirror::mirror_factory>;
obs_source_info osi;
public: // Singleton
static void initialize();
static void finalize();
static std::shared_ptr<factory> get();
static std::shared_ptr<mirror_factory> get();
public:
factory();
~factory();
mirror_factory();
~mirror_factory();
static const char* get_name(void*);
static void get_defaults(obs_data_t*);
@ -77,7 +77,7 @@ namespace source {
static void save(void*, obs_data_t*);
};
class instance {
class mirror_instance {
bool m_active;
obs_source_t* m_self;
float_t m_tick;
@ -117,8 +117,8 @@ namespace source {
void acquire_input(std::string source_name);
public:
instance(obs_data_t*, obs_source_t*);
~instance();
mirror_instance(obs_data_t*, obs_source_t*);
~mirror_instance();
uint32_t get_width();
uint32_t get_height();