aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Arzumanyan <r.arzumanyan@visionlabs.ai>2023-09-12 17:31:30 +0300
committerTimo Rothenpieler <timo@rothenpieler.org>2023-09-28 19:23:51 +0200
commit05f8b2ca0f7e28775837a572c65ce9218f534ee2 (patch)
tree583d3281237fe2f3bdddb11a012554eec6b61a84
parent48fc414c7cc13185b5ffe462b288e95be2517196 (diff)
downloadffmpeg-05f8b2ca0f7e28775837a572c65ce9218f534ee2.tar.gz
avutil/hwcontext_cuda: add option to use current device context
Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
-rwxr-xr-xconfigure9
-rw-r--r--doc/APIchanges3
-rw-r--r--libavutil/hwcontext_cuda.c28
-rw-r--r--libavutil/hwcontext_cuda.h5
-rw-r--r--libavutil/version.h2
5 files changed, 41 insertions, 6 deletions
diff --git a/configure b/configure
index 6f9b223481..e1afcaa586 100755
--- a/configure
+++ b/configure
@@ -6577,10 +6577,11 @@ fi
if ! disabled ffnvcodec; then
ffnv_hdr_list="ffnvcodec/nvEncodeAPI.h ffnvcodec/dynlink_cuda.h ffnvcodec/dynlink_cuviddec.h ffnvcodec/dynlink_nvcuvid.h"
- check_pkg_config ffnvcodec "ffnvcodec >= 12.0.16.0" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 11.1.5.2 ffnvcodec < 12.0" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 11.0.10.2 ffnvcodec < 11.1" "$ffnv_hdr_list" "" || \
- check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.14 ffnvcodec < 8.2" "$ffnv_hdr_list" ""
+ check_pkg_config ffnvcodec "ffnvcodec >= 12.1.14.0" "$ffnv_hdr_list" "" || \
+ check_pkg_config ffnvcodec "ffnvcodec >= 12.0.16.1 ffnvcodec < 12.1" "$ffnv_hdr_list" "" || \
+ check_pkg_config ffnvcodec "ffnvcodec >= 11.1.5.3 ffnvcodec < 12.0" "$ffnv_hdr_list" "" || \
+ check_pkg_config ffnvcodec "ffnvcodec >= 11.0.10.3 ffnvcodec < 11.1" "$ffnv_hdr_list" "" || \
+ check_pkg_config ffnvcodec "ffnvcodec >= 8.1.24.15 ffnvcodec < 8.2" "$ffnv_hdr_list" ""
fi
if enabled_all libglslang libshaderc; then
diff --git a/doc/APIchanges b/doc/APIchanges
index f333ff5b24..f4eb7f6d68 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
API changes, most recent first:
+2023-09-28 - xxxxxxxxxx - lavu 58.26.100 - hwcontext_cuda.h
+ Add AV_CUDA_USE_CURRENT_CONTEXT.
+
2023-09-19 - xxxxxxxxxx - lavu 58.25.100 - avutil.h
Make AV_TIME_BASE_Q compatible with C++.
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 4b298fa93e..c648723285 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -361,6 +361,11 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
hwctx->internal->cuda_device));
if (ret < 0)
return ret;
+ } else if (flags & AV_CUDA_USE_CURRENT_CONTEXT) {
+ ret = CHECK_CU(cu->cuCtxGetCurrent(&hwctx->cuda_ctx));
+ if (ret < 0)
+ return ret;
+ av_log(device_ctx, AV_LOG_INFO, "Using current CUDA context.\n");
} else {
ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
hwctx->internal->cuda_device));
@@ -382,8 +387,21 @@ static int cuda_flags_from_opts(AVHWDeviceContext *device_ctx,
AVDictionary *opts, int *flags)
{
AVDictionaryEntry *primary_ctx_opt = av_dict_get(opts, "primary_ctx", NULL, 0);
+ AVDictionaryEntry *current_ctx_opt = av_dict_get(opts, "current_ctx", NULL, 0);
+
+ int use_primary_ctx = 0, use_current_ctx = 0;
+ if (primary_ctx_opt)
+ use_primary_ctx = strtol(primary_ctx_opt->value, NULL, 10);
+
+ if (current_ctx_opt)
+ use_current_ctx = strtol(current_ctx_opt->value, NULL, 10);
- if (primary_ctx_opt && strtol(primary_ctx_opt->value, NULL, 10)) {
+ if (use_primary_ctx && use_current_ctx) {
+ av_log(device_ctx, AV_LOG_ERROR, "Requested both primary and current CUDA context simultaneously.\n");
+ return AVERROR(EINVAL);
+ }
+
+ if (primary_ctx_opt && use_primary_ctx) {
av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA primary device context\n");
*flags |= AV_CUDA_USE_PRIMARY_CONTEXT;
} else if (primary_ctx_opt) {
@@ -391,6 +409,14 @@ static int cuda_flags_from_opts(AVHWDeviceContext *device_ctx,
*flags &= ~AV_CUDA_USE_PRIMARY_CONTEXT;
}
+ if (current_ctx_opt && use_current_ctx) {
+ av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA current device context\n");
+ *flags |= AV_CUDA_USE_CURRENT_CONTEXT;
+ } else if (current_ctx_opt) {
+ av_log(device_ctx, AV_LOG_VERBOSE, "Disabling use of CUDA current device context\n");
+ *flags &= ~AV_CUDA_USE_CURRENT_CONTEXT;
+ }
+
return 0;
}
diff --git a/libavutil/hwcontext_cuda.h b/libavutil/hwcontext_cuda.h
index cefbe0ceab..cbad434fea 100644
--- a/libavutil/hwcontext_cuda.h
+++ b/libavutil/hwcontext_cuda.h
@@ -63,6 +63,11 @@ typedef struct AVCUDADeviceContext {
#define AV_CUDA_USE_PRIMARY_CONTEXT (1 << 0)
/**
+ * Use current device context instead of creating a new one.
+ */
+#define AV_CUDA_USE_CURRENT_CONTEXT (1 << 1)
+
+/**
* @}
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index 00f229d233..2dc1a647b8 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 58
-#define LIBAVUTIL_VERSION_MINOR 25
+#define LIBAVUTIL_VERSION_MINOR 26
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \