diff mbox series

[FFmpeg-devel,V2,3/3] libavutil/hwcontext_opencl: fix a bug for mapping qsv frame to opencl

Message ID 20211130084406.758250-3-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel,V2,1/3] libavcodec/vaapi_decode: fix the problem that init_pool_size < nb_surface
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Wenbin Chen Nov. 30, 2021, 8:44 a.m. UTC
From: nyanmisaka <nst799610810@gmail.com>

mfxHDLPair was added to qsv, so modify qsv->opencl map function as well.
Now the following commandline works:

ffmpeg -v verbose -init_hw_device vaapi=va:/dev/dri/renderD128 \
-init_hw_device qsv=qs@va -init_hw_device opencl=ocl@va -filter_hw_device ocl \
-hwaccel qsv -hwaccel_output_format qsv -hwaccel_device qs -c:v h264_qsv \
-i input.264 -vf "hwmap=derive_device=opencl,format=opencl,avgblur_opencl, \
hwmap=derive_device=qsv:reverse=1:extra_hw_frames=32,format=qsv" \
-c:v h264_qsv output.264

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavutil/hwcontext_opencl.c | 3 ++-
 libavutil/hwcontext_qsv.h    | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 26a3a24593..ab812999cd 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -48,6 +48,7 @@ 
 #if HAVE_OPENCL_VAAPI_INTEL_MEDIA
 #if CONFIG_LIBMFX
 #include <mfx/mfxstructures.h>
+#include "hwcontext_qsv.h"
 #endif
 #include <va/va.h>
 #include <CL/cl_va_api_media_sharing_intel.h>
@@ -2249,7 +2250,7 @@  static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
 #if CONFIG_LIBMFX
     if (src->format == AV_PIX_FMT_QSV) {
         mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->data[3];
-        va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
+        va_surface = *MFXSURFACEP_TO_VASURFACEP(mfx_surface);
     } else
 #endif
         if (src->format == AV_PIX_FMT_VAAPI) {
diff --git a/libavutil/hwcontext_qsv.h b/libavutil/hwcontext_qsv.h
index b98d611cfc..957df01ef1 100644
--- a/libavutil/hwcontext_qsv.h
+++ b/libavutil/hwcontext_qsv.h
@@ -29,6 +29,11 @@ 
  * contain AVBufferRefs whose data pointer points to an mfxFrameSurface1 struct.
  */
 
+#if CONFIG_VAAPI
+#define MFXSURFACEP_TO_VASURFACEP(surf) \
+    (VASurfaceID*)(((mfxHDLPair*)surf->Data.MemId)->first)
+#endif
+
 /**
  * This struct is allocated as AVHWDeviceContext.hwctx
  */