mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 12:45:35 +08:00
Add hardware accerleration valiation
This commit is contained in:
@@ -10,8 +10,29 @@ VideoEncoderFactory::~VideoEncoderFactory() {}
|
||||
std::unique_ptr<VideoEncoder> VideoEncoderFactory::CreateVideoEncoder(
|
||||
bool hardware_acceleration) {
|
||||
if (hardware_acceleration) {
|
||||
return std::make_unique<NvidiaVideoEncoder>(NvidiaVideoEncoder());
|
||||
if (CheckIsHardwareAccerlerationSupported()) {
|
||||
return std::make_unique<NvidiaVideoEncoder>(NvidiaVideoEncoder());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return std::make_unique<FFmpegVideoEncoder>(FFmpegVideoEncoder());
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoEncoderFactory::CheckIsHardwareAccerlerationSupported() {
|
||||
CUresult cuResult;
|
||||
NV_ENCODE_API_FUNCTION_LIST functionList = {NV_ENCODE_API_FUNCTION_LIST_VER};
|
||||
|
||||
cuResult = cuInit(0);
|
||||
if (cuResult != CUDA_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
NVENCSTATUS nvEncStatus = NvEncodeAPICreateInstance(&functionList);
|
||||
if (nvEncStatus != NV_ENC_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ class VideoEncoderFactory {
|
||||
|
||||
static std::unique_ptr<VideoEncoder> CreateVideoEncoder(
|
||||
bool hardware_acceleration);
|
||||
|
||||
static bool CheckIsHardwareAccerlerationSupported();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user