From patchwork Sat Jul 24 17:39:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29045 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp2395236ios; Sat, 24 Jul 2021 10:39:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfUiGfM9yYRfn/BAebKIBR+0bRv8ukTLBlHbsFDEeBy/XpLErLvMvDbFIcHQBqDa6F5Ymf X-Received: by 2002:a05:6402:5cd:: with SMTP id n13mr12158478edx.345.1627148389000; Sat, 24 Jul 2021 10:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627148388; cv=none; d=google.com; s=arc-20160816; b=Q/P5r44o6hxVwfc9HS3Ph60Y/BAy3t+oIJ8xatauysLf+uS0CvuuoNRBuWRnHkPRFY mkiHX9TFJ/Yt/F5tpo9jGtc19qEPKgXIbZmiMIbzHNdoJWtZ0FtDG898aG3z9So1jYnm PFgzmnYt2ENsGVRhkcL9lbZE6z+KQkEOwi0hJutLzfbnZSuYRprpuyfAFQHHOERJYtJx qDxY+w0Lqsrc8b6RuD3EgzdJHtmUFaOk2LyRPksJnWvzD5/Hg/UbHZ7eVGm+NKZeg0GL vNH5Q1HZb3022y7FtVO4rW2t1ddqo+yTbGeVtHIrDNI3NfJA9wtHIzKCcQ8fl0QiVepQ xxtg== 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:message-id:date:to:from :delivered-to; bh=zg/CGgP5lWM6uFghime9MqyCHe10UIzWXjpjWrg0jRY=; b=YhL43J4Rl0745A3mDNjgD7oZe4ko7M7HA5VgwqywViLCKv6AdL+LDvWnqjp5EZmzrE u6++gdx9MpeyJLubgETgJ3xcPEMYH0ZpAQO3xOiTnReQoEga31QkWNhQDD08TNy4qnx6 Ra4VjHcByMXb31QBcoJmAE3LLHS2uTfpFhqPVE7VLwkZkfLqky3qBMU4HfaF6J77JepI gLdg+FlERUPMcplrkkaGhpk/OEYiqS1/D7kWGYspKop0SqgB0k7ZO3V49kq+M9V0Neh2 pEPKqnBuzRWsstTedX1C/QkionPWjLGkXqiDj4M8FdbwHpucGNqxsBqNuuAfFoMgKlBJ oNiQ== ARC-Authentication-Results: i=1; mx.google.com; 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 j21si12153334edq.100.2021.07.24.10.39.48; Sat, 24 Jul 2021 10:39:48 -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; 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 8BD4B68AA83; Sat, 24 Jul 2021 20:39:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D873068A2AE for ; Sat, 24 Jul 2021 20:39:37 +0300 (EEST) X-ENS-nef-client: 129.199.129.80 ( name = phare.normalesup.org ) Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 16OHdbJr020858 for ; Sat, 24 Jul 2021 19:39:37 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 11A9AE0027; Sat, 24 Jul 2021 19:39:37 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jul 2021 19:39:34 +0200 Message-Id: <20210724173934.414263-1-george@nsup.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Sat, 24 Jul 2021 19:39:37 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH] lavfi/formats: describe conversion in negotiation structure. 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: ajG2Y9Go8Aah Signed-off-by: Nicolas George --- libavfilter/avfiltergraph.c | 45 ++++++++++--------------------------- libavfilter/formats.c | 4 ++++ libavfilter/formats.h | 2 ++ 3 files changed, 18 insertions(+), 33 deletions(-) Obviously to be applied on top of the last two patches. The message when one of the filters changes slightly. I think it is acceptable. The numbering of the automatic filters becomes global. I think it does not matter. diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 37f09cb686..d7a17b429b 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -432,7 +432,7 @@ static int formats_declared(AVFilterContext *f) static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) { int i, j, ret; - int scaler_count = 0, resampler_count = 0; + int converter_count = 0; int count_queried = 0; /* successful calls to query_formats() */ int count_merged = 0; /* successful merge of formats lists */ int count_already_merged = 0; /* lists already merged */ @@ -499,6 +499,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) 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, @@ -509,40 +510,18 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) } /* couldn't merge format lists. auto-insert conversion filter */ - switch (link->type) { - case AVMEDIA_TYPE_VIDEO: - if (!(filter = avfilter_get_by_name("scale"))) { - av_log(log_ctx, AV_LOG_ERROR, "'scale' filter " - "not present, cannot convert pixel formats.\n"); - return AVERROR(EINVAL); - } - - snprintf(inst_name, sizeof(inst_name), "auto_scaler_%d", - scaler_count++); - - if ((ret = avfilter_graph_create_filter(&convert, filter, - inst_name, graph->scale_sws_opts, NULL, - graph)) < 0) - return ret; - break; - case AVMEDIA_TYPE_AUDIO: - if (!(filter = avfilter_get_by_name("aresample"))) { - av_log(log_ctx, AV_LOG_ERROR, "'aresample' filter " - "not present, cannot convert audio formats.\n"); - return AVERROR(EINVAL); - } - - snprintf(inst_name, sizeof(inst_name), "auto_resampler_%d", - resampler_count++); - if ((ret = avfilter_graph_create_filter(&convert, filter, - inst_name, graph->aresample_swr_opts, - NULL, graph)) < 0) - return ret; - break; - default: + 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) return ret; diff --git a/libavfilter/formats.c b/libavfilter/formats.c index eceae8ba9c..3e60a01fbd 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -329,11 +329,15 @@ static const AVFilterFormatsMerger mergers_audio[] = { static const AVFilterNegotiation negotiate_video = { .nb = FF_ARRAY_ELEMS(mergers_video), .mergers = mergers_video, + .conversion_filter = "scale", + .conversion_opts_offset = offsetof(AVFilterGraph, scale_sws_opts), }; static const AVFilterNegotiation negotiate_audio = { .nb = FF_ARRAY_ELEMS(mergers_audio), .mergers = mergers_audio, + .conversion_filter = "aresample", + .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), }; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link) diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 7a1f8408ac..b2dfeba497 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -78,6 +78,8 @@ typedef struct AVFilterFormatMerger { typedef struct AVFilterNegotiation { unsigned nb; const AVFilterFormatsMerger *mergers; + const char *conversion_filter; + unsigned conversion_opts_offset; } AVFilterNegotiation; const AVFilterNegotiation *ff_filter_get_negotiation(AVFilterLink *link);