* [FFmpeg-devel] [PATCH] avcodec/amf: fix hw_device_ctx handling (PR #20979)
@ 2025-11-20 12:39 ArazIusubov via ffmpeg-devel
0 siblings, 0 replies; only message in thread
From: ArazIusubov via ffmpeg-devel @ 2025-11-20 12:39 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: ArazIusubov
PR #20979 opened by ArazIusubov
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20979
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20979.patch
The current behavior allows creating a second AMF hw_device_ctx, which may lead to incorrect behavior or failures.
This patch fixes that assumption and prevents multiple hardware device contexts from being created.
>From cc26a2ff1054987bd0647fa4e698e85605c984be Mon Sep 17 00:00:00 2001
From: Araz Iusubov <Primeadvice@gmail.com>
Date: Thu, 20 Nov 2025 13:34:21 +0100
Subject: [PATCH] avcodec/amf: fix hw_device_ctx handling
---
libavcodec/amfdec.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/libavcodec/amfdec.c b/libavcodec/amfdec.c
index 1a2eb9392c..eb182114fa 100644
--- a/libavcodec/amfdec.c
+++ b/libavcodec/amfdec.c
@@ -274,15 +274,17 @@ static int amf_decode_init(AVCodecContext *avctx)
if (!ctx->in_pkt)
return AVERROR(ENOMEM);
- if (avctx->hw_device_ctx && !avctx->hw_frames_ctx) {
+ if (avctx->hw_device_ctx) {
AVHWDeviceContext *hwdev_ctx;
hwdev_ctx = (AVHWDeviceContext*)avctx->hw_device_ctx->data;
if (hwdev_ctx->type == AV_HWDEVICE_TYPE_AMF)
{
ctx->device_ctx_ref = av_buffer_ref(avctx->hw_device_ctx);
- avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
-
- AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n");
+ if (!avctx->hw_frames_ctx)
+ {
+ avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
+ AMF_GOTO_FAIL_IF_FALSE(avctx, !!avctx->hw_frames_ctx, AVERROR(ENOMEM), "av_hwframe_ctx_alloc failed\n");
+ }
} else {
ret = av_hwdevice_ctx_create_derived(&ctx->device_ctx_ref, AV_HWDEVICE_TYPE_AMF, avctx->hw_device_ctx, 0);
AMF_GOTO_FAIL_IF_FALSE(avctx, ret == 0, ret, "Failed to create derived AMF device context: %s\n", av_err2str(ret));
--
2.49.1
_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-11-20 12:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-20 12:39 [FFmpeg-devel] [PATCH] avcodec/amf: fix hw_device_ctx handling (PR #20979) ArazIusubov via ffmpeg-devel
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git