From patchwork Tue Jun 13 04:18:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42052 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp3424605pzb; Mon, 12 Jun 2023 21:18:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5aRil+RT0SzbEvoTOIhH3hhpxqNZQizwLT9RcJcOicPNQhYE918kldx8UaZjkglfewsa8M X-Received: by 2002:a05:6402:27c9:b0:506:bbf8:5152 with SMTP id c9-20020a05640227c900b00506bbf85152mr7717966ede.9.1686629910482; Mon, 12 Jun 2023 21:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686629910; cv=none; d=google.com; s=arc-20160816; b=TKAijPGqCB3nn6Twxucp4GIn58M8y8saKLOJr4TRUCHbz7M+bH6JEM60LA2Ycl7wHg p5gF/REmlzNW9WKmPIs7bxr1BPjWXiELsoU9LJ06lg7QGsawX3p/rOINlD/nxa1OAfVi 7LOQe0ImoKqHT+G01HhaSUIez1OMDaefrvigLl0RCKNeu42KdGytXggkwp3KVK6HWk+U +4fbw/nDsNKM4i3A8cdzsFnO67IpKuNxCGQ/0l2J6X22FoU197+OE0hd4iH8cxnF6XWw 8OstuwscQSRy3kFI1jXdFgOGX2569Y/c6CNHo7DZeY9aJUB5evQMcBaJbjE/LqKnGS/o JQTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:to:from:date:dkim-signature:delivered-to; bh=SJBDzO+4w9H2KnGQ3ybh1R7iOHA3KmwGZMq7IIsCw74=; b=wIt0LsvN+kHVK54yRjG4+kSmZOEMT8JBDevPRnoX56MevTSjL0jSFu+9LzagsVlJRQ 6B1fkC0VEHnryhYGV8RdyC14J6OUXHkofbi3NQ5iTbKLkwubiqjhRI2farDPmNiOpHQz Ok2gacVbFgUmZD1ncRC062hoL/HyCR30Y6446f/tnaUAx3APDDD+YHYzFe5e3/dLFnyd 6cOOOQHWuHz2x+HWJshQ19Kd8yiY+cpOx8POGEq2X5AEvxzY6Blcf6zP1fSWVk9AT9U7 DHkUwA43kcp7h1/Q+XInFc69JIQ1c5mosWx7N7qeXUs5EBKTKjjgHzoV/qadH07fHQyB UQCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b="JoiNL9Z/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c23-20020aa7c757000000b00518740764a1si367637eds.484.2023.06.12.21.18.29; Mon, 12 Jun 2023 21:18:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b="JoiNL9Z/"; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B25B168C348; Tue, 13 Jun 2023 07:18:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ECA3168C180 for ; Tue, 13 Jun 2023 07:18:18 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id B593C10601A7 for ; Tue, 13 Jun 2023 04:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686629898; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:Sender; bh=GnTnYYi5Tv6cCO4LKmOVxrxGbxdKg1uAXiIh5NNLn/M=; b=JoiNL9Z/fpOHLIamSMlQDm8IDUtm9sfFt7eUZKeVJGnKKROd5ySeggROiuRuFk2B wKeMcX2iJIwTHzPDzy4gnGyZVzHOhfYgpIctj6rulrmag77TJBizP0uLP/v5BwQXY6f u77l/d3xe2Dq52NLs3OPlNI4nqyy+ZdDmsLpzOdD4CfESRqf3WHB8I8wXZGfX2erYSh zvBRet6PjMYjJCZrs3e8CflbB+Z5eb7TszuWzkbnLhoZOfwC0DW6vInl/qI5q1GxAD3 x1pszdG/ZU/OtdDfwK3tR8NckwFJAPzd/yag5k5IUjuIO1hO0CatPrYq+7LqiCZbmg9 4+X4MvWwyw== Date: Tue, 13 Jun 2023 06:18:18 +0200 (CEST) From: Lynne To: Ffmpeg Devel Message-ID: MIME-Version: 1.0 Subject: [FFmpeg-devel] [RFC] [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QKg4aLHit9IT This is a public field, settable before frames context initialization, and propagated to any derived contexts. API users can use it to store state and determine which context is one of theirs. This also allows decoders which create their own contexts to store some state which would be freed only at context destruction. Request for comments. Patch attached. From a9bdbbb64acfcb0540727895b7be4027ab9955f9 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 06:10:50 +0200 Subject: [PATCH 1/5] hwcontext: add a new AVHWFramesContext.opaque field This is a public field, settable before frames context initialization, and propagated to any derived contexts. API users can use it to store state and determine which context is one of theirs. This also allows decoders which create their own contexts to store some state which would be freed only at context destruction. --- libavutil/hwcontext.c | 6 ++++++ libavutil/hwcontext.h | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c index 3396598269..92a8cc907a 100644 --- a/libavutil/hwcontext.c +++ b/libavutil/hwcontext.c @@ -238,6 +238,7 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data) av_buffer_unref(&ctx->internal->source_frames); av_buffer_unref(&ctx->device_ref); + av_buffer_unref(&ctx->opaque); av_freep(&ctx->hwctx); av_freep(&ctx->internal->priv); @@ -913,6 +914,11 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, dst->sw_format = src->sw_format; dst->width = src->width; dst->height = src->height; + dst->opaque = av_buffer_ref(src->opaque); + if (!dst->internal->source_frames) { + ret = AVERROR(ENOMEM); + goto fail; + } dst->internal->source_frames = av_buffer_ref(source_frame_ctx); if (!dst->internal->source_frames) { diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index 7ff08c8608..7655bee33f 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -227,6 +227,15 @@ typedef struct AVHWFramesContext { * Must be set by the user before calling av_hwframe_ctx_init(). */ int width, height; + + /** + * Opaque data. Can be set before calling av_hwframe_ctx_init(). + * MUST NOT be set afterwards. Will be unref'd along with the + * main context at closure. + * + * Will be propagated to any derived contexts. + */ + AVBufferRef *opaque; } AVHWFramesContext; /** -- 2.40.1 From patchwork Tue Jun 13 04:19:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42054 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp3424943pzb; Mon, 12 Jun 2023 21:19:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6SBOVRUyq72XoEt2lxB1napDWsiJtqZMkTKnmBoMaWC4KVw0LgJR9G7wz2Bm6KHjhIAD0l X-Received: by 2002:a17:907:7b97:b0:982:3e4f:ed6e with SMTP id ne23-20020a1709077b9700b009823e4fed6emr433966ejc.47.1686629984579; Mon, 12 Jun 2023 21:19:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686629984; cv=none; d=google.com; s=arc-20160816; b=o1WrF4CGPizcgsIsVr1a+WSzkf6K0f6tiz6f3Fpt1hlcOKClejgFyKmKWUkCoKzXe2 +2LTejZyD12UR1REO9M2UkqbL61FlLVfRvg+I2Uh9+gSSMH2Toc4t+92rpPOe0w6zmqu 1uVg8/xPUe8q1hcaf0uNCFLPaP2HVUyuga21P614ThAE1avUw6QbkZAktmXxxcd0DAk5 IbQk7OtZO6m1xeftOpRwML34O0XzD6OmNavNFL26Ogvc67dzKZNR66iXM9tyhDdYk80l +yLUJQp3j2Y9uw/rXiMUYGw6gCbOBB6aO+K9XXBocfSNbdYbHV6E8PcDyqjr+/g6pS6x fIyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=SmkJ5dAzUD//nx2+yqnvGUZU4SX0+FagelAm8hrCVSw=; b=eqbi+B2TOVqM6Xd1Mb291st5P/3AItbFtCXu3snt1fEf0OtNWz7C52gaeWqT6cJT6z w2NSQ1He2A9u8qG76yYNo8TYgi+2lMWS45sHcsfbTQRkPPtSkEeWQdKE0pgwDWNbI2NS aWpu/cOiPfZ36ZI4NH/HUvJWS34s4sp1lYr6ocTTsTKpMzEGywyuPd049FJCWRBV4RJc 6tP2qbL9WxnmEQKMf4vve1htUeyPFTgZ6A0mHwGg9YE/vCJmpJJxiDPkdslt2JkSo1x+ Z6iKFGR3DFrsT4WmQ97S/TjWB2sOjJiv4KVxESZJapnldDA1wdo/5TG+furX1Z7qxXGD +x/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=qAcPBrJa; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s15-20020a056402164f00b0050bd4957988si6590881edx.455.2023.06.12.21.19.44; Mon, 12 Jun 2023 21:19:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=qAcPBrJa; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF32768C362; Tue, 13 Jun 2023 07:19:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05D1168C1E2 for ; Tue, 13 Jun 2023 07:19:35 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 136A21060148 for ; Tue, 13 Jun 2023 04:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686629974; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=FBAjH4oA1FZS2+kUO9G410nohikmRKptH59bPs7Bgr0=; b=qAcPBrJaxgaAxXbxCV1t+DDDDFEeNzUC7SQmwc9nG9xCmxGxL5GMsmQAwB3SioNS zv24OLAptNim4SGR4zAllnHKpxnXgg/9JbGqzjBqCE7NRGEUh360zOlwRdrJFzbadhn msnnUo9jYhz7Lr94XYqCpPBuFOXFojmd9t/kshYHkK4HWKW8gyaeZkDjuasv4TLvKy2 Ez38nfWWxitqY19pB+CTlAhrjWXorpB0HQY2axNcJTCQILNiAa2CN2yoKdB1ZuHC8Qn XCzoeD9aIu1doFoelM/CMW+i971ZwCznFG+0MxDrW1vYTHIYOfi5HkuzZuPvgVdhLPw pJsytdRMIQ== Date: Tue, 13 Jun 2023 06:19:34 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] vulkan_decode: use the new AVHWFramesContext.opaque field X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: PNKi0NzApZzJ This depends on the previous patch, and allows moving the codec profile to the new AVHWFramesContext.opaque field. Patch attached. From f992905250062711fab7522906a573ff8ab5f716 Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 06:10:20 +0200 Subject: [PATCH 2/5] vulkan_decode: use the new AVHWFramesContext.opaque field --- libavcodec/vulkan_decode.c | 56 +++++++++++++++++++++++--------------- libavcodec/vulkan_decode.h | 6 ++-- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 35e265a5b1..81085273d8 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -196,7 +196,6 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, { FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; - FFVulkanDecodeProfileData *prof = &ctx->profile_data; static const uint8_t startcode_prefix[3] = { 0x0, 0x0, 0x1 }; const size_t startcode_len = add_startcode ? sizeof(startcode_prefix) : 0; @@ -206,8 +205,8 @@ int ff_vk_decode_add_slice(AVCodecContext *avctx, FFVulkanDecodePicture *vp, FFVkVideoBuffer *vkbuf; size_t new_size = vp->slices_size + startcode_len + size + - prof->caps.minBitstreamBufferSizeAlignment; - new_size = FFALIGN(new_size, prof->caps.minBitstreamBufferSizeAlignment); + ctx->caps.minBitstreamBufferSizeAlignment; + new_size = FFALIGN(new_size, ctx->caps.minBitstreamBufferSizeAlignment); slice_off = av_fast_realloc(vp->slice_off, &vp->slice_off_max, (nb + 1)*sizeof(slice_off)); @@ -295,7 +294,6 @@ int ff_vk_decode_frame(AVCodecContext *avctx, FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; - FFVulkanDecodeProfileData *prof = &ctx->profile_data; FFVulkanFunctions *vk = &ctx->s.vkfn; /* Output */ @@ -319,7 +317,7 @@ int ff_vk_decode_frame(AVCodecContext *avctx, VkImageMemoryBarrier2 img_bar[37]; int nb_img_bar = 0; size_t data_size = FFALIGN(vp->slices_size, - prof->caps.minBitstreamBufferSizeAlignment); + ctx->caps.minBitstreamBufferSizeAlignment); FFVkExecContext *exec = ff_vk_exec_get(&ctx->exec_pool); @@ -640,10 +638,10 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx, VkVideoDecodeH264CapabilitiesKHR *h264_caps, VkVideoDecodeH265CapabilitiesKHR *h265_caps, VkVideoDecodeAV1CapabilitiesMESA *av1_caps, + VkVideoCapabilitiesKHR *caps, + VkVideoDecodeCapabilitiesKHR *dec_caps, int cur_profile) { - VkVideoCapabilitiesKHR *caps = &prof->caps; - VkVideoDecodeCapabilitiesKHR *dec_caps = &prof->dec_caps; VkVideoDecodeUsageInfoKHR *usage = &prof->usage; VkVideoProfileInfoKHR *profile = &prof->profile; VkVideoProfileListInfoKHR *profile_list = &prof->profile_list; @@ -703,6 +701,7 @@ static VkResult vulkan_setup_profile(AVCodecContext *avctx, static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ref, enum AVPixelFormat *pix_fmt, VkFormat *vk_fmt, + FFVulkanDecodeProfileData *prof, int *dpb_dedicate) { VkResult ret; @@ -719,9 +718,8 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; FFVulkanFunctions *vk = &ctx->s.vkfn; - FFVulkanDecodeProfileData *prof = &ctx->profile_data; - VkVideoCapabilitiesKHR *caps = &prof->caps; - VkVideoDecodeCapabilitiesKHR *dec_caps = &prof->dec_caps; + VkVideoCapabilitiesKHR *caps = &ctx->caps; + VkVideoDecodeCapabilitiesKHR *dec_caps = &ctx->dec_caps; VkVideoDecodeH264CapabilitiesKHR h264_caps = { .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_CAPABILITIES_KHR, @@ -760,6 +758,8 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ &h264_caps, &h265_caps, &av1_caps, + caps, + dec_caps, cur_profile); if (ret == VK_ERROR_VIDEO_PROFILE_OPERATION_NOT_SUPPORTED_KHR && avctx->flags & AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH && @@ -774,6 +774,8 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ &h264_caps, &h265_caps, &av1_caps, + caps, + dec_caps, cur_profile); } @@ -967,8 +969,8 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx) AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data; AVVulkanFramesContext *hwfc = frames_ctx->hwctx; FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; - FFVulkanDecodeShared *ctx; FFVulkanDecodeProfileData *prof; + AVBufferRef *prof_ref; frames_ctx->sw_format = AV_PIX_FMT_NONE; @@ -976,15 +978,19 @@ int ff_vk_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx) if (err < 0) return err; - ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; - prof = &ctx->profile_data; + prof_ref = av_buffer_allocz(sizeof(*prof)); + if (!prof_ref) + return AVERROR(ENOMEM); + + prof = (FFVulkanDecodeProfileData *)prof_ref->data; err = vulkan_decode_get_profile(avctx, hw_frames_ctx, &frames_ctx->sw_format, &vkfmt, - &dedicated_dpb); + prof, &dedicated_dpb); if (err < 0) return err; + frames_ctx->opaque = prof_ref; frames_ctx->width = avctx->width; frames_ctx->height = avctx->height; frames_ctx->format = AV_PIX_FMT_VULKAN; @@ -1027,10 +1033,10 @@ int ff_vk_decode_init(AVCodecContext *avctx) VkResult ret; FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; FFVulkanDecodeShared *ctx; - FFVulkanDecodeProfileData *prof; FFVulkanContext *s; FFVulkanFunctions *vk; FFVkQueueFamilyCtx qf_dec; + const VkVideoProfileListInfoKHR *profile_list; VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = { .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR, @@ -1064,7 +1070,6 @@ int ff_vk_decode_init(AVCodecContext *avctx) /* Initialize contexts */ ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; - prof = &ctx->profile_data; s = &ctx->s; vk = &ctx->s.vkfn; @@ -1075,6 +1080,13 @@ int ff_vk_decode_init(AVCodecContext *avctx) s->device = (AVHWDeviceContext *)s->frames->device_ref->data; s->hwctx = s->device->hwctx; + profile_list = ff_vk_find_struct(s->hwfc->create_pnext, + VK_STRUCTURE_TYPE_VIDEO_PROFILE_LIST_INFO_KHR); + if (!profile_list) { + av_log(avctx, AV_LOG_ERROR, "Profile list missing from frames context!"); + return AVERROR(EINVAL); + } + err = ff_vk_load_props(s); if (err < 0) goto fail; @@ -1096,13 +1108,13 @@ int ff_vk_decode_init(AVCodecContext *avctx) session_create.flags = 0x0; session_create.queueFamilyIndex = s->hwctx->queue_family_decode_index; - session_create.maxCodedExtent = prof->caps.maxCodedExtent; - session_create.maxDpbSlots = prof->caps.maxDpbSlots; - session_create.maxActiveReferencePictures = prof->caps.maxActiveReferencePictures; + session_create.maxCodedExtent = ctx->caps.maxCodedExtent; + session_create.maxDpbSlots = ctx->caps.maxDpbSlots; + session_create.maxActiveReferencePictures = ctx->caps.maxActiveReferencePictures; session_create.pictureFormat = s->hwfc->format[0]; session_create.referencePictureFormat = session_create.pictureFormat; session_create.pStdHeaderVersion = dec_ext[avctx->codec_id]; - session_create.pVideoProfile = &prof->profile_list.pProfiles[0]; + session_create.pVideoProfile = &profile_list->pProfiles[0]; /* Create decode exec context. * 2 async contexts per thread was experimentally determined to be optimal @@ -1147,14 +1159,14 @@ int ff_vk_decode_init(AVCodecContext *avctx) dpb_frames->height = s->frames->height; dpb_hwfc = dpb_frames->hwctx; - dpb_hwfc->create_pnext = (void *)&prof->profile_list; + dpb_hwfc->create_pnext = (void *)profile_list; dpb_hwfc->format[0] = s->hwfc->format[0]; dpb_hwfc->tiling = VK_IMAGE_TILING_OPTIMAL; dpb_hwfc->usage = VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR | VK_IMAGE_USAGE_SAMPLED_BIT; /* Shuts validator up. */ if (dec->layered_dpb) - dpb_hwfc->nb_layers = prof->caps.maxDpbSlots; + dpb_hwfc->nb_layers = ctx->caps.maxDpbSlots; err = av_hwframe_ctx_init(ctx->dpb_hwfc_ref); if (err < 0) diff --git a/libavcodec/vulkan_decode.h b/libavcodec/vulkan_decode.h index 681d2476cd..3ac103f6b4 100644 --- a/libavcodec/vulkan_decode.h +++ b/libavcodec/vulkan_decode.h @@ -26,8 +26,6 @@ #include "vulkan_video.h" typedef struct FFVulkanDecodeProfileData { - VkVideoCapabilitiesKHR caps; - VkVideoDecodeCapabilitiesKHR dec_caps; VkVideoDecodeH264ProfileInfoKHR h264_profile; VkVideoDecodeH264ProfileInfoKHR h265_profile; VkVideoDecodeAV1ProfileInfoMESA av1_profile; @@ -40,7 +38,9 @@ typedef struct FFVulkanDecodeShared { FFVulkanContext s; FFVkVideoCommon common; FFVkExecPool exec_pool; - FFVulkanDecodeProfileData profile_data; + + VkVideoCapabilitiesKHR caps; + VkVideoDecodeCapabilitiesKHR dec_caps; AVBufferRef *dpb_hwfc_ref; /* Only used for dedicated_dpb */ -- 2.40.1 From patchwork Tue Jun 13 04:20:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42055 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp3425210pzb; Mon, 12 Jun 2023 21:20:29 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7JXBK8aaWBNVc+8cQVg2nrVKLVVgI+YPdOEp87UfCCgq5rt1/3Rh6wsVY2S0z5SaVEMJnk X-Received: by 2002:aa7:c988:0:b0:514:9239:49f2 with SMTP id c8-20020aa7c988000000b00514923949f2mr6957574edt.37.1686630029474; Mon, 12 Jun 2023 21:20:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686630029; cv=none; d=google.com; s=arc-20160816; b=vnrNDZ/7x9N9wQxMoKSDF+/bKyyYWmMJBKzTTPwsIOCppXYgGQBrDATD3e1Uyt4QpF 0ZBwnqqSP1UUk2dsjgJWXj/QHWf1b/oollZ8XQZu2ndle1klWbgAmIn1csV+aeX1IfEp TuD7KnJFtKLN46Cy1QudCkyY7hdxMcwwQW5pRdNlwv0vO1vwWDaxr01p62zl3qc2sh8x VGsYEPdyokiifqyNKVMtLjnHeWXpCyB8sCtDsOLtiAQ7FpuQQqZbuww1Q9Vr3lV8txPc ZWq+TvwwD6FEqOzNQtbaFCPzSVeEmiT74XxwyuGWsk7ikFv3L4OGP5hKGYdZxdwTilFi neSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=A7Nz2mT737N541n00ooB3sXaxEpvHrw9sGXv9JhR1kQ=; b=bUCcpZ5Q9uMhW5iz9/7LGhwWeSuyqKRNbQoshziP0IaUBLCo8fePEzt+oImwwM8JGR 1Lw1YuNL7kqsdwgBjJy223OpekycD8YYMe6i8UkPT6+0q/YjsebTUPFd4POYmuQ9YHTB 0sNWcaEHdfCUF9gKr94a6a1b49530PRiNwO+Y8uNzdPQbuXeGX33eQwrSuID5y9/AB5j n/oMnFrSMjFZ+0m12MpBf1pO0t5AYjrTPQBmqqgM1DZNopE9IX8my12OyhGvbn81TBDN tpSAr5iV/y/Ht1I+E8BSX7KFs5Up4a6WQoUp03kQS8dCRtTecBToduOWG31cVlpVUaEV G+HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=pjRzChCa; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t9-20020aa7d4c9000000b00514ab8a6c74si7110297edr.648.2023.06.12.21.20.29; Mon, 12 Jun 2023 21:20:29 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=pjRzChCa; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D0ABA68C390; Tue, 13 Jun 2023 07:20:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 76C9868C33F for ; Tue, 13 Jun 2023 07:20:20 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 8574E1060154 for ; Tue, 13 Jun 2023 04:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686630020; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=nIxvLWS4m1ZkdCOs8e5tsM2cTsDyLLNgiyrodKg7SY4=; b=pjRzChCaunmFweDThHYeX+koiIfvK8wjobvEU/VTuvqWIXRUT9Bbch/+zhxB5sfp 6E7u8ofI1jXUMN0mJDflSPBOcw0QLNo4NxRVhgLbi02VhNTik1BxoijyQ5t/xzSBHS5 hapRBT4x50mjVghBDdpwZ8wUHCEwEywjbAkK1z/pPZG3fHav+ocU9P+jtGMAJhOFnkS jyoWKvgariTel9pc436Qzf4gRM9wNWJ9fgMJ+4q3fjTkxFI+DKvBq442G7U9xrXq7QX +HN8iDA3KG4o12n3S1e9zJq5/EUHVlC9QBP+ru9+iqgcZuq/uEyMJ9c74j8kW4iREjw sEgOk+y3Wg== Date: Tue, 13 Jun 2023 06:20:20 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] hwcontext_vulkan: call ff_vk_uninit() on device uninit X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HbQm61VVta29 This fixes three memory leaks from ff_vk_load_props(). Does not depend on any other patches. Patch attached. From 75945869e8341058edd1fca72b9ccf46d0086ddc Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 04:35:29 +0200 Subject: [PATCH 3/5] hwcontext_vulkan: call ff_vk_uninit() on device uninit This fixes three memory leaks from ff_vk_load_props(). --- libavutil/hwcontext_vulkan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 1132a61390..c86229ba65 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -1176,6 +1176,8 @@ static void vulkan_device_free(AVHWDeviceContext *ctx) RELEASE_PROPS(hwctx->enabled_inst_extensions, hwctx->nb_enabled_inst_extensions); RELEASE_PROPS(hwctx->enabled_dev_extensions, hwctx->nb_enabled_dev_extensions); + + ff_vk_uninit(&p->vkctx); } static int vulkan_device_create_internal(AVHWDeviceContext *ctx, -- 2.40.1 From patchwork Tue Jun 13 04:21:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42053 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp3425429pzb; Mon, 12 Jun 2023 21:21:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hd/e6QOxV6l4r5QqUX2Xxb2NqEWpoQyr37AcxhnxV9aEjDoKyxHEnlYrI0B/v3zlmUPrl X-Received: by 2002:a17:907:2d0f:b0:965:6075:d0e1 with SMTP id gs15-20020a1709072d0f00b009656075d0e1mr12279009ejc.72.1686630078656; Mon, 12 Jun 2023 21:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686630078; cv=none; d=google.com; s=arc-20160816; b=Sg/bqBQ35EiYnBzWMpanqjBfoZtBbie37x2IaGzxHkvlsqsA5fLdHLk3+y0y6ctCzU vngcgKFlUvILmi4HwNc7KgH6FmJEWoUMr53GYex6fwMjRYLI0OoLSSeNH55k1zAeObsQ k1gZ5txesond7Q0141/y4UrAQxiGL+d29x6zTMRG+LzrZczCGdGEuhLZpt85497gH++I eKOkXFpjS6zt0bhUcFBH4HbpNCwi6gWLste0RzzxkvulJzFs9FVuOADnLreoNg+ja2ul VwJhIZt+N9PavxKzoGIi1kkHO1BS/+YZgjI8Kk2bMj1QpK5IEEbmD0j83df5rjaOTAtu LTKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=p6b3NBUzCL6o6+ZdBfGQGEX1h79tCgb+GGFqcvTnRZA=; b=KDlpdCbPkXK4FAVhGg4DaiJMPc/r69+D8Nx7MRmrWlG0/kz2jxx21mNAh44zQpwF++ d1AGF1q7DfEs16+pMRAnS93gBFxfuoNQ2s43iLctv9gg+UTZaKYJy7NEa1fs+nCofa+m DqLWzkPXSAyUCqGuTVXTQvB6MKjTT5eYZ/7gTA6Yj1N1PCBpO7R9i97tOVae4CKtrFBN QBDFvIMs59hTP2zgFtqKswDpo/NSXs0RdaJB6juff4tSdzgqQKSykmmEcK84uV4KxqSN crdqkXTDuGL5eSs/E55IwfHw83bQRupLGFzWZqDnGqz8GLT0NtZDzO8Pp6a3ZzLVDUeI 1A3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=W0NQw0HJ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r4-20020a1709062cc400b009722bcd89fesi5704984ejr.543.2023.06.12.21.21.17; Mon, 12 Jun 2023 21:21:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=W0NQw0HJ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0A8C468C37B; Tue, 13 Jun 2023 07:21:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 623AA68C37B for ; Tue, 13 Jun 2023 07:21:08 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 709E710601E3 for ; Tue, 13 Jun 2023 04:21:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686630068; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=Gx2x+3xHhaHrq+SXFL+nGfl6nGbPXxrHSLUbQDEHjhI=; b=W0NQw0HJBYm0q3LBexu/KAt5CYHI4wLH4g1BXZyT8N/Nl4ORdRQ7AqXHaZ6ahlk1 g6n8W1fc2SkoIhlgaLP0/6s3X8uQdMdzZoteSxrNRdXhITHtsQbza8aUutwewb58zJw ZZCQPK1hKsUk2FpRlrYTazRqUiAOSSAkHNa4p+A2e7aQijn58byXOhOfsIUHpZZiqBc k2Y2GTCO8z144l5/y9N+boIiCH5CHADrsEVRvu6WbX28CAMu9dCa3qnIal/2MITJaCW X+H01OGXgQNwWS4G+BNEUTk4FnQkpcarkks3lSTLnCqrp1/xNb/daMfhORhZiOXZYGF o9OkZ1qlKg== Date: Tue, 13 Jun 2023 06:21:08 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] hwcontext_vulkan: free temporary array once unneeded X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: H2eP52mdXlvU Fixes a small memory leak. This also prevents leaks on malloc/mutex init errors. Does not depend on any other patches. Patch attached. From 52cdd121f986d36d18b95077f9c748bc9d7d918d Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 04:36:54 +0200 Subject: [PATCH 4/5] hwcontext_vulkan: free temporary array once unneeded Fixes a small memory leak. This also prevents leaks on malloc/mutex init errors. --- libavutil/hwcontext_vulkan.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index c86229ba65..ca802cc86e 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -1427,24 +1427,31 @@ static int vulkan_device_init(AVHWDeviceContext *ctx) vk->GetPhysicalDeviceQueueFamilyProperties(hwctx->phys_dev, &qf_num, qf); p->qf_mutex = av_calloc(qf_num, sizeof(*p->qf_mutex)); - if (!p->qf_mutex) + if (!p->qf_mutex) { + av_free(qf); return AVERROR(ENOMEM); + } p->nb_tot_qfs = qf_num; for (uint32_t i = 0; i < qf_num; i++) { p->qf_mutex[i] = av_calloc(qf[i].queueCount, sizeof(**p->qf_mutex)); - if (!p->qf_mutex[i]) + if (!p->qf_mutex[i]) { + av_free(qf); return AVERROR(ENOMEM); + } for (uint32_t j = 0; j < qf[i].queueCount; j++) { err = pthread_mutex_init(&p->qf_mutex[i][j], NULL); if (err != 0) { av_log(ctx, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", av_err2str(err)); + av_free(qf); return AVERROR(err); } } } + av_free(qf); + graph_index = hwctx->queue_family_index; comp_index = hwctx->queue_family_comp_index; tx_index = hwctx->queue_family_tx_index; -- 2.40.1 From patchwork Tue Jun 13 04:24:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 42056 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp3426301pzb; Mon, 12 Jun 2023 21:24:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VXH+8zRhWw/kNNzeFOPsQUyLxYPiuWE6mlyFbZQZ3M8SxfxQWlt+3+FMvNvVNr0bdpt37 X-Received: by 2002:aa7:cd10:0:b0:514:9e81:9068 with SMTP id b16-20020aa7cd10000000b005149e819068mr6024811edw.13.1686630258250; Mon, 12 Jun 2023 21:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686630258; cv=none; d=google.com; s=arc-20160816; b=bdURuCFvaeR2pZPbUUVXXeZmJlYccwDWnLAp2jSeob7Gt1EIwdvgGoL9NRy9N5i02E Az+b9LBD1O+mTVWLmFCfJCaflzaG2EgKU5rVtSDeKI/Do5DDEK5TrRqZBPDF4CH8MT6I jrf8dP+armKqMXz1YL+VhY6XP6+CTcEUdeDlSPVVqTU2VCv9Jqew2cDEAaylMJjs8QJM Y74tzD6NIdUGdrhu8RBURD7Msn7AbzPD0J03GtrMBwTwB2Rri5oah9l2NJF5vhszCldB ntLTiGa1tdwCF6wxkVvPX6VNfy/ZO6q2c3smIYiOocJTkr9Ykt0JJNcTkm76FsvW6EGI A1dA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:to:from:date :dkim-signature:delivered-to; bh=PqRx9k89CZowNIFnJeKR2dm3rTW629o1u6fOPe4K7Yo=; b=H7VPEmdugmcyzRBNBzNxl9HIIKvElv7Ynds0oJ5waF1KdJflLCTPoWXcp7p+ziGzs0 XFo32/RzSXULyPVB6yD715ahGz9j2Tlzt3ENCmOLxExH119DM6uJLECS+w8jFNzdK3C7 8DUp6KVytvtwAeo1oAuLfkhbsAWgKJO/lbQ3dl44RrxAl0h9synIsTLtm/mli8aKnc7l iGAAiErUTDwSHIdC1d9gFWNr9T6msU60Cq5KraGqJMlPOIuPKMdznTuZ9wTn2htr9sbc F73/aYfzDl4ZKw0GMXgupb39wLnfEN29PuIRt7oi0Oy7ycB8+0KIrFkBkDKu+YpUK/f4 EN2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=H8gjCE7x; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w16-20020aa7d290000000b005187942d065si146192edq.692.2023.06.12.21.24.17; Mon, 12 Jun 2023 21:24:18 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@lynne.ee header.s=s1 header.b=H8gjCE7x; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=lynne.ee Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 38B3E68C37B; Tue, 13 Jun 2023 07:24:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from w4.tutanota.de (w4.tutanota.de [81.3.6.165]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 722B768AD1B for ; Tue, 13 Jun 2023 07:24:08 +0300 (EEST) Received: from tutadb.w10.tutanota.de (unknown [192.168.1.10]) by w4.tutanota.de (Postfix) with ESMTP id 806511060154 for ; Tue, 13 Jun 2023 04:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1686630248; s=s1; d=lynne.ee; h=From:From:To:To:Subject:Subject:Content-Description:Content-ID:Content-Type:Content-Type:Content-Transfer-Encoding:Cc:Date:Date:In-Reply-To:In-Reply-To:MIME-Version:MIME-Version:Message-ID:Message-ID:Reply-To:References:References:Sender; bh=BhjxIVuKjeFe56A8wlI6ncK1/hawDxzO28dpC2Bo6s8=; b=H8gjCE7xTYZhQ8FylRypTKLxycaV1oZrmOAOmyEheKE7TXkDO+UbKoFHUTFfXYZi ZcBGIC2acfvM31mXtze55XsZn6fOJYGXiCF58SwsyAQDy0l+olhfshJ9xOcaKN1cLFP eMI4lhc7fyUfBnrsxD7cva9Q+xqymwegfP++wFKidOlJbUxY3VJW9Yp3nVP/Xr7puQW MvSImdl7SHKRd9BBcXcmof5ipWUZheyxzeDZ/p5+h3P8yIhGCcmdfD2HXjCvhiCOyEa QSVeulmcjtF+279cpz/+k/aSyF2UCG0iivfwpFiyMOOdJn2j2xZSqwFkaZGuwu+g1mY 2BMFTVXOTw== Date: Tue, 13 Jun 2023 06:24:08 +0200 (CEST) From: Lynne To: FFmpeg development discussions and patches Message-ID: In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] vulkan_decode: fix small memory leak X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Xr9J5RRW2jW2 This small memory leak was essentially responsible for keeping decoding working at all. The issue is that the codec profile must be attached to the frames context. We created the codec profile at decoder creation time. Which meant that if the decoder was destroyed, the context became essentially useless, and segfaulted as the profile was a hanging pointer. This was an issue that happened when seeking through H264. This requires using the new AVHWFramesContext.opaque field, as otherwise, the profile attached to the decoder will be freed before the frames context, rendering the frames context useless. Patch attached. From 7d8f1c73308dd29dbf2d46dc09d85808aa1cc6be Mon Sep 17 00:00:00 2001 From: Lynne Date: Tue, 13 Jun 2023 06:13:10 +0200 Subject: [PATCH 5/5] vulkan_decode: fix small memory leak This requires using the new AVHWFramesContext.opaque field, as otherwise, the profile attached to the decoder will be freed before the frames context, rendering the frames context useless. --- libavcodec/vulkan_decode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index 81085273d8..5aad8b213b 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -584,6 +584,8 @@ static void free_common(void *opaque, uint8_t *data) s->hwctx->alloc); ff_vk_uninit(s); + + av_free(ctx); } static int vulkan_decode_bootstrap(AVCodecContext *avctx, AVBufferRef *frames_ref) -- 2.40.1