From patchwork Mon Jan 9 07:12:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 39930 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp2884108pzb; Sun, 8 Jan 2023 23:12:52 -0800 (PST) X-Google-Smtp-Source: AMrXdXsT+DfVseB1ZcuKg4B3UugnSGjVyLdJV35DQmLpegW6yf0HknQoUwHavfkWo3VqVFGr+7M/ X-Received: by 2002:a17:906:2349:b0:7c1:844d:7447 with SMTP id m9-20020a170906234900b007c1844d7447mr54255770eja.35.1673248372336; Sun, 08 Jan 2023 23:12:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673248372; cv=none; d=google.com; s=arc-20160816; b=EA71CisMObc+gH2U9MF6Hz0a23Voq7vqwNI7odQre3bV63Qee7Rd/IZ7Y8ke7et3Rz B4mznBp11iC/xqFyYWVi9T68JZtJ8jU1/EP/MhMpCHqHev5XB0EwXdUb2U7A2sPAeAZe r3uMh8VCkboSk7Nh+7rUVWto8G39alm6PxD37icNx4bSZGj537wllap3ajjQmZZYwGp0 0JMMG/LrRiNMiXvAcSl/UUaW2EMrMtq9Vb60CzerI3zNNHhXm1ygPTGXu8iBkbwCjR/t EfuVuj50SFlZafm3mikYVeSxvofiMggw+FxnRPFnS3CZQZFW5/ysflOa+VbWPAClTqlm YfbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc: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=au7UXobJy9oApSsNU4McS1IqBABCE1GCyDVskvA5VdU=; b=RdM0HUYf/agmsMhtrxBJrxBQotqaHFNB5MrsHMGjhVq4asRL9UzELTTcrUHogYFIrz KoeABEl8Hcrhn0xsWCzbkt8keKUAuZV+QTlhP1Zb2N5XAOuk/JXdqhR2x782AKneX6JX Va13s2ojwWon7Zl9ZaSBqB/aDbTp22D9k3str4Em3tcQbMZwfRaQ4mF4q19P1KSaemfL Ku58dtLId+SIUlM+N7G7wXB/9rWcVRTSk59jpzuqjHXij9NsjPTxxVrlTxl8bev/gPFQ xuOqS+o14fk0uqPXPAzEUipTAgmkxhkxd6Pl7JeSrs1pSMVeb6prpTm7aGh3Iho+5Y1G T0/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=gXY1qaIf; 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 qk31-20020a1709077f9f00b007c60482a110si10342470ejc.625.2023.01.08.23.12.52; Sun, 08 Jan 2023 23:12:52 -0800 (PST) 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=gXY1qaIf; 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 C56FA68BBB6; Mon, 9 Jan 2023 09:12:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C655C68BAE8 for ; Mon, 9 Jan 2023 09:12:31 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673248357; x=1704784357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V+PHgO2pX1LjAytA1jVdbnBbeTwpRI6rSUEbNKVbWNo=; b=gXY1qaIfyl8UyPbv3yDy4ffZ6a8+AmGRRrUllEuVbFx7HuFcipB1S+jD 3z7RVVqB6AWPBU81kcF0m1rhqxciAjO81fBkUoNEHqeVpMGfg4mhcNA+9 X+r35/YCHsgcBS7DY5mel1oYoBNR8eILzbisayl3q3r/9PPNK797IRFtj hMQ+pco8YqelSpnw+lMQIN7H+IKSti3BjFDq2OJdDmjH5/EPVCan9+TRD f8efGk/6ITUU8E2ng1R5EfMnddzgUMkxy0alTjTfcgZ+OoWhWbMvTP/09 OeLQ9YCV0Eayj4Hk2fezsn1Ur41NGZv0rbSzzmDAfmWXmguQKglJHBBWi Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="385110840" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="385110840" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 23:12:27 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10584"; a="745262790" X-IronPort-AV: E=Sophos;i="5.96,311,1665471600"; d="scan'208";a="745262790" Received: from xhh-tgl64.sh.intel.com ([10.238.2.19]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jan 2023 23:12:26 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Jan 2023 15:12:04 +0800 Message-Id: <20230109071210.1829699-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230109071210.1829699-1-haihao.xiang@intel.com> References: <20230109071210.1829699-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] lavfi/vf_vpp_qsv: handle NULL pointer when evaluating an expression 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 Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6AoJLqGIB+Gz From: Haihao Xiang This patch provides default value if the expression is NULL. This is in preparation for reusing the code for other QSV filters. Signed-off-by: Haihao Xiang --- libavfilter/vf_vpp_qsv.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c index 8d4227f841..3a0a395732 100644 --- a/libavfilter/vf_vpp_qsv.c +++ b/libavfilter/vf_vpp_qsv.c @@ -172,14 +172,19 @@ enum var_name { static int eval_expr(AVFilterContext *ctx) { #define PASS_EXPR(e, s) {\ - ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \ - if (ret < 0) {\ - av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s);\ - goto release;\ + if (s) {\ + ret = av_expr_parse(&e, s, var_names, NULL, NULL, NULL, NULL, 0, ctx); \ + if (ret < 0) { \ + av_log(ctx, AV_LOG_ERROR, "Error when passing '%s'.\n", s); \ + goto release; \ + } \ }\ } -#define CALC_EXPR(e, v, i) {\ - i = v = av_expr_eval(e, var_values, NULL); \ +#define CALC_EXPR(e, v, i, d) {\ + if (e)\ + i = v = av_expr_eval(e, var_values, NULL); \ + else\ + i = v = d;\ } VPPContext *vpp = ctx->priv; double var_values[VAR_VARS_NB] = { NAN }; @@ -209,30 +214,29 @@ static int eval_expr(AVFilterContext *ctx) var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR]; /* crop params */ - CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w); - CALC_EXPR(ch_expr, var_values[VAR_CH], vpp->crop_h); + CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w, var_values[VAR_IW]); + CALC_EXPR(ch_expr, var_values[VAR_CH], vpp->crop_h, var_values[VAR_IH]); /* calc again in case cw is relative to ch */ - CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w); + CALC_EXPR(cw_expr, var_values[VAR_CW], vpp->crop_w, var_values[VAR_IW]); CALC_EXPR(w_expr, var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W], - vpp->out_width); + vpp->out_width, var_values[VAR_CW]); CALC_EXPR(h_expr, var_values[VAR_OUT_H] = var_values[VAR_OH] = var_values[VAR_H], - vpp->out_height); + vpp->out_height, var_values[VAR_CH]); /* calc again in case ow is relative to oh */ CALC_EXPR(w_expr, var_values[VAR_OUT_W] = var_values[VAR_OW] = var_values[VAR_W], - vpp->out_width); + vpp->out_width, var_values[VAR_CW]); - - CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x); - CALC_EXPR(cy_expr, var_values[VAR_CY], vpp->crop_y); + CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2); + CALC_EXPR(cy_expr, var_values[VAR_CY], vpp->crop_y, (var_values[VAR_IH] - var_values[VAR_OH]) / 2); /* calc again in case cx is relative to cy */ - CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x); + CALC_EXPR(cx_expr, var_values[VAR_CX], vpp->crop_x, (var_values[VAR_IW] - var_values[VAR_OW]) / 2); if ((vpp->crop_w != var_values[VAR_IW]) || (vpp->crop_h != var_values[VAR_IH])) vpp->use_crop = 1;