diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index 1659fe29..69b42833 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -197,14 +197,16 @@ bool blur::blur_instance::apply_mask_parameters(gs::effect effect, gs_texture_t* return true; } -inline void migrate_settings(obs_data_t* settings) +void blur::blur_instance::load(obs_data_t* settings) { - obs_data_set_default_int(settings, S_VERSION, -1); - int64_t version = obs_data_get_int(settings, S_VERSION); + update(settings); +} +void filter::blur::blur_instance::migrate(obs_data_t* settings, std::uint64_t version) +{ // Now we use a fall-through switch to gradually upgrade each known version change. switch (version) { - case -1: + case 0: /// Blur Type int64_t old_blur = obs_data_get_int(settings, "Filter.Blur.Type"); if (old_blur == 0) { // Box @@ -236,15 +238,10 @@ inline void migrate_settings(obs_data_t* settings) obs_data_set_double(settings, ST_ANGLE, angle); obs_data_unset_user_value(settings, "Filter.Blur.Directional.Angle"); } - - obs_data_set_int(settings, S_VERSION, STREAMFX_VERSION); } void blur::blur_instance::update(obs_data_t* settings) { - // Ensure backwards compatibility. - migrate_settings(settings); - { // Blur Type const char* blur_type = obs_data_get_string(settings, ST_TYPE); const char* blur_subtype = obs_data_get_string(settings, ST_SUBTYPE); @@ -309,11 +306,6 @@ void blur::blur_instance::update(obs_data_t* settings) } } -void blur::blur_instance::load(obs_data_t* settings) -{ - update(settings); -} - void blur::blur_instance::video_tick(float) { // Blur diff --git a/source/filters/filter-blur.hpp b/source/filters/filter-blur.hpp index c161b6f8..572ff360 100644 --- a/source/filters/filter-blur.hpp +++ b/source/filters/filter-blur.hpp @@ -99,8 +99,9 @@ namespace filter::blur { ~blur_instance(); public: - virtual void update(obs_data_t* settings) override; virtual void load(obs_data_t* settings) override; + virtual void migrate(obs_data_t* settings, std::uint64_t version) override; + virtual void update(obs_data_t* settings) override; virtual void video_tick(float time) override; virtual void video_render(gs_effect_t* effect) override; diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 16a76595..a3b42368 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -128,6 +128,8 @@ void color_grade::color_grade_instance::load(obs_data_t* data) update(data); } +void filter::color_grade::color_grade_instance::migrate(obs_data_t* data, std::uint64_t version) {} + void color_grade::color_grade_instance::update(obs_data_t* data) { _lift.x = static_cast(obs_data_get_double(data, ST_LIFT_(RED)) / 100.0); diff --git a/source/filters/filter-color-grade.hpp b/source/filters/filter-color-grade.hpp index 91972bd2..8941355d 100644 --- a/source/filters/filter-color-grade.hpp +++ b/source/filters/filter-color-grade.hpp @@ -72,6 +72,7 @@ namespace filter::color_grade { virtual ~color_grade_instance(); virtual void load(obs_data_t* data) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; virtual void update(obs_data_t* data) override; virtual void video_tick(float time) override; diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index 19455ead..09b1287e 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -54,27 +54,20 @@ void displacement::displacement_instance::load(obs_data_t* settings) update(settings); } -inline void migrate_settings(obs_data_t* settings) +void filter::displacement::displacement_instance::migrate(obs_data_t* data, std::uint64_t version) { - uint64_t version = static_cast(obs_data_get_int(settings, S_VERSION)); - switch (version & STREAMFX_MASK_COMPAT) { case 0: - obs_data_set_double(settings, ST_SCALE, obs_data_get_double(settings, "Filter.Displacement.Scale") * 0.5); - obs_data_set_double(settings, ST_SCALE_TYPE, - obs_data_get_double(settings, "Filter.Displacement.Ratio") * 100.0); - obs_data_unset_user_value(settings, "Filter.Displacement.Ratio"); + obs_data_set_double(data, ST_SCALE, obs_data_get_double(data, "Filter.Displacement.Scale") * 0.5); + obs_data_set_double(data, ST_SCALE_TYPE, obs_data_get_double(data, "Filter.Displacement.Ratio") * 100.0); + obs_data_unset_user_value(data, "Filter.Displacement.Ratio"); case STREAMFX_MAKE_VERSION(0, 8, 0, 0): break; } - - obs_data_set_int(settings, S_VERSION, STREAMFX_VERSION); } void displacement::displacement_instance::update(obs_data_t* settings) { - migrate_settings(settings); - _scale[0] = _scale[1] = static_cast(obs_data_get_double(settings, ST_SCALE)); _scale_type = static_cast(obs_data_get_double(settings, ST_SCALE_TYPE) / 100.0); diff --git a/source/filters/filter-displacement.hpp b/source/filters/filter-displacement.hpp index df4b0be3..da42eb09 100644 --- a/source/filters/filter-displacement.hpp +++ b/source/filters/filter-displacement.hpp @@ -41,6 +41,7 @@ namespace filter::displacement { virtual ~displacement_instance(); virtual void load(obs_data_t* settings) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; virtual void update(obs_data_t* settings) override; virtual void video_tick(float_t) override; diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 5fa1f837..111659c3 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -74,6 +74,13 @@ dynamic_mask::dynamic_mask_instance::dynamic_mask_instance(obs_data_t* settings, dynamic_mask::dynamic_mask_instance::~dynamic_mask_instance() {} +void dynamic_mask::dynamic_mask_instance::load(obs_data_t* settings) +{ + update(settings); +} + +void filter::dynamic_mask::dynamic_mask_instance::migrate(obs_data_t* data, std::uint64_t version) {} + void dynamic_mask::dynamic_mask_instance::update(obs_data_t* settings) { // Update source. @@ -135,11 +142,6 @@ void dynamic_mask::dynamic_mask_instance::update(obs_data_t* settings) } } -void dynamic_mask::dynamic_mask_instance::load(obs_data_t* settings) -{ - update(settings); -} - void dynamic_mask::dynamic_mask_instance::save(obs_data_t* settings) { if (_input) { diff --git a/source/filters/filter-dynamic-mask.hpp b/source/filters/filter-dynamic-mask.hpp index f2f05568..be35e3b2 100644 --- a/source/filters/filter-dynamic-mask.hpp +++ b/source/filters/filter-dynamic-mask.hpp @@ -65,8 +65,9 @@ namespace filter::dynamic_mask { dynamic_mask_instance(obs_data_t* data, obs_source_t* self); virtual ~dynamic_mask_instance(); - virtual void update(obs_data_t* settings) override; virtual void load(obs_data_t* settings) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; + virtual void update(obs_data_t* settings) override; virtual void save(obs_data_t* settings) override; void input_renamed(obs::deprecated_source* src, std::string old_name, std::string new_name); diff --git a/source/filters/filter-nv-face-tracking.cpp b/source/filters/filter-nv-face-tracking.cpp index 35a2ccd3..2bb36f2c 100644 --- a/source/filters/filter-nv-face-tracking.cpp +++ b/source/filters/filter-nv-face-tracking.cpp @@ -195,6 +195,8 @@ void filter::nvidia::face_tracking_instance::load(obs_data_t* data) update(data); } +void filter::nvidia::face_tracking_instance::migrate(obs_data_t* data, std::uint64_t version) {} + void filter::nvidia::face_tracking_instance::update(obs_data_t* data) { _cfg_roi_zoom = obs_data_get_double(data, SK_ROI_ZOOM) / 100.0; diff --git a/source/filters/filter-nv-face-tracking.hpp b/source/filters/filter-nv-face-tracking.hpp index b9915e6e..5f3d9f7e 100644 --- a/source/filters/filter-nv-face-tracking.hpp +++ b/source/filters/filter-nv-face-tracking.hpp @@ -101,6 +101,8 @@ namespace filter::nvidia { virtual void load(obs_data_t* data) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; + virtual void update(obs_data_t* data) override; virtual void video_tick(float seconds) override; diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index d723a0d9..b79a1d35 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -119,6 +119,13 @@ sdf_effects::sdf_effects_instance::sdf_effects_instance(obs_data_t* settings, ob sdf_effects::sdf_effects_instance::~sdf_effects_instance() {} +void sdf_effects::sdf_effects_instance::load(obs_data_t* settings) +{ + update(settings); +} + +void filter::sdf_effects::sdf_effects_instance::migrate(obs_data_t* data, std::uint64_t version) {} + void sdf_effects::sdf_effects_instance::update(obs_data_t* data) { { @@ -254,11 +261,6 @@ void sdf_effects::sdf_effects_instance::update(obs_data_t* data) _sdf_threshold = float_t(obs_data_get_double(data, ST_SDF_THRESHOLD) / 100.0); } -void sdf_effects::sdf_effects_instance::load(obs_data_t* settings) -{ - update(settings); -} - void sdf_effects::sdf_effects_instance::video_tick(float) { uint32_t width = 1; diff --git a/source/filters/filter-sdf-effects.hpp b/source/filters/filter-sdf-effects.hpp index b1daf587..58c9ecbc 100644 --- a/source/filters/filter-sdf-effects.hpp +++ b/source/filters/filter-sdf-effects.hpp @@ -85,8 +85,9 @@ namespace filter::sdf_effects { sdf_effects_instance(obs_data_t* settings, obs_source_t* self); virtual ~sdf_effects_instance(); - virtual void update(obs_data_t* settings) override; virtual void load(obs_data_t* settings) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; + virtual void update(obs_data_t* settings) override; virtual void video_tick(float) override; virtual void video_render(gs_effect_t*) override; diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 44b039de..0d33f336 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -55,6 +55,8 @@ void filter::shader::shader_instance::load(obs_data_t* data) update(data); } +void filter::shader::shader_instance::migrate(obs_data_t* data, std::uint64_t version) {} + void filter::shader::shader_instance::update(obs_data_t* data) { _fx->update(data); diff --git a/source/filters/filter-shader.hpp b/source/filters/filter-shader.hpp index 7f0351cd..01e2517d 100644 --- a/source/filters/filter-shader.hpp +++ b/source/filters/filter-shader.hpp @@ -38,6 +38,7 @@ namespace filter::shader { void properties(obs_properties_t* props); virtual void load(obs_data_t* data) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; virtual void update(obs_data_t* data) override; virtual void video_tick(float_t sec_since_last) override; diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 2a1b2b14..94386d8a 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -113,25 +113,20 @@ transform::transform_instance::~transform_instance() _mipmap_texture.reset(); } -inline void migrate_settings(obs_data_t* settings) -{ - uint64_t version = static_cast(obs_data_get_int(settings, S_VERSION)); - - switch (version & STREAMFX_MASK_COMPAT) { - case 0: - obs_data_set_double(settings, ST_ROTATION_X, -obs_data_get_double(settings, ST_ROTATION_X)); - obs_data_set_double(settings, ST_ROTATION_Y, -obs_data_get_double(settings, ST_ROTATION_Y)); - } - - obs_data_set_int(settings, S_VERSION, STREAMFX_VERSION); -} - void transform::transform_instance::load(obs_data_t* settings) { - migrate_settings(settings); update(settings); } +void filter::transform::transform_instance::migrate(obs_data_t* data, std::uint64_t version) +{ + switch (version & STREAMFX_MASK_COMPAT) { + case 0: + obs_data_set_double(data, ST_ROTATION_X, -obs_data_get_double(data, ST_ROTATION_X)); + obs_data_set_double(data, ST_ROTATION_Y, -obs_data_get_double(data, ST_ROTATION_Y)); + } +} + void transform::transform_instance::update(obs_data_t* settings) { // Camera diff --git a/source/filters/filter-transform.hpp b/source/filters/filter-transform.hpp index dbac4758..d515bad5 100644 --- a/source/filters/filter-transform.hpp +++ b/source/filters/filter-transform.hpp @@ -65,6 +65,7 @@ namespace filter::transform { virtual ~transform_instance() override; virtual void load(obs_data_t* settings) override; + virtual void migrate(obs_data_t* data, std::uint64_t version) override; virtual void update(obs_data_t*) override; virtual void video_tick(float) override; diff --git a/source/obs/obs-source-factory.hpp b/source/obs/obs-source-factory.hpp index 7c42c34e..bbe031c1 100644 --- a/source/obs/obs-source-factory.hpp +++ b/source/obs/obs-source-factory.hpp @@ -37,9 +37,9 @@ namespace obs { _info.destroy = _destroy; _info.get_defaults2 = _get_defaults2; _info.get_properties2 = _get_properties2; + _info.load = _load; _info.update = _update; _info.save = _save; - _info.load = _load; _info.filter_remove = _filter_remove; set_resolution_enabled(true); @@ -251,16 +251,6 @@ namespace obs { return 0; } - static void _update(void* data, obs_data_t* settings) noexcept - try { - if (data) - reinterpret_cast<_instance*>(data)->update(settings); - } catch (const std::exception& ex) { - LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); - } catch (...) { - LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); - } - static void _activate(void* data) noexcept try { if (data) @@ -357,20 +347,39 @@ namespace obs { LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); } - static void _save(void* data, obs_data_t* settings) noexcept + static void _load(void* data, obs_data_t* settings) noexcept try { - if (data) - reinterpret_cast<_instance*>(data)->save(settings); + auto priv = reinterpret_cast<_instance*>(data); + if (priv) { + std::uint64_t version = static_cast(obs_data_get_int(settings, S_VERSION)); + priv->migrate(settings, version); + obs_data_set_int(settings, S_VERSION, static_cast(STREAMFX_VERSION)); + obs_data_set_string(settings, S_COMMIT, STREAMFX_COMMIT); + priv->load(settings); + } } catch (const std::exception& ex) { LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); } catch (...) { LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); } - static void _load(void* data, obs_data_t* settings) noexcept + static void _update(void* data, obs_data_t* settings) noexcept try { if (data) - reinterpret_cast<_instance*>(data)->load(settings); + reinterpret_cast<_instance*>(data)->update(settings); + } catch (const std::exception& ex) { + LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); + } catch (...) { + LOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); + } + + static void _save(void* data, obs_data_t* settings) noexcept + try { + if (data) { + reinterpret_cast<_instance*>(data)->save(settings); + obs_data_set_int(settings, S_VERSION, static_cast(STREAMFX_VERSION)); + obs_data_set_string(settings, S_COMMIT, STREAMFX_COMMIT); + } } catch (const std::exception& ex) { LOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); } catch (...) { @@ -534,8 +543,6 @@ namespace obs { return 0; } - virtual void update(obs_data_t* settings) {} - virtual void activate() {} virtual void deactivate() {} @@ -560,10 +567,14 @@ namespace obs { virtual void enum_active_sources(obs_source_enum_proc_t enum_callback, void* param) {} - virtual void save(obs_data_t* settings) {} - virtual void load(obs_data_t* settings) {} + virtual void migrate(obs_data_t* settings, std::uint64_t version) {} + + virtual void update(obs_data_t* settings) {} + + virtual void save(obs_data_t* settings) {} + virtual void mouse_click(const struct obs_mouse_event* event, int32_t type, bool mouse_up, uint32_t click_count) {} diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index 8dc44ca5..3ac4f3c0 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -91,10 +91,13 @@ uint32_t mirror::mirror_instance::get_height() return _source_size.second; } -static void convert_config(obs_data_t* data) +void mirror::mirror_instance::load(obs_data_t* data) { - uint64_t version = static_cast(obs_data_get_int(data, S_VERSION)); + update(data); +} +void source::mirror::mirror_instance::migrate(obs_data_t* data, std::uint64_t version) +{ switch (version) { case 0: obs_data_set_int(data, ST_SOURCE_AUDIO_LAYOUT, obs_data_get_int(data, "Source.Mirror.Audio.Layout")); @@ -102,15 +105,10 @@ static void convert_config(obs_data_t* data) case STREAMFX_VERSION: break; } - - obs_data_set_int(data, S_VERSION, STREAMFX_VERSION); - obs_data_set_string(data, S_COMMIT, STREAMFX_COMMIT); } void mirror::mirror_instance::update(obs_data_t* data) { - convert_config(data); - // Audio _audio_enabled = obs_data_get_bool(data, ST_SOURCE_AUDIO); _audio_layout = static_cast(obs_data_get_int(data, ST_SOURCE_AUDIO_LAYOUT)); @@ -119,11 +117,6 @@ void mirror::mirror_instance::update(obs_data_t* data) acquire(obs_data_get_string(data, ST_SOURCE)); } -void mirror::mirror_instance::load(obs_data_t* data) -{ - update(data); -} - void mirror::mirror_instance::save(obs_data_t* data) { if (_source) { diff --git a/source/sources/source-mirror.hpp b/source/sources/source-mirror.hpp index 9454c5a7..41625472 100644 --- a/source/sources/source-mirror.hpp +++ b/source/sources/source-mirror.hpp @@ -61,8 +61,9 @@ namespace source::mirror { virtual uint32_t get_width() override; virtual uint32_t get_height() override; - virtual void update(obs_data_t*) override; virtual void load(obs_data_t*) override; + virtual void migrate(obs_data_t*, std::uint64_t) override; + virtual void update(obs_data_t*) override; virtual void save(obs_data_t*) override; virtual void video_tick(float) override;