diff mbox series

[FFmpeg-devel,v2,3/3] lavfi/{denoise, procamp, scale, sharpness}_vaapi: Add passthrough mode

Message ID 20230616005810.792849-3-fei.w.wang@intel.com
State Accepted
Commit 13a10fe8925ddc78500107e34799d84dd568a434
Headers show
Series [FFmpeg-devel,v2,1/3] lavfi/vaapi: Add function to get surface ID from AVFrame | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wang, Fei W June 16, 2023, 12:58 a.m. UTC
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavfilter/vaapi_vpp.c        | 15 ++++++++++++---
 libavfilter/vaapi_vpp.h        |  2 ++
 libavfilter/vf_misc_vaapi.c    |  9 +++++++++
 libavfilter/vf_procamp_vaapi.c | 10 ++++++++++
 libavfilter/vf_scale_vaapi.c   | 13 +++++++++++++
 5 files changed, 46 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/vaapi_vpp.c b/libavfilter/vaapi_vpp.c
index 4de19564e9..cf2592e068 100644
--- a/libavfilter/vaapi_vpp.c
+++ b/libavfilter/vaapi_vpp.c
@@ -95,6 +95,7 @@  int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
 int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
 {
     AVFilterContext *avctx = outlink->src;
+    AVFilterLink   *inlink = avctx->inputs[0];
     VAAPIVPPContext *ctx   = avctx->priv;
     AVVAAPIHWConfig *hwconfig = NULL;
     AVHWFramesConstraints *constraints = NULL;
@@ -111,6 +112,17 @@  int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
     if (!ctx->output_height)
         ctx->output_height = avctx->inputs[0]->h;
 
+    outlink->w = ctx->output_width;
+    outlink->h = ctx->output_height;
+
+    if (ctx->passthrough) {
+        if (inlink->hw_frames_ctx)
+            outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
+        av_log(ctx, AV_LOG_VERBOSE, "Using VAAPI filter passthrough mode.\n");
+
+        return 0;
+    }
+
     av_assert0(ctx->input_frames);
     ctx->device_ref = av_buffer_ref(ctx->input_frames->device_ref);
     if (!ctx->device_ref) {
@@ -214,9 +226,6 @@  int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
         return AVERROR(EIO);
     }
 
-    outlink->w = ctx->output_width;
-    outlink->h = ctx->output_height;
-
     if (ctx->build_filter_params) {
         err = ctx->build_filter_params(avctx);
         if (err < 0)
diff --git a/libavfilter/vaapi_vpp.h b/libavfilter/vaapi_vpp.h
index cc845b854c..6764ab0c39 100644
--- a/libavfilter/vaapi_vpp.h
+++ b/libavfilter/vaapi_vpp.h
@@ -56,6 +56,8 @@  typedef struct VAAPIVPPContext {
     VABufferID         filter_buffers[VAProcFilterCount];
     int                nb_filter_buffers;
 
+    int passthrough;
+
     int (*build_filter_params)(AVFilterContext *avctx);
 
     void (*pipeline_uninit)(AVFilterContext *avctx);
diff --git a/libavfilter/vf_misc_vaapi.c b/libavfilter/vf_misc_vaapi.c
index db3e69679a..71bc5e3c34 100644
--- a/libavfilter/vf_misc_vaapi.c
+++ b/libavfilter/vf_misc_vaapi.c
@@ -131,6 +131,9 @@  static int misc_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
            av_get_pix_fmt_name(input_frame->format),
            input_frame->width, input_frame->height, input_frame->pts);
 
+    if (vpp_ctx->passthrough)
+        return ff_filter_frame(outlink, input_frame);
+
     if (vpp_ctx->va_context == VA_INVALID_ID)
         return AVERROR(EINVAL);
 
@@ -176,11 +179,14 @@  fail:
 static av_cold int denoise_vaapi_init(AVFilterContext *avctx)
 {
     VAAPIVPPContext *vpp_ctx = avctx->priv;
+    DenoiseVAAPIContext *ctx = avctx->priv;
 
     ff_vaapi_vpp_ctx_init(avctx);
     vpp_ctx->pipeline_uninit     = ff_vaapi_vpp_pipeline_uninit;
     vpp_ctx->build_filter_params = denoise_vaapi_build_filter_params;
     vpp_ctx->output_format       = AV_PIX_FMT_NONE;
+    if (ctx->denoise == DENOISE_DEFAULT)
+        vpp_ctx->passthrough = 1;
 
     return 0;
 }
@@ -188,11 +194,14 @@  static av_cold int denoise_vaapi_init(AVFilterContext *avctx)
 static av_cold int sharpness_vaapi_init(AVFilterContext *avctx)
 {
     VAAPIVPPContext *vpp_ctx = avctx->priv;
+    SharpnessVAAPIContext *ctx = avctx->priv;
 
     ff_vaapi_vpp_ctx_init(avctx);
     vpp_ctx->pipeline_uninit     = ff_vaapi_vpp_pipeline_uninit;
     vpp_ctx->build_filter_params = sharpness_vaapi_build_filter_params;
     vpp_ctx->output_format       = AV_PIX_FMT_NONE;
+    if (ctx->sharpness == SHARPNESS_DEFAULT)
+        vpp_ctx->passthrough = 1;
 
     return 0;
 }
diff --git a/libavfilter/vf_procamp_vaapi.c b/libavfilter/vf_procamp_vaapi.c
index 4a3b9d0766..acfc72947c 100644
--- a/libavfilter/vf_procamp_vaapi.c
+++ b/libavfilter/vf_procamp_vaapi.c
@@ -136,6 +136,9 @@  static int procamp_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame
            av_get_pix_fmt_name(input_frame->format),
            input_frame->width, input_frame->height, input_frame->pts);
 
+    if (vpp_ctx->passthrough)
+        return ff_filter_frame(outlink, input_frame);
+
     if (vpp_ctx->va_context == VA_INVALID_ID)
         return AVERROR(EINVAL);
 
@@ -179,11 +182,18 @@  fail:
 static av_cold int procamp_vaapi_init(AVFilterContext *avctx)
 {
     VAAPIVPPContext *vpp_ctx = avctx->priv;
+    ProcampVAAPIContext *ctx = avctx->priv;
+    float eps = 1.0e-10f;
 
     ff_vaapi_vpp_ctx_init(avctx);
     vpp_ctx->pipeline_uninit     = ff_vaapi_vpp_pipeline_uninit;
     vpp_ctx->build_filter_params = procamp_vaapi_build_filter_params;
     vpp_ctx->output_format       = AV_PIX_FMT_NONE;
+    if (fabs(ctx->saturation - SATURATION_DEFAULT) < eps &&
+        fabs(ctx->bright - BRIGHTNESS_DEFAULT) < eps &&
+        fabs(ctx->contrast - CONTRAST_DEFAULT) < eps &&
+        fabs(ctx->hue - HUE_DEFAULT) < eps)
+        vpp_ctx->passthrough = 1;
 
     return 0;
 }
diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index a371077ee0..11bd7a9de9 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -85,6 +85,16 @@  static int scale_vaapi_config_output(AVFilterLink *outlink)
     ff_scale_adjust_dimensions(inlink, &vpp_ctx->output_width, &vpp_ctx->output_height,
                                ctx->force_original_aspect_ratio, ctx->force_divisible_by);
 
+    if (inlink->w == vpp_ctx->output_width && inlink->h == vpp_ctx->output_height &&
+        (vpp_ctx->input_frames->sw_format == vpp_ctx->output_format ||
+         vpp_ctx->output_format == AV_PIX_FMT_NONE) &&
+        ctx->colour_primaries == AVCOL_PRI_UNSPECIFIED &&
+        ctx->colour_transfer == AVCOL_TRC_UNSPECIFIED &&
+        ctx->colour_matrix == AVCOL_SPC_UNSPECIFIED &&
+        ctx->colour_range == AVCOL_RANGE_UNSPECIFIED &&
+        ctx->chroma_location == AVCHROMA_LOC_UNSPECIFIED)
+        vpp_ctx->passthrough = 1;
+
     err = ff_vaapi_vpp_config_output(outlink);
     if (err < 0)
         return err;
@@ -111,6 +121,9 @@  static int scale_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
            av_get_pix_fmt_name(input_frame->format),
            input_frame->width, input_frame->height, input_frame->pts);
 
+   if (vpp_ctx->passthrough)
+       return ff_filter_frame(outlink, input_frame);
+
     if (vpp_ctx->va_context == VA_INVALID_ID)
         return AVERROR(EINVAL);