[2/2] lavu/hwcontext_qsv: Add support for pix_fmt RGB32.

Message ID 1521452016-25232-2-git-send-email-zhong.li@intel.com
State New
Headers show
Series
  • [1/2] lavc/qsvdec: set complete_frame flags for non-interlaced frames.
Related show

Commit Message

Li, Zhong March 19, 2018, 9:33 a.m.
And support nv12/yuyv422/rgb32 formats for qsv_transfer_data

Signed-off-by: ChaoX A Liu <chaox.a.liu@intel.com>
Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavutil/hwcontext_qsv.c | 49 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 10 deletions(-)

Comments

Maxym Dmytrychenko March 19, 2018, 9:56 a.m. | #1
indentation can be adjusted ,
AV_PIX_FMT_YUYV422  - we add it but dont use?

On Mon, Mar 19, 2018 at 10:33 AM, Zhong Li <zhong.li@intel.com> wrote:

> And support nv12/yuyv422/rgb32 formats for qsv_transfer_data
>
> Signed-off-by: ChaoX A Liu <chaox.a.liu@intel.com>
> Signed-off-by: Zhong Li <zhong.li@intel.com>
> ---
>  libavutil/hwcontext_qsv.c | 49 ++++++++++++++++++++++++++++++
> +++++++----------
>  1 file changed, 39 insertions(+), 10 deletions(-)
>
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 5018a05..47afa48 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -90,6 +90,7 @@ static const struct {
>      uint32_t           fourcc;
>  } supported_pixel_formats[] = {
>      { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
> +    { AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
>      { AV_PIX_FMT_P010, MFX_FOURCC_P010 },
>      { AV_PIX_FMT_PAL8, MFX_FOURCC_P8   },
>  };
> @@ -730,6 +731,42 @@ static int qsv_transfer_data_child(AVHWFramesContext
> *ctx, AVFrame *dst,
>      return ret;
>  }
>
> +static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1
> *surface)
> +{
> +    switch (frame->format) {
> +        case AV_PIX_FMT_NV12:
> +            surface->Data.Y  = frame->data[0];
> +            surface->Data.UV = frame->data[1];
> +            break;
> +
> +        case AV_PIX_FMT_YUV420P:
> +            surface->Data.Y = frame->data[0];
> +            surface->Data.U = frame->data[1];
> +            surface->Data.V = frame->data[2];
> +            break;
> +
> +        case AV_PIX_FMT_YUYV422:
> +            surface->Data.Y = frame->data[0];
> +            surface->Data.U = frame->data[0] + 1;
> +            surface->Data.V = frame->data[0] + 3;
> +            break;
> +
> +        case AV_PIX_FMT_RGB32:
> +            surface->Data.B = frame->data[0];
> +            surface->Data.G = frame->data[0] + 1;
> +            surface->Data.R = frame->data[0] + 2;
> +            surface->Data.A = frame->data[0] + 3;
> +            break;
> +
> +        default:
> +            return MFX_ERR_UNSUPPORTED;
> +    }
> +    surface->Data.Pitch     = frame->linesize[0];
> +    surface->Data.TimeStamp = frame->pts;
> +
> +    return 0;
> +}
> +
>  static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
>                                    const AVFrame *src)
>  {
> @@ -749,11 +786,7 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>      }
>
>      out.Info = in->Info;
> -    out.Data.PitchLow = dst->linesize[0];
> -    out.Data.Y        = dst->data[0];
> -    out.Data.U        = dst->data[1];
> -    out.Data.V        = dst->data[2];
> -    out.Data.A        = dst->data[3];
> +    map_frame_to_surface(dst, &out);
>
>      do {
>          err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in,
> &out, NULL, &sync);
> @@ -796,11 +829,7 @@ static int qsv_transfer_data_to(AVHWFramesContext
> *ctx, AVFrame *dst,
>      }
>
>      in.Info = out->Info;
> -    in.Data.PitchLow = src->linesize[0];
> -    in.Data.Y        = src->data[0];
> -    in.Data.U        = src->data[1];
> -    in.Data.V        = src->data[2];
> -    in.Data.A        = src->data[3];
> +    map_frame_to_surface(src, &in);
>
>      do {
>          err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, &in, out,
> NULL, &sync);
> --
> 1.8.3.1
>
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
Li, Zhong March 20, 2018, 8:18 a.m. | #2
> From: libav-devel [mailto:libav-devel-bounces@libav.org] On Behalf Of
> Maxym Dmytrychenko
> Sent: Monday, March 19, 2018 5:56 PM
> To: libav development <libav-devel@libav.org>
> Cc: Liu, ChaoX A <chaox.a.liu@intel.com>
> Subject: Re: [libav-devel] [PATCH 2/2] lavu/hwcontext_qsv: Add support for
> pix_fmt RGB32.
> 
> indentation can be adjusted ,

It is to support RGB format overlay (e.g. lena-rgba.png). 

> AV_PIX_FMT_YUYV422  - we add it but dont use?

If the overlay input movie format is 4:2:2, it will be used. But I prefer to remove it in this patch to make it clearer. 
How do you think?
Maxym Dmytrychenko March 21, 2018, 11:55 a.m. | #3
Clean and specific patch is always good, agree with you on removal here.

On Tue, Mar 20, 2018 at 9:18 AM, Li, Zhong <zhong.li@intel.com> wrote:

> > From: libav-devel [mailto:libav-devel-bounces@libav.org] On Behalf Of
> > Maxym Dmytrychenko
> > Sent: Monday, March 19, 2018 5:56 PM
> > To: libav development <libav-devel@libav.org>
> > Cc: Liu, ChaoX A <chaox.a.liu@intel.com>
> > Subject: Re: [libav-devel] [PATCH 2/2] lavu/hwcontext_qsv: Add support
> for
> > pix_fmt RGB32.
> >
> > indentation can be adjusted ,
>
> It is to support RGB format overlay (e.g. lena-rgba.png).
>
> > AV_PIX_FMT_YUYV422  - we add it but dont use?
>
> If the overlay input movie format is 4:2:2, it will be used. But I prefer
> to remove it in this patch to make it clearer.
> How do you think?
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 5018a05..47afa48 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -90,6 +90,7 @@  static const struct {
     uint32_t           fourcc;
 } supported_pixel_formats[] = {
     { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
+    { AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
     { AV_PIX_FMT_P010, MFX_FOURCC_P010 },
     { AV_PIX_FMT_PAL8, MFX_FOURCC_P8   },
 };
@@ -730,6 +731,42 @@  static int qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst,
     return ret;
 }
 
+static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
+{
+    switch (frame->format) {
+        case AV_PIX_FMT_NV12:
+            surface->Data.Y  = frame->data[0];
+            surface->Data.UV = frame->data[1];
+            break;
+
+        case AV_PIX_FMT_YUV420P:
+            surface->Data.Y = frame->data[0];
+            surface->Data.U = frame->data[1];
+            surface->Data.V = frame->data[2];
+            break;
+
+        case AV_PIX_FMT_YUYV422:
+            surface->Data.Y = frame->data[0];
+            surface->Data.U = frame->data[0] + 1;
+            surface->Data.V = frame->data[0] + 3;
+            break;
+
+        case AV_PIX_FMT_RGB32:
+            surface->Data.B = frame->data[0];
+            surface->Data.G = frame->data[0] + 1;
+            surface->Data.R = frame->data[0] + 2;
+            surface->Data.A = frame->data[0] + 3;
+            break;
+
+        default:
+            return MFX_ERR_UNSUPPORTED;
+    }
+    surface->Data.Pitch     = frame->linesize[0];
+    surface->Data.TimeStamp = frame->pts;
+
+    return 0;
+}
+
 static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
                                   const AVFrame *src)
 {
@@ -749,11 +786,7 @@  static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
     }
 
     out.Info = in->Info;
-    out.Data.PitchLow = dst->linesize[0];
-    out.Data.Y        = dst->data[0];
-    out.Data.U        = dst->data[1];
-    out.Data.V        = dst->data[2];
-    out.Data.A        = dst->data[3];
+    map_frame_to_surface(dst, &out);
 
     do {
         err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in, &out, NULL, &sync);
@@ -796,11 +829,7 @@  static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
     }
 
     in.Info = out->Info;
-    in.Data.PitchLow = src->linesize[0];
-    in.Data.Y        = src->data[0];
-    in.Data.U        = src->data[1];
-    in.Data.V        = src->data[2];
-    in.Data.A        = src->data[3];
+    map_frame_to_surface(src, &in);
 
     do {
         err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, &in, out, NULL, &sync);