From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 7ECA74398D for ; Mon, 4 Jul 2022 08:11:35 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BF8F068B9E9; Mon, 4 Jul 2022 11:11:15 +0300 (EEST) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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); } } } -- 2.35.1.windows.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".