From eb86578fa6a561b973f577b652e9fb7b2c58d8ba Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Sun, 1 Jun 2025 05:09:32 +0200 Subject: [PATCH v2 10/11] fftools/textformat/avtextformat: Move avtext_print_integers to ffprobe.c This is its only user and because this function is so specialised it is very likely to stay that way. So move it back to ffprobe.c (where it already was before d7a3f68feae0b1c3718f9d2671c6d41c60a40680). Signed-off-by: Andreas Rheinhardt --- fftools/ffprobe.c | 27 ++++++++++++++++++++++++++- fftools/textformat/avtextformat.c | 30 ------------------------------ fftools/textformat/avtextformat.h | 3 --- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c index 91976fb8ec..61c2260ea4 100644 --- a/fftools/ffprobe.c +++ b/fftools/ffprobe.c @@ -446,6 +446,31 @@ static void log_callback(void *ptr, int level, const char *fmt, va_list vl) #define print_duration_ts(k, v) avtext_print_ts(tfc, k, v, 1) #define print_val(k, v, u) avtext_print_unit_int(tfc, k, v, u) +static void print_integers(AVTextFormatContext *tfc, const char *key, + const void *data, int size, const char *format, + int columns, int bytes, int offset_add) +{ + AVBPrint bp; + unsigned offset = 0; + + av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC); + av_bprint_chars(&bp, '\n', 1); + while (size) { + av_bprintf(&bp, "%08x: ", offset); + int l = FFMIN(size, columns); + for (int i = 0; i < l; i++) { + if (bytes == 1) av_bprintf(&bp, format, *(const uint8_t*)data); + else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data)); + else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data)); + data = (const char*)data + bytes; + size--; + } + av_bprint_chars(&bp, '\n', 1); + offset += offset_add; + } + avtext_print_string(tfc, key, bp.str, 0); +} + #define REALLOCZ_ARRAY_STREAM(ptr, cur_n, new_n) \ { \ ret = av_reallocp_array(&(ptr), (new_n), sizeof(*(ptr))); \ @@ -477,7 +502,7 @@ static void print_displaymatrix(AVTextFormatContext *tfc, const int32_t matrix[9 double rotation = av_display_rotation_get(matrix); if (isnan(rotation)) rotation = 0; - avtext_print_integers(tfc, "displaymatrix", (void*)matrix, 9, " %11d", 3, 4, 1); + print_integers(tfc, "displaymatrix", matrix, 9, " %11d", 3, 4, 1); print_int("rotation", rotation); } diff --git a/fftools/textformat/avtextformat.c b/fftools/textformat/avtextformat.c index 30a017d1a1..532d0f5bfc 100644 --- a/fftools/textformat/avtextformat.c +++ b/fftools/textformat/avtextformat.c @@ -562,36 +562,6 @@ void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, avtext_print_string(tctx, key, buf, 0); } -void avtext_print_integers(AVTextFormatContext *tctx, const char *key, - uint8_t *data, int size, const char *format, - int columns, int bytes, int offset_add) -{ - AVBPrint bp; - unsigned offset = 0; - int l, i; - - if (!key || !data || !format || columns <= 0 || bytes <= 0) - return; - - av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED); - av_bprintf(&bp, "\n"); - while (size) { - av_bprintf(&bp, "%08x: ", offset); - l = FFMIN(size, columns); - for (i = 0; i < l; i++) { - if (bytes == 1) av_bprintf(&bp, format, *data); - else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data)); - else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data)); - data += bytes; - size--; - } - av_bprintf(&bp, "\n"); - offset += offset_add; - } - avtext_print_string(tctx, key, bp.str, 0); - av_bprint_finalize(&bp, NULL); -} - static const char *writercontext_get_writer_name(void *p) { AVTextWriterContext *wctx = p; diff --git a/fftools/textformat/avtextformat.h b/fftools/textformat/avtextformat.h index bd8c5d742f..4354181df4 100644 --- a/fftools/textformat/avtextformat.h +++ b/fftools/textformat/avtextformat.h @@ -190,9 +190,6 @@ void avtext_print_data(AVTextFormatContext *tctx, const char *key, const uint8_t void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size); -void avtext_print_integers(AVTextFormatContext *tctx, const char *key, uint8_t *data, int size, - const char *format, int columns, int bytes, int offset_add); - const AVTextFormatter *avtext_get_formatter_by_name(const char *name); extern const AVTextFormatter avtextformatter_default; -- 2.45.2