From 4bb32a71bcca14e72a5e1e3c7eeab8943eaf5bcb Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Wed, 23 Jan 2019 22:25:48 +0100 Subject: [PATCH] source-mirror: Use load() and update() for initialization load() is guaranteed to happen after all sources have been created and no earlier, and we can use update() to guarantee that we don't need to duplicate our initialization code in case we go back to initializing earlier than load(). --- source/source-mirror.cpp | 42 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/source/source-mirror.cpp b/source/source-mirror.cpp index 73c93db..a03bd36 100644 --- a/source/source-mirror.cpp +++ b/source/source-mirror.cpp @@ -350,24 +350,6 @@ Source::Mirror::Mirror(obs_data_t* data, obs_source_t* src) m_rescale_keep_orig_size(false), m_width(1), m_height(1), m_audio_enabled(false), m_audio_kill_thread(false), m_audio_have_output(false), m_source_item(nullptr) { - // Initialize Video Rendering - this->m_scene = std::make_shared(obs_scene_get_source(obs_scene_create_private("Source Mirror Internal Scene"))); - this->m_scene_texture = - std::make_shared(this->m_scene, std::make_shared(this->m_self, false, false)); - - // Initialize Rescaling - this->m_rescale_rt = std::make_shared(GS_RGBA, GS_ZS_NONE); - this->m_sampler = std::make_shared(); - this->m_rescale_effect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT); - - // Initialize Audio Rendering - this->m_audio_data.resize(MAX_AUDIO_CHANNELS); - 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::audio_output_cb, this)); - - update(data); m_active = true; } @@ -417,6 +399,26 @@ uint32_t Source::Mirror::get_height() void Source::Mirror::update(obs_data_t* data) { + if (!this->m_scene) { + // Initialize Video Rendering + this->m_scene = std::make_shared( + obs_scene_get_source(obs_scene_create_private("Source Mirror Internal Scene"))); + this->m_scene_texture = std::make_shared( + this->m_scene, std::make_shared(this->m_self, false, false)); + + // Initialize Rescaling + this->m_rescale_rt = std::make_shared(GS_RGBA, GS_ZS_NONE); + this->m_sampler = std::make_shared(); + this->m_rescale_effect = obs_get_base_effect(obs_base_effect::OBS_EFFECT_DEFAULT); + + // Initialize Audio Rendering + this->m_audio_data.resize(MAX_AUDIO_CHANNELS); + 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::audio_output_cb, this)); + } + { // User changed the source we are tracking. release_input(); this->m_source_name = obs_data_get_string(data, P_SOURCE); @@ -650,7 +652,9 @@ void Source::Mirror::enum_active_sources(obs_source_enum_proc_t enum_callback, v } } -void Source::Mirror::load(obs_data_t*) {} +void Source::Mirror::load(obs_data_t* data) { + this->update(data); +} void Source::Mirror::save(obs_data_t* data) {