mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 17:11:52 +08:00
refactor(hwcodec): 简化 hwcodec 库以适配 IP-KVM 场景
移除 IP-KVM 场景不需要的功能模块: - 移除 VRAM 模块 (GPU 显存直接编解码) - 移除 Mux 模块 (视频混流) - 移除 macOS/Android 平台支持 - 移除外部 SDK 依赖 (~9MB) - 移除开发工具和示例程序 简化解码器为仅支持 MJPEG (采集卡输出格式) 简化 NVIDIA 检测代码 (使用 dlopen 替代 SDK) 更新版本号至 0.8.0 更新相关技术文档
This commit is contained in:
@@ -2,83 +2,50 @@
|
||||
#include "../../log.h"
|
||||
#include <cstring>
|
||||
#include <dlfcn.h>
|
||||
#include <dynlink_cuda.h>
|
||||
#include <dynlink_loader.h>
|
||||
#include <errno.h>
|
||||
#include <exception> // Include the necessary header file
|
||||
#include <signal.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
void load_driver(CudaFunctions **pp_cuda_dl, NvencFunctions **pp_nvenc_dl,
|
||||
CuvidFunctions **pp_cvdl)
|
||||
{
|
||||
if (cuda_load_functions(pp_cuda_dl, NULL) < 0)
|
||||
{
|
||||
LOG_TRACE(std::string("cuda_load_functions failed"));
|
||||
throw "cuda_load_functions failed";
|
||||
}
|
||||
if (nvenc_load_functions(pp_nvenc_dl, NULL) < 0)
|
||||
{
|
||||
LOG_TRACE(std::string("nvenc_load_functions failed"));
|
||||
throw "nvenc_load_functions failed";
|
||||
}
|
||||
if (cuvid_load_functions(pp_cvdl, NULL) < 0)
|
||||
{
|
||||
LOG_TRACE(std::string("cuvid_load_functions failed"));
|
||||
throw "cuvid_load_functions failed";
|
||||
}
|
||||
}
|
||||
|
||||
void free_driver(CudaFunctions **pp_cuda_dl, NvencFunctions **pp_nvenc_dl,
|
||||
CuvidFunctions **pp_cvdl)
|
||||
{
|
||||
if (*pp_cvdl)
|
||||
{
|
||||
cuvid_free_functions(pp_cvdl);
|
||||
*pp_cvdl = NULL;
|
||||
}
|
||||
if (*pp_nvenc_dl)
|
||||
{
|
||||
nvenc_free_functions(pp_nvenc_dl);
|
||||
*pp_nvenc_dl = NULL;
|
||||
}
|
||||
if (*pp_cuda_dl)
|
||||
{
|
||||
cuda_free_functions(pp_cuda_dl);
|
||||
*pp_cuda_dl = NULL;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Check for NVIDIA driver support by loading CUDA libraries
|
||||
int linux_support_nv()
|
||||
{
|
||||
try
|
||||
// Try to load NVIDIA CUDA runtime library
|
||||
void *handle = dlopen("libcuda.so.1", RTLD_LAZY);
|
||||
if (!handle)
|
||||
{
|
||||
CudaFunctions *cuda_dl = NULL;
|
||||
NvencFunctions *nvenc_dl = NULL;
|
||||
CuvidFunctions *cvdl = NULL;
|
||||
load_driver(&cuda_dl, &nvenc_dl, &cvdl);
|
||||
free_driver(&cuda_dl, &nvenc_dl, &cvdl);
|
||||
return 0;
|
||||
handle = dlopen("libcuda.so", RTLD_LAZY);
|
||||
}
|
||||
catch (...)
|
||||
if (!handle)
|
||||
{
|
||||
LOG_TRACE(std::string("nvidia driver not support"));
|
||||
LOG_TRACE(std::string("NVIDIA: libcuda.so not found"));
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
dlclose(handle);
|
||||
|
||||
// Also check for nvenc library
|
||||
handle = dlopen("libnvidia-encode.so.1", RTLD_LAZY);
|
||||
if (!handle)
|
||||
{
|
||||
handle = dlopen("libnvidia-encode.so", RTLD_LAZY);
|
||||
}
|
||||
if (!handle)
|
||||
{
|
||||
LOG_TRACE(std::string("NVIDIA: libnvidia-encode.so not found"));
|
||||
return -1;
|
||||
}
|
||||
dlclose(handle);
|
||||
|
||||
LOG_TRACE(std::string("NVIDIA: driver support detected"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int linux_support_amd()
|
||||
{
|
||||
#if defined(__x86_64__) || defined(__aarch64__)
|
||||
#define AMF_DLL_NAME L"libamfrt64.so.1"
|
||||
#define AMF_DLL_NAMEA "libamfrt64.so.1"
|
||||
#else
|
||||
#define AMF_DLL_NAME L"libamfrt32.so.1"
|
||||
#define AMF_DLL_NAMEA "libamfrt32.so.1"
|
||||
#endif
|
||||
void *handle = dlopen(AMF_DLL_NAMEA, RTLD_LAZY);
|
||||
@@ -160,4 +127,4 @@ int linux_support_v4l2m2m() {
|
||||
|
||||
LOG_TRACE(std::string("V4L2 M2M: No M2M device found"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user