Commit c18fda03 authored by Seungha Yang's avatar Seungha Yang 🐑

nvdec,nvenc: Port to dynamic library loading

... and put them into new nvcodec plugin.

* nvcodec plugin
Now each nvenc and nvdec element is moved to be a part of nvcodec plugin
for better interoperability.
Additionally, cuda runtime API header dependencies
(i.e., cuda_runtime_api.h and cuda_gl_interop.h) are removed.
Note that cuda runtime APIs have prefix "cuda". Since 1.16 release with
Windows support, only "cuda.h" and "cudaGL.h" dependent symbols have
been used except for some defined types. However, those types could be
replaced with other types which were defined by "cuda.h".

* dynamic library loading
CUDA library will be opened with g_module_open() instead of build-time linking.
On Windows, nvcuda.dll is installed to system path by CUDA Toolkit
installer, and on *nix, user should ensure that libcuda.so.1 can be
loadable (i.e., via LD_LIBRARY_PATH or default dlopen path)
Therefore, NVIDIA_VIDEO_CODEC_SDK_PATH env build time dependency for Windows
is removed.
parent 5c3879ac
......@@ -881,103 +881,60 @@ 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],, [
PKG_CHECK_MODULES([CUDA], [cuda-10.0 cudart-10.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.2 cudart-9.2],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.1 cudart-9.1],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.0 cudart-9.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-8.0 cudart-8.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-7.5 cudart-7.5],, [
PKG_CHECK_MODULES([CUDA], [cuda-7.0 cudart-7.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-6.5 cudart-6.5],, [
PKG_CHECK_MODULES([CUDA], [cuda-10.1],, [
PKG_CHECK_MODULES([CUDA], [cuda-10.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.2],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.1],, [
PKG_CHECK_MODULES([CUDA], [cuda-9.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-8.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-7.5],, [
PKG_CHECK_MODULES([CUDA], [cuda-7.0],, [
PKG_CHECK_MODULES([CUDA], [cuda-6.5],, [
AC_MSG_WARN([Could not find cuda headers/libraries])])])])])])])])])])
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
HAVE_NVDEC=yes
else
HAVE_NVDEC=no
fi
])
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"
dnl *** USE_NVCODEC ***
translit(dnm, m, l) AM_CONDITIONAL(USE_NVCODEC, true)
AG_GST_CHECK_FEATURE(NVCODEC, [NVIDIA Codec plugin], nvcodec, [
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_NVCODEC="yes"
if test "x$GST_GL_HAVE_API_GL" = "x1"; then
dnl cuda-gl interop header
dnl cudaGL header
save_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$save_CPPFLAGS $CUDA_CFLAGS"
AC_CHECK_HEADER([cuda_gl_interop.h], [
USE_NVENC_GST_GL="yes"
AC_DEFINE(HAVE_NVENC_GST_GL, [1] , [NVENC GStreamer OpenGL support available])
AC_CHECK_HEADER([cudaGL.h], [
USE_NVCODEC_GST_GL="yes"
AC_DEFINE(HAVE_NVCODEC_GST_GL, [1] , [NVCODEC GStreamer OpenGL support available])
], [], [
/* missing headers in old cudaGL.h */
#ifdef __APPLE__
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <cuda.h>
])
CPPFLAGS="$save_CPPFLAGS"
fi
else
HAVE_NVENC="no"
HAVE_NVCODEC="no"
fi
])
AM_CONDITIONAL(USE_NVENC_GST_GL, test "x$USE_NVENC_GST_GL" = "xyes")
AM_CONDITIONAL(USE_NVCODEC_GST_GL, test "x$USE_NVCODEC_GST_GL" = "xyes")
dnl check for tinyalsa
translit(dnm, m, l) AM_CONDITIONAL(USE_TINYALSA, true)
......@@ -2494,8 +2451,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
......
......@@ -119,8 +119,7 @@ option('mplex', type : 'feature', value : 'auto', description : 'mplex audio/vid
option('msdk', type : 'feature', value : 'auto', description : 'Intel Media SDK video encoder/decoder plugin')
option('musepack', type : 'feature', value : 'auto', description : 'libmpcdec Musepack decoder plugin')
option('neon', type : 'feature', value : 'auto', description : 'NEON HTTP source plugin')
option('nvdec', type : 'feature', value : 'auto', description : 'NVIDIA GPU decoder plugin')
option('nvenc', type : 'feature', value : 'auto', description : 'NVIDIA GPU encoder plugin')
option('nvcodec', type : 'feature', value : 'auto', description : 'NVIDIA GPU codec plugin')
option('ofa', type : 'feature', value : 'auto', description : 'Open Fingerprint Architecture library plugin')
option('openal', type : 'feature', value : 'auto', description : 'OpenAL plugin')
option('openexr', type : 'feature', value : 'auto', description : 'OpenEXR plugin')
......
......@@ -94,16 +94,10 @@ else
UVCH264_DIR=
endif
if USE_NVDEC
NVDEC_DIR=nvdec
if USE_NVCODEC
NVCODEC_DIR=nvcodec
else
NVDEC_DIR=
endif
if USE_NVENC
NVENC_DIR=nvenc
else
NVENC_DIR=
NVCODEC_DIR=
endif
if USE_TINYALSA
......@@ -118,10 +112,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) $(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) $(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 wasapi winks winscreencap \
nvdec nvenc tinyalsa msdk
nvcodec tinyalsa msdk
include $(top_srcdir)/common/parallel-subdirs.mak
......@@ -13,6 +13,7 @@ subdir('fbdev')
subdir('ipcpipeline')
subdir('kms')
subdir('msdk')
subdir('nvcodec')
subdir('opensles')
subdir('shm')
subdir('tinyalsa')
......@@ -21,98 +22,3 @@ subdir('wasapi')
subdir('winks')
subdir('winscreencap')
# CUDA dependency
cuda_dep = dependency('', required : false)
cudart_dep = dependency('', required : false)
cuda_libdir = ''
cuda_incdir = ''
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
if not cuda_dep.found() or not cudart_dep.found()
cuda_root = run_command(python3, '-c', 'import os; print(os.environ.get("CUDA_PATH"))').stdout().strip()
if cuda_root != '' and cuda_root != 'None'
if host_machine.system() == 'windows'
arc = ''
if build_machine.cpu_family() == 'x86_64'
arc = 'x64'
else
arc = 'Win32'
endif
cuda_libdir = join_paths (cuda_root, 'lib', arc)
else
cuda_libdir = [join_paths (cuda_root, 'lib'), join_paths (cuda_root, 'lib', 'stubs'),
join_paths (cuda_root, 'lib64'), join_paths (cuda_root, 'lib64', 'stubs')]
endif
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
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 \
gstnvenc.c \
gstnvbaseenc.c \
gstnvh264enc.c \
gstnvh265enc.c
gstnvh265enc.c \
gstcudaloader.c
if USE_NVCODEC_GST_GL
libgstnvcodec_la_SOURCES += \
gstnvdec.c \
gstcuvidloader.c
endif
noinst_HEADERS = \
gstnvdec.h \
gstnvenc.h \
gstcuvidloader.h \
gstnvbaseenc.h \
gstnvh264enc.h \
gstnvh265enc.h \
nvEncodeAPI.h
nvEncodeAPI.h \
cuviddec.h \
nvcuvid.h \
gstcuvidloader.h
libgstnvenc_la_CFLAGS = \
libgstnvcodec_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
$(GST_PBUTILS_CFLAGS) \
$(GST_VIDEO_CFLAGS) \
$(GST_CFLAGS) \
$(CUDA_CFLAGS)
libgstnvenc_la_LIBADD = \
libgstnvcodec_la_LIBADD = \
$(GST_PBUTILS_LIBS) \
$(GST_VIDEO_LIBS) \
$(GST_LIBS) \
$(CUDA_LIBS) \
$(GMODULE_NO_EXPORT_LIBS)
if USE_NVENC_GST_GL
libgstnvenc_la_CFLAGS += $(GST_GL_CFLAGS)
libgstnvenc_la_LIBADD += $(GST_GL_LIBS)
if USE_NVCODEC_GST_GL
libgstnvcodec_la_CFLAGS += $(GST_GL_CFLAGS)
libgstnvcodec_la_LIBADD += $(GST_GL_LIBS)
endif
libgstnvenc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstnvcodec_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
/* GStreamer
* Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstcudaloader.h"
#include <gmodule.h>
#ifndef G_OS_WIN32
#define CUDA_LIBNAME "libcuda.so.1"
#else
#define CUDA_LIBNAME "nvcuda.dll"
#endif
#define LOAD_SYMBOL(name,func) G_STMT_START { \
if (!g_module_symbol (module, G_STRINGIFY (name), (gpointer *) &vtable->func)) { \
GST_ERROR ("Failed to load '%s' from %s, %s", G_STRINGIFY (name), filename, g_module_error()); \
goto error; \
} \
} G_STMT_END;
typedef struct _GstNvCodecCudaVTable
{
gboolean loaded;
CUresult (*CuInit) (unsigned int Flags);
CUresult (*CuGetErrorName) (CUresult error, const char **pStr);
CUresult (*CuGetErrorString) (CUresult error, const char **pStr);
CUresult (*CuCtxCreate) (CUcontext * pctx, unsigned int flags,
CUdevice dev);
CUresult (*CuCtxDestroy) (CUcontext ctx);
CUresult (*CuCtxPopCurrent) (CUcontext * pctx);
CUresult (*CuCtxPushCurrent) (CUcontext ctx);
CUresult (*CuGraphicsMapResources) (unsigned int count,
CUgraphicsResource * resources, CUstream hStream);
CUresult (*CuGraphicsUnmapResources) (unsigned int count,
CUgraphicsResource * resources, CUstream hStream);
CUresult (*CuGraphicsSubResourceGetMappedArray) (CUarray * pArray,
CUgraphicsResource resource, unsigned int arrayIndex,
unsigned int mipLevel);
CUresult (*CuGraphicsResourceGetMappedPointer) (CUdeviceptr * pDevPtr,
size_t * pSize, CUgraphicsResource resource);
CUresult (*CuGraphicsUnregisterResource) (CUgraphicsResource resource);
CUresult (*CuMemAlloc) (CUdeviceptr * dptr, unsigned int bytesize);
CUresult (*CuMemAllocPitch) (CUdeviceptr * dptr, size_t * pPitch,
size_t WidthInBytes, size_t Height, unsigned int ElementSizeBytes);
CUresult (*CuMemcpy2D) (const CUDA_MEMCPY2D * pCopy);
CUresult (*CuMemFree) (CUdeviceptr dptr);
CUresult (*CuDeviceGet) (CUdevice * device, int ordinal);
CUresult (*CuDeviceGetCount) (int *count);
CUresult (*CuDeviceGetName) (char *name, int len, CUdevice dev);
CUresult (*CuDeviceGetAttribute) (int *pi, CUdevice_attribute attrib,
CUdevice dev);
CUresult (*CuGraphicsGLRegisterImage) (CUgraphicsResource * pCudaResource,
unsigned int image, unsigned int target, unsigned int Flags);
CUresult (*CuGraphicsGLRegisterBuffer) (CUgraphicsResource * pCudaResource,
unsigned int buffer, unsigned int Flags);
} GstNvCodecCudaVTable;
static GstNvCodecCudaVTable gst_cuda_vtable = { 0, };
gboolean
gst_cuda_load_library (void)
{
GModule *module;
const gchar *filename = CUDA_LIBNAME;
GstNvCodecCudaVTable *vtable;
if (gst_cuda_vtable.loaded)
return TRUE;
module = g_module_open (filename, G_MODULE_BIND_LAZY);
if (module == NULL) {
GST_ERROR ("Could not open library %s, %s", filename, g_module_error ());
return FALSE;
}
vtable = &gst_cuda_vtable;
/* cuda.h */
LOAD_SYMBOL (cuInit, CuInit);
LOAD_SYMBOL (cuGetErrorName, CuGetErrorName);
LOAD_SYMBOL (cuGetErrorString, CuGetErrorString);
LOAD_SYMBOL (cuCtxCreate, CuCtxCreate);
LOAD_SYMBOL (cuCtxDestroy, CuCtxDestroy);
LOAD_SYMBOL (cuCtxPopCurrent, CuCtxPopCurrent);
LOAD_SYMBOL (cuCtxPushCurrent, CuCtxPushCurrent);
LOAD_SYMBOL (cuGraphicsMapResources, CuGraphicsMapResources);
LOAD_SYMBOL (cuGraphicsUnmapResources, CuGraphicsUnmapResources);
LOAD_SYMBOL (cuGraphicsSubResourceGetMappedArray,
CuGraphicsSubResourceGetMappedArray);
LOAD_SYMBOL (cuGraphicsResourceGetMappedPointer,
CuGraphicsResourceGetMappedPointer);
LOAD_SYMBOL (cuGraphicsUnregisterResource, CuGraphicsUnregisterResource);
LOAD_SYMBOL (cuMemAlloc, CuMemAlloc);
LOAD_SYMBOL (cuMemAllocPitch, CuMemAllocPitch);
LOAD_SYMBOL (cuMemcpy2D, CuMemcpy2D);
LOAD_SYMBOL (cuMemFree, CuMemFree);
LOAD_SYMBOL (cuDeviceGet, CuDeviceGet);
LOAD_SYMBOL (cuDeviceGetCount, CuDeviceGetCount);
LOAD_SYMBOL (cuDeviceGetName, CuDeviceGetName);
LOAD_SYMBOL (cuDeviceGetAttribute, CuDeviceGetAttribute);
/* cudaGL.h */
LOAD_SYMBOL (cuGraphicsGLRegisterImage, CuGraphicsGLRegisterImage);
LOAD_SYMBOL (cuGraphicsGLRegisterBuffer, CuGraphicsGLRegisterBuffer);
vtable->loaded = TRUE;
return TRUE;
error:
g_module_close (module);
return FALSE;
}
CUresult
CuInit (unsigned int Flags)
{
g_assert (gst_cuda_vtable.CuInit != NULL);
return gst_cuda_vtable.CuInit (Flags);
}
CUresult
CuGetErrorName (CUresult error, const char **pStr)
{
g_assert (gst_cuda_vtable.CuGetErrorName != NULL);
return gst_cuda_vtable.CuGetErrorName (error, pStr);
}
CUresult
CuGetErrorString (CUresult error, const char **pStr)
{
g_assert (gst_cuda_vtable.CuGetErrorString != NULL);
return gst_cuda_vtable.CuGetErrorString (error, pStr);
}
CUresult
CuCtxCreate (CUcontext * pctx, unsigned int flags, CUdevice dev)
{
g_assert (gst_cuda_vtable.CuCtxCreate != NULL);
return gst_cuda_vtable.CuCtxCreate (pctx, flags, dev);
}
CUresult
CuCtxDestroy (CUcontext ctx)
{
g_assert (gst_cuda_vtable.CuCtxDestroy != NULL);
return gst_cuda_vtable.CuCtxDestroy (ctx);
}
CUresult
CuCtxPopCurrent (CUcontext * pctx)
{
g_assert (gst_cuda_vtable.CuCtxPopCurrent != NULL);
return gst_cuda_vtable.CuCtxPopCurrent (pctx);
}
CUresult
CuCtxPushCurrent (CUcontext ctx)
{
g_assert (gst_cuda_vtable.CuCtxPushCurrent != NULL);
return gst_cuda_vtable.CuCtxPushCurrent (ctx);
}
CUresult
CuGraphicsMapResources (unsigned int count, CUgraphicsResource * resources,
CUstream hStream)
{
g_assert (gst_cuda_vtable.CuGraphicsMapResources != NULL);
return gst_cuda_vtable.CuGraphicsMapResources (count, resources, hStream);
}
CUresult
CuGraphicsUnmapResources (unsigned int count, CUgraphicsResource * resources,
CUstream hStream)
{
g_assert (gst_cuda_vtable.CuGraphicsUnmapResources != NULL);
return gst_cuda_vtable.CuGraphicsUnmapResources (count, resources, hStream);
}
CUresult
CuGraphicsSubResourceGetMappedArray (CUarray * pArray,
CUgraphicsResource resource, unsigned int arrayIndex, unsigned int mipLevel)
{
g_assert (gst_cuda_vtable.CuGraphicsSubResourceGetMappedArray != NULL);
return gst_cuda_vtable.CuGraphicsSubResourceGetMappedArray (pArray, resource,
arrayIndex, mipLevel);
}
CUresult
CuGraphicsResourceGetMappedPointer (CUdeviceptr * pDevPtr, size_t * pSize,
CUgraphicsResource resource)
{
g_assert (gst_cuda_vtable.CuGraphicsResourceGetMappedPointer != NULL);
return gst_cuda_vtable.CuGraphicsResourceGetMappedPointer (pDevPtr, pSize,
resource);
}
CUresult
CuGraphicsUnregisterResource (CUgraphicsResource resource)
{
g_assert (gst_cuda_vtable.CuGraphicsUnregisterResource != NULL);
return gst_cuda_vtable.CuGraphicsUnregisterResource (resource);
}
CUresult
CuMemAlloc (CUdeviceptr * dptr, unsigned int bytesize)
{
g_assert (gst_cuda_vtable.CuMemAlloc != NULL);
return gst_cuda_vtable.CuMemAlloc (dptr, bytesize);
}
CUresult
CuMemAllocPitch (CUdeviceptr * dptr, size_t * pPitch, size_t WidthInBytes,
size_t Height, unsigned int ElementSizeBytes)
{
g_assert (gst_cuda_vtable.CuMemAllocPitch != NULL);
return gst_cuda_vtable.CuMemAllocPitch (dptr, pPitch, WidthInBytes, Height,
ElementSizeBytes);
}
CUresult
CuMemcpy2D (const CUDA_MEMCPY2D * pCopy)
{
g_assert (gst_cuda_vtable.CuMemcpy2D != NULL);
return gst_cuda_vtable.CuMemcpy2D (pCopy);
}
CUresult
CuMemFree (CUdeviceptr dptr)
{
g_assert (gst_cuda_vtable.CuMemFree != NULL);
return gst_cuda_vtable.CuMemFree (dptr);
}
CUresult
CuDeviceGet (CUdevice * device, int ordinal)
{
g_assert (gst_cuda_vtable.CuDeviceGet != NULL);
return gst_cuda_vtable.CuDeviceGet (device, ordinal);
}
CUresult
CuDeviceGetCount (int *count)
{
g_assert (gst_cuda_vtable.CuDeviceGetCount != NULL);
return gst_cuda_vtable.CuDeviceGetCount (count);
}
CUresult
CuDeviceGetName (char *name, int len, CUdevice dev)
{
g_assert (gst_cuda_vtable.CuDeviceGetName != NULL);
return gst_cuda_vtable.CuDeviceGetName (name, len, dev);
}
CUresult
CuDeviceGetAttribute (int *pi, CUdevice_attribute attrib, CUdevice dev)
{
g_assert (gst_cuda_vtable.CuDeviceGetAttribute != NULL);
return gst_cuda_vtable.CuDeviceGetAttribute (pi, attrib, dev);
}
/* cudaGL.h */
CUresult
CuGraphicsGLRegisterImage (CUgraphicsResource * pCudaResource,
unsigned int image, unsigned int target, unsigned int Flags)
{
g_assert (gst_cuda_vtable.CuGraphicsGLRegisterImage != NULL);
return gst_cuda_vtable.CuGraphicsGLRegisterImage (pCudaResource, image,
target, Flags);
}
CUresult
CuGraphicsGLRegisterBuffer (CUgraphicsResource * pCudaResource,
unsigned int buffer, unsigned int Flags)
{
g_assert (gst_cuda_vtable.CuGraphicsGLRegisterBuffer != NULL);
return gst_cuda_vtable.CuGraphicsGLRegisterBuffer (pCudaResource, buffer,
Flags);
}
/* GStreamer
* Copyright (C) 2019 Seungha Yang <seungha.yang@navercorp.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_CUDA_LOADER_H__
#define __GST_CUDA_LOADER_H__
#include <gst/gst.h>
#include <cuda.h>
G_BEGIN_DECLS
G_GNUC_INTERNAL
gboolean gst_cuda_load_library (void);
/* cuda.h */
G_GNUC_INTERNAL
CUresult CuInit (unsigned int Flags);
G_GNUC_INTERNAL
CUresult CuGetErrorName (CUresult error,
const char **pStr);
G_GNUC_INTERNAL
CUresult CuGetErrorString (CUresult error,
const char **pStr);
G_GNUC_INTERNAL
CUresult CuCtxCreate (CUcontext * pctx,
unsigned int flags,
CUdevice dev);
G_GNUC_INTERNAL
CUresult CuCtxDestroy (CUcontext ctx);
G_GNUC_INTERNAL
CUresult CuCtxPopCurrent (CUcontext * pctx);
G_GNUC_INTERNAL
CUresult CuCtxPushCurrent (CUcontext ctx);
G_GNUC_INTERNAL
CUresult CuGraphicsMapResources (unsigned int count,
CUgraphicsResource * resources,
CUstream hStream);
G_GNUC_INTERNAL
CUresult CuGraphicsUnmapResources (unsigned int count,
CUgraphicsResource * resources,