From fea0d10f67355a79bae7ec9e45176c41da32ab29 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 1 Nov 2023 16:37:52 +0100 Subject: [PATCH] improved UG FFmpeg logger do not prefix messages not starting on new line by timestamps, eg.: $ uv -s embedded -t testcard -d file:n=/dev/null -V [1698853041.393] [lavc] Stream #0:0[1698853041.393] : Video: rawvideo, 1 reference frame (UYVY / 0x59565955), uyvy422, 1920x1080 (0x0), q=2-31, 829440 kb/s[1698853041.393] , [1698853041.393] 25 tbn[1698853041.393] Flush the output only on NL and before it store it in internal thread-local buffer. Locking was removed as static data are now thread-local. this improves 808b3de3 --- src/debug.cpp | 3 ++- src/debug.h | 1 - src/libavcodec/lavc_common.c | 23 +++++++++++------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/debug.cpp b/src/debug.cpp index 4b98d3c2d..d33f439af 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -87,7 +87,8 @@ static void _dprintf(const char *format, ...) #endif /* WIN32 */ } -void log_vprintf(int level, const char *format, va_list ap) +static void +log_vprintf(int level, const char *format, va_list ap) { va_list aq; diff --git a/src/debug.h b/src/debug.h index 27190f1e6..475283f46 100644 --- a/src/debug.h +++ b/src/debug.h @@ -88,7 +88,6 @@ void debug_file_dump(const char *key, void (*serialize)(const void *data, FILE * ///#define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, "[pid/%d +%d %s] ", getpid(), __LINE__, __FILE__), log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) #define debug_msg(...) log_msg(LOG_LEVEL_DEBUG, __VA_ARGS__) void log_msg(int log_level, const char *format, ...) __attribute__((format (printf, 2, 3))); -void log_vprintf(int level, const char *format, va_list ap); void log_msg_once(int log_level, uint32_t id, const char *msg, ...) __attribute__((format (printf, 3, 4))); void log_perror(int log_level, const char *msg); #define MSG(l, ...) log_msg(LOG_LEVEL_ ## l, MOD_NAME __VA_ARGS__) diff --git a/src/libavcodec/lavc_common.c b/src/libavcodec/lavc_common.c index 18259d771..26bb0d19f 100644 --- a/src/libavcodec/lavc_common.c +++ b/src/libavcodec/lavc_common.c @@ -170,21 +170,20 @@ static void av_log_ug_callback(void *avcl, int av_level, const char *fmt, va_lis if (av_log_filter(ff_module_name, fmt)) { return; } - static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - static _Bool nl_presented = 1; - char new_fmt[1024]; - pthread_mutex_lock(&lock); - if (nl_presented) { + static _Thread_local char buf[STR_LEN]; + if (strlen(buf) == 0) { + snprintf(buf + strlen(buf), sizeof buf - strlen(buf), "[lavc"); if (ff_module_name) { - snprintf(new_fmt, sizeof new_fmt, "[lavc %s @ %p] %s", ff_module_name, avcl, fmt); - } else { - snprintf(new_fmt, sizeof new_fmt, "[lavc] %s", fmt); + snprintf(buf + strlen(buf), sizeof buf - strlen(buf), + " %s @ %p", ff_module_name, avcl); } - fmt = new_fmt; + snprintf(buf + strlen(buf), sizeof buf - strlen(buf), "] "); + } + vsnprintf(buf + strlen(buf), sizeof buf - strlen(buf), fmt, vl); + if (buf[strlen(buf) - 1] == '\n') { + log_msg(level, "%s", buf); + buf[0] = '\0'; } - nl_presented = fmt[strlen(fmt) - 1] == '\n'; - log_vprintf(level, fmt, vl); - pthread_mutex_unlock(&lock); } ADD_TO_PARAM("lavcd-log-level",