2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2021-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2021-06-02 21:37:18 +00:00
|
|
|
|
|
|
|
#pragma once
|
2021-10-06 00:15:28 +00:00
|
|
|
#include "obs/gs/gs-effect.hpp"
|
2021-06-02 21:37:18 +00:00
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
#include "obs/gs/gs-texture.hpp"
|
|
|
|
#include "obs/obs-source-factory.hpp"
|
|
|
|
#include "plugin.hpp"
|
|
|
|
#include "util/util-threadpool.hpp"
|
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
|
2021-06-02 21:37:18 +00:00
|
|
|
#include "nvidia/vfx/nvidia-vfx-superresolution.hpp"
|
|
|
|
#endif
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
namespace streamfx::filter::upscaling {
|
|
|
|
enum class upscaling_provider {
|
2021-10-03 19:20:13 +00:00
|
|
|
INVALID = -1,
|
|
|
|
AUTOMATIC = 0,
|
|
|
|
NVIDIA_SUPERRESOLUTION = 1,
|
2021-06-02 21:37:18 +00:00
|
|
|
};
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
const char* cstring(upscaling_provider provider);
|
2021-06-02 21:37:18 +00:00
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
std::string string(upscaling_provider provider);
|
2021-06-02 21:37:18 +00:00
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
class upscaling_instance : public ::streamfx::obs::source_instance {
|
2021-06-02 21:37:18 +00:00
|
|
|
std::pair<uint32_t, uint32_t> _in_size;
|
|
|
|
std::pair<uint32_t, uint32_t> _out_size;
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
std::atomic<upscaling_provider> _provider;
|
|
|
|
upscaling_provider _provider_ui;
|
|
|
|
std::atomic<bool> _provider_ready;
|
|
|
|
std::mutex _provider_lock;
|
|
|
|
std::shared_ptr<util::threadpool::task> _provider_task;
|
2021-06-02 21:37:18 +00:00
|
|
|
|
2021-10-06 00:15:28 +00:00
|
|
|
std::shared_ptr<::streamfx::obs::gs::effect> _standard_effect;
|
|
|
|
std::shared_ptr<::streamfx::obs::gs::sampler> _channel0_sampler;
|
|
|
|
std::shared_ptr<::streamfx::obs::gs::sampler> _channel1_sampler;
|
|
|
|
|
2021-06-02 21:37:18 +00:00
|
|
|
std::shared_ptr<::streamfx::obs::gs::rendertarget> _input;
|
|
|
|
std::shared_ptr<::streamfx::obs::gs::texture> _output;
|
|
|
|
bool _dirty;
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
|
2021-06-02 21:37:18 +00:00
|
|
|
std::shared_ptr<::streamfx::nvidia::vfx::superresolution> _nvidia_fx;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2021-09-27 22:16:21 +00:00
|
|
|
upscaling_instance(obs_data_t* data, obs_source_t* self);
|
|
|
|
~upscaling_instance() override;
|
2021-06-02 21:37:18 +00:00
|
|
|
|
|
|
|
void load(obs_data_t* data) override;
|
|
|
|
void migrate(obs_data_t* data, uint64_t version) override;
|
|
|
|
void update(obs_data_t* data) override;
|
|
|
|
void properties(obs_properties_t* properties);
|
|
|
|
|
|
|
|
uint32_t get_width() override;
|
|
|
|
uint32_t get_height() override;
|
|
|
|
|
|
|
|
void video_tick(float_t time) override;
|
|
|
|
void video_render(gs_effect_t* effect) override;
|
|
|
|
|
|
|
|
private:
|
2021-09-27 22:16:21 +00:00
|
|
|
void switch_provider(upscaling_provider provider);
|
2022-09-18 16:30:15 +00:00
|
|
|
void task_switch_provider(util::threadpool::task_data_t data);
|
2021-06-02 21:37:18 +00:00
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
|
2021-06-02 21:37:18 +00:00
|
|
|
void nvvfxsr_load();
|
|
|
|
void nvvfxsr_unload();
|
|
|
|
void nvvfxsr_size();
|
|
|
|
void nvvfxsr_process();
|
|
|
|
void nvvfxsr_properties(obs_properties_t* props);
|
|
|
|
void nvvfxsr_update(obs_data_t* data);
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2023-05-13 12:35:46 +00:00
|
|
|
class upscaling_factory : public ::streamfx::obs::source_factory<::streamfx::filter::upscaling::upscaling_factory, ::streamfx::filter::upscaling::upscaling_instance> {
|
2021-09-27 22:16:21 +00:00
|
|
|
#ifdef ENABLE_FILTER_UPSCALING_NVIDIA
|
2021-06-02 21:37:18 +00:00
|
|
|
bool _nvidia_available;
|
|
|
|
std::shared_ptr<::streamfx::nvidia::cuda::obs> _nvcuda;
|
|
|
|
std::shared_ptr<::streamfx::nvidia::cv::cv> _nvcvi;
|
|
|
|
std::shared_ptr<::streamfx::nvidia::vfx::vfx> _nvvfx;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
2021-09-27 22:16:21 +00:00
|
|
|
virtual ~upscaling_factory();
|
|
|
|
upscaling_factory();
|
2021-06-02 21:37:18 +00:00
|
|
|
|
|
|
|
virtual const char* get_name() override;
|
|
|
|
|
|
|
|
virtual void get_defaults2(obs_data_t* data) override;
|
2021-09-27 22:16:21 +00:00
|
|
|
virtual obs_properties_t* get_properties2(upscaling_instance* data) override;
|
2021-06-02 21:37:18 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data);
|
|
|
|
#endif
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
bool is_provider_available(upscaling_provider);
|
|
|
|
upscaling_provider find_ideal_provider();
|
2021-06-02 21:37:18 +00:00
|
|
|
|
|
|
|
public: // Singleton
|
2021-09-27 22:16:21 +00:00
|
|
|
static void initialize();
|
|
|
|
static void finalize();
|
2023-05-14 06:56:34 +00:00
|
|
|
static std::shared_ptr<::streamfx::filter::upscaling::upscaling_factory> instance();
|
2021-06-02 21:37:18 +00:00
|
|
|
};
|
|
|
|
|
2021-09-27 22:16:21 +00:00
|
|
|
} // namespace streamfx::filter::upscaling
|