FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dynlink_loader.h
Go to the documentation of this file.
1 /*
2  * This copyright notice applies to this header file only:
3  *
4  * Copyright (c) 2016
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use,
10  * copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the software, and to permit persons to whom the
12  * software is furnished to do so, subject to the following
13  * conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #ifndef AV_COMPAT_CUDA_DYNLINK_LOADER_H
29 #define AV_COMPAT_CUDA_DYNLINK_LOADER_H
30 
34 #include "compat/w32dlfcn.h"
35 
36 #include "libavutil/log.h"
37 #include "libavutil/error.h"
38 
39 #if defined(_WIN32)
40 # define LIB_HANDLE HMODULE
41 #else
42 # define LIB_HANDLE void*
43 #endif
44 
45 #if defined(_WIN32) || defined(__CYGWIN__)
46 # define CUDA_LIBNAME "nvcuda.dll"
47 # define NVCUVID_LIBNAME "nvcuvid.dll"
48 # if ARCH_X86_64
49 # define NVENC_LIBNAME "nvEncodeAPI64.dll"
50 # else
51 # define NVENC_LIBNAME "nvEncodeAPI.dll"
52 # endif
53 #else
54 # define CUDA_LIBNAME "libcuda.so.1"
55 # define NVCUVID_LIBNAME "libnvcuvid.so.1"
56 # define NVENC_LIBNAME "libnvidia-encode.so.1"
57 #endif
58 
59 #define LOAD_LIBRARY(l, path) \
60  do { \
61  if (!((l) = dlopen(path, RTLD_LAZY))) { \
62  av_log(NULL, AV_LOG_ERROR, "Cannot load %s\n", path); \
63  ret = AVERROR_UNKNOWN; \
64  goto error; \
65  } \
66  av_log(NULL, AV_LOG_TRACE, "Loaded lib: %s\n", path); \
67  } while (0)
68 
69 #define LOAD_SYMBOL(fun, symbol) \
70  do { \
71  if (!((f->fun) = dlsym(f->lib, symbol))) { \
72  av_log(NULL, AV_LOG_ERROR, "Cannot load %s\n", symbol); \
73  ret = AVERROR_UNKNOWN; \
74  goto error; \
75  } \
76  av_log(NULL, AV_LOG_TRACE, "Loaded sym: %s\n", symbol); \
77  } while (0)
78 
79 #define GENERIC_LOAD_FUNC_PREAMBLE(T, n, N) \
80  T *f; \
81  int ret; \
82  \
83  n##_free_functions(functions); \
84  \
85  f = *functions = av_mallocz(sizeof(*f)); \
86  if (!f) \
87  return AVERROR(ENOMEM); \
88  \
89  LOAD_LIBRARY(f->lib, N);
90 
91 #define GENERIC_LOAD_FUNC_FINALE(n) \
92  return 0; \
93 error: \
94  n##_free_functions(functions); \
95  return ret;
96 
97 #define GENERIC_FREE_FUNC() \
98  if (!functions) \
99  return; \
100  if (*functions && (*functions)->lib) \
101  dlclose((*functions)->lib); \
102  av_freep(functions);
103 
104 #ifdef AV_COMPAT_DYNLINK_CUDA_H
105 typedef struct CudaFunctions {
120 
122 } CudaFunctions;
123 #else
124 typedef struct CudaFunctions CudaFunctions;
125 #endif
126 
127 typedef struct CuvidFunctions {
137 
148 
151 
152 typedef struct NvencFunctions {
155 
158 
159 #ifdef AV_COMPAT_DYNLINK_CUDA_H
161 {
163 }
164 #endif
165 
167 {
169 }
170 
172 {
174 }
175 
176 #ifdef AV_COMPAT_DYNLINK_CUDA_H
178 {
180 
181  LOAD_SYMBOL(cuInit, "cuInit");
182  LOAD_SYMBOL(cuDeviceGetCount, "cuDeviceGetCount");
183  LOAD_SYMBOL(cuDeviceGet, "cuDeviceGet");
184  LOAD_SYMBOL(cuDeviceGetName, "cuDeviceGetName");
185  LOAD_SYMBOL(cuDeviceComputeCapability, "cuDeviceComputeCapability");
186  LOAD_SYMBOL(cuCtxCreate, "cuCtxCreate_v2");
187  LOAD_SYMBOL(cuCtxPushCurrent, "cuCtxPushCurrent_v2");
188  LOAD_SYMBOL(cuCtxPopCurrent, "cuCtxPopCurrent_v2");
189  LOAD_SYMBOL(cuCtxDestroy, "cuCtxDestroy_v2");
190  LOAD_SYMBOL(cuMemAlloc, "cuMemAlloc_v2");
191  LOAD_SYMBOL(cuMemFree, "cuMemFree_v2");
192  LOAD_SYMBOL(cuMemcpy2D, "cuMemcpy2D_v2");
193  LOAD_SYMBOL(cuGetErrorName, "cuGetErrorName");
194  LOAD_SYMBOL(cuGetErrorString, "cuGetErrorString");
195 
197 }
198 #endif
199 
201 {
203 
204  LOAD_SYMBOL(cuvidCreateDecoder, "cuvidCreateDecoder");
205  LOAD_SYMBOL(cuvidDestroyDecoder, "cuvidDestroyDecoder");
206  LOAD_SYMBOL(cuvidDecodePicture, "cuvidDecodePicture");
207 #ifdef __CUVID_DEVPTR64
208  LOAD_SYMBOL(cuvidMapVideoFrame, "cuvidMapVideoFrame64");
209  LOAD_SYMBOL(cuvidUnmapVideoFrame, "cuvidUnmapVideoFrame64");
210 #else
211  LOAD_SYMBOL(cuvidMapVideoFrame, "cuvidMapVideoFrame");
212  LOAD_SYMBOL(cuvidUnmapVideoFrame, "cuvidUnmapVideoFrame");
213 #endif
214  LOAD_SYMBOL(cuvidCtxLockCreate, "cuvidCtxLockCreate");
215  LOAD_SYMBOL(cuvidCtxLockDestroy, "cuvidCtxLockDestroy");
216  LOAD_SYMBOL(cuvidCtxLock, "cuvidCtxLock");
217  LOAD_SYMBOL(cuvidCtxUnlock, "cuvidCtxUnlock");
218 
219  LOAD_SYMBOL(cuvidCreateVideoSource, "cuvidCreateVideoSource");
220  LOAD_SYMBOL(cuvidCreateVideoSourceW, "cuvidCreateVideoSourceW");
221  LOAD_SYMBOL(cuvidDestroyVideoSource, "cuvidDestroyVideoSource");
222  LOAD_SYMBOL(cuvidSetVideoSourceState, "cuvidSetVideoSourceState");
223  LOAD_SYMBOL(cuvidGetVideoSourceState, "cuvidGetVideoSourceState");
224  LOAD_SYMBOL(cuvidGetSourceVideoFormat, "cuvidGetSourceVideoFormat");
225  LOAD_SYMBOL(cuvidGetSourceAudioFormat, "cuvidGetSourceAudioFormat");
226  LOAD_SYMBOL(cuvidCreateVideoParser, "cuvidCreateVideoParser");
227  LOAD_SYMBOL(cuvidParseVideoData, "cuvidParseVideoData");
228  LOAD_SYMBOL(cuvidDestroyVideoParser, "cuvidDestroyVideoParser");
229 
231 }
232 
234 {
236 
237  LOAD_SYMBOL(NvEncodeAPICreateInstance, "NvEncodeAPICreateInstance");
238  LOAD_SYMBOL(NvEncodeAPIGetMaxSupportedVersion, "NvEncodeAPIGetMaxSupportedVersion");
239 
241 }
242 
243 #undef GENERIC_LOAD_FUNC_PREAMBLE
244 #undef LOAD_LIBRARY
245 #undef LOAD_SYMBOL
246 #undef GENERIC_LOAD_FUNC_FINALE
247 #undef GENERIC_FREE_FUNC
248 #undef CUDA_LIBNAME
249 #undef NVCUVID_LIBNAME
250 #undef NVENC_LIBNAME
251 #undef LIB_HANDLE
252 
253 #endif
254 
tcuvidGetSourceAudioFormat * cuvidGetSourceAudioFormat
tcuDeviceGetName * cuDeviceGetName
tcuvidCtxLockDestroy * cuvidCtxLockDestroy
CUresult CUDAAPI tcuvidDestroyVideoSource(CUvideosource obj)
NvEncodeAPI provides a NVENC Video Encoding interface to NVIDIA GPU devices based on the Kepler archi...
static const struct drawtext_function functions[]
tcuvidCtxUnlock * cuvidCtxUnlock
tcuvidUnmapVideoFrame * cuvidUnmapVideoFrame
LIB_HANDLE lib
NV_ENCODE_API_FUNCTION_LIST.
Definition: nvEncodeAPI.h:3149
tcuvidSetVideoSourceState * cuvidSetVideoSourceState
tcuvidCtxLockCreate * cuvidCtxLockCreate
tcuMemFree_v2 * cuMemFree
tcuvidCtxLock * cuvidCtxLock
int version
Definition: avisynth_c.h:766
tcuvidGetVideoSourceState * cuvidGetVideoSourceState
CUresult CUDAAPI tcuvidCtxLock(CUvideoctxlock lck, unsigned int reserved_flags)
CUresult CUDAAPI tcuvidSetVideoSourceState(CUvideosource obj, cudaVideoState state)
tcuvidCreateVideoParser * cuvidCreateVideoParser
tcuvidMapVideoFrame * cuvidMapVideoFrame
tcuvidDestroyDecoder * cuvidDestroyDecoder
tcuvidDestroyVideoSource * cuvidDestroyVideoSource
LIB_HANDLE lib
tcuCtxPushCurrent_v2 * cuCtxPushCurrent
CUresult CUDAAPI tcuvidGetSourceAudioFormat(CUvideosource obj, CUAUDIOFORMAT *paudfmt, unsigned int flags)
CUresult CUDAAPI tcuvidParseVideoData(CUvideoparser obj, CUVIDSOURCEDATAPACKET *pPacket)
error code definitions
CUresult CUDAAPI tcuvidMapVideoFrame(CUvideodecoder hDecoder, int nPicIdx, unsigned int *pDevPtr, unsigned int *pPitch, CUVIDPROCPARAMS *pVPP)
tcuvidCreateVideoSource * cuvidCreateVideoSource
CUresult CUDAAPI tcuvidCreateVideoParser(CUvideoparser *pObj, CUVIDPARSERPARAMS *pParams)
tcuvidDecodePicture * cuvidDecodePicture
tcuInit * cuInit
tcuvidParseVideoData * cuvidParseVideoData
CUresult CUDAAPI tcuvidCtxLockCreate(CUvideoctxlock *pLock, CUcontext ctx)
tcuCtxCreate_v2 * cuCtxCreate
tcuvidCreateDecoder * cuvidCreateDecoder
CUresult CUDAAPI tcuvidCreateVideoSourceW(CUvideosource *pObj, const wchar_t *pwszFileName, CUVIDSOURCEPARAMS *pParams)
tcuGetErrorString * cuGetErrorString
tcuGetErrorName * cuGetErrorName
CUresult CUDAAPI tcuvidGetSourceVideoFormat(CUvideosource obj, CUVIDEOFORMAT *pvidfmt, unsigned int flags)
CUresult CUDAAPI tcuvidUnmapVideoFrame(CUvideodecoder hDecoder, unsigned int DevPtr)
tcuvidGetSourceVideoFormat * cuvidGetSourceVideoFormat
tcuMemAlloc_v2 * cuMemAlloc
CUresult CUDAAPI tcuvidCtxUnlock(CUvideoctxlock lck, unsigned int reserved_flags)
CUresult CUDAAPI tcuvidCtxLockDestroy(CUvideoctxlock lck)
tcuvidCreateVideoSourceW * cuvidCreateVideoSourceW
tcuMemcpy2D_v2 * cuMemcpy2D
NVENCSTATUS NVENCAPI NvEncodeAPIGetMaxSupportedVersion(uint32_t *version)
Get the largest NvEncodeAPI version supported by the driver.
#define NVENCAPI
Definition: nvEncodeAPI.h:71
CUresult CUDAAPI tcuvidDestroyVideoParser(CUvideoparser obj)
NVENCSTATUS(NVENCAPI *NvEncodeAPICreateInstance)(NV_ENCODE_API_FUNCTION_LIST *functionList)
CUresult CUDAAPI tcuvidDestroyDecoder(CUvideodecoder hDecoder)
CUresult CUDAAPI tcuvidCreateVideoSource(CUvideosource *pObj, const char *pszFileName, CUVIDSOURCEPARAMS *pParams)
tcuDeviceGetCount * cuDeviceGetCount
cudaVideoState CUDAAPI tcuvidGetVideoSourceState(CUvideosource obj)
LIB_HANDLE lib
CUresult CUDAAPI tcuvidDecodePicture(CUvideodecoder hDecoder, CUVIDPICPARAMS *pPicParams)
tcuCtxPopCurrent_v2 * cuCtxPopCurrent
tcuvidDestroyVideoParser * cuvidDestroyVideoParser
tcuDeviceComputeCapability * cuDeviceComputeCapability
tcuCtxDestroy_v2 * cuCtxDestroy
NVENCSTATUS NVENCAPI NvEncodeAPICreateInstance(NV_ENCODE_API_FUNCTION_LIST *functionList)
Entry Point to the NvEncodeAPI interface.
CUresult CUDAAPI tcuvidCreateDecoder(CUvideodecoder *phDecoder, CUVIDDECODECREATEINFO *pdci)
tcuDeviceGet * cuDeviceGet