Add hardware accerleration valiation

This commit is contained in:
dijunkun
2023-09-21 11:26:08 +08:00
parent b4318cc8d6
commit 156172accb
7 changed files with 90 additions and 14 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -9,6 +9,8 @@ class VideoDecoderFactory {
static std::unique_ptr<VideoDecoder> CreateVideoDecoder(
bool hardware_acceleration);
static bool CheckIsHardwareAccerlerationSupported();
};
#endif