[FFmpeg-devel] [PATCH] avutil/hwcontext_cuda: check that the SDK defines cuCtxGetCurrent()

James Almer jamrial at gmail.com
Sun Oct 1 05:24:49 EEST 2023


On 9/30/2023 11:06 PM, James Almer wrote:
> Fixes compilation after 05f8b2ca0f7e28775837a572c65ce9218f534ee2
> 
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>   libavutil/hwcontext_cuda.c          | 4 ++++
>   libavutil/hwcontext_cuda_internal.h | 9 +++++++++
>   2 files changed, 13 insertions(+)
> 
> diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
> index 0312d3b9d7..4f55f6441d 100644
> --- a/libavutil/hwcontext_cuda.c
> +++ b/libavutil/hwcontext_cuda.c
> @@ -362,10 +362,14 @@ static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
>           if (ret < 0)
>               return ret;
>       } else if (flags & AV_CUDA_USE_CURRENT_CONTEXT) {
> +#if NVDECAPI_CHECK_VERSION(12, 1)

Actually no, this check is not enough as cuCtxGetCurrent() was added to 
ffnvcodec headers after the version bump to 12.1

Either we leave things as is and expect to get people to update their 
headers until a new SDK version is released, its changes merged and 
version bumped, or revert the implementation bits of 05f8b2ca0f, leaving 
only the API in place. AVERROR(ENOSYS) would then be returned any time 
AV_CUDA_USE_CURRENT_CONTEXT is requested regardless of what headers are 
present at compile time.

>           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
> +        return AVERROR(ENOSYS);
> +#endif
>       } else {
>           ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
>                                          hwctx->internal->cuda_device));
> diff --git a/libavutil/hwcontext_cuda_internal.h b/libavutil/hwcontext_cuda_internal.h
> index d5633c58d5..fe0963b4e5 100644
> --- a/libavutil/hwcontext_cuda_internal.h
> +++ b/libavutil/hwcontext_cuda_internal.h
> @@ -28,6 +28,15 @@
>    * FFmpeg internal API for CUDA.
>    */
>   
> +#if defined(NVDECAPI_MAJOR_VERSION) && defined(NVDECAPI_MINOR_VERSION)
> +# define NVDECAPI_CHECK_VERSION(major, minor) \
> +    ((major) < NVDECAPI_MAJOR_VERSION || ((major) == NVDECAPI_MAJOR_VERSION && (minor) <= NVDECAPI_MINOR_VERSION))
> +#else
> +/* version macros were added in SDK 8.1 ffnvcodec */
> +# define NVDECAPI_CHECK_VERSION(major, minor) \
> +    ((major) < 8 || ((major) == 8 && (minor) <= 0))
> +#endif
> +
>   struct AVCUDADeviceContextInternal {
>       CudaFunctions *cuda_dl;
>       int is_allocated;


More information about the ffmpeg-devel mailing list