cuda: fix crash if no cuda loaded.

This commit is contained in:
wang-bin
2014-04-03 01:48:14 +08:00
parent c406ac5e97
commit 075a7ced7f
3 changed files with 28 additions and 1 deletions
+6
View File
@@ -130,6 +130,8 @@ public:
nb_dec_surface = 20;
if (!can_load)
return;
if (!isLoaded()) //cuda_api
return;
bitstream_filter_ctx = av_bitstream_filter_init("h264_mp4toannexb");
Q_ASSERT_X(bitstream_filter_ctx, "av_bitstream_filter_init", "Unknown bitstream filter");
initCuda();
@@ -137,6 +139,8 @@ public:
~VideoDecoderCUDAPrivate() {
if (!can_load)
return;
if (!isLoaded()) //cuda_api
return;
av_bitstream_filter_close(bitstream_filter_ctx);
releaseCuda();
}
@@ -267,6 +271,8 @@ bool VideoDecoderCUDA::prepare()
qWarning("VideoDecoderCUDA::prepare(): CUVID library not available");
return false;
}
if (!d.isLoaded()) //cuda_api
return false;
// max decoder surfaces is computed in createCUVIDDecoder. createCUVIDParser use the value
return d.createCUVIDDecoder(mapCodecFromFFmpeg(d.codec_ctx->codec_id), d.codec_ctx->coded_width, d.codec_ctx->coded_height)
&& d.createCUVIDParser();
+21 -1
View File
@@ -6,8 +6,10 @@
class cuda_api::context {
public:
context()
: loaded(true) {
#if !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
context() {
loaded = false;
cuda_dll.setFileName("cuda");
if (!cuda_dll.isLoaded())
cuda_dll.load();
@@ -15,10 +17,22 @@ public:
cuda_dll.setFileName("nvcuda");
cuda_dll.load();
}
if (!cuda_dll.isLoaded()) {
qWarning("can not load cuda!");
return;
}
cuvid_dll.setFileName("nvcuvid");
cuvid_dll.load();
if (!cuvid_dll.isLoaded()) {
qWarning("can not load nvcuvid!");
return;
}
loaded = true;
#endif // !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
}
#if !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
~context() {
loaded = false;
cuvid_dll.unload();
cuda_dll.unload();
}
@@ -26,6 +40,7 @@ public:
QLibrary cuda_dll;
QLibrary cuvid_dll;
#endif // !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
bool loaded;
};
cuda_api::cuda_api()
@@ -38,6 +53,11 @@ cuda_api::~cuda_api()
delete ctx;
}
bool cuda_api::isLoaded() const
{
return ctx->loaded;
}
#if !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
////////////////////////////////////////////////////
/// CUDA functions
+1
View File
@@ -28,6 +28,7 @@ class cuda_api {
public:
cuda_api();
~cuda_api();
bool isLoaded() const;
#if !NV_CONFIG(DLLAPI_CUDA) && !defined(CUDA_LINK)
////////////////////////////////////////////////////
/// CUDA functions