aboutsummaryrefslogtreecommitdiffstats
path: root/fftools/textformat/tf_xml.c
diff options
context:
space:
mode:
authorsoftworkz <softworkz@hotmail.com>2025-04-29 01:35:50 +0200
committersoftworkz <softworkz@hotmail.com>2025-05-15 23:04:44 +0200
commitcee7b8a051739d9fa6b41f961ecec480cdaa02bd (patch)
treee6e29b87d6ec9aa4b45a77988ce81e750109bbb4 /fftools/textformat/tf_xml.c
parente4830b8c5e589ae77d4e1c9dc68a1a6240cfc3c3 (diff)
downloadffmpeg-cee7b8a051739d9fa6b41f961ecec480cdaa02bd.tar.gz
fftools/textformat: Introduce common header and deduplicate code
Also change writer_printf signature in AVTextWriter to use va_list, so that it can be called by the new function writer_printf() in tf_internal.h. Reviewed-by: Stefano Sabatini <stefasab@gmail.com> Signed-off-by: softworkz <softworkz@hotmail.com>
Diffstat (limited to 'fftools/textformat/tf_xml.c')
-rw-r--r--fftools/textformat/tf_xml.c35
1 files changed, 14 insertions, 21 deletions
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,
};
-