From patchwork Tue May 30 00:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wang, Fei W" X-Patchwork-Id: 41884 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp2095466pzb; Mon, 29 May 2023 17:30:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5n297ZdzWfIwWQvBcul0GqRvBM8KaFwZd6TO4XNNXbAreZw/odYb4TfDE4AIbVOh3mAZNI X-Received: by 2002:a17:907:6291:b0:96f:2315:29fe with SMTP id nd17-20020a170907629100b0096f231529femr824648ejc.0.1685406620742; Mon, 29 May 2023 17:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685406620; cv=none; d=google.com; s=arc-20160816; b=rRvqFSM2PtOOHNLVuiPyhtAxV09jTiQPjXyV4CYQ8bX/yzy4BLKXF8wty60c2HpRIY e/EebGicwoH9GYYd4wfpSjRNzh4V82yGEbbjyoF50xXzuInOg9+4YvL1bAEodjBmy1+2 LVUYMJIGqgCLH3gNxTQLq3kW2CIbWj2Q5ufGX/8EW6pNhUOReqFgIJOZPJjxIQgt9svt ynDOPawG+Bnj+kKSU3ny0ZZBmOJqVOJO+h1KaO9SMu/lNO2aB083uMooaFUBi/ujEyxj i+OdUuP/g1/szabB2Mnd9h36dg6LnZzz9fsn3Ig+MpzrnTqva8Jc5zbyFolxxLtQsiN3 tI7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=HA0zzl6rGhVnjeQBLajDrX8Qp3c3+EBCmzIkI5HgdQ4=; b=Rm0NxsJDTlkhhaVWau4vUhJJ/ieIUP4VmYjJgOpF4NrrNCS8yw8f7cgEMk0TwL4pe0 Jaom9kymQ60gGK18EbdgTuoUtGOjK/eme4p14QllO+1Ryteqb/pib+t2ZhiW5e8urQcR mO+6cYO3feDl3PPkv1tjenIB1KsIB99crlhvbt15La0u612N+duqa7Qh7hXEZhmOHwNP DoX03r7AoVj9mURogflelG3TziTOqgsR+tajctNGtIeRxOmXzwE5nT8RtTw2Xg+1nafs Dk/Oh3W9a4CiQ0HDkDV3QISMkM5kgzsaPYkh4NmqYTuJMr493FVcxr4pj2hqjjrtQUbw 7soQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=E4IOC2le; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w8-20020a170906d20800b0096f773a36f2si7533480ejz.710.2023.05.29.17.30.20; Mon, 29 May 2023 17:30:20 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=E4IOC2le; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3D08968C239; Tue, 30 May 2023 03:30:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3470168C165 for ; Tue, 30 May 2023 03:29:56 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685406601; x=1716942601; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=8eXGpZwCjP9jUNOkPbCbi/HDQlPoYrcHPDSF7hns2xs=; b=E4IOC2levz9/3zl9ckz4gkr1an5lPyujfEUEoqAYJjNjz8TYAvfsT5zU K0Wl6gVv2DOtlD5FhfJnWuLubEBaJwTY6koHHDZDlQufP9E5eU3jhIZdR clzTWswC0C2LcIfgQZRn/IcUQt8zdzDNaI+/snhEUBpScCrHQgm6jE7Fw MbRhTKaHJb8K8CEUMHbn7O6mNe7V/gFYVPh12fihw7PyIB6ypkVm3Hy6M YQblOWphEkiQ3gcPXsCdALPTYoN+wro8bTvYLGR3+iUMxzec2q2luEpuQ ODNsdcp3dAySNrkym9BVZJeJTSEAhAVsghrFrYmC/8GIOlB3Bwtp7wzgw g==; X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="383041735" X-IronPort-AV: E=Sophos;i="6.00,201,1681196400"; d="scan'208";a="383041735" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 May 2023 17:29:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10725"; a="1036367630" X-IronPort-AV: E=Sophos;i="6.00,201,1681196400"; d="scan'208";a="1036367630" Received: from t.sh.intel.com ([10.239.159.159]) by fmsmga005.fm.intel.com with ESMTP; 29 May 2023 17:29:47 -0700 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 May 2023 08:29:50 +0800 Message-Id: <20230530002950.1590409-3-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230530002950.1590409-1-fei.w.wang@intel.com> References: <20230530002950.1590409-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1 3/3] lavfi/{denoise, procamp, scale, sharpness}_vaapi: Add passthrough mode X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uiIVlMj4QZ9Q Signed-off-by: Fei Wang --- 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 | 9 +++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) 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..0a4c174ab9 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) + 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) + vpp_ctx->passthrough = 1; return 0; } diff --git a/libavfilter/vf_procamp_vaapi.c b/libavfilter/vf_procamp_vaapi.c index 4a3b9d0766..82c446dc76 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 = 0.0001; 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..aa18891c56 100644 --- a/libavfilter/vf_scale_vaapi.c +++ b/libavfilter/vf_scale_vaapi.c @@ -85,6 +85,15 @@ 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 == outlink->w && inlink->h == outlink->w && + vpp_ctx->input_frames->sw_format == vpp_ctx->output_format && + 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;