[FFmpeg-cvslog] avcodec/nvenc: check maximum driver API version

Timo Rothenpieler git at videolan.org
Sun Aug 28 20:58:30 EEST 2016


ffmpeg | branch: master | Timo Rothenpieler <timo at rothenpieler.org> | Sun Aug 28 19:46:44 2016 +0200| [df615efcf275d87ec6e19be1c1b2f16e9b5d4e72] | committer: Timo Rothenpieler

avcodec/nvenc: check maximum driver API version

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=df615efcf275d87ec6e19be1c1b2f16e9b5d4e72
---

 libavcodec/nvenc.c | 18 ++++++++++++++++++
 libavcodec/nvenc.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c
index 8994af1..553f223 100644
--- a/libavcodec/nvenc.c
+++ b/libavcodec/nvenc.c
@@ -155,8 +155,10 @@ static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
 {
     NvencContext *ctx = avctx->priv_data;
     NvencDynLoadFunctions *dl_fn = &ctx->nvenc_dload_funcs;
+    PNVENCODEAPIGETMAXSUPPORTEDVERSION nvenc_get_max_ver;
     PNVENCODEAPICREATEINSTANCE nvenc_create_instance;
     NVENCSTATUS err;
+    uint32_t nvenc_max_ver;
 
 #if CONFIG_CUDA
     dl_fn->cu_init                      = cuInit;
@@ -183,9 +185,25 @@ static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
 
     LOAD_LIBRARY(dl_fn->nvenc, NVENC_LIBNAME);
 
+    LOAD_SYMBOL(nvenc_get_max_ver, dl_fn->nvenc,
+                "NvEncodeAPIGetMaxSupportedVersion");
     LOAD_SYMBOL(nvenc_create_instance, dl_fn->nvenc,
                 "NvEncodeAPICreateInstance");
 
+    err = nvenc_get_max_ver(&nvenc_max_ver);
+    if (err != NV_ENC_SUCCESS)
+        return nvenc_print_error(avctx, err, "Failed to query nvenc max version");
+
+    av_log(avctx, AV_LOG_VERBOSE, "Loaded Nvenc version %d.%d\n", nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
+
+    if ((NVENCAPI_MAJOR_VERSION << 4 | NVENCAPI_MINOR_VERSION) > nvenc_max_ver) {
+        av_log(avctx, AV_LOG_ERROR, "Driver does not support the required nvenc API version. "
+               "Required: %d.%d Found: %d.%d\n",
+               NVENCAPI_MAJOR_VERSION, NVENCAPI_MINOR_VERSION,
+               nvenc_max_ver >> 4, nvenc_max_ver & 0xf);
+        return AVERROR(ENOSYS);
+    }
+
     dl_fn->nvenc_funcs.version = NV_ENCODE_API_FUNCTION_LIST_VER;
 
     err = nvenc_create_instance(&dl_fn->nvenc_funcs);
diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h
index cd86c47..c57f1ae 100644
--- a/libavcodec/nvenc.h
+++ b/libavcodec/nvenc.h
@@ -72,6 +72,7 @@ typedef CUresult(CUDAAPI *PCUCTXCREATE)(CUcontext *pctx, unsigned int flags, CUd
 typedef CUresult(CUDAAPI *PCUCTXPOPCURRENT)(CUcontext *pctx);
 typedef CUresult(CUDAAPI *PCUCTXDESTROY)(CUcontext ctx);
 
+typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPIGETMAXSUPPORTEDVERSION)(uint32_t* version);
 typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTION_LIST *functionList);
 
 typedef struct NvencDynLoadFunctions



More information about the ffmpeg-cvslog mailing list