From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id E8AEF4D1CA for <ffmpegdev@gitmailbox.com>; Wed, 16 Apr 2025 10:13:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E2586687DC9; Wed, 16 Apr 2025 13:12:51 +0300 (EEST) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 852AE687DBE for <ffmpeg-devel@ffmpeg.org>; Wed, 16 Apr 2025 13:12:45 +0300 (EEST) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7376dd56f60so4462695b3a.3 for <ffmpeg-devel@ffmpeg.org>; Wed, 16 Apr 2025 03:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744798364; x=1745403164; darn=ffmpeg.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc:subject:date :message-id:reply-to; bh=zFD85Da2g+myKsP9/oOXsWtyQrYxgjR5vOcXwp8iW90=; b=HCN+EYGBjoetOcWLME3UY850vpiDV2jq+Gn+yvXmnHWXWfDfO7mL9yPomG3Pmxy08h 0Atrf3RVdf67mo0eaVWynGnctau9bU5HNgG+EYPCLlNbhpwtFqF7XVzChl8+b7KJWpJB qtM8uWZKVRS5KkvLvtIr4lIJxzIU0HkE0yDoN/88e1VMv91/YVt79a3RCXtqNFTf32hU 9TtN0FLSl8KsrhGKxENYK1sZsIFNWj/I5qudm5NoKejpnk7wgvxDdMGU2v396Kg3Qq3k xlL045anLBzo1o/28+fLqL3F9tG4au3+vpJ4UJRLhRhzPjrwanl4Kwl+GAk8tea1sUMZ Mdvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744798364; x=1745403164; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=zFD85Da2g+myKsP9/oOXsWtyQrYxgjR5vOcXwp8iW90=; b=tLp/DlDYDFKd+eOZN88/8VieS3a6RfJ/2YhYYHyA4nVVXUZdot+FJrlDaWUnm/+Qv2 7CetcwGxTvBbDKapRhjmvDpjcEKtM62+mbWz93LppvnDxtqebnge61GZzNTT6Ijg39R3 z49S+1oXl122sWpBKbPzVQ6rzcn/fbAHlqf5kYvMGUtq0af+9+nu9kTuy0lGmi8MomeN XQ+ttyIit9T9FPlyL9ApRCMdzqOhqUYFLDKyovfz+sSwlPU7XbovB1ad0jUJVHQi59KD Y4jpH8JCcZGa+3nNs6jW6hUIdAI7BgrD7PPC9EBWFzegxXnhKuK31eLMnc8Uu+TFOukV VBUg== X-Gm-Message-State: AOJu0Yy3ffM87KZ7VEcf0PRUlwCpuXKhV/BXoCaJqMEhh6tE8IfLi6F5 uM6zupo6YzMtIEiZ/Yay41hTP9Kza6mgpAu/Jk+nagdYvvQ7Tv+OQr4efQ== X-Gm-Gg: ASbGncvYNjj9f9NZiNlcGwMyq/TchIzcZJNns2JLTMk2NcKcms715D7+K0317JXwlBE OVihvb8NUaUVYekJYKiga/hxF3COBaw8zU1KOPBfaNb9IgPSMwhnvNjTDl41kh1+Sn5T/HusTxu zFoEUweH1oWpDRZ9CjJ5kxi0PqjgXdTqbSrg4TPXBF2+vWX6w+6yROdQNWwdq1HBL0XWYeMsKU1 DdmLy3vgp4DedoRPA8q3ImHjNyyUh6+mV7IECy1k2I1739qaZOjO4Xzk05cKv6GdqhN0fyC3d57 dBdDZkV4ZDeVFHee8H8psj7NOedDLsWjXu4Y+RqxmgUpBEMUAsHrcf22Jyk= X-Google-Smtp-Source: AGHT+IFB0tDxHaYVDIFqNPtQWuYopPC6SR7760NYOZteIFjuUmOyVCSEnSAoTpfJzD8PasYOebYFeg== X-Received: by 2002:a05:6a00:3a0e:b0:739:56c2:b661 with SMTP id d2e1a72fcca58-73c26716c1cmr1876002b3a.12.1744798363397; Wed, 16 Apr 2025 03:12:43 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73bd2198958sm10026725b3a.30.2025.04.16.03.12.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Apr 2025 03:12:43 -0700 (PDT) From: softworkz <ffmpegagent@gmail.com> X-Google-Original-From: softworkz <softworkz@hotmail.com> Message-Id: <9e77a447b890d6c71798986302a4c323ae46e821.1744798340.git.ffmpegagent@gmail.com> In-Reply-To: <pull.66.v2.ffstaging.FFmpeg.1744798340.ffmpegagent@gmail.com> References: <pull.66.ffstaging.FFmpeg.1744634826.ffmpegagent@gmail.com> <pull.66.v2.ffstaging.FFmpeg.1744798340.ffmpegagent@gmail.com> Date: Wed, 16 Apr 2025 10:12:13 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v2 03/10] fftools/textformat: Introduce common header and deduplicate code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: softworkz <softworkz@hotmail.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> Archived-At: <https://master.gitmailbox.com/ffmpegdev/9e77a447b890d6c71798986302a4c323ae46e821.1744798340.git.ffmpegagent@gmail.com/> List-Archive: <https://master.gitmailbox.com/ffmpegdev/> List-Post: <mailto:ffmpegdev@gitmailbox.com> From: softworkz <softworkz@hotmail.com> Signed-off-by: softworkz <softworkz@hotmail.com> --- fftools/textformat/avtextwriters.h | 2 +- fftools/textformat/tf_compact.c | 32 ++++------- fftools/textformat/tf_default.c | 27 +++------- fftools/textformat/tf_flat.c | 25 +++------ fftools/textformat/tf_ini.c | 24 +++------ fftools/textformat/tf_internal.h | 85 ++++++++++++++++++++++++++++++ fftools/textformat/tf_json.c | 38 +++++-------- fftools/textformat/tf_xml.c | 35 +++++------- fftools/textformat/tw_avio.c | 9 ++-- fftools/textformat/tw_buffer.c | 7 +-- fftools/textformat/tw_stdout.c | 8 +-- 11 files changed, 150 insertions(+), 142 deletions(-) create mode 100644 fftools/textformat/tf_internal.h diff --git a/fftools/textformat/avtextwriters.h b/fftools/textformat/avtextwriters.h index 34db3f1832..fd6da747eb 100644 --- a/fftools/textformat/avtextwriters.h +++ b/fftools/textformat/avtextwriters.h @@ -41,7 +41,7 @@ typedef struct AVTextWriter { void (*uninit)(AVTextWriterContext *wctx); void (*writer_w8)(AVTextWriterContext *wctx, int b); void (*writer_put_str)(AVTextWriterContext *wctx, const char *str); - void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...); + void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, va_list vl); } AVTextWriter; typedef struct AVTextWriterContext { diff --git a/fftools/textformat/tf_compact.c b/fftools/textformat/tf_compact.c index d4ac296a42..e52888239e 100644 --- a/fftools/textformat/tf_compact.c +++ b/fftools/textformat/tf_compact.c @@ -28,23 +28,7 @@ #include "libavutil/bprint.h" #include "libavutil/error.h" #include "libavutil/opt.h" - - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} +#include "tf_internal.h" /* Compact output */ @@ -157,9 +141,12 @@ static av_cold int compact_init(AVTextFormatContext *wctx) static void compact_print_section_header(AVTextFormatContext *wctx, const void *data) { CompactContext *compact = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + + if (!section) + return; + compact->terminate_line[wctx->level] = 1; compact->has_nested_elems[wctx->level] = 0; @@ -210,8 +197,11 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void * static void compact_print_section_footer(AVTextFormatContext *wctx) { - const struct AVTextFormatSection *section = wctx->section[wctx->level]; CompactContext *compact = wctx->priv; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + + if (!section) + return; if (!compact->nested_section[wctx->level] && compact->terminate_line[wctx->level] && diff --git a/fftools/textformat/tf_default.c b/fftools/textformat/tf_default.c index ad97173b0b..019bda9d44 100644 --- a/fftools/textformat/tf_default.c +++ b/fftools/textformat/tf_default.c @@ -27,21 +27,7 @@ #include "avtextformat.h" #include "libavutil/bprint.h" #include "libavutil/opt.h" - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} +#include "tf_internal.h" /* Default output */ @@ -80,9 +66,11 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void * { DefaultContext *def = wctx->priv; char buf[32]; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + + if (!section) + return; av_bprint_clear(&wctx->section_pbuf[wctx->level]); if (parent_section && @@ -104,7 +92,8 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void * static void default_print_section_footer(AVTextFormatContext *wctx) { DefaultContext *def = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + char buf[32]; if (!section) diff --git a/fftools/textformat/tf_flat.c b/fftools/textformat/tf_flat.c index f692971bcc..d5517f109b 100644 --- a/fftools/textformat/tf_flat.c +++ b/fftools/textformat/tf_flat.c @@ -28,22 +28,7 @@ #include "libavutil/bprint.h" #include "libavutil/error.h" #include "libavutil/opt.h" - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} - +#include "tf_internal.h" /* Flat output */ @@ -118,9 +103,11 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat { FlatContext *flat = wctx->priv; AVBPrint *buf = &wctx->section_pbuf[wctx->level]; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + + if (!section) + return; /* build section header */ av_bprint_clear(buf); diff --git a/fftools/textformat/tf_ini.c b/fftools/textformat/tf_ini.c index dd77d0e8bf..8959785295 100644 --- a/fftools/textformat/tf_ini.c +++ b/fftools/textformat/tf_ini.c @@ -28,21 +28,7 @@ #include "libavutil/bprint.h" #include "libavutil/opt.h" - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} +#include "tf_internal.h" /* Default output */ @@ -104,9 +90,11 @@ static void ini_print_section_header(AVTextFormatContext *wctx, const void *data { INIContext *ini = wctx->priv; AVBPrint *buf = &wctx->section_pbuf[wctx->level]; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + + if (!section) + return; av_bprint_clear(buf); if (!parent_section) { diff --git a/fftools/textformat/tf_internal.h b/fftools/textformat/tf_internal.h new file mode 100644 index 0000000000..7b326328cb --- /dev/null +++ b/fftools/textformat/tf_internal.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) The FFmpeg developers + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Internal utilities for text formatters. + */ + +#ifndef FFTOOLS_TEXTFORMAT_TF_INTERNAL_H +#define FFTOOLS_TEXTFORMAT_TF_INTERNAL_H + +#include "avtextformat.h" + +#define DEFINE_FORMATTER_CLASS(name) \ +static const char *name##_get_name(void *ctx) \ +{ \ + return #name ; \ +} \ +static const AVClass name##_class = { \ + .class_name = #name, \ + .item_name = name##_get_name, \ + .option = name##_options \ +} + + +/** + * Safely validate and access a section at a given level + */ +static inline const AVTextFormatSection *tf_get_section(AVTextFormatContext *tfc, int level) +{ + if (!tfc || level < 0 || level >= SECTION_MAX_NB_LEVELS || !tfc->section[level]) { + if (tfc) + av_log(tfc, AV_LOG_ERROR, "Invalid section access at level %d\n", level); + return NULL; + } + return tfc->section[level]; +} + +/** + * Safely access the parent section + */ +static inline const AVTextFormatSection *tf_get_parent_section(AVTextFormatContext *tfc, int level) +{ + if (level <= 0) + return NULL; + + return tf_get_section(tfc, level - 1); +} + +static inline void writer_w8(AVTextFormatContext *wctx, int b) +{ + wctx->writer->writer->writer_w8(wctx->writer, b); +} + +static inline void writer_put_str(AVTextFormatContext *wctx, const char *str) +{ + wctx->writer->writer->writer_put_str(wctx->writer, str); +} + +static inline void writer_printf(AVTextFormatContext *wctx, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + wctx->writer->writer->writer_printf(wctx->writer, fmt, args); + va_end(args); +} + +#endif /* FFTOOLS_TEXTFORMAT_TF_INTERNAL_H */ diff --git a/fftools/textformat/tf_json.c b/fftools/textformat/tf_json.c index e86cdbf5d9..8072fa44a4 100644 --- a/fftools/textformat/tf_json.c +++ b/fftools/textformat/tf_json.c @@ -27,22 +27,7 @@ #include "avtextformat.h" #include "libavutil/bprint.h" #include "libavutil/opt.h" - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} - +#include "tf_internal.h" /* JSON output */ @@ -103,13 +88,14 @@ static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx static void json_print_section_header(AVTextFormatContext *wctx, const void *data) { + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); JSONContext *json = wctx->priv; AVBPrint buf; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; - if (wctx->level && wctx->nb_item[wctx->level-1]) + if (!section) + return; + if (wctx->level && wctx->nb_item[wctx->level - 1]) writer_put_str(wctx, ",\n"); @@ -143,8 +129,11 @@ static void json_print_section_header(AVTextFormatContext *wctx, const void *dat static void json_print_section_footer(AVTextFormatContext *wctx) { + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); JSONContext *json = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; + + if (!section) + return; if (wctx->level == 0) { json->indent_level--; @@ -177,9 +166,8 @@ static inline void json_print_item_str(AVTextFormatContext *wctx, static void json_print_str(AVTextFormatContext *wctx, const char *key, const char *value) { + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); JSONContext *json = wctx->priv; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) writer_put_str(wctx, json->item_sep); @@ -190,9 +178,8 @@ static void json_print_str(AVTextFormatContext *wctx, const char *key, const cha static void json_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) { + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); JSONContext *json = wctx->priv; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; AVBPrint buf; if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) @@ -216,4 +203,3 @@ const AVTextFormatter avtextformatter_json = { .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &json_class, }; - diff --git a/fftools/textformat/tf_xml.c b/fftools/textformat/tf_xml.c index 28abfc6400..6b09e09ab4 100644 --- a/fftools/textformat/tf_xml.c +++ b/fftools/textformat/tf_xml.c @@ -25,21 +25,7 @@ #include "libavutil/bprint.h" #include "libavutil/error.h" #include "libavutil/opt.h" - -#define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) -#define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) -#define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) - -#define DEFINE_FORMATTER_CLASS(name) \ -static const char *name##_get_name(void *ctx) \ -{ \ - return #name ; \ -} \ -static const AVClass name##_class = { \ - .class_name = #name, \ - .item_name = name##_get_name, \ - .option = name##_options \ -} +#include "tf_internal.h" /* XML output */ @@ -90,9 +76,11 @@ static av_cold int xml_init(AVTextFormatContext *wctx) static void xml_print_section_header(AVTextFormatContext *wctx, const void *data) { XMLContext *xml = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; - const struct AVTextFormatSection *parent_section = wctx->level ? - wctx->section[wctx->level-1] : NULL; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); + + if (!section) + return; if (wctx->level == 0) { const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " @@ -138,7 +126,10 @@ static void xml_print_section_header(AVTextFormatContext *wctx, const void *data static void xml_print_section_footer(AVTextFormatContext *wctx) { XMLContext *xml = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + + if (!section) + return; if (wctx->level == 0) { writer_printf(wctx, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : ""); @@ -158,7 +149,10 @@ static void xml_print_value(AVTextFormatContext *wctx, const char *key, { AVBPrint buf; XMLContext *xml = wctx->priv; - const struct AVTextFormatSection *section = wctx->section[wctx->level]; + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + + if (!section) + return; av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); @@ -216,4 +210,3 @@ const AVTextFormatter avtextformatter_xml = { .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &xml_class, }; - diff --git a/fftools/textformat/tw_avio.c b/fftools/textformat/tw_avio.c index b1743fb43a..48868ebf5d 100644 --- a/fftools/textformat/tw_avio.c +++ b/fftools/textformat/tw_avio.c @@ -56,14 +56,11 @@ static void io_put_str(AVTextWriterContext *wctx, const char *str) avio_write(ctx->avio_context, (const unsigned char *)str, (int)strlen(str)); } -static void io_printf(AVTextWriterContext *wctx, const char *fmt, ...) +static void io_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl) { IOWriterContext *ctx = wctx->priv; - va_list ap; - va_start(ap, fmt); - avio_vprintf(ctx->avio_context, fmt, ap); - va_end(ap); + avio_vprintf(ctx->avio_context, fmt, vl); } @@ -78,7 +75,7 @@ const AVTextWriter avtextwriter_avio = { int avtextwriter_create_file(AVTextWriterContext **pwctx, const char *output_filename) { - if (!pwctx || !output_filename || !output_filename[0]) + if (!output_filename || !output_filename[0]) return AVERROR(EINVAL); IOWriterContext *ctx; diff --git a/fftools/textformat/tw_buffer.c b/fftools/textformat/tw_buffer.c index f8b38414a6..f861722247 100644 --- a/fftools/textformat/tw_buffer.c +++ b/fftools/textformat/tw_buffer.c @@ -56,14 +56,11 @@ static void buffer_put_str(AVTextWriterContext *wctx, const char *str) av_bprintf(ctx->buffer, "%s", str); } -static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, ...) +static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl) { BufferWriterContext *ctx = wctx->priv; - va_list vargs; - va_start(vargs, fmt); - av_vbprintf(ctx->buffer, fmt, vargs); - va_end(vargs); + av_vbprintf(ctx->buffer, fmt, vl); } diff --git a/fftools/textformat/tw_stdout.c b/fftools/textformat/tw_stdout.c index 23de6f671f..dace55f38a 100644 --- a/fftools/textformat/tw_stdout.c +++ b/fftools/textformat/tw_stdout.c @@ -53,13 +53,9 @@ static inline void stdout_put_str(AVTextWriterContext *wctx, const char *str) printf("%s", str); } -static inline void stdout_printf(AVTextWriterContext *wctx, const char *fmt, ...) +static inline void stdout_printf(AVTextWriterContext *wctx, const char *fmt, va_list vl) { - va_list ap; - - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); + vprintf(fmt, vl); } -- ffmpeg-codebot _______________________________________________ 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".