From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id 13EA04BF7B
	for <ffmpegdev@gitmailbox.com>; Thu,  6 Mar 2025 20:59:41 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 05EBA68F0C4;
	Thu,  6 Mar 2025 22:59:31 +0200 (EET)
Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com
 [209.85.214.182])
 by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C4C4E68F0A9
 for <ffmpeg-devel@ffmpeg.org>; Thu,  6 Mar 2025 22:59:24 +0200 (EET)
Received: by mail-pl1-f182.google.com with SMTP id
 d9443c01a7336-22409077c06so24642295ad.1
 for <ffmpeg-devel@ffmpeg.org>; Thu, 06 Mar 2025 12:59:24 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1741294763; x=1741899563; darn=ffmpeg.org;
 h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date
 :references:in-reply-to:message-id:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=Qg6+d6P0mO0+z7RMyIX5Frh8luZPLS6ja39+NTK2ccY=;
 b=FYzjgv9fiBUi+6Eb686+QaUW+I0Ltw31MHQGklIQbub2xioED+gd62oNGKSXzG3FGp
 j2Q/azlQWvJKp46TtgIUFOTmNhJ1Hpc+O+bpUNM6EN5uwT4qMpk7mPBH910va+cvQXBk
 l5+vg4k7Cr2zlcA7nxByKw8d3ngV+kIcbO7zEiu2j/GM3vY/uRC3kpHbJDFQTourJF/a
 Dsc4JoIDdTHrcE+pmqjNXhkkTQFKTSCh8aVSMfgPn+VTT9i/3WQQ1Cv5Fp/tvJ7OKRaP
 TQQMbwFXBPRZ4pe1nM42rvtXISsk9Nq7IDHYstqvnG+alkCz20ZJKEUpGWG6PtX3qGOm
 JqMQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1741294763; x=1741899563;
 h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date
 :references:in-reply-to:message-id:from:x-gm-message-state:from:to
 :cc:subject:date:message-id:reply-to;
 bh=Qg6+d6P0mO0+z7RMyIX5Frh8luZPLS6ja39+NTK2ccY=;
 b=CWOq/8Utp8yJ/ZxIb2JQkouwH9QcQYhDkQ2abPdeSwUzbLqhIhMVMWHlBw0VNdiTKk
 07EqbsDHNo1novsFRlDNql7J3f2QQ+GRP+p+HdVjJYEshwllV7GRxiXPXR/FxavxjuFX
 9Hg2V30udctxqq3cv7ZqAEQwwOLfNoueZ85iWWn2ILifpgby7pu/i5kuA8FNCX+YxvgG
 pHc9PTDP4/Vrn7HH7GMVTcXBqw3AtJTBtLAag/lk1sCkcOdzy1PGpY2Dy9Ljm6Rmt8pF
 DQhi3fFu+7EoNJ9PwNWBfuEZ3snG+76MsScKs3ZtZ9acX2FSwAR5stN77dP8kqWif9ZK
 h6lw==
X-Gm-Message-State: AOJu0YwxDmd33zd2HyvOn5J1A82CEjSea+wfvB2EMBjrDu6R45CKzI86
 xTf4YldeScfHQfiQdmZdCsmbN6L9Dt/pnEGEHC5Q5EK+oKrLinpjrOAlyB73
X-Gm-Gg: ASbGncuTOznW+uUqSC3lmoAJf1DXcPV4cfrfLoNapLR2/1K6IYBYq7CrOCW2/K33SkX
 jGByAu4+7fn2RsbBalAWn1s0T0gmrz+IWsxy58S0ib/Qs4mcK1p+hR1wHsJvdSuQ0UAsX2FHqBz
 07lfgSsBoRnIjTIRxhtXIHgRtGsnmSidP13Q/Qyrde60gAhJmnMmj16e3vR3DAe+1ZLlNmzeRWI
 ja8b9e6tJ0Gp3I1JntpKvmI1A2bd7/WKAg/FY7PlQH81FSDBTXmDcRvIzBpizbEo4dGLOHUvk6H
 zh1L0C2/8Zm5Xhp6WljbZ/tZdT1j42SfyWCyl89HbY5Sbwe2J0tbaEpRc8GDGwA=
X-Google-Smtp-Source: AGHT+IF46wzveJEeAKTp9wIl/FKr8nCqQIhITDustXy9gliPlz06Mi8ksVNtlW8EL6E9LHVUnMo4kg==
X-Received: by 2002:a17:902:e80f:b0:223:668d:eba9 with SMTP id
 d9443c01a7336-2242888017bmr10435325ad.10.1741294762971; 
 Thu, 06 Mar 2025 12:59:22 -0800 (PST)
Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-224109ebcedsm17032655ad.98.2025.03.06.12.59.22
 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
 Thu, 06 Mar 2025 12:59:22 -0800 (PST)
From: softworkz <ffmpegagent@gmail.com>
X-Google-Original-From: softworkz <softworkz@hotmail.com>
Message-Id: <b8702de13b42e42940a3186060fed0a7a53455f9.1741294751.git.ffmpegagent@gmail.com>
In-Reply-To: <pull.59.v3.ffstaging.FFmpeg.1741294751.ffmpegagent@gmail.com>
References: <pull.59.v2.ffstaging.FFmpeg.1741198783.ffmpegagent@gmail.com>
 <pull.59.v3.ffstaging.FFmpeg.1741294751.ffmpegagent@gmail.com>
Date: Thu, 06 Mar 2025 20:59:08 +0000
Fcc: Sent
MIME-Version: 1.0
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH v3 1/4] avutil/log: Add callback for context
 prefix formatting
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: softworkz <softworkz@hotmail.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/b8702de13b42e42940a3186060fed0a7a53455f9.1741294751.git.ffmpegagent@gmail.com/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

From: softworkz <softworkz@hotmail.com>

also adds a log flag AV_LOG_PRINT_MEMADDRESSES, which is meant to
control prefix formatting. The actual formatting has to be performed
by the consuming application which needs to provide a formatting
callback via av_log_set_formatprefix_callback.

Signed-off-by: softworkz <softworkz@hotmail.com>
---
 doc/APIchanges      |  4 ++++
 libavutil/log.c     | 24 ++++++++++++++++++------
 libavutil/log.h     | 29 +++++++++++++++++++++++++++++
 libavutil/version.h |  2 +-
 4 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 5a64836e25..92e4a2e055 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -1,5 +1,9 @@
 The last version increases of all libraries were on 2024-03-07
 
+2025-03-xx - xxxxxxxxxx - lavu 59.59.100 - log.h
+  Add flag AV_LOG_PRINT_MEMADDRESSES, av_log_set_formatprefix_callback,
+  av_log_formatprefix_default_callback
+
 API changes, most recent first:
 
 2025-03-01 - xxxxxxxxxx - lavu 59.58.100 - pixfmt.h
diff --git a/libavutil/log.c b/libavutil/log.c
index c5ee876a88..6697bdba70 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -315,6 +315,14 @@ static void format_date_now(AVBPrint* bp_time, int include_date)
     }
 }
 
+void av_log_formatprefix_default_callback(AVBPrint* buffer, AVClass** avcl, int log_flags)
+{
+    av_bprintf(buffer+0, "[%s @ %p] ", item_name(avcl, *avcl), avcl);
+}
+
+static void (*av_log_formatprefix_callback)(AVBPrint* part, AVClass** avcl, int log_flags) =
+    av_log_formatprefix_default_callback;
+
 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
                         AVBPrint part[5], int *print_prefix, int type[2])
 {
@@ -327,17 +335,16 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
 
     if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
     if (*print_prefix && avc) {
+
         if (avc->parent_log_context_offset) {
-            AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
-                                   avc->parent_log_context_offset);
+            AVClass** parent = *(AVClass ***) ((uint8_t *)avcl + avc->parent_log_context_offset);
             if (parent && *parent) {
-                av_bprintf(part+0, "[%s @ %p] ",
-                           item_name(parent, *parent), parent);
+                av_log_formatprefix_callback(part, parent, flags);
                 if(type) type[0] = get_category(parent);
             }
         }
-        av_bprintf(part+1, "[%s @ %p] ",
-                   item_name(avcl, avc), avcl);
+        av_log_formatprefix_callback(part, avcl, flags);
+
         if(type) type[1] = get_category(avcl);
     }
 
@@ -485,6 +492,11 @@ int av_log_get_flags(void)
     return flags;
 }
 
+void av_log_set_formatprefix_callback(void (*callback)(AVBPrint* buffer, AVClass** avcl, int log_flags))
+{
+    av_log_formatprefix_callback = callback;
+}
+
 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
 {
     av_log_callback = callback;
diff --git a/libavutil/log.h b/libavutil/log.h
index dd094307ce..a69888c1ad 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -24,6 +24,7 @@
 #include <stdarg.h>
 #include "attributes.h"
 #include "version.h"
+#include "bprint.h"
 
 typedef enum {
     AV_CLASS_CATEGORY_NA = 0,
@@ -323,6 +324,29 @@ int av_log_get_level(void);
  */
 void av_log_set_level(int level);
 
+/**
+ * Set the prefix formatting callback
+ *
+ * @note The callback must be thread safe, even if the application does not use
+ *       threads itself as some codecs are multithreaded.
+ *
+ * @see av_log_formatprefix_default_callback
+ *
+ * @param callback A formatting function with a compatible signature.
+ */
+void av_log_set_formatprefix_callback(void (*callback)(AVBPrint* buffer, AVClass** avcl, int log_flags));
+
+/**
+ * Default prefix formatting callback
+ *
+ * It prints the message to stderr, optionally colorizing it.
+ *
+ * @param buffer A pointer to the print buffer.
+ * @param avcl The AVClass reference for which to format the prefix.
+ * @param log_flags The enabled logging flags
+ */
+void av_log_formatprefix_default_callback(AVBPrint* buffer, AVClass** avcl, int log_flags);
+
 /**
  * Set the logging callback
  *
@@ -416,6 +440,11 @@ int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
  */
 #define AV_LOG_PRINT_DATETIME 8
 
+/**
+ * Print memory addresses instead of logical ids in the AVClass prefix.
+ */
+#define AV_LOG_PRINT_MEMADDRESSES 16
+
 void av_log_set_flags(int arg);
 int av_log_get_flags(void);
 
diff --git a/libavutil/version.h b/libavutil/version.h
index 4b584fd569..b6467e2a6d 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  59
-#define LIBAVUTIL_VERSION_MINOR  58
+#define LIBAVUTIL_VERSION_MINOR  59
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
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".