diff options
author | softworkz <softworkz@hotmail.com> | 2025-04-29 01:35:50 +0200 |
---|---|---|
committer | softworkz <softworkz@hotmail.com> | 2025-05-15 23:04:44 +0200 |
commit | cee7b8a051739d9fa6b41f961ecec480cdaa02bd (patch) | |
tree | e6e29b87d6ec9aa4b45a77988ce81e750109bbb4 /fftools/textformat/tf_json.c | |
parent | e4830b8c5e589ae77d4e1c9dc68a1a6240cfc3c3 (diff) | |
download | ffmpeg-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_json.c')
-rw-r--r-- | fftools/textformat/tf_json.c | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/fftools/textformat/tf_json.c b/fftools/textformat/tf_json.c index 50c3d90440..78ea5dc21f 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,10 +88,13 @@ 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 AVTextFormatSection *section = wctx->section[wctx->level]; - const AVTextFormatSection *parent_section = wctx->level ? wctx->section[wctx->level - 1] : NULL; + + if (!section) + return; if (wctx->level && wctx->nb_item[wctx->level - 1]) writer_put_str(wctx, ",\n"); @@ -141,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--; @@ -175,9 +166,12 @@ static inline void json_print_item_str(AVTextFormatContext *wctx, static void json_print_str(AVTextFormatContext *wctx, const char *key, const char *value) { + const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); + 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 (!section) + return; 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); @@ -188,10 +182,14 @@ 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 *section = tf_get_section(wctx, wctx->level); + const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); JSONContext *json = wctx->priv; - const AVTextFormatSection *parent_section = wctx->level ? wctx->section[wctx->level - 1] : NULL; AVBPrint buf; + if (!section) + return; + 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); if (!json->compact) @@ -213,4 +211,3 @@ const AVTextFormatter avtextformatter_json = { .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, .priv_class = &json_class, }; - |