Files
crossdesk/src/media/video/decode/video_decoder_factory.cpp
2023-10-07 10:07:45 +08:00

50 lines
1.2 KiB
C++

#include "video_decoder_factory.h"
#if __APPLE__
#include "ffmpeg/ffmpeg_video_decoder.h"
#else
#include "ffmpeg/ffmpeg_video_decoder.h"
#include "nvcodec/nvidia_video_decoder.h"
#endif
#include "log.h"
VideoDecoderFactory::VideoDecoderFactory() {}
VideoDecoderFactory::~VideoDecoderFactory() {}
std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
bool hardware_acceleration) {
#if __APPLE__
return std::make_unique<FfmpegVideoDecoder>(FfmpegVideoDecoder());
#else
if (hardware_acceleration) {
if (CheckIsHardwareAccerlerationSupported()) {
return std::make_unique<NvidiaVideoDecoder>(NvidiaVideoDecoder());
} else {
return nullptr;
}
} else {
return std::make_unique<FfmpegVideoDecoder>(FfmpegVideoDecoder());
}
#endif
}
bool VideoDecoderFactory::CheckIsHardwareAccerlerationSupported() {
#if __APPLE__
return false;
#else
CUresult cuResult;
CUvideoctxlock cudaCtxLock;
cuResult = cuvidCtxLockCreate(&cudaCtxLock, 0);
if (cuResult != CUDA_SUCCESS) {
LOG_WARN(
"System not support hardware accelerated decode, use default software "
"decoder");
return false;
}
return true;
#endif
}