Commit 05f8b2ca authored by Roman Arzumanyan's avatar Roman Arzumanyan Committed by Timo Rothenpieler

avutil/hwcontext_cuda: add option to use current device context

Signed-off-by: 's avatarTimo Rothenpieler <timo@rothenpieler.org>
parent 48fc414c
......@@ -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
......
......@@ -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++.
......
......@@ -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;
}
......
......@@ -62,6 +62,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)
/**
* @}
*/
......
......@@ -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, \
......
Markdown is supported
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