From patchwork Wed Mar 2 18:40:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 34584 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6838:d078:0:0:0:0 with SMTP id x24csp4904229nkx; Wed, 2 Mar 2022 10:41:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxa2Vedv+RGUS1QkKRe8p/B0OiD0s1Or4MIOAqJYulXEqHgNCBsA9m4dL2RIBYpFCm8Sbva X-Received: by 2002:a50:e08c:0:b0:407:cdc6:809e with SMTP id f12-20020a50e08c000000b00407cdc6809emr30270271edl.162.1646246467086; Wed, 02 Mar 2022 10:41:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646246467; cv=none; d=google.com; s=arc-20160816; b=r2q0FHDTpH9ErwjR4IFHuqK/WDsetSRPJX+7wICih80/X8VdbXrJ3WWq6JDJq/IXA3 hvWR4kMxATvIhgni+He2sxilFybujvPSDXzBCGXpUx1xQ3gi0f1rOJq7vaR6FoIbtEpK bF1H3uLzpx6aBdg1VbwxJDsD8YSJoZS67lD1q1B4+ko5eAizp+6SCdHb8UBVw6P1jn0t O9IwDgKyygTKbwgWf/U8XHU3lZcrlDdWDj7UWNZReQuuDYJzhsfsXaKTVA+XF0CnspHI BGrI7hmgLBR9t+fcsNCENHpKcnsfScwWDvUfhX6gS4orq/AKzvRDn/oqtuqhjl/D2ze1 EvRw== 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=lk1KFGCP8Y3Au0vO/Qs7Xr33g0ujzoPEBmN1pOWvRPo=; b=bNdwJCdupy1g3/BxIRUjAytAoNAcBoRneHyHJa2aFYDbMSkQ1EM+4H+/aUvmrRZ8// 36pCOo142r+57b06gqz0zpZv9qOId0okTOCsp5qoNev+jQ0ow8Fz3za5AUw+L9LhHa23 alFdkRRFONeR9RacgCi0EleRWBvWknIwZv4gcgJ4yRoCjGNvKNjg0u03Kw1zFz1lgq3a SRLPe//Q6uf2S+PqdfaGfUb5Ul2bjVSU0fK153uGgCByqrj4CoMP6FoQJQ/EsJV3ZNpU q4Dg1D7AN22e0S8RD19HkfOpHF8cnyv0MoLTJywuV79OwmMg3Jmp9KrkBylaMyAolId5 q+rw== 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 y18-20020a056402271200b00410d7262743si14322853edd.568.2022.03.02.10.40.45; Wed, 02 Mar 2022 10:41:07 -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; 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 E116B68B1FF; Wed, 2 Mar 2022 20:40:32 +0200 (EET) 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 BDA3268B31C for ; Wed, 2 Mar 2022 20:40:25 +0200 (EET) 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 222IeOx5010650 for ; Wed, 2 Mar 2022 19:40:25 +0100 Received: by phare.normalesup.org (Postfix, from userid 1001) id AFE2AE62AD; Wed, 2 Mar 2022 19:40:24 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Mar 2022 19:40:19 +0100 Message-Id: <20220302184023.285022-1-george@nsup.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Wed, 02 Mar 2022 19:40:25 +0100 (CET) Subject: [FFmpeg-devel] [PATCH 1/5] lavfi/graphdump: add plain listing output 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: B0mcf4HeQ64h Signed-off-by: Nicolas George --- libavfilter/avfilter.h | 5 ++- libavfilter/graphdump.c | 79 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) Unchanged since last summer. The last patch is what this is needed for. diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index b105dc3159..b338766609 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -1153,7 +1153,10 @@ int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const * Dump a graph into a human-readable string representation. * * @param graph the graph to dump - * @param options formatting options; currently ignored + * @param options formatting options; can be NULL, empty + * or "f=aa" for clumsy ascii-art drawing, + * or "f=tech" for plain listing; + * other values silently ignored * @return a string, or NULL in case of memory allocation failure; * the string must be freed using av_free */ diff --git a/libavfilter/graphdump.c b/libavfilter/graphdump.c index cf8914b558..80dbccc66a 100644 --- a/libavfilter/graphdump.c +++ b/libavfilter/graphdump.c @@ -27,6 +27,9 @@ #include "avfilter.h" #include "internal.h" +#define FORMAT_AA 0 +#define FORMAT_TECH 1 + static int print_link_prop(AVBPrint *buf, AVFilterLink *link) { const char *format; @@ -60,7 +63,51 @@ static int print_link_prop(AVBPrint *buf, AVFilterLink *link) return buf->len; } -static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph) +static inline const char *fcname(const AVFilterContext *filter) +{ + return filter->name ? filter->name : ""; +} + +static void dump_tech(AVBPrint *buf, AVFilterGraph *graph) +{ + unsigned i, j; + + for (i = 0; i < graph->nb_filters; i++) { + AVFilterContext *filter = graph->filters[i]; + + if (i) + av_bprintf(buf, "\n"); + av_bprintf(buf, "Filter: %s (%s)\n", fcname(filter), filter->filter->name); + + for (j = 0; j < filter->nb_inputs; j++) { + AVFilterPad *pad = &filter->input_pads[j]; + AVFilterLink *link = filter->inputs[j]; + AVFilterPad *ppad = link->srcpad; + AVFilterContext *peer = link->src; + + av_bprintf(buf, " in %d: %s ← %s.%d:%s ", + j, pad->name, + fcname(peer), FF_OUTLINK_IDX(link), ppad->name); + print_link_prop(buf, link); + av_bprintf(buf, "\n"); + } + + for (j = 0; j < filter->nb_outputs; j++) { + AVFilterPad *pad = &filter->output_pads[j]; + AVFilterLink *link = filter->outputs[j]; + AVFilterPad *ppad = link->dstpad; + AVFilterContext *peer = link->dst; + + av_bprintf(buf, " out %d: %s → %s.%d:%s ", + j, pad->name, + fcname(peer), FF_INLINK_IDX(link), ppad->name); + print_link_prop(buf, link); + av_bprintf(buf, "\n"); + } + } +} + +static void dump_ascii_art(AVBPrint *buf, AVFilterGraph *graph) { unsigned i, j, x, e; @@ -152,17 +199,43 @@ static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph) } } +static void avfilter_graph_dump_to_buf(AVBPrint *buf, AVFilterGraph *graph, const char *options) +{ + unsigned format = FORMAT_AA; + + /* For a very long time, options was ignored. + Having a string for that task was a mistake, but it is not important. + It is not worth a proper parsing. + */ + if (options && *options) { + if (!strcmp("f=aa", options)) { + format = FORMAT_AA; + } else if (!strcmp("f=tech", options)) { + format = FORMAT_TECH; + } + /* ignore other values */ + } + switch (format) { + case FORMAT_AA: + dump_ascii_art(buf, graph); + break; + case FORMAT_TECH: + dump_tech(buf, graph); + break; + } +} + char *avfilter_graph_dump(AVFilterGraph *graph, const char *options) { AVBPrint buf; char *dump = NULL; av_bprint_init(&buf, 0, AV_BPRINT_SIZE_COUNT_ONLY); - avfilter_graph_dump_to_buf(&buf, graph); + avfilter_graph_dump_to_buf(&buf, graph, options); dump = av_malloc(buf.len + 1); if (!dump) return NULL; av_bprint_init_for_buffer(&buf, dump, buf.len + 1); - avfilter_graph_dump_to_buf(&buf, graph); + avfilter_graph_dump_to_buf(&buf, graph, options); return dump; }