From patchwork Fri Jun 16 00:58:10 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: 42127 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c526:b0:117:ac03:c9de with SMTP id gm38csp1173035pzb; Thu, 15 Jun 2023 17:59:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5bo3gfUWwGUqTdUXD+mJHszeED15ADAmO+m4SZ8Gswx2J6NWM/oYP0lRoVmoH8Wyfg0qSL X-Received: by 2002:a17:907:72c2:b0:982:3bae:afda with SMTP id du2-20020a17090772c200b009823baeafdamr382655ejc.45.1686877146001; Thu, 15 Jun 2023 17:59:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686877145; cv=none; d=google.com; s=arc-20160816; b=ijb3dLtekWxdwNsBkwdLtwnxlVnyV6JDgNBRVUP7du4kNkx6XKSmgPPCUOTDnZPnog yJokndk2zrUgvzGoomqOR0D60GXEj90K194jEto4UeEY0WFpXGsr7c1qRMCCvtDpZANk EWis7pCTP+B5uqH4p/m3WN3wlFLZEqKhGKrB8H0DMkSUmVkffSm1HLkfUinJsB6IOQPW 4ZY73uVlyRuwrCwNCbBhDL2r/Xi4WiiuWXTH2vu6WBzqDcec6y8Fmj555Va1rPn3nXQb MRUc8+MzGPhH1lVpv6mDkkk4xwFaiTeouuUYwTb5o7LHIoy8rW2kNg6yxxWmrg6fhlUZ v6WA== 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=NZEEr9icnq+fNmNKR3mENYJ4dp8Eh0se1AiGxQwNEfY=; b=N9EdiE5C4+tlScamx4xSMTiADIPgecB7PNtpIm5PpbKRWYiseb9fzDDnZWdx098IeU KnAj/uKlkxJSt/FOZCzhnS2K21ra9Sblk1BCUqYA56jBVMHhdHKoq+UEvOuiQ06mZZC/ dD36FrEzAxkmQo1X+rCDCplrBaB8e0Gx1MuwB7KbKDb7PJwYP6eVVrpHaMl/iFAUxAke kqPkZ/plgwdGfJhJosy337+EqtEwXnnFuPENW+eV7nc2SB0wP1QyLWDQ4/6vjtqGx5b6 YDRCI+l1ZMjdLf7Z5Efh57PBm6rDI/12MDhddA/VKIA4Kh4XvN/EKDQR0nNrtfwK3PSh sguQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b="mq/DIPRx"; 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 g7-20020a1709061c8700b009829826728dsi1740868ejh.640.2023.06.15.17.59.05; Thu, 15 Jun 2023 17:59:05 -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="mq/DIPRx"; 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 CB7EA68C5AA; Fri, 16 Jun 2023 03:58:50 +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 EB7B068C57D for ; Fri, 16 Jun 2023 03:58:42 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686877128; x=1718413128; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=fenZm1y7FSoRLrhbT1tLQfQ7R8zBYUlf2d2gv4mWTig=; b=mq/DIPRx09aSxgqH93mqIeZQ1uISpk2k6i2sEEwCYrZyp0VjBw2vh2qH qLWb15PctwlqqkFClGtrTOtQ9EUGBD9K5isp61y4H5xrymQMNu4K42iT+ JwkOdqQkMNLHXAR7rJRBT03ybeDWJlQe6hiRfdyU0U21DAmwbZ2MKIEM0 J+cCQWjBX/zZrCtXBijG6iKi7VpwNluCSO3IJHuYtP24j+y1081lUKB8E w2159Q+enJoadFC+R9Kbofd3QZTy6SBA8n2gb52zwidK5bjbMtrcbnRXh b7gnWsin6pYy0w7svUrS+ESIRDO7kH1KsL5e/fUkKdBQUnE52mWeponrW A==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="387700945" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="387700945" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 17:58:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="1042892219" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="1042892219" Received: from t-dg2.sh.intel.com ([10.238.200.108]) by fmsmga005.fm.intel.com with ESMTP; 15 Jun 2023 17:58:23 -0700 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 16 Jun 2023 08:58:10 +0800 Message-Id: <20230616005810.792849-3-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230616005810.792849-1-fei.w.wang@intel.com> References: <20230616005810.792849-1-fei.w.wang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 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: AP46iAWlZcBi 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 | 13 +++++++++++++ 5 files changed, 46 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..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);