mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +00:00
filter/nv-face-tracking: Adjust to match coding guidelines
This commit is contained in:
parent
7f5916dd72
commit
8d7f2ffec7
2 changed files with 40 additions and 38 deletions
|
@ -54,7 +54,7 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_
|
||||||
|
|
||||||
_geometry(), _filters(), _values(),
|
_geometry(), _filters(), _values(),
|
||||||
|
|
||||||
_cuda(::nvidia::cuda::obs::get()), _cuda_stream(),
|
_cuda(::streamfx::nvidia::cuda::obs::get()), _cuda_stream(),
|
||||||
|
|
||||||
_ar_library(face_tracking_factory::get()->get_ar()), _ar_loaded(false), _ar_feature(), _ar_is_tracking(false),
|
_ar_library(face_tracking_factory::get()->get_ar()), _ar_loaded(false), _ar_feature(), _ar_is_tracking(false),
|
||||||
_ar_bboxes_confidence(), _ar_bboxes_data(), _ar_bboxes(), _ar_texture(), _ar_texture_cuda_fresh(false),
|
_ar_bboxes_confidence(), _ar_bboxes_data(), _ar_bboxes(), _ar_texture(), _ar_texture_cuda_fresh(false),
|
||||||
|
@ -73,11 +73,12 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ // Create render target, vertex buffer, and CUDA stream.
|
{ // Create render target, vertex buffer, and CUDA stream.
|
||||||
auto gctx = streamfx::obs::gs::context{};
|
auto gctx = streamfx::obs::gs::context{};
|
||||||
_rt = std::make_shared<streamfx::obs::gs::rendertarget>(GS_RGBA_UNORM, GS_ZS_NONE);
|
_rt = std::make_shared<streamfx::obs::gs::rendertarget>(GS_RGBA_UNORM, GS_ZS_NONE);
|
||||||
_geometry = std::make_shared<streamfx::obs::gs::vertex_buffer>(uint32_t(4), uint8_t(1));
|
_geometry = std::make_shared<streamfx::obs::gs::vertex_buffer>(uint32_t(4), uint8_t(1));
|
||||||
auto cctx = _cuda->get_context()->enter();
|
auto cctx = _cuda->get_context()->enter();
|
||||||
_cuda_stream = std::make_shared<::nvidia::cuda::stream>(::nvidia::cuda::stream_flags::NON_BLOCKING, 0);
|
_cuda_stream =
|
||||||
|
std::make_shared<::streamfx::nvidia::cuda::stream>(::streamfx::nvidia::cuda::stream_flags::NON_BLOCKING, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // Asynchronously load Face Tracking.
|
{ // Asynchronously load Face Tracking.
|
||||||
|
@ -278,9 +279,10 @@ void face_tracking_instance::async_track(std::shared_ptr<void> ptr)
|
||||||
"%s: Reallocate CUDA Buffers", obs_source_get_name(_self)};
|
"%s: Reallocate CUDA Buffers", obs_source_get_name(_self)};
|
||||||
#endif
|
#endif
|
||||||
// Assign new texture and allocate new memory.
|
// Assign new texture and allocate new memory.
|
||||||
std::size_t pitch = _ar_texture->get_width() * 4ul;
|
std::size_t pitch = _ar_texture->get_width() * 4ul;
|
||||||
_ar_texture_cuda = std::make_shared<::nvidia::cuda::gstexture>(_ar_texture);
|
_ar_texture_cuda = std::make_shared<::streamfx::nvidia::cuda::gstexture>(_ar_texture);
|
||||||
_ar_texture_cuda_mem = std::make_shared<::nvidia::cuda::memory>(pitch * _ar_texture->get_height());
|
_ar_texture_cuda_mem =
|
||||||
|
std::make_shared<::streamfx::nvidia::cuda::memory>(pitch * _ar_texture->get_height());
|
||||||
if (auto res = _ar_library->image_init(&_ar_image, static_cast<unsigned int>(_ar_texture->get_width()),
|
if (auto res = _ar_library->image_init(&_ar_image, static_cast<unsigned int>(_ar_texture->get_width()),
|
||||||
static_cast<unsigned int>(_ar_texture->get_height()),
|
static_cast<unsigned int>(_ar_texture->get_height()),
|
||||||
static_cast<int>(pitch),
|
static_cast<int>(pitch),
|
||||||
|
@ -320,26 +322,26 @@ void face_tracking_instance::async_track(std::shared_ptr<void> ptr)
|
||||||
#ifdef ENABLE_PROFILING
|
#ifdef ENABLE_PROFILING
|
||||||
auto prof = _profile_ar_copy->track();
|
auto prof = _profile_ar_copy->track();
|
||||||
#endif
|
#endif
|
||||||
::nvidia::cuda::memcpy2d_v2_t mc;
|
::streamfx::nvidia::cuda::memcpy2d_v2_t mc;
|
||||||
mc.src_x_in_bytes = 0;
|
mc.src_x_in_bytes = 0;
|
||||||
mc.src_y = 0;
|
mc.src_y = 0;
|
||||||
mc.src_memory_type = ::nvidia::cuda::memory_type::ARRAY;
|
mc.src_memory_type = ::streamfx::nvidia::cuda::memory_type::ARRAY;
|
||||||
mc.src_host = nullptr;
|
mc.src_host = nullptr;
|
||||||
mc.src_device = 0;
|
mc.src_device = 0;
|
||||||
mc.src_array = _ar_texture_cuda->map(_cuda_stream);
|
mc.src_array = _ar_texture_cuda->map(_cuda_stream);
|
||||||
mc.src_pitch = static_cast<size_t>(_ar_image.pitch);
|
mc.src_pitch = static_cast<size_t>(_ar_image.pitch);
|
||||||
mc.dst_x_in_bytes = 0;
|
mc.dst_x_in_bytes = 0;
|
||||||
mc.dst_y = 0;
|
mc.dst_y = 0;
|
||||||
mc.dst_memory_type = ::nvidia::cuda::memory_type::DEVICE;
|
mc.dst_memory_type = ::streamfx::nvidia::cuda::memory_type::DEVICE;
|
||||||
mc.dst_host = 0;
|
mc.dst_host = 0;
|
||||||
mc.dst_device = reinterpret_cast<::nvidia::cuda::device_ptr_t>(_ar_image.pixels);
|
mc.dst_device = reinterpret_cast<::streamfx::nvidia::cuda::device_ptr_t>(_ar_image.pixels);
|
||||||
mc.dst_array = 0;
|
mc.dst_array = 0;
|
||||||
mc.dst_pitch = static_cast<size_t>(_ar_image.pitch);
|
mc.dst_pitch = static_cast<size_t>(_ar_image.pitch);
|
||||||
mc.width_in_bytes = static_cast<size_t>(_ar_image.pitch);
|
mc.width_in_bytes = static_cast<size_t>(_ar_image.pitch);
|
||||||
mc.height = _ar_image.height;
|
mc.height = _ar_image.height;
|
||||||
|
|
||||||
if (::nvidia::cuda::result res = _cuda->get_cuda()->cuMemcpy2DAsync(&mc, _cuda_stream->get());
|
if (::streamfx::nvidia::cuda::result res = _cuda->get_cuda()->cuMemcpy2DAsync(&mc, _cuda_stream->get());
|
||||||
res != ::nvidia::cuda::result::SUCCESS) {
|
res != ::streamfx::nvidia::cuda::result::SUCCESS) {
|
||||||
DLOG_ERROR("<%s> Failed to prepare buffers for tracking.", obs_source_get_name(_self));
|
DLOG_ERROR("<%s> Failed to prepare buffers for tracking.", obs_source_get_name(_self));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -619,10 +621,10 @@ bool face_tracking_instance::button_profile(obs_properties_t* props, obs_propert
|
||||||
face_tracking_factory::face_tracking_factory()
|
face_tracking_factory::face_tracking_factory()
|
||||||
{
|
{
|
||||||
// Try and load CUDA.
|
// Try and load CUDA.
|
||||||
_cuda = ::nvidia::cuda::obs::get();
|
_cuda = ::streamfx::nvidia::cuda::obs::get();
|
||||||
|
|
||||||
// Try and load AR.
|
// Try and load AR.
|
||||||
_ar = std::make_shared<::nvidia::ar::ar>();
|
_ar = std::make_shared<::streamfx::nvidia::ar::ar>();
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
_info.id = S_PREFIX "filter-nvidia-face-tracking";
|
_info.id = S_PREFIX "filter-nvidia-face-tracking";
|
||||||
|
@ -696,7 +698,7 @@ obs_properties_t* face_tracking_factory::get_properties2(face_tracking_instance*
|
||||||
return pr;
|
return pr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<::nvidia::ar::ar> face_tracking_factory::get_ar()
|
std::shared_ptr<::streamfx::nvidia::ar::ar> face_tracking_factory::get_ar()
|
||||||
{
|
{
|
||||||
return _ar;
|
return _ar;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,25 +63,25 @@ namespace streamfx::filter::nvidia {
|
||||||
} _values;
|
} _values;
|
||||||
|
|
||||||
// Nvidia CUDA interop
|
// Nvidia CUDA interop
|
||||||
std::shared_ptr<::nvidia::cuda::obs> _cuda;
|
std::shared_ptr<::streamfx::nvidia::cuda::obs> _cuda;
|
||||||
std::shared_ptr<::nvidia::cuda::stream> _cuda_stream;
|
std::shared_ptr<::streamfx::nvidia::cuda::stream> _cuda_stream;
|
||||||
|
|
||||||
// Nvidia AR interop
|
// Nvidia AR interop
|
||||||
std::shared_ptr<::nvidia::ar::ar> _ar_library;
|
std::shared_ptr<::streamfx::nvidia::ar::ar> _ar_library;
|
||||||
std::atomic_bool _ar_loaded;
|
std::atomic_bool _ar_loaded;
|
||||||
std::shared_ptr<nvAR_Feature> _ar_feature;
|
std::shared_ptr<nvAR_Feature> _ar_feature;
|
||||||
std::atomic_bool _ar_is_tracking;
|
std::atomic_bool _ar_is_tracking;
|
||||||
std::mutex _ar_lock;
|
std::mutex _ar_lock;
|
||||||
std::vector<float_t> _ar_bboxes_confidence;
|
std::vector<float_t> _ar_bboxes_confidence;
|
||||||
std::vector<NvAR_Rect> _ar_bboxes_data;
|
std::vector<NvAR_Rect> _ar_bboxes_data;
|
||||||
NvAR_BBoxes _ar_bboxes;
|
NvAR_BBoxes _ar_bboxes;
|
||||||
std::shared_ptr<streamfx::obs::gs::texture> _ar_texture;
|
std::shared_ptr<streamfx::obs::gs::texture> _ar_texture;
|
||||||
bool _ar_texture_cuda_fresh;
|
bool _ar_texture_cuda_fresh;
|
||||||
std::shared_ptr<::nvidia::cuda::gstexture> _ar_texture_cuda;
|
std::shared_ptr<::streamfx::nvidia::cuda::gstexture> _ar_texture_cuda;
|
||||||
std::shared_ptr<::nvidia::cuda::memory> _ar_texture_cuda_mem;
|
std::shared_ptr<::streamfx::nvidia::cuda::memory> _ar_texture_cuda_mem;
|
||||||
NvCVImage _ar_image;
|
NvCVImage _ar_image;
|
||||||
NvCVImage _ar_image_bgr;
|
NvCVImage _ar_image_bgr;
|
||||||
NvCVImage _ar_image_temp;
|
NvCVImage _ar_image_temp;
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
std::shared_ptr<::streamfx::util::threadpool::task> _async_initialize;
|
std::shared_ptr<::streamfx::util::threadpool::task> _async_initialize;
|
||||||
|
@ -129,8 +129,8 @@ namespace streamfx::filter::nvidia {
|
||||||
|
|
||||||
class face_tracking_factory
|
class face_tracking_factory
|
||||||
: public obs::source_factory<filter::nvidia::face_tracking_factory, filter::nvidia::face_tracking_instance> {
|
: public obs::source_factory<filter::nvidia::face_tracking_factory, filter::nvidia::face_tracking_instance> {
|
||||||
std::shared_ptr<::nvidia::cuda::obs> _cuda;
|
std::shared_ptr<::streamfx::nvidia::cuda::obs> _cuda;
|
||||||
std::shared_ptr<::nvidia::ar::ar> _ar;
|
std::shared_ptr<::streamfx::nvidia::ar::ar> _ar;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
face_tracking_factory();
|
face_tracking_factory();
|
||||||
|
@ -142,7 +142,7 @@ namespace streamfx::filter::nvidia {
|
||||||
|
|
||||||
virtual obs_properties_t* get_properties2(filter::nvidia::face_tracking_instance* data) override;
|
virtual obs_properties_t* get_properties2(filter::nvidia::face_tracking_instance* data) override;
|
||||||
|
|
||||||
std::shared_ptr<::nvidia::ar::ar> get_ar();
|
std::shared_ptr<::streamfx::nvidia::ar::ar> get_ar();
|
||||||
|
|
||||||
public: // Singleton
|
public: // Singleton
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
Loading…
Reference in a new issue