From 03e6ce0dbc7f802ffa4e2695f95ba5c806e42166 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Mon, 27 Sep 2021 23:48:30 +0200 Subject: [PATCH] filter/video-superresolution: Fix missing UI when selecting Providers --- .../filters/filter-video-superresolution.cpp | 48 ++++++++++++------- .../filters/filter-video-superresolution.hpp | 4 +- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/source/filters/filter-video-superresolution.cpp b/source/filters/filter-video-superresolution.cpp index e136194a..2ef17502 100644 --- a/source/filters/filter-video-superresolution.cpp +++ b/source/filters/filter-video-superresolution.cpp @@ -138,16 +138,12 @@ void video_superresolution_instance::update(obs_data_t* data) video_superresolution_provider provider = static_cast(obs_data_get_int(data, ST_KEY_PROVIDER)); if (provider == video_superresolution_provider::AUTOMATIC) { - for (auto v : provider_priority) { - if (video_superresolution_factory::get()->is_provider_available(v)) { - provider = v; - break; - } - } + provider = video_superresolution_factory::get()->find_ideal_provider(); } // Check if the provider was changed, and if so switch. if (provider != _provider) { + _provider_ui = provider; switch_provider(provider); } @@ -168,18 +164,14 @@ void video_superresolution_instance::update(obs_data_t* data) void streamfx::filter::video_superresolution::video_superresolution_instance::properties(obs_properties_t* properties) { - if (_provider_ready) { - std::unique_lock ul(_provider_lock); - - switch (_provider) { + switch (_provider_ui) { #ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA - case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: - nvvfxsr_properties(properties); - break; + case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: + nvvfxsr_properties(properties); + break; #endif - default: - break; - } + default: + break; } } @@ -543,6 +535,17 @@ void video_superresolution_factory::get_defaults2(obs_data_t* data) #endif } +static bool modified_provider(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept +try { + return true; +} catch (const std::exception& ex) { + DLOG_ERROR("Unexpected exception in function '%s': %s.", __FUNCTION_NAME__, ex.what()); + return false; +} catch (...) { + DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); + return false; +} + obs_properties_t* video_superresolution_factory::get_properties2(video_superresolution_instance* data) { obs_properties_t* pr = obs_properties_create(); @@ -565,6 +568,7 @@ obs_properties_t* video_superresolution_factory::get_properties2(video_superreso { auto p = obs_properties_add_list(grp, ST_KEY_PROVIDER, D_TRANSLATE(ST_I18N_PROVIDER), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + obs_property_set_modified_callback(p, modified_provider); obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC), static_cast(video_superresolution_provider::AUTOMATIC)); obs_property_list_add_int( @@ -603,6 +607,18 @@ bool streamfx::filter::video_superresolution::video_superresolution_factory::is_ } } +video_superresolution_provider + streamfx::filter::video_superresolution::video_superresolution_factory::find_ideal_provider() +{ + for (auto v : provider_priority) { + if (video_superresolution_factory::get()->is_provider_available(v)) { + return v; + break; + } + } + return video_superresolution_provider::AUTOMATIC; +} + std::shared_ptr _video_superresolution_factory_instance = nullptr; void video_superresolution_factory::initialize() diff --git a/source/filters/filter-video-superresolution.hpp b/source/filters/filter-video-superresolution.hpp index 7e4a88db..53cc7367 100644 --- a/source/filters/filter-video-superresolution.hpp +++ b/source/filters/filter-video-superresolution.hpp @@ -49,6 +49,7 @@ namespace streamfx::filter::video_superresolution { std::atomic _provider_ready; std::atomic _provider; + video_superresolution_provider _provider_ui; std::mutex _provider_lock; std::shared_ptr _provider_task; @@ -113,7 +114,8 @@ namespace streamfx::filter::video_superresolution { static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data); #endif - bool is_provider_available(video_superresolution_provider); + bool is_provider_available(video_superresolution_provider); + video_superresolution_provider find_ideal_provider(); public: // Singleton static void initialize();