From acaaee034a43a7bb1461152477a5553a299435fd Mon Sep 17 00:00:00 2001 From: Lynne Date: Mon, 6 Mar 2023 02:04:53 +0100 Subject: [PATCH 63/97] hwcontext_vulkan: move VulkanFramesPriv to hwcontext_vulkan_internal The issue is that during calls to avcodec_get_hw_frames_parameters, avctx->internal->hwaccel_priv_data isn't guaranteed to exist. However, we need to attach some structures to create_pnext, in order to create frames we can decode into. We have nowhere to put them, and they have to be valid for the entire lifetime. Hence, we put them into the hwcontext's frames priv structure. --- libavutil/Makefile | 1 + libavutil/hwcontext_vulkan.c | 15 ++------- libavutil/hwcontext_vulkan_internal.h | 46 +++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 libavutil/hwcontext_vulkan_internal.h diff --git a/libavutil/Makefile b/libavutil/Makefile index bd9c6f9e32..fbcb2d2a88 100644 --- a/libavutil/Makefile +++ b/libavutil/Makefile @@ -216,6 +216,7 @@ SKIPHEADERS-$(CONFIG_VAAPI) += hwcontext_vaapi.h SKIPHEADERS-$(CONFIG_VIDEOTOOLBOX) += hwcontext_videotoolbox.h SKIPHEADERS-$(CONFIG_VDPAU) += hwcontext_vdpau.h SKIPHEADERS-$(CONFIG_VULKAN) += hwcontext_vulkan.h vulkan.h \ + hwcontext_vulkan_internal.h \ vulkan_functions.h \ vulkan_loader.h diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 85ac48f307..2910208df1 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -40,6 +40,7 @@ #include "avassert.h" #include "hwcontext_internal.h" #include "hwcontext_vulkan.h" +#include "hwcontext_vulkan_internal.h" #include "vulkan.h" #include "vulkan_loader.h" @@ -119,18 +120,6 @@ typedef struct VulkanDevicePriv { int dev_is_nvidia; } VulkanDevicePriv; -typedef struct VulkanFramesPriv { - /* Image conversions */ - FFVkExecPool compute_exec; - - /* Image transfers */ - FFVkExecPool upload_exec; - FFVkExecPool download_exec; - - /* Modifier info list to free at uninit */ - VkImageDrmFormatModifierListCreateInfoEXT *modifier_info; -} VulkanFramesPriv; - typedef struct AVVkFrameInternal { pthread_mutex_t update_mutex; @@ -2163,6 +2152,8 @@ static void vulkan_frames_uninit(AVHWFramesContext *hwfc) ff_vk_exec_pool_free(&p->vkctx, &fp->compute_exec); ff_vk_exec_pool_free(&p->vkctx, &fp->upload_exec); ff_vk_exec_pool_free(&p->vkctx, &fp->download_exec); + + av_freep(&fp->video_profile_data); } static int vulkan_frames_init(AVHWFramesContext *hwfc) diff --git a/libavutil/hwcontext_vulkan_internal.h b/libavutil/hwcontext_vulkan_internal.h new file mode 100644 index 0000000000..1fdf1663f5 --- /dev/null +++ b/libavutil/hwcontext_vulkan_internal.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) Lynne + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_HWCONTEXT_VULKAN_INTERNAL_H +#define AVUTIL_HWCONTEXT_VULKAN_INTERNAL_H + +/** + * @file + * FFmpeg internal API for CUDA. + */ + +#include "vulkan.h" + +typedef struct VulkanFramesPriv { + /* Image conversions */ + FFVkExecPool compute_exec; + + /* Image transfers */ + FFVkExecPool upload_exec; + FFVkExecPool download_exec; + + /* Modifier info list to free at uninit */ + VkImageDrmFormatModifierListCreateInfoEXT *modifier_info; + + /* Used by the decoder in case there's no contex */ + void *video_profile_data; +} VulkanFramesPriv; + +#endif /* AVUTIL_HWCONTEXT_VULKAN_INTERNAL_H */ -- 2.40.0