diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2011-12-08 13:54:05 +0100 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2011-12-08 18:47:47 +0100 |
commit | 26c6fec9d911300177f8f386a4e85a308d94c322 (patch) | |
tree | f6f2b9e1c53fbc46f6cfe57c5238994e4b790b14 /libavutil | |
parent | 15c481614bb410cfa147f8051024d42b01eadff8 (diff) | |
download | ffmpeg-26c6fec9d911300177f8f386a4e85a308d94c322.tar.gz |
lavu: introduce av_log_format_line.
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/avutil.h | 2 | ||||
-rw-r--r-- | libavutil/log.c | 35 | ||||
-rw-r--r-- | libavutil/log.h | 10 |
3 files changed, 32 insertions, 15 deletions
diff --git a/libavutil/avutil.h b/libavutil/avutil.h index af43cc5e8f..acc4c22b87 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -153,7 +153,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 30 +#define LIBAVUTIL_VERSION_MINOR 31 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/log.c b/libavutil/log.c index 3182885ace..3161e4e7ff 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -92,40 +92,47 @@ static void sanitize(uint8_t *line){ } } -void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) +void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, + char *line, int line_size, int *print_prefix) { - static int print_prefix = 1; - static int count; - static char prev[1024]; - char line[1024]; - static int is_atty; AVClass* avc = ptr ? *(AVClass **) ptr : NULL; - if (level > av_log_level) - return; line[0] = 0; -#undef fprintf - if (print_prefix && avc) { + if (*print_prefix && avc) { if (avc->parent_log_context_offset) { AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + avc->parent_log_context_offset); if (parent && *parent) { - snprintf(line, sizeof(line), "[%s @ %p] ", + snprintf(line, line_size, "[%s @ %p] ", (*parent)->item_name(parent), parent); } } - snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", + snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr); } - vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); + vsnprintf(line + strlen(line), line_size - strlen(line), fmt, vl); + + *print_prefix = strlen(line) && line[strlen(line) - 1] == '\n'; +} + +void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) +{ + static int print_prefix = 1; + static int count; + static char prev[1024]; + char line[1024]; + static int is_atty; - print_prefix = strlen(line) && line[strlen(line) - 1] == '\n'; + if (level > av_log_level) + return; + av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); #if HAVE_ISATTY if (!is_atty) is_atty = isatty(2) ? 1 : -1; #endif +#undef fprintf if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ count++; if (is_atty == 1) diff --git a/libavutil/log.h b/libavutil/log.h index b8683302a2..02a0e1ac8c 100644 --- a/libavutil/log.h +++ b/libavutil/log.h @@ -148,6 +148,16 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); const char* av_default_item_name(void* ctx); /** + * Format a line of log the same way as the default callback. + * @param line buffer to receive the formated line + * @param line_size size of the buffer + * @param print_prefix used to store whether the prefix must be printed; + * must point to a persistent integer initially set to 1 + */ +void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, + char *line, int line_size, int *print_prefix); + +/** * av_dlog macros * Useful to print debug messages that shouldn't get compiled in normally. */ |