PR #24112 opened by DmitriiGershenkop
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24112
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24112.patch

NOTICE: to be merged after #24077

Some filters in some versions of AMF can pick unexpected engine and output 
memory format if it is not enforced, which might have a negative effect on 
interoperability with different APIs.



>From 7e2b88ccaf9383e3f6fcac55b8c7cdc21ad0e4a2 Mon Sep 17 00:00:00 2001
From: Dmitrii Gershenkop <[email protected]>
Date: Wed, 12 Aug 2026 16:49:40 +0200
Subject: [PATCH] avfilter/vf_{vpp,sr,vqe}_amf: Enforce memory type

---
 libavfilter/vf_sr_amf.c  | 5 +++++
 libavfilter/vf_vpp_amf.c | 7 ++++++-
 libavfilter/vf_vqe_amf.c | 6 +++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/libavfilter/vf_sr_amf.c b/libavfilter/vf_sr_amf.c
index 8f3ae7ed80..17bfdc2a03 100644
--- a/libavfilter/vf_sr_amf.c
+++ b/libavfilter/vf_sr_amf.c
@@ -89,6 +89,7 @@ static int amf_filter_config_output(AVFilterLink *outlink)
     int err;
     AMF_RESULT res;
     enum AVPixelFormat in_format;
+    enum AMF_MEMORY_TYPE mem_type = AMF_MEMORY_UNKNOWN;
 
     err = amf_init_filter_config(outlink, &in_format);
     if (err < 0)
@@ -103,6 +104,10 @@ static int amf_filter_config_output(AVFilterLink *outlink)
     res = 
ctx->amf_device_ctx->factory->pVtbl->CreateComponent(ctx->amf_device_ctx->factory,
 ctx->amf_device_ctx->context, AMFHQScaler, &ctx->component);
     AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_FILTER_NOT_FOUND, 
"CreateComponent(%ls) failed with error %d\n", AMFHQScaler, res);
 
+    mem_type = av_amf_get_memory_type(ctx->amf_device_ctx);
+    if (mem_type != AMF_MEMORY_UNKNOWN)
+        AMF_ASSIGN_PROPERTY_INT64(res, ctx->component, 
AMF_HQ_SCALER_ENGINE_TYPE, mem_type);
+
     out_size.width = outlink->w;
     out_size.height = outlink->h;
     AMF_ASSIGN_PROPERTY_SIZE(res, ctx->component, AMF_HQ_SCALER_OUTPUT_SIZE, 
out_size);
diff --git a/libavfilter/vf_vpp_amf.c b/libavfilter/vf_vpp_amf.c
index e836cec68a..839a075ea7 100644
--- a/libavfilter/vf_vpp_amf.c
+++ b/libavfilter/vf_vpp_amf.c
@@ -90,6 +90,7 @@ static int amf_filter_config_output(AVFilterLink *outlink)
     const AVFrameSideData *sd;
     enum AMF_VIDEO_CONVERTER_COLOR_PROFILE_ENUM amf_color_profile;
     enum AVPixelFormat in_format;
+    enum AMF_MEMORY_TYPE mem_type = AMF_MEMORY_UNKNOWN;
 
     ret = amf_init_filter_config(outlink, &in_format);
     if (ret < 0)
@@ -98,7 +99,11 @@ static int amf_filter_config_output(AVFilterLink *outlink)
     hwframes_out = (AVHWFramesContext*)ctx->hwframes_out_ref->data;
     res = 
ctx->amf_device_ctx->factory->pVtbl->CreateComponent(ctx->amf_device_ctx->factory,
 ctx->amf_device_ctx->context, AMFVideoConverter, &ctx->component);
     AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_FILTER_NOT_FOUND, 
"CreateComponent(%ls) failed with error %d\n", AMFVideoConverter, res);
-    // FIXME: add checks whether we have HW context
+
+    mem_type = av_amf_get_memory_type(ctx->amf_device_ctx);
+    if (mem_type != AMF_MEMORY_UNKNOWN)
+        AMF_ASSIGN_PROPERTY_INT64(res, ctx->component, 
AMF_VIDEO_CONVERTER_MEMORY_TYPE, mem_type);
+
     AMF_ASSIGN_PROPERTY_INT64(res, ctx->component, 
AMF_VIDEO_CONVERTER_OUTPUT_FORMAT, 
(amf_int32)av_av_to_amf_format(hwframes_out->sw_format));
     AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, 
"AMFConverter-SetProperty() failed with error %d\n", res);
 
diff --git a/libavfilter/vf_vqe_amf.c b/libavfilter/vf_vqe_amf.c
index d7249d999b..74268283a2 100644
--- a/libavfilter/vf_vqe_amf.c
+++ b/libavfilter/vf_vqe_amf.c
@@ -94,6 +94,7 @@ static int amf_vqe_filter_config_output(AVFilterLink *outlink)
     AMFVQEFilterContext *vqe_ctx = avctx->priv;
     AMFFilterContext    *amf_ctx = &vqe_ctx->common;
     AVAMFDeviceContext  *device_ctx = NULL;
+    enum AMF_MEMORY_TYPE mem_type = AMF_MEMORY_UNKNOWN;
 
     int err;
     AMF_RESULT res;
@@ -110,8 +111,11 @@ static int amf_vqe_filter_config_output(AVFilterLink 
*outlink)
 
     amf_filter = amf_ctx->component;
 
-    if (vqe_ctx->engine_type != -1)
+    mem_type = av_amf_get_memory_type(device_ctx);
+    if (vqe_ctx->engine_type != -1) {
         AMF_ASSIGN_PROPERTY_INT64(res, amf_filter, 
AMF_VIDEO_ENHANCER_ENGINE_TYPE, vqe_ctx->engine_type);
+    } else if (mem_type != AMF_MEMORY_UNKNOWN)
+        AMF_ASSIGN_PROPERTY_INT64(res, amf_filter, 
AMF_VIDEO_ENHANCER_ENGINE_TYPE, mem_type);
 
     AMF_ASSIGN_PROPERTY_DOUBLE(res, amf_filter, AMF_VE_FCR_ATTENUATION, 
vqe_ctx->attenuation);
     AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "Failed to set 
VQ enhancer attenuation: %d\n", res);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to