diff mbox series

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

Message ID 20220111065538.750653-2-wenbin.chen@intel.com
State Accepted
Commit 4cc7239d8bf812387200dd54c0d1120ff68c2bce
Headers show
Series [FFmpeg-devel,V5,1/2] libavcodec/vaapi_decode: fix the problem that init_pool_size < nb_surface | expand

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
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Chen, Wenbin Jan. 11, 2022, 6:55 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 | 14 +++++++++++++-
 libavutil/hwcontext_qsv.c    | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

Comments

Chen, Wenbin Jan. 20, 2022, 7:21 a.m. UTC | #1
> 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 | 14 +++++++++++++-
>  libavutil/hwcontext_qsv.c    | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index 26a3a24593..4e2ab18ede 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -72,6 +72,12 @@
>  #include "hwcontext_drm.h"
>  #endif
> 
> +#if HAVE_OPENCL_VAAPI_INTEL_MEDIA && CONFIG_LIBMFX
> +extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                          enum AVHWDeviceType base_dev_typ,
> +                                          void **base_handle);
> +#endif
> +
> 
>  typedef struct OpenCLDeviceContext {
>      // Default command queue to use for transfer/mapping operations on
> @@ -2248,8 +2254,14 @@ static int
> opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
> 
>  #if CONFIG_LIBMFX
>      if (src->format == AV_PIX_FMT_QSV) {
> +        void *base_handle;
>          mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->data[3];
> -        va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
> +        err = ff_qsv_get_surface_base_handle(mfx_surface,
> +                                             AV_HWDEVICE_TYPE_VAAPI,
> +                                             &base_handle);
> +        if (err < 0)
> +            return err;
> +        va_surface = *(VASurfaceID *)base_handle;
>      } else
>  #endif
>          if (src->format == AV_PIX_FMT_VAAPI) {
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 853fb7f60d..6d9b8324c2 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -112,6 +112,40 @@ static const struct {
>  #endif
>  };
> 
> +extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                          enum AVHWDeviceType base_dev_type,
> +                                          void **base_handle);
> +
> +/**
> + * Caller needs to allocate enough space for base_handle pointer.
> + **/
> +int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                   enum AVHWDeviceType base_dev_type,
> +                                   void **base_handle)
> +{
> +    mfxHDLPair *handle_pair;
> +    handle_pair = surf->Data.MemId;
> +    switch (base_dev_type) {
> +#if CONFIG_VAAPI
> +    case AV_HWDEVICE_TYPE_VAAPI:
> +        base_handle[0] = handle_pair->first;
> +        return 0;
> +#endif
> +#if CONFIG_D3D11VA
> +    case AV_HWDEVICE_TYPE_D3D11VA:
> +        base_handle[0] = handle_pair->first;
> +        base_handle[1] = handle_pair->secode;
> +        return 0;
> +#endif
> +#if CONFIG_DXVA2
> +    case AV_HWDEVICE_TYPE_DXVA2:
> +        base_handle[0] = handle_pair->first;
> +        return 0;
> +#endif
> +    }
> +    return AVERROR(EINVAL);
> +}
> +
>  static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
>  {
>      int i;
> --
> 2.25.1
> 

ping

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Xiang, Haihao Jan. 27, 2022, 5:35 a.m. UTC | #2
On Tue, 2022-01-11 at 14:55 +0800, Wenbin Chen wrote:
> 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 | 14 +++++++++++++-
>  libavutil/hwcontext_qsv.c    | 34 ++++++++++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+), 1 deletion(-)
> 
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index 26a3a24593..4e2ab18ede 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -72,6 +72,12 @@
>  #include "hwcontext_drm.h"
>  #endif
>  
> +#if HAVE_OPENCL_VAAPI_INTEL_MEDIA && CONFIG_LIBMFX
> +extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                          enum AVHWDeviceType base_dev_typ,
> +                                          void **base_handle);
> +#endif
> +
>  
>  typedef struct OpenCLDeviceContext {
>      // Default command queue to use for transfer/mapping operations on
> @@ -2248,8 +2254,14 @@ static int opencl_map_from_qsv(AVHWFramesContext
> *dst_fc, AVFrame *dst,
>  
>  #if CONFIG_LIBMFX
>      if (src->format == AV_PIX_FMT_QSV) {
> +        void *base_handle;
>          mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->data[3];
> -        va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
> +        err = ff_qsv_get_surface_base_handle(mfx_surface,
> +                                             AV_HWDEVICE_TYPE_VAAPI,
> +                                             &base_handle);
> +        if (err < 0)
> +            return err;
> +        va_surface = *(VASurfaceID *)base_handle;
>      } else
>  #endif
>          if (src->format == AV_PIX_FMT_VAAPI) {
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 853fb7f60d..6d9b8324c2 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -112,6 +112,40 @@ static const struct {
>  #endif
>  };
>  
> +extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                          enum AVHWDeviceType base_dev_type,
> +                                          void **base_handle);
> +
> +/**
> + * Caller needs to allocate enough space for base_handle pointer.
> + **/
> +int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
> +                                   enum AVHWDeviceType base_dev_type,
> +                                   void **base_handle)
> +{
> +    mfxHDLPair *handle_pair;
> +    handle_pair = surf->Data.MemId;
> +    switch (base_dev_type) {
> +#if CONFIG_VAAPI
> +    case AV_HWDEVICE_TYPE_VAAPI:
> +        base_handle[0] = handle_pair->first;
> +        return 0;
> +#endif
> +#if CONFIG_D3D11VA
> +    case AV_HWDEVICE_TYPE_D3D11VA:
> +        base_handle[0] = handle_pair->first;
> +        base_handle[1] = handle_pair->secode;
> +        return 0;
> +#endif
> +#if CONFIG_DXVA2
> +    case AV_HWDEVICE_TYPE_DXVA2:
> +        base_handle[0] = handle_pair->first;
> +        return 0;
> +#endif
> +    }
> +    return AVERROR(EINVAL);
> +}
> +
>  static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
>  {
>      int i;

LGTM, will apply

-Haihao
diff mbox series

Patch

diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 26a3a24593..4e2ab18ede 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -72,6 +72,12 @@ 
 #include "hwcontext_drm.h"
 #endif
 
+#if HAVE_OPENCL_VAAPI_INTEL_MEDIA && CONFIG_LIBMFX
+extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
+                                          enum AVHWDeviceType base_dev_typ,
+                                          void **base_handle);
+#endif
+
 
 typedef struct OpenCLDeviceContext {
     // Default command queue to use for transfer/mapping operations on
@@ -2248,8 +2254,14 @@  static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
 
 #if CONFIG_LIBMFX
     if (src->format == AV_PIX_FMT_QSV) {
+        void *base_handle;
         mfxFrameSurface1 *mfx_surface = (mfxFrameSurface1*)src->data[3];
-        va_surface = *(VASurfaceID*)mfx_surface->Data.MemId;
+        err = ff_qsv_get_surface_base_handle(mfx_surface,
+                                             AV_HWDEVICE_TYPE_VAAPI,
+                                             &base_handle);
+        if (err < 0)
+            return err;
+        va_surface = *(VASurfaceID *)base_handle;
     } else
 #endif
         if (src->format == AV_PIX_FMT_VAAPI) {
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 853fb7f60d..6d9b8324c2 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -112,6 +112,40 @@  static const struct {
 #endif
 };
 
+extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
+                                          enum AVHWDeviceType base_dev_type,
+                                          void **base_handle);
+
+/**
+ * Caller needs to allocate enough space for base_handle pointer.
+ **/
+int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
+                                   enum AVHWDeviceType base_dev_type,
+                                   void **base_handle)
+{
+    mfxHDLPair *handle_pair;
+    handle_pair = surf->Data.MemId;
+    switch (base_dev_type) {
+#if CONFIG_VAAPI
+    case AV_HWDEVICE_TYPE_VAAPI:
+        base_handle[0] = handle_pair->first;
+        return 0;
+#endif
+#if CONFIG_D3D11VA
+    case AV_HWDEVICE_TYPE_D3D11VA:
+        base_handle[0] = handle_pair->first;
+        base_handle[1] = handle_pair->secode;
+        return 0;
+#endif
+#if CONFIG_DXVA2
+    case AV_HWDEVICE_TYPE_DXVA2:
+        base_handle[0] = handle_pair->first;
+        return 0;
+#endif
+    }
+    return AVERROR(EINVAL);
+}
+
 static uint32_t qsv_fourcc_from_pix_fmt(enum AVPixelFormat pix_fmt)
 {
     int i;