Commit 57f8571a authored by Seungha Yang's avatar Seungha Yang 🐑
Browse files

nvcodec: Explicitly disable linking CUDA libraries

Since we moved to dynamic CUDA library loading, only CUDA header files
are required for build. Additionally, this can make it easy to detect
direct use of CUDA API without our vfunc table, because it results to
build error.
parent ff2c257c
......@@ -932,10 +932,9 @@ AG_GST_CHECK_FEATURE(CUDA, [NVIDIA CUDA API],, [
HAVE_CUDA="yes"
if test "x$CUDA_PREFIX" != "x"; then
dnl only override if not already set
if test "x$CUDA_CFLAGS" = "x" -a "x$CUDA_LIBS" = "x"; then
if test "x$CUDA_CFLAGS" = "x"; then
dnl this is an educated guess, user can always override these
CUDA_CFLAGS="-I$CUDA_PREFIX/include"
CUDA_LIBS="-L$CUDA_PREFIX/lib -L$CUDA_PREFIX/lib64 -L$CUDA_PREFIX/lib/stubs -L$CUDA_PREFIX/lib64/stubs -lcuda -lcudart"
fi
else
PKG_CHECK_MODULES([CUDA], [cuda-10.1 cudart-10.1],, [
......@@ -951,42 +950,17 @@ AG_GST_CHECK_FEATURE(CUDA, [NVIDIA CUDA API],, [
fi
HAVE_CUDA_H=no
HAVE_CUDART_H=no
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CUDA_CFLAGS $save_CPPFLAGS "
AC_CHECK_HEADER([cuda.h], [HAVE_CUDA_H=yes],
AC_MSG_WARN([Could not find cuda.h]))
AC_CHECK_HEADER([cuda_runtime_api.h], [HAVE_CUDART_H=yes],
AC_MSG_WARN([Could not find cuda_runtime_api.h]))
CPPFLAGS=$save_CPPFLAGS
dnl libcuda and libcudart libraries
save_LIBS="$LIBS"
LIBS="$CUDA_LIBS $save_LIBS"
HAVE_CUDART_LIB="no"
AC_CHECK_LIB(cudart,cudaGetErrorString,[HAVE_CUDART_LIB="yes"], [
AC_MSG_WARN([Could not find cudart library])])
HAVE_CUDA_LIB="no"
AC_CHECK_LIB(cuda,cuInit,[HAVE_CUDA_LIB="yes"], [
AC_MSG_WARN([Could not find cuda library])])
LIBS="$save_LIBS"
])
dnl *** NVDEC ***
translit(dnm, m, l) AM_CONDITIONAL(USE_NVDEC, true)
AG_GST_CHECK_FEATURE(NVDEC, [nvdec], nvdec, [
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CUDA_CFLAGS $save_CPPFLAGS"
CPPFLAGS=$save_CPPFLAGS
HAVE_NVCUVID=no
save_LIBS="$LIBS"
LIBS="$CUDA_LIBS $save_LIBS"
AC_CHECK_LIB(nvcuvid, cuvidCtxLock, [HAVE_NVCUVID=yes],
AC_MSG_WARN([Could not find library nvcuvid]))
LIBS="$save_LIBS"
if test "x$HAVE_NVCUVID" = "xyes"; then
if test "x$HAVE_CUDA_H" = "xyes"; then
HAVE_NVDEC=yes
AC_DEFINE(HAVE_NVDEC, [1] , [Define NVDEC available])
else
......@@ -997,24 +971,9 @@ AG_GST_CHECK_FEATURE(NVDEC, [nvdec], nvdec, [
dnl *** NVENC ***
translit(dnm, m, l) AM_CONDITIONAL(USE_NVENC, true)
AG_GST_CHECK_FEATURE(NVENC, [NVIDIA Encode API], nvenc, [
dnl libnvnidia-encode library
HAVE_NVENCODE_LIB=no
AC_ARG_VAR(NVENCODE_LIBS, [linker flags for nvidia-encode])
saved_LIBS="$LIBS"
LIBS="$NVENCODE_LIBS $saved_LIBS"
AC_CHECK_LIB(nvidia-encode, NvEncodeAPICreateInstance, [HAVE_NVENCODE_LIB="yes"],
AC_MSG_WARN([Could not find library nvidia-encode]))
NVENCODE_LIBS="$NVENCODE_LIBS -lnvidia-encode"
AC_SUBST(NVENCODE_LIBS)
LIBS="$saved_LIBS"
USE_NVENC_GST_GL=no
if test "x$HAVE_CUDA_H" = "xyes" \
-a "x$HAVE_CUDART_H" = "xyes" \
-a "x$HAVE_CUDA_LIB" = "xyes" \
-a "x$HAVE_CUDART_LIB" = "xyes" \
-a "x$HAVE_NVENCODE_LIB" = "xyes"; then
HAVE_NVENC="yes"
if test "x$HAVE_CUDA_H" = "xyes"; then
HAVE_NVENC=yes
if test "x$GST_GL_HAVE_API_GL" = "x1"; then
dnl cuda-gl interop header
save_CPPFLAGS="$CPPFLAGS"
......@@ -1027,7 +986,7 @@ AG_GST_CHECK_FEATURE(NVENC, [NVIDIA Encode API], nvenc, [
fi
AC_DEFINE(HAVE_NVENC, [1] , [Define NVENC available])
else
HAVE_NVENC="no"
HAVE_NVENC=no
fi
])
AM_CONDITIONAL(USE_NVENC_GST_GL, test "x$USE_NVENC_GST_GL" = "xyes")
......
......@@ -40,9 +40,7 @@ libgstnvcodec_la_LIBADD = \
$(GST_PBUTILS_LIBS) \
$(GST_VIDEO_LIBS) \
$(GST_LIBS) \
$(GMODULE_NO_EXPORT_LIBS) \
$(CUDA_LIBS) \
-lnvcuvid
$(GMODULE_NO_EXPORT_LIBS)
libgstnvcodec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
......
......@@ -19,9 +19,7 @@ nvdec_option = get_option('nvdec')
nvenc_option = get_option('nvenc')
cuda_dep = dependency('', required : false)
cudart_dep = dependency('', required : false)
nvcuvid_dep = dependency('', required : false)
cuda_libdir = ''
cuda_header_dep = dependency('', required : false)
cuda_incdir = ''
use_nvenc_gl = false
extra_c_args = []
......@@ -35,31 +33,9 @@ if host_machine.system() == 'windows'
# On windows, CUDA_PATH env will be set by installer
cuda_root = run_command(python3, '-c', 'import os; print(os.environ.get("CUDA_PATH"))').stdout().strip()
if cuda_root != '' and cuda_root != 'None'
arc = ''
if build_machine.cpu_family() == 'x86_64'
arc = 'x64'
else
arc = 'Win32'
endif
cuda_libdir = join_paths (cuda_root, 'lib', arc)
cuda_incdir = join_paths (cuda_root, 'include')
cuda_lib = cc.find_library('cuda', dirs: cuda_libdir, required: false)
cudart_lib = cc.find_library('cudart', dirs: cuda_libdir, required: false)
if cuda_lib.found()
cuda_header_found = cc.has_header('cuda.h', args: '-I' + cuda_incdir)
cuda_lib_found = cc.has_function('cuInit', dependencies: cuda_lib)
if cuda_header_found and cuda_lib_found
cuda_dep = declare_dependency(include_directories: include_directories(cuda_incdir),
dependencies: cuda_lib)
endif
endif
if cudart_lib.found()
cudart_header_found = cc.has_header('cuda_runtime_api.h', args: '-I' + cuda_incdir)
cudart_lib_found = cc.has_function('cudaGetErrorString', dependencies: cudart_lib)
if cudart_header_found and cudart_lib_found
cudart_dep = declare_dependency(dependencies: cudart_lib)
endif
if cc.has_header('cuda.h', args: '-I' + cuda_incdir)
cuda_header_dep = declare_dependency(include_directories: include_directories(cuda_incdir))
endif
endif
else
......@@ -80,33 +56,20 @@ else
foreach v : cuda_versions
if cuda_ver == ''
cuda_dep = dependency('cuda-' + v, required: false)
cudart_dep = dependency('cudart-' + v, required: false)
if cuda_dep.found() and cudart_dep.found()
if cuda_dep.found()
cuda_ver = v
endif
endif
endforeach
if cuda_dep.found()
cuda_header_found = cc.has_header('cuda.h', dependencies: cuda_dep)
cuda_lib_found = cc.has_function('cuInit', dependencies: cuda_dep)
if not cuda_header_found or not cuda_lib_found
message ('Missing required header and/or function in cuda dependency')
cuda_dep = dependency('', required : false)
endif
endif
if cudart_dep.found()
cudart_header_found = cc.has_header('cuda_runtime_api.h', dependencies: cudart_dep)
cudart_lib_found = cc.has_function('cudaGetErrorString', dependencies: cudart_dep)
if not cudart_header_found or not cudart_lib_found
message ('Missing required header and/or function in cudart dependency')
cudart_dep = dependency('', required : false)
if cc.has_header('cuda.h', dependencies: cuda_dep)
cuda_header_dep = cuda_dep.partial_dependency(compile_args : true, includes : true)
endif
endif
endif
if not cuda_dep.found() or not cudart_dep.found()
if not cuda_header_dep.found()
if nvdec_option.enabled()
error('The nvdec plugin was enabled explicitly, but required CUDA library was not found.')
endif
......@@ -120,33 +83,8 @@ endif
# NVDEC dependency
if not nvdec_option.disabled()
nvcuvid_incdirs = []
if host_machine.system() == 'windows'
cuda_libdirs = [cuda_libdir]
# NOTE: Newer CUDA toolkit versions do not ship with the nvcuvid library, and
# you must get it from the Nvidia Video Codec SDK. The SDK ships as a zip
# file, so there's no installer and you have to set this env var yourself.
video_sdk_root = run_command(python3, '-c', 'import os; print(os.environ.get("NVIDIA_VIDEO_CODEC_SDK_PATH"))').stdout().strip()
if video_sdk_root != '' and video_sdk_root != 'None'
cuda_libdirs += [join_paths(video_sdk_root, 'Samples', 'NvCodec', 'Lib', arc)]
nvcuvid_incdirs = include_directories(join_paths(video_sdk_root, 'Samples', 'NvCodec', 'NvDecoder'))
endif
nvcuvid_lib = cc.find_library('nvcuvid', dirs: cuda_libdirs, required: nvdec_option)
else
nvcuvid_lib = cc.find_library('nvcuvid', required: nvdec_option)
endif
if nvcuvid_lib.found() and cc.has_function('cuvidCtxLock', dependencies: nvcuvid_lib)
nvcuvid_dep = declare_dependency(dependencies: nvcuvid_lib,
include_directories: nvcuvid_incdirs)
extra_c_args += ['-DHAVE_NVDEC=1']
nvcodec_sources += nvdec_sources
endif
if nvdec_option.enabled() and not nvcuvid_dep.found()
error('The nvdec plugin was enabled explicitly, but required nvcuvid library was not found.')
endif
extra_c_args += ['-DHAVE_NVDEC=1']
nvcodec_sources += nvdec_sources
endif
# NVENC dependency
......@@ -173,7 +111,7 @@ gstnvcodec = library('gstnvcodec',
nvcodec_sources,
c_args : gst_plugins_bad_args + extra_c_args,
include_directories : [configinc],
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, cuda_dep, cudart_dep, nvcuvid_dep, gmodule_dep],
dependencies : [gstbase_dep, gstvideo_dep, gstpbutils_dep, gstgl_dep, cuda_header_dep, gmodule_dep],
install : true,
install_dir : plugins_install_dir,
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment