autoframing: Check if NVIDIA component is available

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2023-09-30 05:35:55 +02:00 committed by Xaymar
parent 3239f5e5b9
commit 4ebc96997e
3 changed files with 30 additions and 15 deletions

View File

@ -6,4 +6,19 @@ cmake_minimum_required(VERSION 3.26)
project("AutoFraming") project("AutoFraming")
list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ") list(APPEND CMAKE_MESSAGE_INDENT "[${PROJECT_NAME}] ")
streamfx_add_component("Auto-Framing") streamfx_add_component("Auto-Framing"
RESOLVER streamfx_auto_framing_resolver
)
streamfx_add_component_dependency("NVIDIA" OPTIONAL)
function(streamfx_auto_framing_resolver)
# Providers
#- NVIDIA
streamfx_enabled_component("NVIDIA" T_CHECK)
if(T_CHECK)
target_compile_definitions(${COMPONENT_TARGET}
PRIVATE ENABLE_NVIDIA
)
endif()
endfunction()

View File

@ -146,7 +146,7 @@ autoframing_instance::~autoframing_instance()
// TODO: Make this asynchronous. // TODO: Make this asynchronous.
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_DENOISING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_unload(); nvar_facedetection_unload();
break; break;
@ -358,7 +358,7 @@ void autoframing_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_UPSCALING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_update(data); nvar_facedetection_update(data);
break; break;
@ -375,7 +375,7 @@ void autoframing_instance::update(obs_data_t* data)
void streamfx::filter::autoframing::autoframing_instance::properties(obs_properties_t* properties) void streamfx::filter::autoframing::autoframing_instance::properties(obs_properties_t* properties)
{ {
switch (_provider_ui) { switch (_provider_ui) {
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_properties(properties); nvar_facedetection_properties(properties);
break; break;
@ -490,7 +490,7 @@ void autoframing_instance::video_render(gs_effect_t* effect)
std::unique_lock<std::mutex> ul(_provider_lock); std::unique_lock<std::mutex> ul(_provider_lock);
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_DENOISING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_process(); nvar_facedetection_process();
break; break;
@ -864,7 +864,7 @@ void streamfx::filter::autoframing::autoframing_instance::task_switch_provider(u
try { try {
// Unload the previous provider. // Unload the previous provider.
switch (spd->provider) { switch (spd->provider) {
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_unload(); nvar_facedetection_unload();
break; break;
@ -875,7 +875,7 @@ void streamfx::filter::autoframing::autoframing_instance::task_switch_provider(u
// Load the new provider. // Load the new provider.
switch (_provider) { switch (_provider) {
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
nvar_facedetection_load(); nvar_facedetection_load();
break; break;
@ -894,7 +894,7 @@ void streamfx::filter::autoframing::autoframing_instance::task_switch_provider(u
} }
} }
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
void streamfx::filter::autoframing::autoframing_instance::nvar_facedetection_load() void streamfx::filter::autoframing::autoframing_instance::nvar_facedetection_load()
{ {
_nvidia_fx = std::make_shared<::streamfx::nvidia::ar::facedetection>(); _nvidia_fx = std::make_shared<::streamfx::nvidia::ar::facedetection>();
@ -1008,7 +1008,7 @@ autoframing_factory::autoframing_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_AUTOFRAMING_NVIDIA #ifdef ENABLE_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();
@ -1213,7 +1213,7 @@ obs_properties_t* autoframing_factory::get_properties2(autoframing_instance* dat
auto p = obs_properties_add_list(grp, ST_KEY_ADVANCED_PROVIDER, D_TRANSLATE(ST_I18N_ADVANCED_PROVIDER), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); auto p = obs_properties_add_list(grp, ST_KEY_ADVANCED_PROVIDER, D_TRANSLATE(ST_I18N_ADVANCED_PROVIDER), OBS_COMBO_TYPE_LIST, 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), static_cast<int64_t>(tracking_provider::AUTOMATIC)); obs_property_list_add_int(p, D_TRANSLATE(S_STATE_AUTOMATIC), static_cast<int64_t>(tracking_provider::AUTOMATIC));
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
obs_property_list_add_int(p, D_TRANSLATE(ST_I18N_ADVANCED_PROVIDER_NVIDIA_FACEDETECTION), static_cast<int64_t>(tracking_provider::NVIDIA_FACEDETECTION)); obs_property_list_add_int(p, D_TRANSLATE(ST_I18N_ADVANCED_PROVIDER_NVIDIA_FACEDETECTION), static_cast<int64_t>(tracking_provider::NVIDIA_FACEDETECTION));
#endif #endif
} }
@ -1235,7 +1235,7 @@ bool streamfx::filter::autoframing::autoframing_factory::on_manual_open(obs_prop
bool streamfx::filter::autoframing::autoframing_factory::is_provider_available(tracking_provider provider) bool streamfx::filter::autoframing::autoframing_factory::is_provider_available(tracking_provider provider)
{ {
switch (provider) { switch (provider) {
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
case tracking_provider::NVIDIA_FACEDETECTION: case tracking_provider::NVIDIA_FACEDETECTION:
return _nvidia_available; return _nvidia_available;
#endif #endif

View File

@ -19,7 +19,7 @@
#include <mutex> #include <mutex>
#include "warning-enable.hpp" #include "warning-enable.hpp"
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
#include "nvidia/ar/nvidia-ar-facedetection.hpp" #include "nvidia/ar/nvidia-ar-facedetection.hpp"
#endif #endif
@ -81,7 +81,7 @@ namespace streamfx::filter::autoframing {
std::mutex _provider_lock; std::mutex _provider_lock;
std::shared_ptr<util::threadpool::task> _provider_task; std::shared_ptr<util::threadpool::task> _provider_task;
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
std::shared_ptr<::streamfx::nvidia::ar::facedetection> _nvidia_fx; std::shared_ptr<::streamfx::nvidia::ar::facedetection> _nvidia_fx;
#endif #endif
@ -135,7 +135,7 @@ namespace streamfx::filter::autoframing {
void switch_provider(tracking_provider provider); void switch_provider(tracking_provider provider);
void task_switch_provider(util::threadpool::task_data_t data); void task_switch_provider(util::threadpool::task_data_t data);
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_NVIDIA
void nvar_facedetection_load(); void nvar_facedetection_load();
void nvar_facedetection_unload(); void nvar_facedetection_unload();
void nvar_facedetection_process(); void nvar_facedetection_process();
@ -145,7 +145,7 @@ namespace streamfx::filter::autoframing {
}; };
class autoframing_factory : public obs::source_factory<streamfx::filter::autoframing::autoframing_factory, streamfx::filter::autoframing::autoframing_instance> { class autoframing_factory : public obs::source_factory<streamfx::filter::autoframing::autoframing_factory, streamfx::filter::autoframing::autoframing_instance> {
#ifdef ENABLE_FILTER_AUTOFRAMING_NVIDIA #ifdef ENABLE_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;