From patchwork Mon Jul 4 08:09:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 36642 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp2666337pzh; Mon, 4 Jul 2022 01:11:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u17z1xHwLfEYgwGBKpVNE2kmCUULU+nzSJy9vJe6YF7HuIbZMoV86rr5Ne6Ox8mylRig5i X-Received: by 2002:a17:907:1dc6:b0:72a:5e9a:91be with SMTP id og6-20020a1709071dc600b0072a5e9a91bemr22434740ejc.730.1656922298175; Mon, 04 Jul 2022 01:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656922298; cv=none; d=google.com; s=arc-20160816; b=dipiSDAIHnjhRZhck4RbQbQpGmyFmo/mOw0F/f8sancViwij6Q9AZlZ758Q7VZZX7M fS7MPaUdTwL74DWBHDwURrII1mc65LrPZ6Sar+8joBpc9RqU6uxRgRHoHc87juR3Lxn6 aCRzcS7LlB7MXqEhHHNu2QPhkORP+PLh0eiM/tm7RPVoje6dPXcSWoHq8VX5nyFzUZeR VfBJ8qUgiAvTA6mgn0xteotClcFs232PoQiRC8WBhW0WW4EnuHcuMx1JM9gwu8n/o2EY OyyAf+plk2yTFyLlH/7c7PnCUOheP7WtCJa+RJVS0l/Cgn/CKAmCbm3/tv+36hq0PUhg yj9A== 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=t8PbA2iclTGgx4JAfZQ+DIyIMr1BVPOhIkbzMSp5PEE=; b=QpzqegAPWcrJTL8/rIXs1s70iTatP90d5TavEHYo00TyXsGoAt7CDihze021DNiOmf JbUdhSu/497wjFP+JeQ7bEag4R53j7TBeRFbqps5tLR0zOMf95DWSlT3/EIUaLrVQ4mn IB/5xxzetXJqYShTURK7MIb6AUwRW0RmZk8IeUzz5vbGzjfd/I3vUTNSjuPJNooOzvMx qZ9JgroESrVVzQwnYsIGaqfz1WJtwLdV3MBW0hPE+PH0I4/ZUyWh8wm3zAHtp8u4jXQD VopnEdLbKFsagDLZItYGYnplMMVItEf7U7jTQq9vavK1HKaE/L1wPoxeNcV08JOJ7JMC jllg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=W3FTRfao; 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 dz9-20020a0564021d4900b00437a255e8e9si13672449edb.509.2022.07.04.01.11.37; Mon, 04 Jul 2022 01:11:38 -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=W3FTRfao; 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 02CCE68B951; Mon, 4 Jul 2022 11:11:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BBED68B9E9 for ; Mon, 4 Jul 2022 11:11:08 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1656922273; x=1688458273; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WcUvov7hoTbB6x0Z39U4SYeGYpcM9Zlq6sdhV+cFcIA=; b=W3FTRfaoet7wXJq8lX0xE2M4A2FJiJDL0tPNrqcX4/MAitBtOlo3olQM mViO6GCu7NGvgQ7Xi5N0VUoEjtZtbrpMkp0+ECbersfuXJFApDWX7dFpE q3NDWEvo3kIZqIV4/xPZifZ0KOl6GvPSJWl6ku4n+9MZTtWYzg6pYiU9g 3F9+vcFunHALXM9PuzLhQgnnTwfYL7ZqykILWaGD2On/ZKOtzRZBzTL0Z oJyfYNEFIwOcjXlsNk1dN00L8SykR0KEYPJEL4JDvr4wAIfiENg5pwZL6 RwSdVtO5gkpTKIZAxwpe6OX4tW7/hXr1Q8KMOtTj7btsiWtLmD+LZPSkM g==; X-IronPort-AV: E=McAfee;i="6400,9594,10397"; a="262861135" X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262861135" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Jul 2022 01:11:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="660122915" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.39]) by fmsmga004.fm.intel.com with ESMTP; 04 Jul 2022 01:11:04 -0700 From: Tong Wu To: ffmpeg-devel@ffmpeg.org Date: Mon, 4 Jul 2022 16:09:55 +0800 Message-Id: <20220704080957.425-3-tong1.wu@intel.com> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220704080957.425-1-tong1.wu@intel.com> References: <20220704080957.425-1-tong1.wu@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 3/5] lavfi/avfiltergraph: move convert codes into functions 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: Tong Wu Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: eFUHKju8Edha This patch moves the auto-insert filter codes into two functions. Signed-off-by: Tong Wu --- libavfilter/avfiltergraph.c | 128 ++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 49 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index b7dbfc063b..2e6938b049 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -393,6 +393,74 @@ static int formats_declared(AVFilterContext *f) return 1; } +static int insert_auto_filter(AVFilterContext **convert, AVFilterGraph *graph, + AVFilterLink *link, const AVFilterNegotiation *neg, + int *converter_count, void *log_ctx) +{ + int ret; + const AVFilter *filter; + AVFilterContext *ctx; + AVFilterLink *inlink, *outlink; + char inst_name[30]; + const char *opts; + + if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { + av_log(log_ctx, AV_LOG_ERROR, + "'%s' filter not present, cannot convert formats.\n", + neg->conversion_filter); + return AVERROR(EINVAL); + } + snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", + neg->conversion_filter, (*converter_count)++); + opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); + ret = avfilter_graph_create_filter(&ctx, filter, inst_name, opts, NULL, graph); + if (ret < 0) + return ret; + + if ((ret = avfilter_insert_filter(link, ctx, 0, 0)) < 0) + return ret; + + if ((ret = filter_query_formats(ctx)) < 0) + return ret; + + inlink = ctx->inputs[0]; + outlink = ctx->outputs[0]; + av_assert0( inlink->incfg.formats->refcount > 0); + av_assert0( inlink->outcfg.formats->refcount > 0); + av_assert0(outlink->incfg.formats->refcount > 0); + av_assert0(outlink->outcfg.formats->refcount > 0); + if (outlink->type == AVMEDIA_TYPE_AUDIO) { + av_assert0( inlink-> incfg.samplerates->refcount > 0); + av_assert0( inlink->outcfg.samplerates->refcount > 0); + av_assert0(outlink-> incfg.samplerates->refcount > 0); + av_assert0(outlink->outcfg.samplerates->refcount > 0); + av_assert0( inlink-> incfg.channel_layouts->refcount > 0); + av_assert0( inlink->outcfg.channel_layouts->refcount > 0); + av_assert0(outlink-> incfg.channel_layouts->refcount > 0); + av_assert0(outlink->outcfg.channel_layouts->refcount > 0); + } + + *convert = ctx; + return 0; +} + +static int merge_auto_filter(AVFilterContext *convert, const AVFilterNegotiation *neg) +{ + int ret; + AVFilterLink *inlink = convert->inputs[0]; + AVFilterLink *outlink = convert->outputs[0]; +#define MERGE(merger, link) \ + ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \ + FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg))) + for (unsigned neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { + const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; + if ((ret = MERGE(m, inlink)) <= 0 || + (ret = MERGE(m, outlink)) <= 0) + break; + } + return ret; +} + /** * Perform one round of query_formats() and merging formats lists on the * filter graph. @@ -470,10 +538,6 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) if (convert_needed) { AVFilterContext *convert; - const AVFilter *filter; - AVFilterLink *inlink, *outlink; - char inst_name[30]; - const char *opts; if (graph->disable_auto_convert) { av_log(log_ctx, AV_LOG_ERROR, @@ -484,54 +548,20 @@ static int query_formats(AVFilterGraph *graph, void *log_ctx) } /* couldn't merge format lists. auto-insert conversion filter */ - if (!(filter = avfilter_get_by_name(neg->conversion_filter))) { - av_log(log_ctx, AV_LOG_ERROR, - "'%s' filter not present, cannot convert formats.\n", - neg->conversion_filter); - return AVERROR(EINVAL); - } - snprintf(inst_name, sizeof(inst_name), "auto_%s_%d", - neg->conversion_filter, converter_count++); - opts = FF_FIELD_AT(char *, neg->conversion_opts_offset, *graph); - ret = avfilter_graph_create_filter(&convert, filter, inst_name, opts, NULL, graph); - if (ret < 0) - return ret; - if ((ret = avfilter_insert_filter(link, convert, 0, 0)) < 0) + ret = insert_auto_filter(&convert, graph, link, neg, &converter_count, log_ctx); + if (ret < 0) { + av_log(log_ctx, AV_LOG_ERROR, "Failed to insert an auto filter.\n"); return ret; + } - if ((ret = filter_query_formats(convert)) < 0) + ret = merge_auto_filter(convert, neg); + if (ret < 0) return ret; - - inlink = convert->inputs[0]; - outlink = convert->outputs[0]; - av_assert0( inlink->incfg.formats->refcount > 0); - av_assert0( inlink->outcfg.formats->refcount > 0); - av_assert0(outlink->incfg.formats->refcount > 0); - av_assert0(outlink->outcfg.formats->refcount > 0); - if (outlink->type == AVMEDIA_TYPE_AUDIO) { - av_assert0( inlink-> incfg.samplerates->refcount > 0); - av_assert0( inlink->outcfg.samplerates->refcount > 0); - av_assert0(outlink-> incfg.samplerates->refcount > 0); - av_assert0(outlink->outcfg.samplerates->refcount > 0); - av_assert0( inlink-> incfg.channel_layouts->refcount > 0); - av_assert0( inlink->outcfg.channel_layouts->refcount > 0); - av_assert0(outlink-> incfg.channel_layouts->refcount > 0); - av_assert0(outlink->outcfg.channel_layouts->refcount > 0); - } -#define MERGE(merger, link) \ - ((merger)->merge(FF_FIELD_AT(void *, (merger)->offset, (link)->incfg), \ - FF_FIELD_AT(void *, (merger)->offset, (link)->outcfg))) - for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { - const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; - if ((ret = MERGE(m, inlink)) <= 0 || - (ret = MERGE(m, outlink)) <= 0) { - if (ret < 0) - return ret; - av_log(log_ctx, AV_LOG_ERROR, - "Impossible to convert between the formats supported by the filter " - "'%s' and the filter '%s'\n", link->src->name, link->dst->name); - return AVERROR(ENOSYS); - } + else if (ret == 0) { + av_log(log_ctx, AV_LOG_ERROR, + "Impossible to convert between the formats supported by the filter " + "'%s' and the filter '%s'\n", link->src->name, link->dst->name); + return AVERROR(ENOSYS); } } }