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",