From patchwork Thu Aug 19 15:30:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29618 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp403595iov; Thu, 19 Aug 2021 08:31:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8nYlVALwBddxHx8bGORrCv/SBLrNWCZqqK9BMP4RRx68SCRHDbD4U/07dlKHNutc68Az0 X-Received: by 2002:a17:906:544f:: with SMTP id d15mr16331241ejp.520.1629387078467; Thu, 19 Aug 2021 08:31:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629387078; cv=none; d=google.com; s=arc-20160816; b=WrvaMAF5bpv1P1nSJsgJe9lS0KM4UPwbdt3arQ6xtn5g3BWUuSIZMYaOCTJ4B1Nuus lldyYJT+thla+fat9gh9XaT35puE7J9NHl4lzgJytg2iaayRIy0cfOKikLewifSnFDL7 TiCfnsiV2DgD0c2XJrgY4V8/HVa7D1DVD4phghNIHmU+VzuWK0DQJBo4QGD35Sac2nhy uo7A7/FPp/HCM/8rDCLDJifA+oov/aFbC2QSN7m2jCaJWYvD2gXfBtKu50FxYnVUA2BT DRna8ZSoa1F145D4QPW1x9vL0TMH2YU62SanDq+c1uirENfp8IJ28ymMYT3XztY/Mhs4 HDSA== 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=VUQVlSvn7vg2s8lCGK8Q9NT5VS1s0c4yLzAr63roZTk=; b=GS7ScvfiyBY26zw8MhYD2yCifaStl6YH7e8jonl+q5wpjeY9pd7iMVd5khX17ba4qL C8Vf7CnP5QE0D9j/IivPdmJGr1hmJ8mvKemDKm1AayPi4XH1ULN7nWyyeqdGTzhs9Lfs gLg3bjR5wmth0Xv6btVrrp+gxLQLcWuLkMd4OSCnXtQBJ/QPTT464nM5ewC8/U4CD+Iy XoL46Y41j8VzezhO+mWMs5i9SWwWtJ5aIfyTNOqtzo7PHxiIclaeVXJog/LFV1P2i+tw wzImvXGbmfEahLDpRaJCGpFSebaahLA4/ftVI7fOMkUD0fXML8VIK7zq/S4MMTKJbduX Wx0Q== 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 dz8si3521811edb.137.2021.08.19.08.31.12; Thu, 19 Aug 2021 08:31:18 -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 889BE68A26E; Thu, 19 Aug 2021 18:31:08 +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 E95F96804F6 for ; Thu, 19 Aug 2021 18:31:01 +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 17JFV0bs024254 for ; Thu, 19 Aug 2021 17:31:01 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id D8AF6EB5BD; Thu, 19 Aug 2021 17:31:00 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 19 Aug 2021 17:30:55 +0200 Message-Id: <20210819153057.149696-1-george@nsup.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 19 Aug 2021 17:31:01 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 1/3] lavfi/formats: cosmetic: move negotiation stuff at the end 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: 7LKjqmXKFEee It was between AVFilterFormats and AVFilterChannelLayouts. Signed-off-by: Nicolas George --- libavfilter/formats.h | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) The last commit is the one I sent earlier, just rebased on top of this cosmetic change because it makes no sense to add almost a hundred lines of documentation just to move it in the next commit. Since these three patches are cosmetic and internal documentation, I will push soon, probably as soon as I have something new to post on top of them. But please comment nonetheless. Anton and Michael: you are the authors of the redundant similarity logics in swap and pick_formats() (see the FIXME comments in the third patche), I would appreciate if you had a look at it. Michael, in particular, if you have test cases covering this logic that are not part of FATE, please share them, or even better make them part of FATE if possible. diff --git a/libavfilter/formats.h b/libavfilter/formats.h index ed513c265a..a9cfa14e95 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -69,21 +69,6 @@ struct AVFilterFormats { struct AVFilterFormats ***refs; ///< references to this list }; -typedef struct AVFilterFormatMerger { - unsigned offset; - int (*merge)(void *a, void *b); - int (*can_merge)(const void *a, const void *b); -} AVFilterFormatsMerger; - -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); - /** * A list of supported channel layouts. * @@ -330,4 +315,19 @@ int ff_formats_check_sample_rates(void *log, const AVFilterFormats *fmts); */ int ff_formats_check_channel_layouts(void *log, const AVFilterChannelLayouts *fmts); +typedef struct AVFilterFormatMerger { + unsigned offset; + int (*merge)(void *a, void *b); + int (*can_merge)(const void *a, const void *b); +} AVFilterFormatsMerger; + +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); + #endif /* AVFILTER_FORMATS_H */ From patchwork Thu Aug 19 15:30:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29617 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp403853iov; Thu, 19 Aug 2021 08:31:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw144F+ryhIO9A5KcCug9LGUs4UYNlvRO+8jYAFuYmYHXxIbMyCBdddOCs1burXRRL9IydT X-Received: by 2002:a17:906:32d6:: with SMTP id k22mr15866410ejk.228.1629387094444; Thu, 19 Aug 2021 08:31:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629387094; cv=none; d=google.com; s=arc-20160816; b=kWox5D9fvFmop0Pfvr9hsnhVc3cTfUstAE++QU96esF6R9cXNManousSKaArdPg+ps m+SWLFsVzreiG9r5ijZv6tMzVQNnwuvK0bMrB2gDU+qF2XPTEoeHOdmirdybHG04mkWg 0WR5TlZvNTZ5OYGTiOjdXsBDhIDHAX3Py6Qqv5RZXVtn6LtL5aUXxnYwOoz7OodiOR3e vgBslrA7Nos8peDor8Wkuzh/o5xbF6RT3NxTDasopWQQAHskB3LFgh7rlpZ9yqv1ck// uAeKbnIhDcpZ8FSkZMMuWKJiBg9cAGVydoCqOBmY/e29y1d6Mo8DZ9TgYhwjTpjfMBpy vyzQ== 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:delivered-to; bh=61DoNLa9Xsl3FGgqcgMUSMoc5tRqG1JmRsbJS5f5s88=; b=J5vNAlCfuye0wqaSRheOaeRhAmFIC0QRY7I7YXAwIr6vqO+7nC4ds0aowg4Mh/MlLO bSKL2pIjcqVsMChD1vz8/fL/KMteCVDBdXH9hA7BASiH1y2hVUW5uLv8e4n9w00dlemh ZV6c/DELDSjp/bZOWTjPdU8e3bC9p6scORY0yF6AVVYzCY2o7uIn3S5I/77AGQAHmu1I zefR7r8jL0BSBfBCN4DWRX0i42+qblDYy1Q4G9xWP1jYPPsuRTrL6DEhdjwfeYxV5nX/ 1BtBSztFh5nzIqME5nfzhWgs7eGQvTOdVVBcxSj86L55dEkflo2C0SYNukNS1NQicdcZ gZaw== 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 f9si3438382ejl.743.2021.08.19.08.31.24; Thu, 19 Aug 2021 08:31:34 -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 A571F68A410; Thu, 19 Aug 2021 18:31:09 +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 6B37E6804F6 for ; Thu, 19 Aug 2021 18:31:02 +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 17JFV1sM024262 for ; Thu, 19 Aug 2021 17:31:01 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 9D53EEB5BC; Thu, 19 Aug 2021 17:31:01 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 19 Aug 2021 17:30:56 +0200 Message-Id: <20210819153057.149696-2-george@nsup.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210819153057.149696-1-george@nsup.org> References: <20210819153057.149696-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 19 Aug 2021 17:31:02 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/3] lavfi/formats: rename AVFilterNegotiation.nb to nb_mergers 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: x9qTPdM7QioL Signed-off-by: Nicolas George --- libavfilter/avfiltergraph.c | 6 +++--- libavfilter/formats.c | 4 ++-- libavfilter/formats.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 41a91a9bda..8c6d43a0c7 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -465,7 +465,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) neg = ff_filter_get_negotiation(link); av_assert0(neg); - for (neg_step = 1; neg_step < neg->nb; neg_step++) { + for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) { const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; void *a = FF_FIELD_AT(void *, m->offset, link->incfg); void *b = FF_FIELD_AT(void *, m->offset, link->outcfg); @@ -474,7 +474,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) break; } } - for (neg_step = 0; neg_step < neg->nb; neg_step++) { + for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; void *a = FF_FIELD_AT(void *, m->offset, link->incfg); void *b = FF_FIELD_AT(void *, m->offset, link->outcfg); @@ -542,7 +542,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) av_assert0(outlink-> incfg.channel_layouts->refcount > 0); av_assert0(outlink->outcfg.channel_layouts->refcount > 0); } - for (neg_step = 0; neg_step < neg->nb; neg_step++) { + for (neg_step = 0; neg_step < neg->nb_mergers; neg_step++) { const AVFilterFormatsMerger *m = &neg->mergers[neg_step]; void *ia = FF_FIELD_AT(void *, m->offset, inlink->incfg); void *ib = FF_FIELD_AT(void *, m->offset, inlink->outcfg); diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 9e39d65a3c..ca85b4094b 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -327,14 +327,14 @@ static const AVFilterFormatsMerger mergers_audio[] = { }; static const AVFilterNegotiation negotiate_video = { - .nb = FF_ARRAY_ELEMS(mergers_video), + .nb_mergers = 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), + .nb_mergers = FF_ARRAY_ELEMS(mergers_audio), .mergers = mergers_audio, .conversion_filter = "aresample", .conversion_opts_offset = offsetof(AVFilterGraph, aresample_swr_opts), diff --git a/libavfilter/formats.h b/libavfilter/formats.h index a9cfa14e95..d94977a3aa 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -322,7 +322,7 @@ typedef struct AVFilterFormatMerger { } AVFilterFormatsMerger; typedef struct AVFilterNegotiation { - unsigned nb; + unsigned nb_mergers; const AVFilterFormatsMerger *mergers; const char *conversion_filter; unsigned conversion_opts_offset; From patchwork Thu Aug 19 15:30:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 29616 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp403902iov; Thu, 19 Aug 2021 08:31:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0tWYUBBRwVbkCw0SpvpWTfKSFFNM1JK4+DGi1+iHhGVHQ7knF7Ry1aq30HLDCvkT+GjKv X-Received: by 2002:adf:a1ca:: with SMTP id v10mr4529133wrv.177.1629387097260; Thu, 19 Aug 2021 08:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629387097; cv=none; d=google.com; s=arc-20160816; b=ym73ZanWkyt9qMTiqeR9xY58qF5rZJxCf8wD/BK/lrL9xgMyESZ6T6p38HREpCK0JI ztxVHEVfPvHZ8H+dcMbyd7LdLf2cCorbGYWERMi0xwlhm5f6cO9iXow7kjjEL+hzwfJY 1DgztbhfLMBVBYGonbe1suk1I+f2GT2wOJD0e4y3kA06OQrNqb2Ee2zbpEUig6pVwzNF p2puJxZs745/aUPt255QmgG0oPCvSo/KUgOoMfizIMzVT5kh588bVknF/CXymZ6ztRwt eJEHX+lsXtzsNxQhGJYTzSZm+JRBgnUfBdJX26H0tomgbjVPx/rsDSIBqvIgjp8WCId7 NNbg== 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:delivered-to; bh=a+84UPAUq3CSBUgAzhmYXO2Oorv5TJEw9p2XxN+FKzs=; b=fBOQ5ZtVQ82PpKTqTrH1q/W5nNE4/g1jyOdxKv0rN+PkciTmahIYsAs+9M7XaQ4EEs 5vItYxhFWJIMXlpaP0KdZzqs9BLoALLeOklopRqp/Kollh+5/j/myPcFx/ORnhK+UnS2 EG8qT1ojvbBmw/mIhbRj0AVsPcGJPH2Zeopv1ub/epPWEQaRnw/traWu23WmaVplMEJh MXYaSOS6mUAkp6Ys+DQYF7IQFkLfQxOZlYxryIEhNMAImZUIUt44oDQZaqyl7MrKvQ3W xh5IAVtb2jwjw+NrsX7P2tVdp+d976oB58p4HWbJiLP8ed1zSK4+ax16s+VktjzR0yel njnQ== 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 co23si3429425edb.302.2021.08.19.08.31.36; Thu, 19 Aug 2021 08:31:37 -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 AA3D368A3E8; Thu, 19 Aug 2021 18:31:10 +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 445BB68A2FE for ; Thu, 19 Aug 2021 18:31:03 +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 17JFV2Gf024265 for ; Thu, 19 Aug 2021 17:31:02 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id 76CE8EB5BC; Thu, 19 Aug 2021 17:31:02 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Thu, 19 Aug 2021 17:30:57 +0200 Message-Id: <20210819153057.149696-3-george@nsup.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210819153057.149696-1-george@nsup.org> References: <20210819153057.149696-1-george@nsup.org> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Thu, 19 Aug 2021 17:31:02 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 3/3] lavfi/formats: document the negotiation process 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: sHEKXfYxI/5/ Signed-off-by: Nicolas George --- libavfilter/formats.h | 85 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/libavfilter/formats.h b/libavfilter/formats.h index d94977a3aa..7c8258ed08 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -321,6 +321,91 @@ typedef struct AVFilterFormatMerger { int (*can_merge)(const void *a, const void *b); } AVFilterFormatsMerger; +/** + * Callbacks and properties to describe the steps of a format negotiation. + * + * The steps are: + * + * 1. query_formats(): call the callbacks on all filter to set lists of + * supported formats. + * When links on a filter must eventually have the same + * format, the lists of supported formats are the same + * object in memory. + * See: + * http://www.normalesup.org/~george/articles/format_negotiation_in_libavfilter/#12 + * + * + * 2. query_formats(): merge lists of supported formats or insert automatic + * conversion filters. + * Compute the intersection of the lists of supported + * formats on the ends of links. If it succeeds, replace + * both objects with the intersection everywhere they + * are referenced. + * If the intersection is empty, insert an automatic + * conversion filter. + * If several formats are negotiated at once (format, + * rate, layout), only merge if all three can be, since + * the conversion filter can convert all three at once. + * This process goes on as long as progress is made. + * See: + * http://www.normalesup.org/~george/articles/format_negotiation_in_libavfilter/#14 + * http://www.normalesup.org/~george/articles/format_negotiation_in_libavfilter/#29 + * + * 3. reduce_formats(): try to reduce format conversion within filters. + * For each link where there is only one supported + * formats on output, for each output of the connected + * filter, if the media type is the same and said + * format is supported, keep only this one. + * This process goes on as long as progress is made. + * Rationale: conversion filters will set a large list + * of supported formats on outputs but users will + * expect the output to be as close as possible as the + * input (examples: scale without changing the pixel + * format, resample without changint the layout). + * FIXME: this can probably be done by merging the + * input and output lists instead of re-implementing + * the logic. + * + * 4. swap_sample_fmts(): + * swap_samplerates(): + * swap_channel_layouts(): For each filter with an input with only one + * supported format, when outputs have several + * supported formats, put the best one with + * reference to the input at the beginning of the + * list, to prepare it for being picked up by + * pick_formats(). + * The best format is the one that is most + * similar to the input while not losing too much + * information. + * This process need to run only once. + * FIXME: reduce_formats() operates on all inputs + * with a single format, swap_*() operates on the + * first one only: check if the difference makes + * sense. + * TODO: the swapping done for one filter can + * override the swapping done for another filter + * connected to the same list of formats, maybe + * it would be better to compute a total score + * for all connected filters and use the score to + * pick the format instead of just swapping. + * TODO: make the similarity logic available as + * public functions in libavutil. + * + * 5. pick_formats(): Choose one format from the lists of supported formats, + * use it for the link and reduce the list to a single + * element to force other filters connected to the same + * list to use it. + * First process all links where there is a single format + * and the output links of all filters with an input, + * trying to preserve similarity between input and + * outputs. + * Repeat as long as process is made. + * Then do a final run for the remaining filters. + * FIXME: the similarity logic (the ref argument to + * pick_format()) added in FFmpeg duplicates and + * overrides the swapping logic added in libav. Better + * merge them into a score system. + */ typedef struct AVFilterNegotiation { unsigned nb_mergers; const AVFilterFormatsMerger *mergers;