mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-27 04:35:34 +08:00
Add hardware accerleration valiation
This commit is contained in:
@@ -727,7 +727,10 @@ int NvDecoder::Decode(const uint8_t *pData, int nSize, int nFlags,
|
||||
if (!pData || nSize == 0) {
|
||||
packet.flags |= CUVID_PKT_ENDOFSTREAM;
|
||||
}
|
||||
NVDEC_API_CALL(cuvidParseVideoData(m_hParser, &packet));
|
||||
// NVDEC_API_CALL(cuvidParseVideoData(m_hParser, &packet));
|
||||
if (CUDA_SUCCESS != cuvidParseVideoData(m_hParser, &packet)) {
|
||||
return 0;
|
||||
}
|
||||
m_cuvidStream = 0;
|
||||
|
||||
return m_nDecodedFrame;
|
||||
|
||||
@@ -10,8 +10,24 @@ VideoDecoderFactory::~VideoDecoderFactory() {}
|
||||
std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
|
||||
bool hardware_acceleration) {
|
||||
if (hardware_acceleration) {
|
||||
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
|
||||
if (CheckIsHardwareAccerlerationSupported()) {
|
||||
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
return std::make_unique<FfmpegVideoDecoder>(FfmpegVideoDecoder());
|
||||
}
|
||||
}
|
||||
|
||||
bool VideoDecoderFactory::CheckIsHardwareAccerlerationSupported() {
|
||||
CUresult cuResult;
|
||||
|
||||
CUvideoctxlock cudaCtxLock;
|
||||
cuResult = cuvidCtxLockCreate(&cudaCtxLock, 0);
|
||||
if (cuResult != CUDA_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -9,6 +9,8 @@ class VideoDecoderFactory {
|
||||
|
||||
static std::unique_ptr<VideoDecoder> CreateVideoDecoder(
|
||||
bool hardware_acceleration);
|
||||
|
||||
static bool CheckIsHardwareAccerlerationSupported();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -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