diff mbox

[FFmpeg-devel] lavf/qsv_scale: add scaling mode option

Message ID 1547628886-17523-1-git-send-email-zhong.li@intel.com
State New
Headers show

Commit Message

Zhong Li Jan. 16, 2019, 8:54 a.m. UTC
Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavfilter/vf_scale_qsv.c | 36 +++++++++++++++++++++++++++++++-----
 1 file changed, 31 insertions(+), 5 deletions(-)

Comments

Max Dmitrichenko Jan. 16, 2019, 12:12 p.m. UTC | #1
On Wed, Jan 16, 2019 at 9:55 AM Zhong Li <zhong.li@intel.com> wrote:

> Signed-off-by: Zhong Li <zhong.li@intel.com>
> ---
>  libavfilter/vf_scale_qsv.c | 36 +++++++++++++++++++++++++++++++-----
>  1 file changed, 31 insertions(+), 5 deletions(-)
>
> diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
> index 7d593b2..f9f708e 100644
> --- a/libavfilter/vf_scale_qsv.c
> +++ b/libavfilter/vf_scale_qsv.c
> @@ -69,6 +69,8 @@ enum var_name {
>      VARS_NB
>  };
>
> +#define QSV_HAVE_SCALING_CONFIG  QSV_VERSION_ATLEAST(1, 19)
> +
>  typedef struct QSVScaleContext {
>      const AVClass *class;
>
> @@ -88,7 +90,14 @@ typedef struct QSVScaleContext {
>      int             nb_surface_ptrs_out;
>
>      mfxExtOpaqueSurfaceAlloc opaque_alloc;
> -    mfxExtBuffer            *ext_buffers[1];
> +
> +#if QSV_HAVE_SCALING_CONFIG
> +    mfxExtVPPScaling         scale_conf;
> +#endif
> +    int                      mode;
> +
> +    mfxExtBuffer             *ext_buffers[1 + QSV_HAVE_SCALING_CONFIG];
> +    int                      num_ext_buf;
>
>      int shift_width, shift_height;
>
> @@ -285,6 +294,8 @@ static int init_out_session(AVFilterContext *ctx)
>      mfxStatus err;
>      int i;
>
> +    s->num_ext_buf = 0;
> +
>      /* extract the properties of the "master" session given to us */
>      err = MFXQueryIMPL(device_hwctx->session, &impl);
>      if (err == MFX_ERR_NONE)
> @@ -357,10 +368,7 @@ static int init_out_session(AVFilterContext *ctx)
>          s->opaque_alloc.Header.BufferId =
> MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
>          s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
>
> -        s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc;
> -
> -        par.ExtParam    = s->ext_buffers;
> -        par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
> +        s->ext_buffers[s->num_ext_buf++] =
> (mfxExtBuffer*)&s->opaque_alloc;
>
>          par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY |
> MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
>      } else {
> @@ -396,6 +404,18 @@ static int init_out_session(AVFilterContext *ctx)
>          par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY |
> MFX_IOPATTERN_OUT_VIDEO_MEMORY;
>      }
>
> +#if QSV_HAVE_SCALING_CONFIG
> +    memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling));
> +    s->scale_conf.Header.BufferId     = MFX_EXTBUFF_VPP_SCALING;
> +    s->scale_conf.Header.BufferSz     = sizeof(mfxExtVPPScaling);
> +    s->scale_conf.ScalingMode         = s->mode;
> +    s->ext_buffers[s->num_ext_buf++]  = (mfxExtBuffer*)&s->scale_conf;
> +    av_log(ctx, AV_LOG_VERBOSE, "Scaling mode: %"PRIu16"\n", s->mode);
> +#endif
> +
> +    par.ExtParam    = s->ext_buffers;
> +    par.NumExtParam = s->num_ext_buf;
> +
>      par.AsyncDepth = 1;    // TODO async
>
>      par.vpp.In  = in_frames_hwctx->surfaces[0].Info;
> @@ -595,6 +615,12 @@ static const AVOption options[] = {
>      { "h",      "Output video height", OFFSET(h_expr),
>  AV_OPT_TYPE_STRING, { .str = "ih"   }, .flags = FLAGS },
>      { "format", "Output pixel format", OFFSET(format_str),
> AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
>
> +#if QSV_HAVE_SCALING_CONFIG
> +    { "mode",      "set scaling mode",    OFFSET(mode),
> AV_OPT_TYPE_INT,    { .i64 = MFX_SCALING_MODE_DEFAULT},
> MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, FLAGS, "mode"},
> +    { "low_power", "low power mode",        0,
>  AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX,
> FLAGS, "mode"},
> +    { "hq",        "high quality mode",     0,
>  AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_QUALITY},  INT_MIN, INT_MAX,
> FLAGS, "mode"},
> +#endif
> +
>      { NULL },
>  };
>
> --
> 2.7.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


seems to be quiet straight forward and simple.

regards
Max Dm
diff mbox

Patch

diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 7d593b2..f9f708e 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -69,6 +69,8 @@  enum var_name {
     VARS_NB
 };
 
+#define QSV_HAVE_SCALING_CONFIG  QSV_VERSION_ATLEAST(1, 19)
+
 typedef struct QSVScaleContext {
     const AVClass *class;
 
@@ -88,7 +90,14 @@  typedef struct QSVScaleContext {
     int             nb_surface_ptrs_out;
 
     mfxExtOpaqueSurfaceAlloc opaque_alloc;
-    mfxExtBuffer            *ext_buffers[1];
+
+#if QSV_HAVE_SCALING_CONFIG
+    mfxExtVPPScaling         scale_conf;
+#endif
+    int                      mode;
+
+    mfxExtBuffer             *ext_buffers[1 + QSV_HAVE_SCALING_CONFIG];
+    int                      num_ext_buf;
 
     int shift_width, shift_height;
 
@@ -285,6 +294,8 @@  static int init_out_session(AVFilterContext *ctx)
     mfxStatus err;
     int i;
 
+    s->num_ext_buf = 0;
+
     /* extract the properties of the "master" session given to us */
     err = MFXQueryIMPL(device_hwctx->session, &impl);
     if (err == MFX_ERR_NONE)
@@ -357,10 +368,7 @@  static int init_out_session(AVFilterContext *ctx)
         s->opaque_alloc.Header.BufferId = MFX_EXTBUFF_OPAQUE_SURFACE_ALLOCATION;
         s->opaque_alloc.Header.BufferSz = sizeof(s->opaque_alloc);
 
-        s->ext_buffers[0] = (mfxExtBuffer*)&s->opaque_alloc;
-
-        par.ExtParam    = s->ext_buffers;
-        par.NumExtParam = FF_ARRAY_ELEMS(s->ext_buffers);
+        s->ext_buffers[s->num_ext_buf++] = (mfxExtBuffer*)&s->opaque_alloc;
 
         par.IOPattern = MFX_IOPATTERN_IN_OPAQUE_MEMORY | MFX_IOPATTERN_OUT_OPAQUE_MEMORY;
     } else {
@@ -396,6 +404,18 @@  static int init_out_session(AVFilterContext *ctx)
         par.IOPattern = MFX_IOPATTERN_IN_VIDEO_MEMORY | MFX_IOPATTERN_OUT_VIDEO_MEMORY;
     }
 
+#if QSV_HAVE_SCALING_CONFIG
+    memset(&s->scale_conf, 0, sizeof(mfxExtVPPScaling));
+    s->scale_conf.Header.BufferId     = MFX_EXTBUFF_VPP_SCALING;
+    s->scale_conf.Header.BufferSz     = sizeof(mfxExtVPPScaling);
+    s->scale_conf.ScalingMode         = s->mode;
+    s->ext_buffers[s->num_ext_buf++]  = (mfxExtBuffer*)&s->scale_conf;
+    av_log(ctx, AV_LOG_VERBOSE, "Scaling mode: %"PRIu16"\n", s->mode);
+#endif
+
+    par.ExtParam    = s->ext_buffers;
+    par.NumExtParam = s->num_ext_buf;
+
     par.AsyncDepth = 1;    // TODO async
 
     par.vpp.In  = in_frames_hwctx->surfaces[0].Info;
@@ -595,6 +615,12 @@  static const AVOption options[] = {
     { "h",      "Output video height", OFFSET(h_expr),     AV_OPT_TYPE_STRING, { .str = "ih"   }, .flags = FLAGS },
     { "format", "Output pixel format", OFFSET(format_str), AV_OPT_TYPE_STRING, { .str = "same" }, .flags = FLAGS },
 
+#if QSV_HAVE_SCALING_CONFIG
+    { "mode",      "set scaling mode",    OFFSET(mode),    AV_OPT_TYPE_INT,    { .i64 = MFX_SCALING_MODE_DEFAULT}, MFX_SCALING_MODE_DEFAULT, MFX_SCALING_MODE_QUALITY, FLAGS, "mode"},
+    { "low_power", "low power mode",        0,             AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_LOWPOWER}, INT_MIN, INT_MAX, FLAGS, "mode"},
+    { "hq",        "high quality mode",     0,             AV_OPT_TYPE_CONST,  { .i64 = MFX_SCALING_MODE_QUALITY},  INT_MIN, INT_MAX, FLAGS, "mode"},
+#endif
+
     { NULL },
 };