Allow linking to CUDA dynamically instead of dlopen()ing it at runtime
This commit is contained in:
parent
bd49be885e
commit
c51b2c79a7
6
configure
vendored
6
configure
vendored
@ -179,6 +179,7 @@ Individual component options:
|
||||
External library support:
|
||||
--enable-avisynth enable reading of AviSynth script files [no]
|
||||
--enable-bzlib enable bzlib [autodetect]
|
||||
--enable-cuda enable dynamically linked CUDA [no]
|
||||
--enable-frei0r enable frei0r video filtering
|
||||
--enable-gnutls enable gnutls [no]
|
||||
--enable-libbs2b enable bs2b DSP library [no]
|
||||
@ -1238,6 +1239,7 @@ EXAMPLE_LIST="
|
||||
EXTERNAL_LIBRARY_LIST="
|
||||
avisynth
|
||||
bzlib
|
||||
cuda
|
||||
frei0r
|
||||
gnutls
|
||||
libbs2b
|
||||
@ -4043,6 +4045,7 @@ die_license_disabled gpl libxavs
|
||||
die_license_disabled gpl libxvid
|
||||
die_license_disabled gpl x11grab
|
||||
|
||||
die_license_disabled nonfree cuda
|
||||
die_license_disabled nonfree libfaac
|
||||
die_license_disabled nonfree libfdk_aac
|
||||
die_license_disabled nonfree nvenc
|
||||
@ -4523,6 +4526,7 @@ done
|
||||
enabled avisynth && { check_lib2 "avisynth/avisynth_c.h windows.h" LoadLibrary ||
|
||||
check_lib2 "avxsynth/avxsynth_c.h dlfcn.h" dlopen -ldl ||
|
||||
die "ERROR: LoadLibrary/dlopen not found, or avisynth header not found"; }
|
||||
enabled cuda && check_lib cuda.h cuInit -lcuda
|
||||
enabled frei0r && { check_header frei0r.h || die "ERROR: frei0r.h header not found"; }
|
||||
enabled gnutls && require_pkg_config gnutls gnutls/gnutls.h gnutls_global_init
|
||||
enabled libbs2b && require_pkg_config libbs2b bs2b.h bs2b_open
|
||||
@ -4617,7 +4621,7 @@ if enabled libdc1394; then
|
||||
fi
|
||||
|
||||
if enabled nvenc; then
|
||||
check_header cuda.h || die "ERROR: cuda.h not found.";
|
||||
enabled cuda || check_header cuda.h || die "ERROR: cuda.h not found.";
|
||||
check_header nvEncodeAPI.h || die "ERROR: nvEncodeAPI.h not found.";
|
||||
check_cpp_condition nvEncodeAPI.h "NVENCAPI_MAJOR_VERSION >= 5" ||
|
||||
die "ERROR: NVENC API version 4 or older is not supported";
|
||||
|
@ -148,6 +148,16 @@ static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
|
||||
PNVENCODEAPICREATEINSTANCE nvenc_create_instance;
|
||||
NVENCSTATUS err;
|
||||
|
||||
#if CONFIG_CUDA
|
||||
nvel->cu_init = cuInit;
|
||||
nvel->cu_device_get_count = cuDeviceGetCount;
|
||||
nvel->cu_device_get = cuDeviceGet;
|
||||
nvel->cu_device_get_name = cuDeviceGetName;
|
||||
nvel->cu_device_compute_capability = cuDeviceComputeCapability;
|
||||
nvel->cu_ctx_create = cuCtxCreate_v2;
|
||||
nvel->cu_ctx_pop_current = cuCtxPopCurrent_v2;
|
||||
nvel->cu_ctx_destroy = cuCtxDestroy_v2;
|
||||
#else
|
||||
LOAD_LIBRARY(nvel->cuda, CUDA_LIBNAME);
|
||||
|
||||
LOAD_SYMBOL(nvel->cu_init, nvel->cuda, "cuInit");
|
||||
@ -159,6 +169,7 @@ static av_cold int nvenc_load_libraries(AVCodecContext *avctx)
|
||||
LOAD_SYMBOL(nvel->cu_ctx_create, nvel->cuda, "cuCtxCreate_v2");
|
||||
LOAD_SYMBOL(nvel->cu_ctx_pop_current, nvel->cuda, "cuCtxPopCurrent_v2");
|
||||
LOAD_SYMBOL(nvel->cu_ctx_destroy, nvel->cuda, "cuCtxDestroy_v2");
|
||||
#endif
|
||||
|
||||
LOAD_LIBRARY(nvel->nvenc, NVENC_LIBNAME);
|
||||
|
||||
@ -859,8 +870,10 @@ av_cold int ff_nvenc_encode_close(AVCodecContext *avctx)
|
||||
if (ctx->nvel.nvenc)
|
||||
dlclose(ctx->nvel.nvenc);
|
||||
|
||||
#if !CONFIG_CUDA
|
||||
if (ctx->nvel.cuda)
|
||||
dlclose(ctx->nvel.cuda);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <cuda.h>
|
||||
#include <nvEncodeAPI.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "libavutil/fifo.h"
|
||||
#include "libavutil/opt.h"
|
||||
|
||||
@ -47,7 +49,9 @@ typedef NVENCSTATUS (NVENCAPI *PNVENCODEAPICREATEINSTANCE)(NV_ENCODE_API_FUNCTIO
|
||||
|
||||
typedef struct NVENCLibraryContext
|
||||
{
|
||||
#if !CONFIG_CUDA
|
||||
void *cuda;
|
||||
#endif
|
||||
void *nvenc;
|
||||
|
||||
PCUINIT cu_init;
|
||||
|
Loading…
Reference in New Issue
Block a user