From patchwork Tue Aug 2 16:54:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 37089 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1649:b0:8b:613a:194d with SMTP id no9csp3256582pzb; Tue, 2 Aug 2022 09:54:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR623w3L8p0nAqkHQE6BsuMs2/Tgq5PzbvAhE7TJk3MPOHSTi21mJvvNAU1LxVjxndcrtnrr X-Received: by 2002:a05:6402:331f:b0:43d:931c:6945 with SMTP id e31-20020a056402331f00b0043d931c6945mr12072618eda.199.1659459285266; Tue, 02 Aug 2022 09:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659459285; cv=none; d=google.com; s=arc-20160816; b=M+bYhIRei/h8h6nrqqz7QZCL6GUlkU1o/UFtbKWeNxkb7vh0nJIvNFmPlzgUNTJag5 cKwU1PIp+GjYcKCQDHCF7tq7p7EHhysbONW0FR3/4owp7TpJIvLLU6N/C2ORT3JCFl+c nMnS4EHTuM6Cwrq3CibUomwv4BuV57VGgZHZ+AiYls5NZ/FlG/1qo+60HBr02GKIPBjR lJOwrE2RDoI8hUTr+v87MOmsd13HFVqIj0jhLacwv2H6SMoE5le0+eV2oO39vR81+h+x BW5ewb+K3242tSRxCEnNS0lt8mZmfMurOmuDCzFU7lJ2zIvTWW1QH3KjFxC8zhYy2sw9 KdDA== 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=nedzHDfKTMTvla6FshcDingPKWvMcgdXVy/3j769WnI=; b=kM31WueGp3zk1VDPkD0NmaRbL8MHDrlL5ZjqXxUaxcIypnwTIEwCuucMMcfw42vRW4 LfKKmpZSu3jfyvoEYtEOWtJ46mvFAEjRwqFdTKMvvy6XusMmgSHNxJYlN0LX4HRFMQ/0 vU42orKyntTkEiB8R5DkdB9pDQ0GTL1dIGN5OUxdjMNaivmEwwuflwvqoq+O3KB+oBhy LCx6cCXBoTdV8tCUkpgunMuU/TS43pBkTYfwk/gOAzRoghORaIHggTpsq9ZSC8zbDW3o 3qun1tTGwyIubwtzrHOWUg5v31cjgA45vqCsquNNUC270pFcmynUZq2vOiKjsvR7iaZH AFOQ== 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 r17-20020a05640251d100b0043d81c2b085si2922143edd.224.2022.08.02.09.54.45; Tue, 02 Aug 2022 09:54:45 -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 B6A0068BA7A; Tue, 2 Aug 2022 19:54:34 +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 E96FC68B9FD for ; Tue, 2 Aug 2022 19:54:25 +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 272GsOma017564 for ; Tue, 2 Aug 2022 18:54:25 +0200 Received: by phare.normalesup.org (Postfix, from userid 1001) id D9ACDEB5BC; Tue, 2 Aug 2022 18:54:24 +0200 (CEST) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Tue, 2 Aug 2022 18:54:16 +0200 Message-Id: <20220802165421.137563-2-george@nsup.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220802165421.137563-1-george@nsup.org> References: <20220802165421.137563-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]); Tue, 02 Aug 2022 18:54:25 +0200 (CEST) Subject: [FFmpeg-devel] [PATCH 2/7] 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: eD7qEkpa5D1s Signed-off-by: Nicolas George --- libavfilter/avfilter.h | 5 ++- libavfilter/graphdump.c | 79 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) Identical to the one posted months ago. diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 2e8197c9a6..ad38f1bdc2 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -1163,7 +1163,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 80f7bf6c98..992183a882 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; @@ -62,7 +65,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; @@ -154,17 +201,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; }