filter/video-superresolution: Fix missing UI when selecting Providers

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-09-27 23:48:30 +02:00
parent 37666b0dc1
commit 03e6ce0dbc
2 changed files with 35 additions and 17 deletions

View file

@ -138,16 +138,12 @@ void video_superresolution_instance::update(obs_data_t* data)
video_superresolution_provider provider = video_superresolution_provider provider =
static_cast<video_superresolution_provider>(obs_data_get_int(data, ST_KEY_PROVIDER)); static_cast<video_superresolution_provider>(obs_data_get_int(data, ST_KEY_PROVIDER));
if (provider == video_superresolution_provider::AUTOMATIC) { if (provider == video_superresolution_provider::AUTOMATIC) {
for (auto v : provider_priority) { provider = video_superresolution_factory::get()->find_ideal_provider();
if (video_superresolution_factory::get()->is_provider_available(v)) {
provider = v;
break;
}
}
} }
// Check if the provider was changed, and if so switch. // Check if the provider was changed, and if so switch.
if (provider != _provider) { if (provider != _provider) {
_provider_ui = provider;
switch_provider(provider); switch_provider(provider);
} }
@ -168,10 +164,7 @@ void video_superresolution_instance::update(obs_data_t* data)
void streamfx::filter::video_superresolution::video_superresolution_instance::properties(obs_properties_t* properties) void streamfx::filter::video_superresolution::video_superresolution_instance::properties(obs_properties_t* properties)
{ {
if (_provider_ready) { switch (_provider_ui) {
std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_properties(properties); nvvfxsr_properties(properties);
@ -180,7 +173,6 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::pr
default: default:
break; break;
} }
}
} }
uint32_t streamfx::filter::video_superresolution::video_superresolution_instance::get_width() uint32_t streamfx::filter::video_superresolution::video_superresolution_instance::get_width()
@ -543,6 +535,17 @@ void video_superresolution_factory::get_defaults2(obs_data_t* data)
#endif #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* video_superresolution_factory::get_properties2(video_superresolution_instance* data)
{ {
obs_properties_t* pr = obs_properties_create(); 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, auto p = obs_properties_add_list(grp, ST_KEY_PROVIDER, D_TRANSLATE(ST_I18N_PROVIDER), OBS_COMBO_TYPE_LIST,
OBS_COMBO_FORMAT_INT); OBS_COMBO_FORMAT_INT);
obs_property_set_modified_callback(p, modified_provider);
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC), obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC),
static_cast<int64_t>(video_superresolution_provider::AUTOMATIC)); static_cast<int64_t>(video_superresolution_provider::AUTOMATIC));
obs_property_list_add_int( 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> _video_superresolution_factory_instance = nullptr; std::shared_ptr<video_superresolution_factory> _video_superresolution_factory_instance = nullptr;
void video_superresolution_factory::initialize() void video_superresolution_factory::initialize()

View file

@ -49,6 +49,7 @@ namespace streamfx::filter::video_superresolution {
std::atomic<bool> _provider_ready; std::atomic<bool> _provider_ready;
std::atomic<video_superresolution_provider> _provider; std::atomic<video_superresolution_provider> _provider;
video_superresolution_provider _provider_ui;
std::mutex _provider_lock; std::mutex _provider_lock;
std::shared_ptr<util::threadpool::task> _provider_task; std::shared_ptr<util::threadpool::task> _provider_task;
@ -114,6 +115,7 @@ namespace streamfx::filter::video_superresolution {
#endif #endif
bool is_provider_available(video_superresolution_provider); bool is_provider_available(video_superresolution_provider);
video_superresolution_provider find_ideal_provider();
public: // Singleton public: // Singleton
static void initialize(); static void initialize();