diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-09-15 00:29:58 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2023-09-15 02:38:22 +0200 |
commit | c1b6235d4158b3771e2a2ee7d5754477df7edc59 (patch) | |
tree | dd6f21ba33aaf14f352f2437ec04fb974291e2af /libavcodec/vulkan_av1.c | |
parent | dfac782b13fc607f7b18067635b07bbcabc4db8f (diff) | |
download | ffmpeg-c1b6235d4158b3771e2a2ee7d5754477df7edc59.tar.gz |
avcodec/vulkan_decode: Factor creating session params out, fix leak
All Vulkan HWAccels share the same boilerplate code for creating
session params and this includes a common bug: In case actually
creating the video session parameters fails, the buffer destined
to hold them leaks; in case of HEVC this is also true if
get_data_set_buf() fails.
This commit factors this code out and fixes the leak.
Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec/vulkan_av1.c')
-rw-r--r-- | libavcodec/vulkan_av1.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index adaebb2818..b1373722ef 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -104,12 +104,9 @@ static int vk_av1_fill_pict(AVCodecContext *avctx, const AV1Frame **ref_src, static int vk_av1_create_params(AVCodecContext *avctx, AVBufferRef **buf) { - VkResult ret; - const AV1DecContext *s = avctx->priv_data; FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data; FFVulkanDecodeShared *ctx = (FFVulkanDecodeShared *)dec->shared_ref->data; - FFVulkanFunctions *vk = &ctx->s.vkfn; const AV1RawSequenceHeader *seq = s->raw_seq; @@ -118,10 +115,7 @@ static int vk_av1_create_params(AVCodecContext *avctx, AVBufferRef **buf) VkVideoDecodeAV1SessionParametersCreateInfoMESA av1_params; VkVideoSessionParametersCreateInfoKHR session_params_create; - AVBufferRef *tmp; - VkVideoSessionParametersKHR *par = av_malloc(sizeof(*par)); - if (!par) - return AVERROR(ENOMEM); + int err; av1_sequence_header = (StdVideoAV1MESASequenceHeader) { .flags = (StdVideoAV1MESASequenceHeaderFlags) { @@ -189,26 +183,12 @@ static int vk_av1_create_params(AVCodecContext *avctx, AVBufferRef **buf) .videoSessionParametersTemplate = NULL, }; - /* Create session parameters */ - ret = vk->CreateVideoSessionParametersKHR(ctx->s.hwctx->act_dev, &session_params_create, - ctx->s.hwctx->alloc, par); - if (ret != VK_SUCCESS) { - av_log(avctx, AV_LOG_ERROR, "Unable to create Vulkan video session parameters: %s!\n", - ff_vk_ret2str(ret)); - return AVERROR_EXTERNAL; - } - - tmp = av_buffer_create((uint8_t *)par, sizeof(*par), ff_vk_decode_free_params, - ctx, 0); - if (!tmp) { - ff_vk_decode_free_params(ctx, (uint8_t *)par); - return AVERROR(ENOMEM); - } + err = ff_vk_decode_create_params(buf, avctx, ctx, &session_params_create); + if (err < 0) + return err; av_log(avctx, AV_LOG_DEBUG, "Created frame parameters\n"); - *buf = tmp; - return 0; } |