Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: softworkz <ffmpegagent@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: softworkz <softworkz@hotmail.com>
Subject: [FFmpeg-devel] [PATCH v3 3/4] fftools: Provide a log formatting callback for context prefixes
Date: Thu, 06 Mar 2025 20:59:10 +0000
Message-ID: <105adac4ba8120c87db97690333845b42bbaa899.1741294751.git.ffmpegagent@gmail.com> (raw)
In-Reply-To: <pull.59.v3.ffstaging.FFmpeg.1741294751.ffmpegagent@gmail.com>

From: softworkz <softworkz@hotmail.com>

This allows to print logical ids instead of memory addresses.
The benefits are:

- Smaller log file sizes
- The disambiguation is much easier to recognize and to follow
- It eventually allows comparing and viewing log file diffs
  without almost every line being different due to those addresses
---
 fftools/cmdutils.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 fftools/cmdutils.h |  5 ++++
 fftools/ffmpeg.c   |  1 +
 fftools/ffplay.c   |  1 +
 fftools/ffprobe.c  |  1 +
 5 files changed, 77 insertions(+)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 8ac20bf049..9f93eb6523 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -59,6 +59,56 @@ AVDictionary *format_opts, *codec_opts;
 
 int hide_banner = 0;
 
+static int nb_class_ids;
+
+#define NB_CLASS_IDS 1000
+static struct class_ids {
+    void *avcl;
+    uint64_t class_hash;
+    unsigned id;
+} class_ids[NB_CLASS_IDS];
+
+static uint64_t fnv_hash(const char *str)
+{
+    // FNV-1a 64-bit hash algorithm
+    uint64_t hash = 0xcbf29ce484222325ULL;
+    while (*str) {
+        hash ^= (unsigned char)*str++;
+        hash *= 0x100000001b3ULL;
+    }
+    return hash;
+}
+
+static unsigned get_class_id(void* avcl)
+{
+    AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
+    const char* class_name = avc->item_name(avcl);
+    unsigned i, nb_ids = 0;
+    uint64_t class_hash;
+
+    for (i = 0; i < NB_CLASS_IDS && class_ids[i].avcl; i++) {
+        if (class_ids[i].avcl == avcl)
+            return class_ids[i].id;
+    }
+
+    class_hash = fnv_hash(avc->class_name);
+
+    for (i = 0; i < NB_CLASS_IDS; i++) {
+        if (class_ids[i].class_hash == class_hash)
+            nb_ids++;
+
+        if (!class_ids[i].avcl) {
+            class_ids[i].avcl = avcl;
+            class_ids[i].class_hash = class_hash;
+            class_ids[i].id = nb_ids;
+            return class_ids[i].id;
+        }
+    }
+
+    // exceeded NB_CLASS_IDS entries in class_ids[]
+    return 0;
+}
+
 void uninit_opts(void)
 {
     av_dict_free(&swr_opts);
@@ -550,6 +600,25 @@ static void check_options(const OptionDef *po)
     }
 }
 
+static const char *item_name(void *obj, const AVClass *cls)
+{
+    return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
+}
+
+static void log_formatprefix_callback(AVBPrint* buffer, AVClass** avcl, int log_flags)
+{
+    const int print_mem = log_flags & AV_LOG_PRINT_MEMADDRESSES;
+    if (print_mem)
+        av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
+    else
+        av_bprintf(buffer+0, "[%s #%u] ", item_name(avcl, *avcl), get_class_id(avcl));
+}
+
+void init_logformatting(void)
+{
+    av_log_set_formatprefix_callback(&log_formatprefix_callback);
+}
+
 void parse_loglevel(int argc, char **argv, const OptionDef *options)
 {
     int idx;
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 316b6a8c64..182d894ff9 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -401,6 +401,11 @@ int split_commandline(OptionParseContext *octx, int argc, char *argv[],
  */
 void uninit_parse_context(OptionParseContext *octx);
 
+/**
+ * Sets up formatting callbacks for logging
+ */
+void init_logformatting(void);
+
 /**
  * Find the '-loglevel' option in the command line args and apply it.
  */
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index dc321fb4a2..f84a7024be 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -955,6 +955,7 @@ int main(int argc, char **argv)
     setvbuf(stderr,NULL,_IONBF,0); /* win32 runtime needs this */
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    init_logformatting();
     parse_loglevel(argc, argv, options);
 
 #if CONFIG_AVDEVICE
diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index 2a572fc3aa..2e093c0069 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -3762,6 +3762,7 @@ int main(int argc, char **argv)
     init_dynload();
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    init_logformatting();
     parse_loglevel(argc, argv, options);
 
     /* register all codecs, demux and protocols */
diff --git a/fftools/ffprobe.c b/fftools/ffprobe.c
index 7341731d2f..3a9f2128fd 100644
--- a/fftools/ffprobe.c
+++ b/fftools/ffprobe.c
@@ -4652,6 +4652,7 @@ int main(int argc, char **argv)
     init_dynload();
 
     av_log_set_flags(AV_LOG_SKIP_REPEATED);
+    init_logformatting();
 
     options = real_options;
     parse_loglevel(argc, argv, options);
-- 
ffmpeg-codebot

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2025-03-06 21:00 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-05 15:38 [FFmpeg-devel] [PATCH] avutil/log: Replace addresses in log output with simple ids softworkz
2025-03-05 15:40 ` Nicolas George
2025-03-05 15:45   ` Soft Works
2025-03-05 15:48   ` Soft Works
2025-03-06 10:08     ` Nicolas George
2025-03-06 17:02       ` Soft Works
2025-03-06 17:38         ` Marvin Scholz
2025-03-06 17:44           ` Soft Works
2025-03-06 17:49             ` Marvin Scholz
2025-03-06 18:16               ` Soft Works
2025-03-06 18:58                 ` Marvin Scholz
2025-03-06 19:27                   ` Soft Works
2025-03-06 20:01                     ` Marvin Scholz
2025-03-06 20:48                       ` Soft Works
2025-03-06 20:56       ` Soft Works
2025-03-05 15:42 ` Soft Works
2025-03-05 16:23 ` Gyan Doshi
2025-03-05 16:30   ` Soft Works
2025-03-05 17:14     ` Gyan Doshi
2025-03-05 18:19 ` [FFmpeg-devel] [PATCH v2 0/3] " ffmpegagent
2025-03-05 18:19   ` [FFmpeg-devel] [PATCH v2 1/3] " softworkz
2025-03-05 18:19   ` [FFmpeg-devel] [PATCH v2 2/3] fftools/opt_common: add memaddresses log flag softworkz
2025-03-05 18:19   ` [FFmpeg-devel] [PATCH v2 3/3] doc/fftools-common-opts: document " softworkz
2025-03-06 10:04   ` [FFmpeg-devel] [PATCH v2 0/3] avutil/log: Replace addresses in log output with simple ids Nicolas George
2025-03-06 16:38     ` Soft Works
2025-03-06 16:43       ` Nicolas George
2025-03-06 17:05         ` Soft Works
2025-03-06 17:38           ` Soft Works
2025-03-06 20:59   ` [FFmpeg-devel] [PATCH v3 0/4] " ffmpegagent
2025-03-06 20:59     ` [FFmpeg-devel] [PATCH v3 1/4] avutil/log: Add callback for context prefix formatting softworkz
2025-03-06 20:59     ` [FFmpeg-devel] [PATCH v3 2/4] fftools/opt_common: add memaddresses log flag softworkz
2025-03-06 20:59     ` softworkz [this message]
2025-03-06 20:59     ` [FFmpeg-devel] [PATCH v3 4/4] doc/fftools-common-opts: document " softworkz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=105adac4ba8120c87db97690333845b42bbaa899.1741294751.git.ffmpegagent@gmail.com \
    --to=ffmpegagent@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=softworkz@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git