chore(libvideo2x)!: replace the C API with C++ API (#1245)

* chore(libvideo2x)!: replace the C API with C++ API
* fix: convert wide string to u8 for av_opt_set
* style: removed unnecessary enum and struct specifiers

Signed-off-by: k4yt3x <i@k4yt3x.com>
This commit is contained in:
K4YT3X
2024-12-02 07:24:30 +00:00
committed by GitHub
parent 24d43a8478
commit f8dcad3aef
27 changed files with 420 additions and 457 deletions

View File

@@ -28,32 +28,33 @@ void ProcessorFactory::register_processor(ProcessorType type, Creator creator) {
// Create a processor instance
std::unique_ptr<Processor> ProcessorFactory::create_processor(
const ProcessorConfig *processor_config,
const ProcessorConfig &proc_cfg,
uint32_t vk_device_index
) const {
auto it = creators.find(processor_config->processor_type);
auto it = creators.find(proc_cfg.processor_type);
if (it == creators.end()) {
spdlog::critical(
"Processor type not registered: {}", static_cast<int>(processor_config->processor_type)
"Processor type not registered: {}", static_cast<int>(proc_cfg.processor_type)
);
return nullptr;
}
// Call the corresponding creator function
return it->second(processor_config, vk_device_index);
return it->second(proc_cfg, vk_device_index);
}
// Initialize default processors
void ProcessorFactory::init_default_processors(ProcessorFactory &factory) {
factory.register_processor(
PROCESSOR_LIBPLACEBO,
[](const ProcessorConfig *config, uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &cfg = config->config.libplacebo;
if (!cfg.shader_path) {
ProcessorType::Libplacebo,
[](const ProcessorConfig &proc_cfg,
uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &config = std::get<LibplaceboConfig>(proc_cfg.config);
if (config.shader_path.empty()) {
spdlog::critical("Shader path must be provided for the libplacebo filter");
return nullptr;
}
if (config->width <= 0 || config->height <= 0) {
if (proc_cfg.width <= 0 || proc_cfg.height <= 0) {
spdlog::critical(
"Output width and height must be provided for the libplacebo filter"
);
@@ -61,39 +62,41 @@ void ProcessorFactory::init_default_processors(ProcessorFactory &factory) {
}
return std::make_unique<FilterLibplacebo>(
vk_device_index,
std::filesystem::path(cfg.shader_path),
config->width,
config->height
std::filesystem::path(config.shader_path),
proc_cfg.width,
proc_cfg.height
);
}
);
factory.register_processor(
PROCESSOR_REALESRGAN,
[](const ProcessorConfig *config, uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &cfg = config->config.realesrgan;
if (config->scaling_factor <= 0) {
ProcessorType::RealESRGAN,
[](const ProcessorConfig &proc_cfg,
uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &config = std::get<RealESRGANConfig>(proc_cfg.config);
if (proc_cfg.scaling_factor <= 0) {
spdlog::critical("Scaling factor must be provided for the RealESRGAN filter");
return nullptr;
}
if (!cfg.model_name) {
if (config.model_name.empty()) {
spdlog::critical("Model name must be provided for the RealESRGAN filter");
return nullptr;
}
return std::make_unique<FilterRealesrgan>(
static_cast<int>(vk_device_index),
cfg.tta_mode,
config->scaling_factor,
cfg.model_name
config.tta_mode,
proc_cfg.scaling_factor,
config.model_name
);
}
);
factory.register_processor(
PROCESSOR_RIFE,
[](const ProcessorConfig *config, uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &cfg = config->config.rife;
if (!cfg.model_name) {
ProcessorType::RIFE,
[](const ProcessorConfig &proc_cfg,
uint32_t vk_device_index) -> std::unique_ptr<Processor> {
const auto &cfg = std::get<RIFEConfig>(proc_cfg.config);
if (cfg.model_name.empty()) {
spdlog::critical("Model name must be provided for the RIFE filter");
return nullptr;
}