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.
Unified · Split
| @@ -36,7 +36,7 @@ typedef struct AVTextWriter { · 35 unmodified lines | |||
| 36 | void (*uninit)(AVTextWriterContext *wctx); | 36 | void (*uninit)(AVTextWriterContext *wctx); |
| 37 | void (*writer_w8)(AVTextWriterContext *wctx, int b); | 37 | void (*writer_w8)(AVTextWriterContext *wctx, int b); |
| 38 | void (*writer_put_str)(AVTextWriterContext *wctx, const char *str); | 38 | void (*writer_put_str)(AVTextWriterContext *wctx, const char *str); |
| 39 | void (*writer_printf)(AVTextWriterContext *wctx, const char *fmt, ...); | 39 | void (*writer_vprintf)(AVTextWriterContext *wctx, const char *fmt, va_list vl); |
| 40 | } AVTextWriter; | 40 | } AVTextWriter; |
| 41 | 41 | ||
| 42 | typedef struct AVTextWriterContext { | 42 | typedef struct AVTextWriterContext { |
| @@ -28,23 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include "libavutil/bprint.h" | 28 | #include "libavutil/bprint.h" |
| 29 | #include "libavutil/error.h" | 29 | #include "libavutil/error.h" |
| 30 | #include "libavutil/opt.h" | 30 | #include "libavutil/opt.h" |
| 31 | 31 | #include "tf_internal.h" | |
| 32 | |||
| 33 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 34 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 35 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 36 | |||
| 37 | |||
| 38 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 39 | static const char *name##_get_name(void *ctx) \ | ||
| 40 | { \ | ||
| 41 | return #name ; \ | ||
| 42 | } \ | ||
| 43 | static const AVClass name##_class = { \ | ||
| 44 | .class_name = #name, \ | ||
| 45 | .item_name = name##_get_name, \ | ||
| 46 | .option = name##_options \ | ||
| 47 | } | ||
| 48 | 32 | ||
| 49 | 33 | ||
| 50 | /* Compact output */ | 34 | /* Compact output */ |
| @@ -157,9 +141,12 @@ static av_cold int compact_init(AVTextFormatContext *wctx) · 106 unmodified lines | |||
| 157 | static void compact_print_section_header(AVTextFormatContext *wctx, const void *data) | 141 | static void compact_print_section_header(AVTextFormatContext *wctx, const void *data) |
| 158 | { | 142 | { |
| 159 | CompactContext *compact = wctx->priv; | 143 | CompactContext *compact = wctx->priv; |
| 160 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 144 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 161 | const struct AVTextFormatSection *parent_section = wctx->level ? | 145 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); |
| 162 | wctx->section[wctx->level-1] : NULL; | 146 | |
| 147 | if (!section) | ||
| 148 | return; | ||
| 149 | |||
| 163 | compact->terminate_line[wctx->level] = 1; | 150 | compact->terminate_line[wctx->level] = 1; |
| 164 | compact->has_nested_elems[wctx->level] = 0; | 151 | compact->has_nested_elems[wctx->level] = 0; |
| 165 | 152 | ||
| @@ -208,8 +195,11 @@ static void compact_print_section_header(AVTextFormatContext *wctx, const void * · 42 unmodified lines | |||
| 208 | 195 | ||
| 209 | static void compact_print_section_footer(AVTextFormatContext *wctx) | 196 | static void compact_print_section_footer(AVTextFormatContext *wctx) |
| 210 | { | 197 | { |
| 211 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | ||
| 212 | CompactContext *compact = wctx->priv; | 198 | CompactContext *compact = wctx->priv; |
| 199 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | ||
| 200 | |||
| 201 | if (!section) | ||
| 202 | return; | ||
| 213 | 203 | ||
| 214 | if (!compact->nested_section[wctx->level] && | 204 | if (!compact->nested_section[wctx->level] && |
| 215 | compact->terminate_line[wctx->level] && | 205 | compact->terminate_line[wctx->level] && |
| @@ -27,21 +27,7 @@ · 26 unmodified lines | |||
| 27 | #include "avtextformat.h" | 27 | #include "avtextformat.h" |
| 28 | #include "libavutil/bprint.h" | 28 | #include "libavutil/bprint.h" |
| 29 | #include "libavutil/opt.h" | 29 | #include "libavutil/opt.h" |
| 30 | 30 | #include "tf_internal.h" | |
| 31 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 32 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 33 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 34 | |||
| 35 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 36 | static const char *name##_get_name(void *ctx) \ | ||
| 37 | { \ | ||
| 38 | return #name ; \ | ||
| 39 | } \ | ||
| 40 | static const AVClass name##_class = { \ | ||
| 41 | .class_name = #name, \ | ||
| 42 | .item_name = name##_get_name, \ | ||
| 43 | .option = name##_options \ | ||
| 44 | } | ||
| 45 | 31 | ||
| 46 | /* Default output */ | 32 | /* Default output */ |
| 47 | 33 | ||
| @@ -80,9 +66,11 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void * · 32 unmodified lines | |||
| 80 | { | 66 | { |
| 81 | DefaultContext *def = wctx->priv; | 67 | DefaultContext *def = wctx->priv; |
| 82 | char buf[32]; | 68 | char buf[32]; |
| 83 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 69 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 84 | const struct AVTextFormatSection *parent_section = wctx->level ? | 70 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); |
| 85 | wctx->section[wctx->level-1] : NULL; | 71 | |
| 72 | if (!section) | ||
| 73 | return; | ||
| 86 | 74 | ||
| 87 | av_bprint_clear(&wctx->section_pbuf[wctx->level]); | 75 | av_bprint_clear(&wctx->section_pbuf[wctx->level]); |
| 88 | if (parent_section && | 76 | if (parent_section && |
| @@ -104,7 +92,8 @@ static void default_print_section_header(AVTextFormatContext *wctx, const void * · 15 unmodified lines | |||
| 104 | static void default_print_section_footer(AVTextFormatContext *wctx) | 92 | static void default_print_section_footer(AVTextFormatContext *wctx) |
| 105 | { | 93 | { |
| 106 | DefaultContext *def = wctx->priv; | 94 | DefaultContext *def = wctx->priv; |
| 107 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 95 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 96 | |||
| 108 | char buf[32]; | 97 | char buf[32]; |
| 109 | 98 | ||
| 110 | if (!section) | 99 | if (!section) |
| @@ -28,22 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include "libavutil/bprint.h" | 28 | #include "libavutil/bprint.h" |
| 29 | #include "libavutil/error.h" | 29 | #include "libavutil/error.h" |
| 30 | #include "libavutil/opt.h" | 30 | #include "libavutil/opt.h" |
| 31 | 31 | #include "tf_internal.h" | |
| 32 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 33 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 34 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 35 | |||
| 36 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 37 | static const char *name##_get_name(void *ctx) \ | ||
| 38 | { \ | ||
| 39 | return #name ; \ | ||
| 40 | } \ | ||
| 41 | static const AVClass name##_class = { \ | ||
| 42 | .class_name = #name, \ | ||
| 43 | .item_name = name##_get_name, \ | ||
| 44 | .option = name##_options \ | ||
| 45 | } | ||
| 46 | |||
| 47 | 32 | ||
| 48 | /* Flat output */ | 33 | /* Flat output */ |
| 49 | 34 | ||
| @@ -118,9 +103,11 @@ static void flat_print_section_header(AVTextFormatContext *wctx, const void *dat · 68 unmodified lines | |||
| 118 | { | 103 | { |
| 119 | FlatContext *flat = wctx->priv; | 104 | FlatContext *flat = wctx->priv; |
| 120 | AVBPrint *buf = &wctx->section_pbuf[wctx->level]; | 105 | AVBPrint *buf = &wctx->section_pbuf[wctx->level]; |
| 121 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 106 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 122 | const struct AVTextFormatSection *parent_section = wctx->level ? | 107 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); |
| 123 | wctx->section[wctx->level-1] : NULL; | 108 | |
| 109 | if (!section) | ||
| 110 | return; | ||
| 124 | 111 | ||
| 125 | /* build section header */ | 112 | /* build section header */ |
| 126 | av_bprint_clear(buf); | 113 | av_bprint_clear(buf); |
| @@ -28,21 +28,7 @@ · 27 unmodified lines | |||
| 28 | 28 | ||
| 29 | #include "libavutil/bprint.h" | 29 | #include "libavutil/bprint.h" |
| 30 | #include "libavutil/opt.h" | 30 | #include "libavutil/opt.h" |
| 31 | 31 | #include "tf_internal.h" | |
| 32 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 33 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 34 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 35 | |||
| 36 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 37 | static const char *name##_get_name(void *ctx) \ | ||
| 38 | { \ | ||
| 39 | return #name ; \ | ||
| 40 | } \ | ||
| 41 | static const AVClass name##_class = { \ | ||
| 42 | .class_name = #name, \ | ||
| 43 | .item_name = name##_get_name, \ | ||
| 44 | .option = name##_options \ | ||
| 45 | } | ||
| 46 | 32 | ||
| 47 | /* Default output */ | 33 | /* Default output */ |
| 48 | 34 | ||
| @@ -104,9 +90,11 @@ static void ini_print_section_header(AVTextFormatContext *wctx, const void *data · 55 unmodified lines | |||
| 104 | { | 90 | { |
| 105 | INIContext *ini = wctx->priv; | 91 | INIContext *ini = wctx->priv; |
| 106 | AVBPrint *buf = &wctx->section_pbuf[wctx->level]; | 92 | AVBPrint *buf = &wctx->section_pbuf[wctx->level]; |
| 107 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 93 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 108 | const struct AVTextFormatSection *parent_section = wctx->level ? | 94 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); |
| 109 | wctx->section[wctx->level-1] : NULL; | 95 | |
| 96 | if (!section) | ||
| 97 | return; | ||
| 110 | 98 | ||
| 111 | av_bprint_clear(buf); | 99 | av_bprint_clear(buf); |
| 112 | if (!parent_section) { | 100 | if (!parent_section) { |
| @@ -0,0 +1,85 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) The FFmpeg developers | ||
| 3 | * | ||
| 4 | * This file is part of FFmpeg. | ||
| 5 | * | ||
| 6 | * FFmpeg is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU Lesser General Public | ||
| 8 | * License as published by the Free Software Foundation; either | ||
| 9 | * version 2.1 of the License, or (at your option) any later version. | ||
| 10 | * | ||
| 11 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 14 | * Lesser General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU Lesser General Public | ||
| 17 | * License along with FFmpeg; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | */ | ||
| 20 | |||
| 21 | /** | ||
| 22 | * @file | ||
| 23 | * Internal utilities for text formatters. | ||
| 24 | */ | ||
| 25 | |||
| 26 | #ifndef FFTOOLS_TEXTFORMAT_TF_INTERNAL_H | ||
| 27 | #define FFTOOLS_TEXTFORMAT_TF_INTERNAL_H | ||
| 28 | |||
| 29 | #include "avtextformat.h" | ||
| 30 | |||
| 31 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 32 | static const char *name##_get_name(void *ctx) \ | ||
| 33 | { \ | ||
| 34 | return #name ; \ | ||
| 35 | } \ | ||
| 36 | static const AVClass name##_class = { \ | ||
| 37 | .class_name = #name, \ | ||
| 38 | .item_name = name##_get_name, \ | ||
| 39 | .option = name##_options \ | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | /** | ||
| 44 | * Safely validate and access a section at a given level | ||
| 45 | */ | ||
| 46 | static inline const AVTextFormatSection *tf_get_section(AVTextFormatContext *tfc, int level) | ||
| 47 | { | ||
| 48 | if (!tfc || level < 0 || level >= SECTION_MAX_NB_LEVELS || !tfc->section[level]) { | ||
| 49 | if (tfc) | ||
| 50 | av_log(tfc, AV_LOG_ERROR, "Invalid section access at level %d\n", level); | ||
| 51 | return NULL; | ||
| 52 | } | ||
| 53 | return tfc->section[level]; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Safely access the parent section | ||
| 58 | */ | ||
| 59 | static inline const AVTextFormatSection *tf_get_parent_section(AVTextFormatContext *tfc, int level) | ||
| 60 | { | ||
| 61 | if (level <= 0) | ||
| 62 | return NULL; | ||
| 63 | |||
| 64 | return tf_get_section(tfc, level - 1); | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline void writer_w8(AVTextFormatContext *wctx, int b) | ||
| 68 | { | ||
| 69 | wctx->writer->writer->writer_w8(wctx->writer, b); | ||
| 70 | } | ||
| 71 | |||
| 72 | static inline void writer_put_str(AVTextFormatContext *wctx, const char *str) | ||
| 73 | { | ||
| 74 | wctx->writer->writer->writer_put_str(wctx->writer, str); | ||
| 75 | } | ||
| 76 | |||
| 77 | static inline void writer_printf(AVTextFormatContext *wctx, const char *fmt, ...) | ||
| 78 | { | ||
| 79 | va_list args; | ||
| 80 | va_start(args, fmt); | ||
| 81 | wctx->writer->writer->writer_vprintf(wctx->writer, fmt, args); | ||
| 82 | va_end(args); | ||
| 83 | } | ||
| 84 | |||
| 85 | #endif /* FFTOOLS_TEXTFORMAT_TF_INTERNAL_H */ | ||
| @@ -27,22 +27,7 @@ · 26 unmodified lines | |||
| 27 | #include "avtextformat.h" | 27 | #include "avtextformat.h" |
| 28 | #include "libavutil/bprint.h" | 28 | #include "libavutil/bprint.h" |
| 29 | #include "libavutil/opt.h" | 29 | #include "libavutil/opt.h" |
| 30 | 30 | #include "tf_internal.h" | |
| 31 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 32 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 33 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 34 | |||
| 35 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 36 | static const char *name##_get_name(void *ctx) \ | ||
| 37 | { \ | ||
| 38 | return #name ; \ | ||
| 39 | } \ | ||
| 40 | static const AVClass name##_class = { \ | ||
| 41 | .class_name = #name, \ | ||
| 42 | .item_name = name##_get_name, \ | ||
| 43 | .option = name##_options \ | ||
| 44 | } | ||
| 45 | |||
| 46 | 31 | ||
| 47 | /* JSON output */ | 32 | /* JSON output */ |
| 48 | 33 | ||
| @@ -103,10 +88,13 @@ static const char *json_escape_str(AVBPrint *dst, const char *src, void *log_ctx · 54 unmodified lines | |||
| 103 | 88 | ||
| 104 | static void json_print_section_header(AVTextFormatContext *wctx, const void *data) | 89 | static void json_print_section_header(AVTextFormatContext *wctx, const void *data) |
| 105 | { | 90 | { |
| 91 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | ||
| 92 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); | ||
| 106 | JSONContext *json = wctx->priv; | 93 | JSONContext *json = wctx->priv; |
| 107 | AVBPrint buf; | 94 | AVBPrint buf; |
| 108 | const AVTextFormatSection *section = wctx->section[wctx->level]; | 95 | |
| 109 | const AVTextFormatSection *parent_section = wctx->level ? wctx->section[wctx->level - 1] : NULL; | 96 | if (!section) |
| 97 | return; | ||
| 110 | 98 | ||
| 111 | if (wctx->level && wctx->nb_item[wctx->level - 1]) | 99 | if (wctx->level && wctx->nb_item[wctx->level - 1]) |
| 112 | writer_put_str(wctx, ",\n"); | 100 | writer_put_str(wctx, ",\n"); |
| @@ -141,8 +129,11 @@ static void json_print_section_header(AVTextFormatContext *wctx, const void *dat · 28 unmodified lines | |||
| 141 | 129 | ||
| 142 | static void json_print_section_footer(AVTextFormatContext *wctx) | 130 | static void json_print_section_footer(AVTextFormatContext *wctx) |
| 143 | { | 131 | { |
| 132 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | ||
| 144 | JSONContext *json = wctx->priv; | 133 | JSONContext *json = wctx->priv; |
| 145 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 134 | |
| 135 | if (!section) | ||
| 136 | return; | ||
| 146 | 137 | ||
| 147 | if (wctx->level == 0) { | 138 | if (wctx->level == 0) { |
| 148 | json->indent_level--; | 139 | json->indent_level--; |
| @@ -175,9 +166,12 @@ static inline void json_print_item_str(AVTextFormatContext *wctx, · 26 unmodified lines | |||
| 175 | 166 | ||
| 176 | static void json_print_str(AVTextFormatContext *wctx, const char *key, const char *value) | 167 | static void json_print_str(AVTextFormatContext *wctx, const char *key, const char *value) |
| 177 | { | 168 | { |
| 169 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | ||
| 170 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); | ||
| 178 | JSONContext *json = wctx->priv; | 171 | JSONContext *json = wctx->priv; |
| 179 | const struct AVTextFormatSection *parent_section = wctx->level ? | 172 | |
| 180 | wctx->section[wctx->level-1] : NULL; | 173 | if (!section) |
| 174 | return; | ||
| 181 | 175 | ||
| 182 | if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) | 176 | if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) |
| 183 | writer_put_str(wctx, json->item_sep); | 177 | writer_put_str(wctx, json->item_sep); |
| @@ -188,10 +182,14 @@ static void json_print_str(AVTextFormatContext *wctx, const char *key, const cha · 4 unmodified lines | |||
| 188 | 182 | ||
| 189 | static void json_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) | 183 | static void json_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) |
| 190 | { | 184 | { |
| 185 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | ||
| 186 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); | ||
| 191 | JSONContext *json = wctx->priv; | 187 | JSONContext *json = wctx->priv; |
| 192 | const AVTextFormatSection *parent_section = wctx->level ? wctx->section[wctx->level - 1] : NULL; | ||
| 193 | AVBPrint buf; | 188 | AVBPrint buf; |
| 194 | 189 | ||
| 190 | if (!section) | ||
| 191 | return; | ||
| 192 | |||
| 195 | if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) | 193 | if (wctx->nb_item[wctx->level] || (parent_section && parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE)) |
| 196 | writer_put_str(wctx, json->item_sep); | 194 | writer_put_str(wctx, json->item_sep); |
| 197 | if (!json->compact) | 195 | if (!json->compact) |
| @@ -213,4 +211,3 @@ const AVTextFormatter avtextformatter_json = { · 15 unmodified lines | |||
| 213 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, | 211 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, |
| 214 | .priv_class = &json_class, | 212 | .priv_class = &json_class, |
| 215 | }; | 213 | }; |
| 216 | |||
| @@ -25,21 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include "libavutil/bprint.h" | 25 | #include "libavutil/bprint.h" |
| 26 | #include "libavutil/error.h" | 26 | #include "libavutil/error.h" |
| 27 | #include "libavutil/opt.h" | 27 | #include "libavutil/opt.h" |
| 28 | 28 | #include "tf_internal.h" | |
| 29 | #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_) | ||
| 30 | #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_) | ||
| 31 | #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__) | ||
| 32 | |||
| 33 | #define DEFINE_FORMATTER_CLASS(name) \ | ||
| 34 | static const char *name##_get_name(void *ctx) \ | ||
| 35 | { \ | ||
| 36 | return #name ; \ | ||
| 37 | } \ | ||
| 38 | static const AVClass name##_class = { \ | ||
| 39 | .class_name = #name, \ | ||
| 40 | .item_name = name##_get_name, \ | ||
| 41 | .option = name##_options \ | ||
| 42 | } | ||
| 43 | 29 | ||
| 44 | /* XML output */ | 30 | /* XML output */ |
| 45 | 31 | ||
| @@ -90,9 +76,11 @@ static av_cold int xml_init(AVTextFormatContext *wctx) · 44 unmodified lines | |||
| 90 | static void xml_print_section_header(AVTextFormatContext *wctx, const void *data) | 76 | static void xml_print_section_header(AVTextFormatContext *wctx, const void *data) |
| 91 | { | 77 | { |
| 92 | XMLContext *xml = wctx->priv; | 78 | XMLContext *xml = wctx->priv; |
| 93 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 79 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 94 | const struct AVTextFormatSection *parent_section = wctx->level ? | 80 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); |
| 95 | wctx->section[wctx->level-1] : NULL; | 81 | |
| 82 | if (!section) | ||
| 83 | return; | ||
| 96 | 84 | ||
| 97 | if (wctx->level == 0) { | 85 | if (wctx->level == 0) { |
| 98 | const char *qual = " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " | 86 | 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 · 39 unmodified lines | |||
| 138 | static void xml_print_section_footer(AVTextFormatContext *wctx) | 126 | static void xml_print_section_footer(AVTextFormatContext *wctx) |
| 139 | { | 127 | { |
| 140 | XMLContext *xml = wctx->priv; | 128 | XMLContext *xml = wctx->priv; |
| 141 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 129 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 130 | |||
| 131 | if (!section) | ||
| 132 | return; | ||
| 142 | 133 | ||
| 143 | if (wctx->level == 0) { | 134 | if (wctx->level == 0) { |
| 144 | writer_printf(wctx, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : ""); | 135 | writer_printf(wctx, "</%sffprobe>\n", xml->fully_qualified ? "ffprobe:" : ""); |
| @@ -158,7 +149,10 @@ static void xml_print_value(AVTextFormatContext *wctx, const char *key, · 13 unmodified lines | |||
| 158 | { | 149 | { |
| 159 | AVBPrint buf; | 150 | AVBPrint buf; |
| 160 | XMLContext *xml = wctx->priv; | 151 | XMLContext *xml = wctx->priv; |
| 161 | const struct AVTextFormatSection *section = wctx->section[wctx->level]; | 152 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); |
| 153 | |||
| 154 | if (!section) | ||
| 155 | return; | ||
| 162 | 156 | ||
| 163 | av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); | 157 | av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); |
| 164 | 158 | ||
| @@ -216,4 +210,3 @@ const AVTextFormatter avtextformatter_xml = { · 51 unmodified lines | |||
| 216 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, | 210 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, |
| 217 | .priv_class = &xml_class, | 211 | .priv_class = &xml_class, |
| 218 | }; | 212 | }; |
| 219 | |||
| @@ -57,14 +57,11 @@ static void io_put_str(AVTextWriterContext *wctx, const char *str) · 56 unmodified lines | |||
| 57 | avio_write(ctx->avio_context, (const unsigned char *)str, (int)strlen(str)); | 57 | avio_write(ctx->avio_context, (const unsigned char *)str, (int)strlen(str)); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | static void io_printf(AVTextWriterContext *wctx, const char *fmt, ...) | 60 | static void io_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl) |
| 61 | { | 61 | { |
| 62 | IOWriterContext *ctx = wctx->priv; | 62 | IOWriterContext *ctx = wctx->priv; |
| 63 | va_list ap; | ||
| 64 | 63 | ||
| 65 | va_start(ap, fmt); | 64 | avio_vprintf(ctx->avio_context, fmt, vl); |
| 66 | avio_vprintf(ctx->avio_context, fmt, ap); | ||
| 67 | va_end(ap); | ||
| 68 | } | 65 | } |
| 69 | 66 | ||
| 70 | 67 | ||
| @@ -73,7 +70,7 @@ const AVTextWriter avtextwriter_avio = { · 2 unmodified lines | |||
| 73 | .priv_size = sizeof(IOWriterContext), | 70 | .priv_size = sizeof(IOWriterContext), |
| 74 | .uninit = iowriter_uninit, | 71 | .uninit = iowriter_uninit, |
| 75 | .writer_put_str = io_put_str, | 72 | .writer_put_str = io_put_str, |
| 76 | .writer_printf = io_printf, | 73 | .writer_vprintf = io_vprintf, |
| 77 | .writer_w8 = io_w8 | 74 | .writer_w8 = io_w8 |
| 78 | }; | 75 | }; |
| 79 | 76 | ||
| @@ -56,14 +56,11 @@ static void buffer_put_str(AVTextWriterContext *wctx, const char *str) · 55 unmodified lines | |||
| 56 | av_bprintf(ctx->buffer, "%s", str); | 56 | av_bprintf(ctx->buffer, "%s", str); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | static void buffer_printf(AVTextWriterContext *wctx, const char *fmt, ...) | 59 | static void buffer_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl) |
| 60 | { | 60 | { |
| 61 | BufferWriterContext *ctx = wctx->priv; | 61 | BufferWriterContext *ctx = wctx->priv; |
| 62 | 62 | ||
| 63 | va_list vargs; | 63 | av_vbprintf(ctx->buffer, fmt, vl); |
| 64 | va_start(vargs, fmt); | ||
| 65 | av_vbprintf(ctx->buffer, fmt, vargs); | ||
| 66 | va_end(vargs); | ||
| 67 | } | 64 | } |
| 68 | 65 | ||
| 69 | 66 | ||
| @@ -72,7 +69,7 @@ const AVTextWriter avtextwriter_buffer = { · 2 unmodified lines | |||
| 72 | .priv_size = sizeof(BufferWriterContext), | 69 | .priv_size = sizeof(BufferWriterContext), |
| 73 | .priv_class = &bufferwriter_class, | 70 | .priv_class = &bufferwriter_class, |
| 74 | .writer_put_str = buffer_put_str, | 71 | .writer_put_str = buffer_put_str, |
| 75 | .writer_printf = buffer_printf, | 72 | .writer_vprintf = buffer_vprintf, |
| 76 | .writer_w8 = buffer_w8 | 73 | .writer_w8 = buffer_w8 |
| 77 | }; | 74 | }; |
| 78 | 75 | ||
| @@ -53,13 +53,9 @@ static inline void stdout_put_str(AVTextWriterContext *wctx, const char *str) · 52 unmodified lines | |||
| 53 | printf("%s", str); | 53 | printf("%s", str); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | static inline void stdout_printf(AVTextWriterContext *wctx, const char *fmt, ...) | 56 | static inline void stdout_vprintf(AVTextWriterContext *wctx, const char *fmt, va_list vl) |
| 57 | { | 57 | { |
| 58 | va_list ap; | 58 | vprintf(fmt, vl); |
| 59 | |||
| 60 | va_start(ap, fmt); | ||
| 61 | vprintf(fmt, ap); | ||
| 62 | va_end(ap); | ||
| 63 | } | 59 | } |
| 64 | 60 | ||
| 65 | 61 | ||
| @@ -68,7 +64,7 @@ static const AVTextWriter avtextwriter_stdout = { · 2 unmodified lines | |||
| 68 | .priv_size = sizeof(StdOutWriterContext), | 64 | .priv_size = sizeof(StdOutWriterContext), |
| 69 | .priv_class = &stdoutwriter_class, | 65 | .priv_class = &stdoutwriter_class, |
| 70 | .writer_put_str = stdout_put_str, | 66 | .writer_put_str = stdout_put_str, |
| 71 | .writer_printf = stdout_printf, | 67 | .writer_vprintf = stdout_vprintf, |
| 72 | .writer_w8 = stdout_w8 | 68 | .writer_w8 = stdout_w8 |
| 73 | }; | 69 | }; |
| 74 | 70 | ||