[FFmpeg-devel] [PATCH 6/8] ffprobe/avtextformat: Rename writer to formatter

softworkz ffmpegagent at gmail.com
Thu Feb 27 16:01:38 EET 2025


From: softworkz <softworkz at hotmail.com>

..except for the actrual writers

Signed-off-by: softworkz <softworkz at hotmail.com>
---
 fftools/ffprobe.c                   | 100 ++++++++++++++--------------
 libavutil/avtextformat.h            |  14 ++--
 libavutil/textformat/avtextformat.c |  48 ++++++-------
 3 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 5dc9803d5c..25eb3f0b61 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -412,36 +412,36 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl)
 #define writer_put_str(wctx_, str_) (wctx_)->writer_put_str(wctx_, str_)
 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer_printf(wctx_, fmt_, __VA_ARGS__)
 
-#define MAX_REGISTERED_WRITERS_NB 64
+#define MAX_REGISTERED_FORMATTERS_NB 64
 
-static const AVTextFormatter *registered_writers[MAX_REGISTERED_WRITERS_NB + 1];
+static const AVTextFormatter *registered_formatters[MAX_REGISTERED_FORMATTERS_NB + 1];
 
-static int writer_register(const AVTextFormatter *writer)
+static int formatter_register(const AVTextFormatter *formatter)
 {
-    static int next_registered_writer_idx = 0;
+    static int next_registered_formatter_idx = 0;
 
-    if (next_registered_writer_idx == MAX_REGISTERED_WRITERS_NB)
+    if (next_registered_formatter_idx == MAX_REGISTERED_FORMATTERS_NB)
         return AVERROR(ENOMEM);
 
-    registered_writers[next_registered_writer_idx++] = writer;
+    registered_formatters[next_registered_formatter_idx++] = formatter;
     return 0;
 }
 
-static const AVTextFormatter *writer_get_by_name(const char *name)
+static const AVTextFormatter *formatter_get_by_name(const char *name)
 {
     int i;
 
-    for (i = 0; registered_writers[i]; i++)
-        if (!strcmp(registered_writers[i]->name, name))
-            return registered_writers[i];
+    for (i = 0; registered_formatters[i]; i++)
+        if (!strcmp(registered_formatters[i]->name, name))
+            return registered_formatters[i];
 
     return NULL;
 }
 
 
-/* WRITERS */
+/* FORMATTERS */
 
-#define DEFINE_WRITER_CLASS(name)                   \
+#define DEFINE_FORMATTER_CLASS(name)                   \
 static const char *name##_get_name(void *ctx)       \
 {                                                   \
     return #name ;                                  \
@@ -472,7 +472,7 @@ static const AVOption default_options[] = {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(default);
+DEFINE_FORMATTER_CLASS(default);
 
 /* lame uppercasing routine, assumes the string is lower case ASCII */
 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
@@ -630,7 +630,7 @@ static const AVOption compact_options[]= {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(compact);
+DEFINE_FORMATTER_CLASS(compact);
 
 static av_cold int compact_init(AVTextFormatContext *wctx)
 {
@@ -768,7 +768,7 @@ static const AVOption csv_options[] = {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(csv);
+DEFINE_FORMATTER_CLASS(csv);
 
 static const AVTextFormatter csv_formatter = {
     .name                 = "csv",
@@ -802,7 +802,7 @@ static const AVOption flat_options[]= {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(flat);
+DEFINE_FORMATTER_CLASS(flat);
 
 static av_cold int flat_init(AVTextFormatContext *wctx)
 {
@@ -923,7 +923,7 @@ static const AVOption ini_options[] = {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(ini);
+DEFINE_FORMATTER_CLASS(ini);
 
 static char *ini_escape_str(AVBPrint *dst, const char *src)
 {
@@ -1030,7 +1030,7 @@ static const AVOption json_options[]= {
     { NULL }
 };
 
-DEFINE_WRITER_CLASS(json);
+DEFINE_FORMATTER_CLASS(json);
 
 static av_cold int json_init(AVTextFormatContext *wctx)
 {
@@ -1200,7 +1200,7 @@ static const AVOption xml_options[] = {
     {NULL},
 };
 
-DEFINE_WRITER_CLASS(xml);
+DEFINE_FORMATTER_CLASS(xml);
 
 static av_cold int xml_init(AVTextFormatContext *wctx)
 {
@@ -3381,7 +3381,7 @@ static void close_input_file(InputFile *ifile)
     avformat_close_input(&ifile->fmt_ctx);
 }
 
-static int probe_file(AVTextFormatContext *wctx, const char *filename,
+static int probe_file(AVTextFormatContext *tctx, const char *filename,
                       const char *print_filename)
 {
     InputFile ifile = { 0 };
@@ -3423,40 +3423,40 @@ static int probe_file(AVTextFormatContext *wctx, const char *filename,
 
     if (do_read_frames || do_read_packets) {
         if (do_show_frames && do_show_packets &&
-            wctx->writer->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT)
+            tctx->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT)
             section_id = SECTION_ID_PACKETS_AND_FRAMES;
         else if (do_show_packets && !do_show_frames)
             section_id = SECTION_ID_PACKETS;
         else // (!do_show_packets && do_show_frames)
             section_id = SECTION_ID_FRAMES;
         if (do_show_frames || do_show_packets)
-            avtext_print_section_header(wctx, NULL, section_id);
-        ret = read_packets(wctx, &ifile);
+            avtext_print_section_header(tctx, NULL, section_id);
+        ret = read_packets(tctx, &ifile);
         if (do_show_frames || do_show_packets)
-            avtext_print_section_footer(wctx);
+            avtext_print_section_footer(tctx);
         CHECK_END;
     }
 
     if (do_show_programs) {
-        ret = show_programs(wctx, &ifile);
+        ret = show_programs(tctx, &ifile);
         CHECK_END;
     }
 
     if (do_show_stream_groups) {
-        ret = show_stream_groups(wctx, &ifile);
+        ret = show_stream_groups(tctx, &ifile);
         CHECK_END;
     }
 
     if (do_show_streams) {
-        ret = show_streams(wctx, &ifile);
+        ret = show_streams(tctx, &ifile);
         CHECK_END;
     }
     if (do_show_chapters) {
-        ret = show_chapters(wctx, &ifile);
+        ret = show_chapters(tctx, &ifile);
         CHECK_END;
     }
     if (do_show_format) {
-        ret = show_format(wctx, &ifile);
+        ret = show_format(tctx, &ifile);
         CHECK_END;
     }
 
@@ -4019,10 +4019,10 @@ static inline int check_section_show_entries(int section_id)
 
 int main(int argc, char **argv)
 {
-    const AVTextFormatter *w;
-    AVTextFormatContext *wctx;
+    const AVTextFormatter *f;
+    AVTextFormatContext *tctx;
     char *buf;
-    char *w_name = NULL, *w_args = NULL;
+    char *f_name = NULL, *f_args = NULL;
     int ret, input_ret, i;
 
     init_dynload();
@@ -4084,7 +4084,7 @@ int main(int argc, char **argv)
         goto end;
     }
 
-    writer_register_all();
+    formatters_register_all();
 
     if (!output_format)
         output_format = av_strdup("default");
@@ -4092,37 +4092,37 @@ int main(int argc, char **argv)
         ret = AVERROR(ENOMEM);
         goto end;
     }
-    w_name = av_strtok(output_format, "=", &buf);
-    if (!w_name) {
+    f_name = av_strtok(output_format, "=", &buf);
+    if (!f_name) {
         av_log(NULL, AV_LOG_ERROR,
                "No name specified for the output format\n");
         ret = AVERROR(EINVAL);
         goto end;
     }
-    w_args = buf;
+    f_args = buf;
 
-    w = writer_get_by_name(w_name);
-    if (!w) {
-        av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", w_name);
+    f = formatter_get_by_name(f_name);
+    if (!f) {
+        av_log(NULL, AV_LOG_ERROR, "Unknown output format with name '%s'\n", f_name);
         ret = AVERROR(EINVAL);
         goto end;
     }
 
-    if ((ret = avtext_context_open(&wctx, w, w_args,
+    if ((ret = avtext_context_open(&tctx, f, f_args,
                            sections, FF_ARRAY_ELEMS(sections), output_filename, show_value_unit,
                             use_value_prefix, use_byte_value_binary_prefix, use_value_sexagesimal_format,
                             show_optional_fields, show_data_hash)) >= 0) {
-        if (w == &xml_formatter)
-            wctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
+        if (f == &avtextformatter_xml)
+            tctx->string_validation_utf8_flags |= AV_UTF8_FLAG_EXCLUDE_XML_INVALID_CONTROL_CODES;
 
-        avtext_print_section_header(wctx, NULL, SECTION_ID_ROOT);
+        avtext_print_section_header(tctx, NULL, SECTION_ID_ROOT);
 
         if (do_show_program_version)
-            ffprobe_show_program_version(wctx);
+            ffprobe_show_program_version(tctx);
         if (do_show_library_versions)
-            ffprobe_show_library_versions(wctx);
+            ffprobe_show_library_versions(tctx);
         if (do_show_pixel_formats)
-            ffprobe_show_pixel_formats(wctx);
+            ffprobe_show_pixel_formats(tctx);
 
         if (!input_filename &&
             ((do_show_format || do_show_programs || do_show_stream_groups || do_show_streams || do_show_chapters || do_show_packets || do_show_error) ||
@@ -4132,15 +4132,15 @@ int main(int argc, char **argv)
             av_log(NULL, AV_LOG_ERROR, "Use -h to get full help or, even better, run 'man %s'.\n", program_name);
             ret = AVERROR(EINVAL);
         } else if (input_filename) {
-            ret = probe_file(wctx, input_filename, print_input_filename);
+            ret = probe_file(tctx, input_filename, print_input_filename);
             if (ret < 0 && do_show_error)
-                show_error(wctx, ret);
+                show_error(tctx, ret);
         }
 
         input_ret = ret;
 
-        avtext_print_section_footer(wctx);
-        ret = avtext_context_close(&wctx);
+        avtext_print_section_footer(tctx);
+        ret = avtext_context_close(&tctx);
         if (ret < 0)
             av_log(NULL, AV_LOG_ERROR, "Writing output failed: %s\n", av_err2str(ret));
 
diff --git a/libavutil/avtextformat.h b/libavutil/avtextformat.h
index 68db9445c9..c7cdfe4144 100644
--- a/libavutil/avtextformat.h
+++ b/libavutil/avtextformat.h
@@ -66,8 +66,8 @@ typedef enum {
 } StringValidation;
 
 typedef struct AVTextFormatter {
-    const AVClass *priv_class;      ///< private class of the writer, if any
-    int priv_size;                  ///< private size for the writer context
+    const AVClass *priv_class;      ///< private class of the formatter, if any
+    int priv_size;                  ///< private size for the formatter context
     const char *name;
 
     int  (*init)  (AVTextFormatContext *wctx);
@@ -85,15 +85,15 @@ typedef struct AVTextFormatter {
 #define SECTION_MAX_NB_SECTIONS 100
 
 struct AVTextFormatContext {
-    const AVClass *class;           ///< class of the writer
-    const AVTextFormatter *writer;           ///< the AVTextFormatter of which this is an instance
+    const AVClass *class;           ///< class of the formatter
+    const AVTextFormatter *formatter;           ///< the AVTextFormatter of which this is an instance
     AVIOContext *avio;              ///< the I/O context used to write
 
     void (* writer_w8)(AVTextFormatContext *wctx, int b);
     void (* writer_put_str)(AVTextFormatContext *wctx, const char *str);
     void (* writer_printf)(AVTextFormatContext *wctx, const char *fmt, ...);
 
-    char *name;                     ///< name of this writer instance
+    char *name;                     ///< name of this formatter instance
     void *priv;                     ///< private data for use by the filter
 
     const struct AVTextFormatSection *sections; ///< array containing all sections
@@ -108,7 +108,7 @@ struct AVTextFormatContext {
     /** section per each level */
     const struct AVTextFormatSection *section[SECTION_MAX_NB_LEVELS];
     AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
-                                                  ///  used by various writers
+                                                  ///  used by various formatters
 
     int show_optional_fields;
     int show_value_unit;
@@ -126,7 +126,7 @@ struct AVTextFormatContext {
 #define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
 #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
 
-int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writer, const char *args,
+int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *formatter, const AVTextFormatter *writer, const char *args,
                         const struct AVTextFormatSection *sections, int nb_sections,
                         const char *output_filename,
                         int show_value_unit,
diff --git a/libavutil/textformat/avtextformat.c b/libavutil/textformat/avtextformat.c
index 63a07051ce..90b6545a88 100644
--- a/libavutil/textformat/avtextformat.c
+++ b/libavutil/textformat/avtextformat.c
@@ -54,10 +54,10 @@ static const struct {
     { 1.125899906842624e15, 1e15, "Pi", "P" },
 };
 
-static const char *avtext_context_get_writer_name(void *p)
+static const char *avtext_context_get_formatter_name(void *p)
 {
     AVTextFormatContext *wctx = p;
-    return wctx->writer->name;
+    return wctx->formatter->name;
 }
 
 #define OFFSET(x) offsetof(AVTextFormatContext, x)
@@ -77,14 +77,14 @@ static const AVOption textcontext_options[] = {
 static void *trextcontext_child_next(void *obj, void *prev)
 {
     AVTextFormatContext *ctx = obj;
-    if (!prev && ctx->writer && ctx->writer->priv_class && ctx->priv)
+    if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
         return ctx->priv;
     return NULL;
 }
 
 static const AVClass textcontext_class = {
     .class_name = "AVTextContext",
-    .item_name  = avtext_context_get_writer_name,
+    .item_name  = avtext_context_get_formatter_name,
     .option     = textcontext_options,
     .version    = LIBAVUTIL_VERSION_INT,
     .child_next = trextcontext_child_next,
@@ -148,11 +148,11 @@ int avtext_context_close(AVTextFormatContext **pwctx)
 
     av_hash_freep(&wctx->hash);
 
-    if (wctx->writer->uninit)
-        wctx->writer->uninit(wctx);
+    if (wctx->formatter->uninit)
+        wctx->formatter->uninit(wctx);
     for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
         av_bprint_finalize(&wctx->section_pbuf[i], NULL);
-    if (wctx->writer->priv_class)
+    if (wctx->formatter->priv_class)
         av_opt_free(wctx->priv);
     av_freep(&wctx->priv);
     av_opt_free(wctx);
@@ -165,7 +165,7 @@ int avtext_context_close(AVTextFormatContext **pwctx)
 }
 
 
-int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writer, const char *args,
+int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *formatter, const AVTextFormatter *writer, const char *args,
                         const struct AVTextFormatSection *sections, int nb_sections,
                         const char *output_filename,
                         int show_value_unit,
@@ -183,7 +183,7 @@ int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writ
         goto fail;
     }
 
-    if (!(wctx->priv = av_mallocz(writer->priv_size))) {
+    if (!(wctx->priv = av_mallocz(formatter->priv_size))) {
         ret = AVERROR(ENOMEM);
         goto fail;
     }
@@ -200,16 +200,16 @@ int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writ
     }
 
     wctx->class = &textcontext_class;
-    wctx->writer = writer;
+    wctx->formatter = formatter;
     wctx->level = -1;
     wctx->sections = sections;
     wctx->nb_sections = nb_sections;
 
     av_opt_set_defaults(wctx);
 
-    if (writer->priv_class) {
+    if (formatter->priv_class) {
         void *priv_ctx = wctx->priv;
-        *(const AVClass **)priv_ctx = writer->priv_class;
+        *(const AVClass **)priv_ctx = formatter->priv_class;
         av_opt_set_defaults(priv_ctx);
     }
 
@@ -219,14 +219,14 @@ int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writ
         const AVDictionaryEntry *opt = NULL;
 
         if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
-            av_log(wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to writer context\n", args);
+            av_log(wctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to textformat context\n", args);
             av_dict_free(&opts);
             goto fail;
         }
 
         while ((opt = av_dict_iterate(opts, opt))) {
             if ((ret = av_opt_set(wctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
-                av_log(wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to writer context\n",
+                av_log(wctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to textformat context\n",
                        opt->key, opt->value);
                 av_dict_free(&opts);
                 goto fail;
@@ -287,8 +287,8 @@ int avtext_context_open(AVTextFormatContext **pwctx, const AVTextFormatter *writ
     for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
         av_bprint_init(&wctx->section_pbuf[i], 1, AV_BPRINT_SIZE_UNLIMITED);
 
-    if (wctx->writer->init)
-        ret = wctx->writer->init(wctx);
+    if (wctx->formatter->init)
+        ret = wctx->formatter->init(wctx);
     if (ret < 0)
         goto fail;
 
@@ -319,8 +319,8 @@ void avtext_print_section_header(AVTextFormatContext *wctx,
     memset(wctx->nb_item_type[wctx->level], 0, sizeof(wctx->nb_item_type[wctx->level]));
     wctx->section[wctx->level] = &wctx->sections[section_id];
 
-    if (wctx->writer->print_section_header)
-        wctx->writer->print_section_header(wctx, data);
+    if (wctx->formatter->print_section_header)
+        wctx->formatter->print_section_header(wctx, data);
 }
 
 void avtext_print_section_footer(AVTextFormatContext *wctx)
@@ -334,8 +334,8 @@ void avtext_print_section_footer(AVTextFormatContext *wctx)
         wctx->nb_item_type[wctx->level - 1][section_id]++;
     }
 
-    if (wctx->writer->print_section_footer)
-        wctx->writer->print_section_footer(wctx);
+    if (wctx->formatter->print_section_footer)
+        wctx->formatter->print_section_footer(wctx);
     wctx->level--;
 }
 
@@ -345,7 +345,7 @@ void avtext_print_integer(AVTextFormatContext *wctx,
     const struct AVTextFormatSection *section = wctx->section[wctx->level];
 
     if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
-        wctx->writer->print_integer(wctx, key, val);
+        wctx->formatter->print_integer(wctx, key, val);
         wctx->nb_item[wctx->level]++;
     }
 }
@@ -482,7 +482,7 @@ int avtext_print_string(AVTextFormatContext *wctx, const char *key, const char *
     if (wctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_NEVER ||
         (wctx->show_optional_fields == SHOW_OPTIONAL_FIELDS_AUTO
         && (flags & AV_TEXTFORMAT_PRINT_STRING_OPTIONAL)
-        && !(wctx->writer->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS)))
+        && !(wctx->formatter->flags & AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS)))
         return 0;
 
     if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
@@ -492,7 +492,7 @@ int avtext_print_string(AVTextFormatContext *wctx, const char *key, const char *
             if (ret < 0) goto end;
             ret = validate_string(wctx, &val1, val);
             if (ret < 0) goto end;
-            wctx->writer->print_string(wctx, key1, val1);
+            wctx->formatter->print_string(wctx, key1, val1);
         end:
             if (ret < 0) {
                 av_log(wctx, AV_LOG_ERROR,
@@ -502,7 +502,7 @@ int avtext_print_string(AVTextFormatContext *wctx, const char *key, const char *
             av_free(key1);
             av_free(val1);
         } else {
-            wctx->writer->print_string(wctx, key, val);
+            wctx->formatter->print_string(wctx, key, val);
         }
 
         wctx->nb_item[wctx->level]++;
-- 
ffmpeg-codebot



More information about the ffmpeg-devel mailing list