[2/2] lavf/qsvvpp: bypass vpp if not needed.

Message ID 1522332076-23028-2-git-send-email-zhong.li@intel.com
State New
Headers show
Series
  • [V4,1/2] lavc/qsvdec: expose frame pic_type and key_frame
Related show

Commit Message

Li, Zhong March 29, 2018, 2:01 p.m.
It is benefit to performance for specific case.

Signed-off-by: Zhong Li <zhong.li@intel.com>
---
 libavfilter/vf_vpp_qsv.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

Comments

Maxym Dmytrychenko April 2, 2018, 11:40 a.m. | #1
going to the right direction, can we see more details about " specific
case." ?

On Thu, Mar 29, 2018 at 4:01 PM, Zhong Li <zhong.li@intel.com> wrote:

> It is benefit to performance for specific case.
>
> Signed-off-by: Zhong Li <zhong.li@intel.com>
> ---
>  libavfilter/vf_vpp_qsv.c | 28 +++++++++++++++++++++++++---
>  1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> index 610e821..568dee5 100644
> --- a/libavfilter/vf_vpp_qsv.c
> +++ b/libavfilter/vf_vpp_qsv.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/eval.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/mathematics.h"
>
>  #include "formats.h"
>  #include "internal.h"
> @@ -249,6 +250,7 @@ static int config_output(AVFilterLink *outlink)
>      QSVVPPParam     param = { NULL };
>      QSVVPPCrop      crop  = { 0 };
>      mfxExtBuffer    *ext_buf[ENH_FILTERS_COUNT];
> +    AVFilterLink    *inlink = ctx->inputs[0];
>
>      outlink->w          = vpp->out_width;
>      outlink->h          = vpp->out_height;
> @@ -320,14 +322,34 @@ static int config_output(AVFilterLink *outlink)
>          param.ext_buf[param.num_ext_buf++] =
> (mfxExtBuffer*)&vpp->procamp_conf;
>      }
>
> -    return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
> +    if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise
> ||
> +        vpp->detail || vpp->procamp || inlink->w != outlink->w ||
> inlink->h != outlink->h)
> +        return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
> +    else {
> +        av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
> +        if (inlink->hw_frames_ctx)
> +            outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_
> frames_ctx);
> +    }
> +
> +    return 0;
>  }
>
>  static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
>  {
> -    VPPContext *vpp = inlink->dst->priv;
> +    int              ret = 0;
> +    AVFilterContext  *ctx = inlink->dst;
> +    VPPContext       *vpp = inlink->dst->priv;
> +    AVFilterLink     *outlink = ctx->outputs[0];
> +
> +    if (vpp->qsv)
> +        ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
> +    else {
> +        if (picref->pts != AV_NOPTS_VALUE)
> +            picref->pts = av_rescale_q(picref->pts, inlink->time_base,
> outlink->time_base);
> +        ret = ff_filter_frame(outlink, picref);
> +    }
>
> -    return ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
> +    return ret;
>  }
>
>  static int query_formats(AVFilterContext *ctx)
> --
> 1.8.3.1
>
> _______________________________________________
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
Li, Zhong April 3, 2018, 10:30 a.m. | #2
> From: libav-devel [mailto:libav-devel-bounces@libav.org] On Behalf Of
> Maxym Dmytrychenko
> Sent: Monday, April 2, 2018 7:41 PM
> To: libav development <libav-devel@libav.org>
> Subject: Re: [libav-devel] [PATCH 2/2] lavf/qsvvpp: bypass vpp if not needed.
> 
> going to the right direction, can we see more details about " specific case." ?

The "specific case" means "if vpp not needed case". 
For example, add the option "vpp_qsv=w=1280:h=720" for an input with native resolution 1280x720.

I am happy to update it if everything else is ok. 

> 
> On Thu, Mar 29, 2018 at 4:01 PM, Zhong Li <zhong.li@intel.com> wrote:
> 
> > It is benefit to performance for specific case.

Patch

diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 610e821..568dee5 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -27,6 +27,7 @@ 
 #include "libavutil/eval.h"
 #include "libavutil/avassert.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/mathematics.h"
 
 #include "formats.h"
 #include "internal.h"
@@ -249,6 +250,7 @@  static int config_output(AVFilterLink *outlink)
     QSVVPPParam     param = { NULL };
     QSVVPPCrop      crop  = { 0 };
     mfxExtBuffer    *ext_buf[ENH_FILTERS_COUNT];
+    AVFilterLink    *inlink = ctx->inputs[0];
 
     outlink->w          = vpp->out_width;
     outlink->h          = vpp->out_height;
@@ -320,14 +322,34 @@  static int config_output(AVFilterLink *outlink)
         param.ext_buf[param.num_ext_buf++] = (mfxExtBuffer*)&vpp->procamp_conf;
     }
 
-    return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
+    if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise ||
+        vpp->detail || vpp->procamp || inlink->w != outlink->w || inlink->h != outlink->h)
+        return ff_qsvvpp_create(ctx, &vpp->qsv, &param);
+    else {
+        av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
+        if (inlink->hw_frames_ctx)
+            outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+    }
+
+    return 0;
 }
 
 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
 {
-    VPPContext *vpp = inlink->dst->priv;
+    int              ret = 0;
+    AVFilterContext  *ctx = inlink->dst;
+    VPPContext       *vpp = inlink->dst->priv;
+    AVFilterLink     *outlink = ctx->outputs[0];
+
+    if (vpp->qsv)
+        ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+    else {
+        if (picref->pts != AV_NOPTS_VALUE)
+            picref->pts = av_rescale_q(picref->pts, inlink->time_base, outlink->time_base);
+        ret = ff_filter_frame(outlink, picref);
+    }
 
-    return ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
+    return ret;
 }
 
 static int query_formats(AVFilterContext *ctx)