Commit 6f257716 authored by Seungha Yang's avatar Seungha Yang 🐑
Browse files

Move nvdec and nvenc to nvcodec

The is prework for CUDA library dynamic loading and also
for better nvenc/nvdec interoperability via CUDA APIs
parent aaee2820
......@@ -988,6 +988,7 @@ AG_GST_CHECK_FEATURE(NVDEC, [nvdec], nvdec, [
if test "x$HAVE_NVCUVID" = "xyes"; then
HAVE_NVDEC=yes
AC_DEFINE(HAVE_NVDEC, [1] , [Define NVDEC available])
else
HAVE_NVDEC=no
fi
......@@ -1024,6 +1025,7 @@ AG_GST_CHECK_FEATURE(NVENC, [NVIDIA Encode API], nvenc, [
])
CPPFLAGS="$save_CPPFLAGS"
fi
AC_DEFINE(HAVE_NVENC, [1] , [Define NVENC available])
else
HAVE_NVENC="no"
fi
......@@ -2600,8 +2602,7 @@ sys/fbdev/Makefile
sys/ipcpipeline/Makefile
sys/kms/Makefile
sys/msdk/Makefile
sys/nvdec/Makefile
sys/nvenc/Makefile
sys/nvcodec/Makefile
sys/opensles/Makefile
sys/shm/Makefile
sys/tinyalsa/Makefile
......
......@@ -101,15 +101,13 @@ UVCH264_DIR=
endif
if USE_NVDEC
NVDEC_DIR=nvdec
NVCODEC_DIR=nvcodec
else
NVDEC_DIR=
endif
if USE_NVENC
NVENC_DIR=nvenc
NVCODEC_DIR=nvcodec
else
NVENC_DIR=
NVCODEC_DIR=
endif
endif
if USE_TINYALSA
......@@ -124,10 +122,10 @@ else
MSDK_DIR=
endif
SUBDIRS = $(ANDROID_MEDIA_DIR) $(APPLE_MEDIA_DIR) $(BLUEZ_DIR) $(D3DVIDEOSINK_DIR) $(DECKLINK_DIR) $(DIRECTSOUND_DIR) $(WINKS_DIR) $(DVB_DIR) $(FBDEV_DIR) $(IPCPIPELINE_DIR) $(KMS_DIR) $(OPENSLES_DIR) $(SHM_DIR) $(UVCH264_DIR) $(VDPAU_DIR) $(WININET_DIR) $(WINSCREENCAP_DIR) $(WASAPI_DIR) $(NVDEC_DIR) $(NVENC_DIR) $(TINYALSA_DIR) $(MSDK_DIR)
SUBDIRS = $(ANDROID_MEDIA_DIR) $(APPLE_MEDIA_DIR) $(BLUEZ_DIR) $(D3DVIDEOSINK_DIR) $(DECKLINK_DIR) $(DIRECTSOUND_DIR) $(WINKS_DIR) $(DVB_DIR) $(FBDEV_DIR) $(IPCPIPELINE_DIR) $(KMS_DIR) $(OPENSLES_DIR) $(SHM_DIR) $(UVCH264_DIR) $(VDPAU_DIR) $(WININET_DIR) $(WINSCREENCAP_DIR) $(WASAPI_DIR) $(NVCODEC_DIR) $(TINYALSA_DIR) $(MSDK_DIR)
DIST_SUBDIRS = androidmedia applemedia bluez d3dvideosink decklink directsound dvb fbdev ipcpipeline kms dshowdecwrapper dshowsrcwrapper dshowvideosink \
opensles shm uvch264 vdpau wasapi winks winscreencap \
nvdec nvenc tinyalsa msdk
nvcodec tinyalsa msdk
include $(top_srcdir)/common/parallel-subdirs.mak
......@@ -12,6 +12,7 @@ subdir('fbdev')
subdir('ipcpipeline')
subdir('kms')
subdir('msdk')
subdir('nvcodec')
subdir('opensles')
subdir('shm')
subdir('tinyalsa')
......@@ -20,93 +21,3 @@ subdir('vdpau')
subdir('wasapi')
subdir('winks')
subdir('winscreencap')
# CUDA dependency
cuda_dep = dependency('', required : false)
cudart_dep = dependency('', required : false)
cuda_libdir = ''
cuda_incdir = ''
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
endif
endif
else
cuda_versions = [
'10.1',
'10.0',
'9.2',
'9.1',
'9.0',
'8.0',
'7.5',
'7.0',
'6.5',
]
cuda_ver = ''
# FIXME: use break syntax when we use meson >= '0.49'
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()
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)
endif
endif
endif
if cuda_dep.found() and cudart_dep.found()
subdir('nvdec')
subdir('nvenc')
elif get_option('nvdec').enabled()
error('The nvdec plugin was enabled explicitly, but required CUDA dependencies were not found.')
elif get_option('nvenc').enabled()
error('The nvenc plugin was enabled explicitly, but required CUDA dependencies were not found.')
endif
plugin_LTLIBRARIES = libgstnvenc.la
plugin_LTLIBRARIES = libgstnvcodec.la
libgstnvenc_la_SOURCES = \
libgstnvcodec_la_SOURCES = \
plugin.c
if USE_NVDEC
libgstnvcodec_la_SOURCES += \
gstnvdec.c
endif
if USE_NVENC
libgstnvcodec_la_SOURCES += \
gstnvenc.c \
gstnvbaseenc.c \
gstnvh264enc.c \
gstnvh265enc.c
endif
noinst_HEADERS = \
gstnvdec.h \
gstnvenc.h \
gstnvbaseenc.h \
gstnvh264enc.h \
gstnvh265enc.h
libgstnvenc_la_CFLAGS = \
libgstnvcodec_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
$(GST_GL_CFLAGS) \
$(GST_PBUTILS_CFLAGS) \
$(GST_VIDEO_CFLAGS) \
$(GST_CFLAGS) \
$(CUDA_CFLAGS)
libgstnvenc_la_LIBADD = \
libgstnvcodec_la_LIBADD = \
$(GST_GL_LIBS) \
$(GST_PBUTILS_LIBS) \
$(GST_VIDEO_LIBS) \
$(GST_LIBS) \
$(GMODULE_NO_EXPORT_LIBS) \
$(CUDA_LIBS) \
$(GMODULE_NO_EXPORT_LIBS)
-lnvcuvid
if USE_NVENC_GST_GL
libgstnvenc_la_CFLAGS += $(GST_GL_CFLAGS)
libgstnvenc_la_LIBADD += $(GST_GL_LIBS)
endif
libgstnvenc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstnvcodec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
EXTRA_DIST = \
nvEncodeAPI.h
......@@ -362,8 +362,8 @@ load_nvenc_library (void)
return TRUE;
}
static gboolean
plugin_init (GstPlugin * plugin)
gboolean
gst_nvenc_plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_nvenc_debug, "nvenc", 0, "Nvidia NVENC encoder");
......@@ -384,9 +384,3 @@ plugin_init (GstPlugin * plugin)
return TRUE;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
nvenc,
"GStreamer NVENC plugin",
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
......@@ -36,4 +36,6 @@ gboolean gst_nvenc_cmp_guid (GUID g1, GUID g2);
NV_ENC_BUFFER_FORMAT gst_nvenc_get_nv_buffer_format (GstVideoFormat fmt);
gboolean gst_nvenc_plugin_init (GstPlugin * plugin);
#endif /* __GST_NVENC_H_INCLUDED__ */
nvdec_sources = [
'gstnvdec.c',
]
nvenc_sources = [
'gstnvbaseenc.c',
'gstnvenc.c',
'gstnvh264enc.c',
'gstnvh265enc.c',
]
nvcodec_sources = [
'plugin.c',
]
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_incdir = ''
use_nvenc_gl = false
extra_c_args = []
if nvdec_option.disabled() and nvenc_option.disabled()
subdir_done()
endif
# CUDA dependency
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
endif
endif
else
cuda_versions = [
'10.1',
'10.0',
'9.2',
'9.1',
'9.0',
'8.0',
'7.5',
'7.0',
'6.5',
]
cuda_ver = ''
# FIXME: use break syntax when we use meson >= '0.49'
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()
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)
endif
endif
endif
if not cuda_dep.found() or not cudart_dep.found()
if nvdec_option.enabled()
error('The nvdec plugin was enabled explicitly, but required CUDA library was not found.')
endif
if nvenc_option.enabled()
error('The nvenc plugin was enabled explicitly, but required CUDA library was not found.')
endif
subdir_done()
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
endif
# NVENC dependency
if not nvenc_option.disabled()
if host_machine.system() == 'windows'
if cc.has_header('cuda_gl_interop.h', args: '-I' + cuda_incdir)
use_nvenc_gl = true
endif
else
if cc.has_header('cuda_gl_interop.h', dependencies: cuda_dep)
use_nvenc_gl = true
endif
endif
if use_nvenc_gl
extra_c_args += ['-DHAVE_NVENC_GST_GL=1']
endif
extra_c_args += ['-DHAVE_NVENC=1']
nvcodec_sources += nvenc_sources
endif
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],
install : true,
install_dir : plugins_install_dir,
)
pkgconfig.generate(gstnvcodec, install_dir : plugins_pkgconfig_install_dir)
......@@ -29,15 +29,33 @@
#include "config.h"
#endif
#include <gst/gst.h>
#ifdef HAVE_NVDEC
#include "gstnvdec.h"
#endif
#ifdef HAVE_NVENC
#include "gstnvenc.h"
#endif
static gboolean
plugin_init (GstPlugin * plugin)
{
return gst_element_register (plugin, "nvdec", GST_RANK_PRIMARY,
gboolean ret = TRUE;
#ifdef HAVE_NVDEC
ret &= gst_element_register (plugin, "nvdec", GST_RANK_PRIMARY,
GST_TYPE_NVDEC);
#endif
#ifdef HAVE_NVENC
ret &= gst_nvenc_plugin_init (plugin);
#endif
return ret;
}
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, nvdec,
"GStreamer NVDEC plugin", plugin_init, VERSION, "BSD",
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_VERSION_MINOR, nvcodec,
"GStreamer NVCODEC plugin", plugin_init, VERSION, "LGPL",
GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
plugin_LTLIBRARIES = libgstnvdec.la
libgstnvdec_la_SOURCES = \
gstnvdec.c \
plugin.c
noinst_HEADERS = \
gstnvdec.h
libgstnvdec_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
$(GST_GL_CFLAGS) \
$(GST_PBUTILS_CFLAGS) \
$(GST_VIDEO_CFLAGS) \
$(GST_CFLAGS) \
$(CUDA_CFLAGS)
libgstnvdec_la_LIBADD = \
$(GST_GL_LIBS) \
$(GST_PBUTILS_LIBS) \
$(GST_VIDEO_LIBS) \
$(GST_LIBS)
libgstnvdec_la_LIBADD += $(CUDA_LIBS) -lnvcuvid
libgstnvdec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
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