filter/upscaling: 'Video Super-Resolution' -> 'Upscaling'

The previous name was too strict on what could be put into the effect, and would result in additional clutter in the Filter menu when we eventually decide to support other Upscaling methods than Super-Resolution networks.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-09-28 00:16:21 +02:00
parent 03e6ce0dbc
commit 843a76d1c6
5 changed files with 141 additions and 149 deletions

View file

@ -305,8 +305,8 @@ set(${PREFIX}ENABLE_FILTER_NVIDIA_FACE_TRACKING ON CACHE BOOL "Enable NVIDIA Fac
set(${PREFIX}ENABLE_FILTER_SDF_EFFECTS ON CACHE BOOL "Enable SDF Effects Filter") set(${PREFIX}ENABLE_FILTER_SDF_EFFECTS ON CACHE BOOL "Enable SDF Effects Filter")
set(${PREFIX}ENABLE_FILTER_SHADER ON CACHE BOOL "Enable Shader Filter") set(${PREFIX}ENABLE_FILTER_SHADER ON CACHE BOOL "Enable Shader Filter")
set(${PREFIX}ENABLE_FILTER_TRANSFORM ON CACHE BOOL "Enable Transform Filter") set(${PREFIX}ENABLE_FILTER_TRANSFORM ON CACHE BOOL "Enable Transform Filter")
set(${PREFIX}ENABLE_FILTER_VIDEO_SUPERRESOLUTION ON CACHE BOOL "Enable Video Super-Resolution filter") set(${PREFIX}ENABLE_FILTER_UPSCALING ON CACHE BOOL "Enable Upscaling Filter")
set(${PREFIX}ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA ON CACHE BOOL "Enable NVIDIA Video Super-Resolution for Video Super-Resolution Filter") set(${PREFIX}ENABLE_FILTER_UPSCALING_NVIDIA ON CACHE BOOL "Enable NVIDIA provider(s) for Upscaling Filter")
## Sources ## Sources
set(${PREFIX}ENABLE_SOURCE_MIRROR ON CACHE BOOL "Enable Mirror Source") set(${PREFIX}ENABLE_SOURCE_MIRROR ON CACHE BOOL "Enable Mirror Source")
@ -696,20 +696,20 @@ function(feature_filter_transform RESOLVE)
is_feature_enabled(FILTER_TRANSFORM T_CHECK) is_feature_enabled(FILTER_TRANSFORM T_CHECK)
endfunction() endfunction()
function(feature_filter_video_superresolution RESOLVE) function(feature_filter_upscaling RESOLVE)
is_feature_enabled(FILTER_VIDEO_SUPERRESOLUTION T_CHECK) is_feature_enabled(FILTER_UPSCALING T_CHECK)
if(RESOLVE AND T_CHECK) if(RESOLVE AND T_CHECK)
# Verify that the requirements for the providers are available # Verify that the requirements for the providers are available
if(NOT HAVE_NVIDIA_VFX_SDK) if(NOT HAVE_NVIDIA_VFX_SDK)
message(WARNING "${LOGPREFIX}: 'NVIDIA Video Effects SDK' is missing. Disabling Video Super-Resolution provider...") message(WARNING "${LOGPREFIX}: 'NVIDIA Video Effects SDK' is missing. Disabling NVIDIA provider(s)...")
set_feature_disabled(FILTER_VIDEO_SUPERRESOLUTION_NVIDIA ON) set_feature_disabled(FILTER_UPSCALING_NVIDIA ON)
endif() endif()
# Verify that we have at least one provider for Video Super-Resolution. # Verify that we have at least one provider for Video Super-Resolution.
is_feature_enabled(FILTER_VIDEO_SUPERRESOLUTION_NVIDIA T_CHECK_NVIDIA) is_feature_enabled(FILTER_UPSCALING_NVIDIA T_CHECK_NVIDIA)
if (NOT T_CHECK_NVIDIA) if (NOT T_CHECK_NVIDIA)
message(WARNING "${LOGPREFIX}: Video Super-Resolution has no available providers. Disabling...") message(WARNING "${LOGPREFIX}: Upscaling has no available providers. Disabling...")
set_feature_disabled(FILTER_VIDEO_SUPERRESOLUTION ON) set_feature_disabled(FILTER_UPSCALING ON)
endif() endif()
elseif(T_CHECK) elseif(T_CHECK)
set(REQUIRE_NVIDIA_VFX_SDK ON PARENT_SCOPE) set(REQUIRE_NVIDIA_VFX_SDK ON PARENT_SCOPE)
@ -771,7 +771,7 @@ feature_filter_nvidia_face_tracking(OFF)
feature_filter_sdf_effects(OFF) feature_filter_sdf_effects(OFF)
feature_filter_shader(OFF) feature_filter_shader(OFF)
feature_filter_transform(OFF) feature_filter_transform(OFF)
feature_filter_video_superresolution(OFF) feature_filter_upscaling(OFF)
feature_source_mirror(OFF) feature_source_mirror(OFF)
feature_source_shader(OFF) feature_source_shader(OFF)
feature_transition_shader(OFF) feature_transition_shader(OFF)
@ -926,7 +926,7 @@ feature_filter_nvidia_face_tracking(ON)
feature_filter_sdf_effects(ON) feature_filter_sdf_effects(ON)
feature_filter_shader(ON) feature_filter_shader(ON)
feature_filter_transform(ON) feature_filter_transform(ON)
feature_filter_video_superresolution(ON) feature_filter_upscaling(ON)
feature_source_mirror(ON) feature_source_mirror(ON)
feature_source_shader(ON) feature_source_shader(ON)
feature_transition_shader(ON) feature_transition_shader(ON)
@ -1391,19 +1391,19 @@ if(T_CHECK)
endif() endif()
# Filter/Video Super-Resolution # Filter/Video Super-Resolution
is_feature_enabled(FILTER_VIDEO_SUPERRESOLUTION T_CHECK) is_feature_enabled(FILTER_UPSCALING T_CHECK)
if(T_CHECK) if(T_CHECK)
list(APPEND PROJECT_PRIVATE_SOURCE list(APPEND PROJECT_PRIVATE_SOURCE
"source/filters/filter-video-superresolution.hpp" "source/filters/filter-upscaling.hpp"
"source/filters/filter-video-superresolution.cpp" "source/filters/filter-upscaling.cpp"
) )
list(APPEND PROJECT_DEFINITIONS list(APPEND PROJECT_DEFINITIONS
ENABLE_FILTER_VIDEO_SUPERRESOLUTION ENABLE_FILTER_UPSCALING
) )
is_feature_enabled(FILTER_VIDEO_SUPERRESOLUTION_NVIDIA T_CHECK) is_feature_enabled(FILTER_UPSCALING_NVIDIA T_CHECK)
if (T_CHECK) if (T_CHECK)
list(APPEND PROJECT_DEFINITIONS list(APPEND PROJECT_DEFINITIONS
ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA ENABLE_FILTER_UPSCALING_NVIDIA
) )
endif() endif()
endif() endif()

View file

@ -335,15 +335,15 @@ Filter.Transform.Rotation.Order.ZXY="Roll, Pitch, Yaw"
Filter.Transform.Rotation.Order.ZYX="Roll, Yaw, Pitch" Filter.Transform.Rotation.Order.ZYX="Roll, Yaw, Pitch"
Filter.Transform.Mipmapping="Enable Mipmapping" Filter.Transform.Mipmapping="Enable Mipmapping"
# Filter - Video Super-Resolution # Filter - Upscaling
Filter.VideoSuperResolution="Video Super-Resolution" Filter.Upscaling="Upscaling"
Filter.VideoSuperResolution.Provider="Provider" Filter.Upscaling.Provider="Provider"
Filter.VideoSuperResolution.Provider.NVIDIAVideoSuperResolution="NVIDIA Video Super-Resolution, powered by NVIDIA Broadcast" Filter.Upscaling.Provider.NVIDIAVideoSuperResolution="NVIDIA Video Super-Resolution, powered by NVIDIA Broadcast"
Filter.VideoSuperResolution.NVIDIA.SuperRes="NVIDIA Video Super-Resolution" Filter.Upscaling.NVIDIA.SuperRes="NVIDIA Video Super-Resolution"
Filter.VideoSuperResolution.NVIDIA.SuperRes.Scale="Scale" Filter.Upscaling.NVIDIA.SuperRes.Scale="Scale"
Filter.VideoSuperResolution.NVIDIA.SuperRes.Strength="Strength" Filter.Upscaling.NVIDIA.SuperRes.Strength="Strength"
Filter.VideoSuperResolution.NVIDIA.SuperRes.Strength.Weak="Weak" Filter.Upscaling.NVIDIA.SuperRes.Strength.Weak="Weak"
Filter.VideoSuperResolution.NVIDIA.SuperRes.Strength.Strong="Strong" Filter.Upscaling.NVIDIA.SuperRes.Strength.Strong="Strong"
# Source - Mirror # Source - Mirror
Source.Mirror="Source Mirror" Source.Mirror="Source Mirror"

View file

@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
#include "filter-video-superresolution.hpp" #include "filter-upscaling.hpp"
#include <algorithm> #include <algorithm>
#include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-helper.hpp"
#include "plugin.hpp" #include "plugin.hpp"
@ -38,12 +38,12 @@
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__) #define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif #endif
#define ST_I18N "Filter.VideoSuperResolution" #define ST_I18N "Filter.Upscaling"
#define ST_KEY_PROVIDER "Provider" #define ST_KEY_PROVIDER "Provider"
#define ST_I18N_PROVIDER ST_I18N "." ST_KEY_PROVIDER #define ST_I18N_PROVIDER ST_I18N "." ST_KEY_PROVIDER
#define ST_I18N_PROVIDER_NVIDIA_SUPERRES ST_I18N_PROVIDER ".NVIDIAVideoSuperResolution" #define ST_I18N_PROVIDER_NVIDIA_SUPERRES ST_I18N_PROVIDER ".NVIDIA.VideoSuperResolution"
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#define ST_KEY_NVIDIA_SUPERRES "NVIDIA.SuperRes" #define ST_KEY_NVIDIA_SUPERRES "NVIDIA.SuperRes"
#define ST_I18N_NVIDIA_SUPERRES ST_I18N "." ST_KEY_NVIDIA_SUPERRES #define ST_I18N_NVIDIA_SUPERRES ST_I18N "." ST_KEY_NVIDIA_SUPERRES
#define ST_KEY_NVIDIA_SUPERRES_STRENGTH "NVIDIA.SuperRes.Strength" #define ST_KEY_NVIDIA_SUPERRES_STRENGTH "NVIDIA.SuperRes.Strength"
@ -54,35 +54,35 @@
#define ST_I18N_NVIDIA_SUPERRES_SCALE ST_I18N "." ST_KEY_NVIDIA_SUPERRES_SCALE #define ST_I18N_NVIDIA_SUPERRES_SCALE ST_I18N "." ST_KEY_NVIDIA_SUPERRES_SCALE
#endif #endif
using streamfx::filter::video_superresolution::video_superresolution_factory; using streamfx::filter::upscaling::upscaling_factory;
using streamfx::filter::video_superresolution::video_superresolution_instance; using streamfx::filter::upscaling::upscaling_instance;
using streamfx::filter::video_superresolution::video_superresolution_provider; using streamfx::filter::upscaling::upscaling_provider;
static constexpr std::string_view HELP_URL = static constexpr std::string_view HELP_URL =
"https://github.com/Xaymar/obs-StreamFX/wiki/Filter-Video-Super-Resolution"; "https://github.com/Xaymar/obs-StreamFX/wiki/Filter-Upscaling";
/** Priority of providers for automatic selection if more than one is available. /** Priority of providers for automatic selection if more than one is available.
* *
*/ */
static video_superresolution_provider provider_priority[] = { static upscaling_provider provider_priority[] = {
video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION, upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION,
}; };
const char* streamfx::filter::video_superresolution::cstring(video_superresolution_provider provider) const char* streamfx::filter::upscaling::cstring(upscaling_provider provider)
{ {
switch (provider) { switch (provider) {
case video_superresolution_provider::INVALID: case upscaling_provider::INVALID:
return "N/A"; return "N/A";
case video_superresolution_provider::AUTOMATIC: case upscaling_provider::AUTOMATIC:
return D_TRANSLATE(S_STATE_AUTOMATIC); return D_TRANSLATE(S_STATE_AUTOMATIC);
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
return D_TRANSLATE(ST_I18N_PROVIDER_NVIDIA_SUPERRES); return D_TRANSLATE(ST_I18N_PROVIDER_NVIDIA_SUPERRES);
default: default:
throw std::runtime_error("Missing Conversion Entry"); throw std::runtime_error("Missing Conversion Entry");
} }
} }
std::string streamfx::filter::video_superresolution::string(video_superresolution_provider provider) std::string streamfx::filter::upscaling::string(upscaling_provider provider)
{ {
return cstring(provider); return cstring(provider);
} }
@ -90,11 +90,11 @@ std::string streamfx::filter::video_superresolution::string(video_superresolutio
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Instance // Instance
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
video_superresolution_instance::video_superresolution_instance(obs_data_t* data, obs_source_t* self) upscaling_instance::upscaling_instance(obs_data_t* data, obs_source_t* self)
: obs::source_instance(data, self), : obs::source_instance(data, self),
_in_size(1, 1), _out_size(1, 1), _provider_ready(false), _provider(video_superresolution_provider::INVALID), _in_size(1, 1), _out_size(1, 1), _provider_ready(false), _provider(upscaling_provider::INVALID), _provider_lock(),
_provider_lock(), _provider_task(), _input(), _output(), _dirty(false) _provider_task(), _input(), _output(), _dirty(false)
{ {
{ {
::streamfx::obs::gs::context gctx; ::streamfx::obs::gs::context gctx;
@ -110,13 +110,13 @@ video_superresolution_instance::video_superresolution_instance(obs_data_t* data,
} }
} }
video_superresolution_instance::~video_superresolution_instance() upscaling_instance::~upscaling_instance()
{ {
// TODO: Make this asynchronous. // TODO: Make this asynchronous.
std::unique_lock<std::mutex> ul(_provider_lock); std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_unload(); nvvfxsr_unload();
break; break;
#endif #endif
@ -125,20 +125,19 @@ video_superresolution_instance::~video_superresolution_instance()
} }
} }
void video_superresolution_instance::load(obs_data_t* data) void upscaling_instance::load(obs_data_t* data)
{ {
update(data); update(data);
} }
void video_superresolution_instance::migrate(obs_data_t* data, uint64_t version) {} void upscaling_instance::migrate(obs_data_t* data, uint64_t version) {}
void video_superresolution_instance::update(obs_data_t* data) void upscaling_instance::update(obs_data_t* data)
{ {
// Check if the user changed which Denoising provider we use. // Check if the user changed which Denoising provider we use.
video_superresolution_provider provider = upscaling_provider provider = static_cast<upscaling_provider>(obs_data_get_int(data, ST_KEY_PROVIDER));
static_cast<video_superresolution_provider>(obs_data_get_int(data, ST_KEY_PROVIDER)); if (provider == upscaling_provider::AUTOMATIC) {
if (provider == video_superresolution_provider::AUTOMATIC) { provider = upscaling_factory::get()->find_ideal_provider();
provider = video_superresolution_factory::get()->find_ideal_provider();
} }
// Check if the provider was changed, and if so switch. // Check if the provider was changed, and if so switch.
@ -151,8 +150,8 @@ void video_superresolution_instance::update(obs_data_t* data)
std::unique_lock<std::mutex> ul(_provider_lock); std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_update(data); nvvfxsr_update(data);
break; break;
#endif #endif
@ -162,11 +161,11 @@ 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::upscaling::upscaling_instance::properties(obs_properties_t* properties)
{ {
switch (_provider_ui) { switch (_provider_ui) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_properties(properties); nvvfxsr_properties(properties);
break; break;
#endif #endif
@ -175,17 +174,17 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::pr
} }
} }
uint32_t streamfx::filter::video_superresolution::video_superresolution_instance::get_width() uint32_t streamfx::filter::upscaling::upscaling_instance::get_width()
{ {
return std::max<uint32_t>(_out_size.first, 1); return std::max<uint32_t>(_out_size.first, 1);
} }
uint32_t streamfx::filter::video_superresolution::video_superresolution_instance::get_height() uint32_t streamfx::filter::upscaling::upscaling_instance::get_height()
{ {
return std::max<uint32_t>(_out_size.second, 1); return std::max<uint32_t>(_out_size.second, 1);
} }
void video_superresolution_instance::video_tick(float_t time) void upscaling_instance::video_tick(float_t time)
{ {
auto target = obs_filter_get_target(_self); auto target = obs_filter_get_target(_self);
auto width = obs_source_get_base_width(target); auto width = obs_source_get_base_width(target);
@ -198,8 +197,8 @@ void video_superresolution_instance::video_tick(float_t time)
std::unique_lock<std::mutex> ul(_provider_lock); std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_size(); nvvfxsr_size();
break; break;
#endif #endif
@ -211,7 +210,7 @@ void video_superresolution_instance::video_tick(float_t time)
_dirty = true; _dirty = true;
} }
void video_superresolution_instance::video_render(gs_effect_t* effect) void upscaling_instance::video_render(gs_effect_t* effect)
{ {
auto parent = obs_filter_get_parent(_self); auto parent = obs_filter_get_parent(_self);
auto target = obs_filter_get_target(_self); auto target = obs_filter_get_target(_self);
@ -285,8 +284,8 @@ void video_superresolution_instance::video_render(gs_effect_t* effect)
::streamfx::obs::gs::debug_marker profiler1{::streamfx::obs::gs::debug_color_convert, "Process"}; ::streamfx::obs::gs::debug_marker profiler1{::streamfx::obs::gs::debug_color_convert, "Process"};
#endif #endif
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_process(); nvvfxsr_process();
break; break;
#endif #endif
@ -320,11 +319,10 @@ void video_superresolution_instance::video_render(gs_effect_t* effect)
} }
struct switch_provider_data_t { struct switch_provider_data_t {
video_superresolution_provider provider; upscaling_provider provider;
}; };
void streamfx::filter::video_superresolution::video_superresolution_instance::switch_provider( void streamfx::filter::upscaling::upscaling_instance::switch_provider(upscaling_provider provider)
video_superresolution_provider provider)
{ {
std::unique_lock<std::mutex> ul(_provider_lock); std::unique_lock<std::mutex> ul(_provider_lock);
@ -353,11 +351,10 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::sw
// 3. Then spawn a new task to switch provider. // 3. Then spawn a new task to switch provider.
_provider_task = streamfx::threadpool()->push( _provider_task = streamfx::threadpool()->push(
std::bind(&video_superresolution_instance::task_switch_provider, this, std::placeholders::_1), spd); std::bind(&upscaling_instance::task_switch_provider, this, std::placeholders::_1), spd);
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::task_switch_provider( void streamfx::filter::upscaling::upscaling_instance::task_switch_provider(util::threadpool_data_t data)
util::threadpool_data_t data)
{ {
std::shared_ptr<switch_provider_data_t> spd = std::static_pointer_cast<switch_provider_data_t>(data); std::shared_ptr<switch_provider_data_t> spd = std::static_pointer_cast<switch_provider_data_t>(data);
@ -370,8 +367,8 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::ta
try { try {
// 3. Unload the previous provider. // 3. Unload the previous provider.
switch (spd->provider) { switch (spd->provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_unload(); nvvfxsr_unload();
break; break;
#endif #endif
@ -381,8 +378,8 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::ta
// 4. Load the new provider. // 4. Load the new provider.
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
nvvfxsr_load(); nvvfxsr_load();
{ {
auto data = obs_source_get_settings(_self); auto data = obs_source_get_settings(_self);
@ -407,18 +404,18 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::ta
} }
} }
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_load() void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_load()
{ {
_nvidia_fx = std::make_shared<::streamfx::nvidia::vfx::superresolution>(); _nvidia_fx = std::make_shared<::streamfx::nvidia::vfx::superresolution>();
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_unload() void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_unload()
{ {
_nvidia_fx.reset(); _nvidia_fx.reset();
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_size() void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_size()
{ {
if (!_nvidia_fx) { if (!_nvidia_fx) {
return; return;
@ -428,7 +425,7 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::nv
_nvidia_fx->size(in_size, _in_size, _out_size); _nvidia_fx->size(in_size, _in_size, _out_size);
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_process() void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_process()
{ {
if (!_nvidia_fx) { if (!_nvidia_fx) {
_output = _input->get_texture(); _output = _input->get_texture();
@ -438,8 +435,7 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::nv
_output = _nvidia_fx->process(_input->get_texture()); _output = _nvidia_fx->process(_input->get_texture());
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_properties( void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_properties(obs_properties_t* props)
obs_properties_t* props)
{ {
obs_properties_t* grp = obs_properties_create(); obs_properties_t* grp = obs_properties_create();
obs_properties_add_group(props, ST_KEY_NVIDIA_SUPERRES, D_TRANSLATE(ST_I18N_NVIDIA_SUPERRES), OBS_GROUP_NORMAL, obs_properties_add_group(props, ST_KEY_NVIDIA_SUPERRES, D_TRANSLATE(ST_I18N_NVIDIA_SUPERRES), OBS_GROUP_NORMAL,
@ -460,7 +456,7 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::nv
} }
} }
void streamfx::filter::video_superresolution::video_superresolution_instance::nvvfxsr_update(obs_data_t* data) void streamfx::filter::upscaling::upscaling_instance::nvvfxsr_update(obs_data_t* data)
{ {
if (!_nvidia_fx) if (!_nvidia_fx)
return; return;
@ -475,14 +471,14 @@ void streamfx::filter::video_superresolution::video_superresolution_instance::nv
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Factory // Factory
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
video_superresolution_factory::~video_superresolution_factory() {} upscaling_factory::~upscaling_factory() {}
video_superresolution_factory::video_superresolution_factory() upscaling_factory::upscaling_factory()
{ {
bool any_available = false; bool any_available = false;
// 1. Try and load any configured providers. // 1. Try and load any configured providers.
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
try { try {
// Load CVImage and Video Effects SDK. // Load CVImage and Video Effects SDK.
_nvcuda = ::streamfx::nvidia::cuda::obs::get(); _nvcuda = ::streamfx::nvidia::cuda::obs::get();
@ -520,16 +516,16 @@ video_superresolution_factory::video_superresolution_factory()
finish_setup(); finish_setup();
} }
const char* video_superresolution_factory::get_name() const char* upscaling_factory::get_name()
{ {
return D_TRANSLATE(ST_I18N); return D_TRANSLATE(ST_I18N);
} }
void video_superresolution_factory::get_defaults2(obs_data_t* data) void upscaling_factory::get_defaults2(obs_data_t* data)
{ {
obs_data_set_default_int(data, ST_KEY_PROVIDER, static_cast<int64_t>(video_superresolution_provider::AUTOMATIC)); obs_data_set_default_int(data, ST_KEY_PROVIDER, static_cast<int64_t>(upscaling_provider::AUTOMATIC));
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_SCALE, 150.); obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_SCALE, 150.);
obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_STRENGTH, 0.); obs_data_set_default_double(data, ST_KEY_NVIDIA_SUPERRES_STRENGTH, 0.);
#endif #endif
@ -546,14 +542,14 @@ try {
return false; return false;
} }
obs_properties_t* video_superresolution_factory::get_properties2(video_superresolution_instance* data) obs_properties_t* upscaling_factory::get_properties2(upscaling_instance* data)
{ {
obs_properties_t* pr = obs_properties_create(); obs_properties_t* pr = obs_properties_create();
#ifdef ENABLE_FRONTEND #ifdef ENABLE_FRONTEND
{ {
obs_properties_add_button2(pr, S_MANUAL_OPEN, D_TRANSLATE(S_MANUAL_OPEN), obs_properties_add_button2(pr, S_MANUAL_OPEN, D_TRANSLATE(S_MANUAL_OPEN), upscaling_factory::on_manual_open,
video_superresolution_factory::on_manual_open, nullptr); nullptr);
} }
#endif #endif
@ -570,10 +566,9 @@ obs_properties_t* video_superresolution_factory::get_properties2(video_superreso
OBS_COMBO_FORMAT_INT); OBS_COMBO_FORMAT_INT);
obs_property_set_modified_callback(p, modified_provider); 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>(upscaling_provider::AUTOMATIC));
obs_property_list_add_int( obs_property_list_add_int(p, D_TRANSLATE(ST_I18N_PROVIDER_NVIDIA_SUPERRES),
p, D_TRANSLATE(ST_I18N_PROVIDER_NVIDIA_SUPERRES), static_cast<int64_t>(upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION));
static_cast<int64_t>(video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION));
} }
} }
@ -581,7 +576,7 @@ obs_properties_t* video_superresolution_factory::get_properties2(video_superreso
} }
#ifdef ENABLE_FRONTEND #ifdef ENABLE_FRONTEND
bool video_superresolution_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data) bool upscaling_factory::on_manual_open(obs_properties_t* props, obs_property_t* property, void* data)
try { try {
streamfx::open_url(HELP_URL); streamfx::open_url(HELP_URL);
return false; return false;
@ -594,12 +589,11 @@ try {
} }
#endif #endif
bool streamfx::filter::video_superresolution::video_superresolution_factory::is_provider_available( bool streamfx::filter::upscaling::upscaling_factory::is_provider_available(upscaling_provider provider)
video_superresolution_provider provider)
{ {
switch (provider) { switch (provider) {
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
case video_superresolution_provider::NVIDIA_VIDEO_SUPERRESOLUTION: case upscaling_provider::NVIDIA_VIDEO_SUPERRESOLUTION:
return _nvidia_available; return _nvidia_available;
#endif #endif
default: default:
@ -607,36 +601,35 @@ bool streamfx::filter::video_superresolution::video_superresolution_factory::is_
} }
} }
video_superresolution_provider upscaling_provider streamfx::filter::upscaling::upscaling_factory::find_ideal_provider()
streamfx::filter::video_superresolution::video_superresolution_factory::find_ideal_provider()
{ {
for (auto v : provider_priority) { for (auto v : provider_priority) {
if (video_superresolution_factory::get()->is_provider_available(v)) { if (upscaling_factory::get()->is_provider_available(v)) {
return v; return v;
break; break;
} }
} }
return video_superresolution_provider::AUTOMATIC; return upscaling_provider::AUTOMATIC;
} }
std::shared_ptr<video_superresolution_factory> _video_superresolution_factory_instance = nullptr; std::shared_ptr<upscaling_factory> _video_superresolution_factory_instance = nullptr;
void video_superresolution_factory::initialize() void upscaling_factory::initialize()
try { try {
if (!_video_superresolution_factory_instance) if (!_video_superresolution_factory_instance)
_video_superresolution_factory_instance = std::make_shared<video_superresolution_factory>(); _video_superresolution_factory_instance = std::make_shared<upscaling_factory>();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
D_LOG_ERROR("Failed to initialize due to error: %s", ex.what()); D_LOG_ERROR("Failed to initialize due to error: %s", ex.what());
} catch (...) { } catch (...) {
D_LOG_ERROR("Failed to initialize due to unknown error.", ""); D_LOG_ERROR("Failed to initialize due to unknown error.", "");
} }
void video_superresolution_factory::finalize() void upscaling_factory::finalize()
{ {
_video_superresolution_factory_instance.reset(); _video_superresolution_factory_instance.reset();
} }
std::shared_ptr<video_superresolution_factory> video_superresolution_factory::get() std::shared_ptr<upscaling_factory> upscaling_factory::get()
{ {
return _video_superresolution_factory_instance; return _video_superresolution_factory_instance;
} }

View file

@ -28,28 +28,28 @@
#include "plugin.hpp" #include "plugin.hpp"
#include "util/util-threadpool.hpp" #include "util/util-threadpool.hpp"
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#include "nvidia/vfx/nvidia-vfx-superresolution.hpp" #include "nvidia/vfx/nvidia-vfx-superresolution.hpp"
#endif #endif
namespace streamfx::filter::video_superresolution { namespace streamfx::filter::upscaling {
enum class video_superresolution_provider { enum class upscaling_provider {
INVALID = -1, INVALID = -1,
AUTOMATIC = 0, AUTOMATIC = 0,
NVIDIA_VIDEO_SUPERRESOLUTION = 1, NVIDIA_VIDEO_SUPERRESOLUTION = 1,
}; };
const char* cstring(video_superresolution_provider provider); const char* cstring(upscaling_provider provider);
std::string string(video_superresolution_provider provider); std::string string(upscaling_provider provider);
class video_superresolution_instance : public ::streamfx::obs::source_instance { class upscaling_instance : public ::streamfx::obs::source_instance {
std::pair<uint32_t, uint32_t> _in_size; std::pair<uint32_t, uint32_t> _in_size;
std::pair<uint32_t, uint32_t> _out_size; std::pair<uint32_t, uint32_t> _out_size;
std::atomic<upscaling_provider> _provider;
upscaling_provider _provider_ui;
std::atomic<bool> _provider_ready; std::atomic<bool> _provider_ready;
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;
@ -57,13 +57,13 @@ namespace streamfx::filter::video_superresolution {
std::shared_ptr<::streamfx::obs::gs::texture> _output; std::shared_ptr<::streamfx::obs::gs::texture> _output;
bool _dirty; bool _dirty;
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
std::shared_ptr<::streamfx::nvidia::vfx::superresolution> _nvidia_fx; std::shared_ptr<::streamfx::nvidia::vfx::superresolution> _nvidia_fx;
#endif #endif
public: public:
video_superresolution_instance(obs_data_t* data, obs_source_t* self); upscaling_instance(obs_data_t* data, obs_source_t* self);
~video_superresolution_instance() override; ~upscaling_instance() override;
void load(obs_data_t* data) override; void load(obs_data_t* data) override;
void migrate(obs_data_t* data, uint64_t version) override; void migrate(obs_data_t* data, uint64_t version) override;
@ -77,10 +77,10 @@ namespace streamfx::filter::video_superresolution {
void video_render(gs_effect_t* effect) override; void video_render(gs_effect_t* effect) override;
private: private:
void switch_provider(video_superresolution_provider provider); void switch_provider(upscaling_provider provider);
void task_switch_provider(util::threadpool_data_t data); void task_switch_provider(util::threadpool_data_t data);
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
void nvvfxsr_load(); void nvvfxsr_load();
void nvvfxsr_unload(); void nvvfxsr_unload();
void nvvfxsr_size(); void nvvfxsr_size();
@ -90,11 +90,10 @@ namespace streamfx::filter::video_superresolution {
#endif #endif
}; };
class video_superresolution_factory class upscaling_factory
: public ::streamfx::obs::source_factory< : public ::streamfx::obs::source_factory<::streamfx::filter::upscaling::upscaling_factory,
::streamfx::filter::video_superresolution::video_superresolution_factory, ::streamfx::filter::upscaling::upscaling_instance> {
::streamfx::filter::video_superresolution::video_superresolution_instance> { #ifdef ENABLE_FILTER_UPSCALING_NVIDIA
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION_NVIDIA
bool _nvidia_available; bool _nvidia_available;
std::shared_ptr<::streamfx::nvidia::cuda::obs> _nvcuda; std::shared_ptr<::streamfx::nvidia::cuda::obs> _nvcuda;
std::shared_ptr<::streamfx::nvidia::cv::cv> _nvcvi; std::shared_ptr<::streamfx::nvidia::cv::cv> _nvcvi;
@ -102,25 +101,25 @@ namespace streamfx::filter::video_superresolution {
#endif #endif
public: public:
virtual ~video_superresolution_factory(); virtual ~upscaling_factory();
video_superresolution_factory(); upscaling_factory();
virtual const char* get_name() override; virtual const char* get_name() override;
virtual void get_defaults2(obs_data_t* data) override; virtual void get_defaults2(obs_data_t* data) override;
virtual obs_properties_t* get_properties2(video_superresolution_instance* data) override; virtual obs_properties_t* get_properties2(upscaling_instance* data) override;
#ifdef ENABLE_FRONTEND #ifdef ENABLE_FRONTEND
static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data); static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data);
#endif #endif
bool is_provider_available(video_superresolution_provider); bool is_provider_available(upscaling_provider);
video_superresolution_provider find_ideal_provider(); upscaling_provider find_ideal_provider();
public: // Singleton public: // Singleton
static void initialize(); static void initialize();
static void finalize(); static void finalize();
static std::shared_ptr<::streamfx::filter::video_superresolution::video_superresolution_factory> get(); static std::shared_ptr<::streamfx::filter::upscaling::upscaling_factory> get();
}; };
} // namespace streamfx::filter::video_superresolution } // namespace streamfx::filter::upscaling

View file

@ -59,8 +59,8 @@
#ifdef ENABLE_FILTER_TRANSFORM #ifdef ENABLE_FILTER_TRANSFORM
#include "filters/filter-transform.hpp" #include "filters/filter-transform.hpp"
#endif #endif
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION #ifdef ENABLE_FILTER_UPSCALING
#include "filters/filter-video-superresolution.hpp" #include "filters/filter-upscaling.hpp"
#endif #endif
#ifdef ENABLE_SOURCE_MIRROR #ifdef ENABLE_SOURCE_MIRROR
@ -167,8 +167,8 @@ try {
#ifdef ENABLE_FILTER_TRANSFORM #ifdef ENABLE_FILTER_TRANSFORM
streamfx::filter::transform::transform_factory::initialize(); streamfx::filter::transform::transform_factory::initialize();
#endif #endif
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION #ifdef ENABLE_FILTER_UPSCALING
streamfx::filter::video_superresolution::video_superresolution_factory::initialize(); streamfx::filter::upscaling::upscaling_factory::initialize();
#endif #endif
} }
@ -256,8 +256,8 @@ try {
#ifdef ENABLE_FILTER_TRANSFORM #ifdef ENABLE_FILTER_TRANSFORM
streamfx::filter::transform::transform_factory::finalize(); streamfx::filter::transform::transform_factory::finalize();
#endif #endif
#ifdef ENABLE_FILTER_VIDEO_SUPERRESOLUTION #ifdef ENABLE_FILTER_UPSCALING
streamfx::filter::video_superresolution::video_superresolution_factory::finalize(); streamfx::filter::upscaling::upscaling_factory::finalize();
#endif #endif
} }