]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/log.c
avio: add a destructor for AVIOContext
[ffmpeg] / libavutil / log.c
index d38e40bfda5ee7818d94487d4c68a824a7881f16..37427efaf107f2acda7be20bf87a825483353b4e 100644 (file)
 #include "internal.h"
 #include "log.h"
 
+#if HAVE_VALGRIND_VALGRIND_H
+#include <valgrind/valgrind.h>
+/* this is the log level at which valgrind will output a full backtrace */
+#define BACKTRACE_LOGLEVEL AV_LOG_ERROR
+#endif
+
 static int av_log_level = AV_LOG_INFO;
 static int flags;
 
+#define NB_LEVELS 8
 #if HAVE_SETCONSOLETEXTATTRIBUTE
 #include <windows.h>
-static const uint8_t color[] = { 12, 12, 12, 14, 7, 10, 11 };
+static const uint8_t color[NB_LEVELS] = { 12, 12, 12, 14, 7, 10, 11, 8};
 static int16_t background, attr_orig;
 static HANDLE con;
 #define set_color(x)  SetConsoleTextAttribute(con, background | color[x])
 #define reset_color() SetConsoleTextAttribute(con, attr_orig)
 #define print_256color(x)
 #else
-static const uint8_t color[] = { 0x41, 0x41, 0x11, 0x03, 9, 0x02, 0x06 };
+static const uint8_t color[NB_LEVELS] = {
+    0x41, 0x41, 0x11, 0x03, 9, 0x02, 0x06, 0x07
+};
 #define set_color(x)  fprintf(stderr, "\033[%d;3%dm", color[x] >> 4, color[x]&15)
 #define print_256color(x) fprintf(stderr, "\033[38;5;%dm", x)
 #define reset_color() fprintf(stderr, "\033[0m")
@@ -159,8 +168,13 @@ void av_log_default_callback(void *avcl, int level, const char *fmt, va_list vl)
         fprintf(stderr, "    Last message repeated %d times\n", count);
         count = 0;
     }
-    colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, line);
+    colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, line);
     av_strlcpy(prev, line, sizeof line);
+
+#if CONFIG_VALGRIND_BACKTRACE
+    if (level <= BACKTRACE_LOGLEVEL)
+        VALGRIND_PRINTF_BACKTRACE("");
+#endif
 }
 
 static void (*av_log_callback)(void*, int, const char*, va_list) =