1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

lavu: introduce av_log_format_line.

This commit is contained in:
Nicolas George 2011-12-08 13:54:05 +01:00
parent 15c481614b
commit 26c6fec9d9
4 changed files with 40 additions and 20 deletions

View File

@ -13,6 +13,9 @@ libavutil: 2011-04-18
API changes, most recent first: API changes, most recent first:
2011-12-08 - xxxxxxx - lavu 51.31.0
Add av_log_format_line.
2011-12-03 - xxxxxxx - lavu 51.30.0 2011-12-03 - xxxxxxx - lavu 51.30.0
Add AVERROR_BUG. Add AVERROR_BUG.

View File

@ -153,7 +153,7 @@
*/ */
#define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MAJOR 51
#define LIBAVUTIL_VERSION_MINOR 30 #define LIBAVUTIL_VERSION_MINOR 31
#define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

View File

@ -92,6 +92,29 @@ static void sanitize(uint8_t *line){
} }
} }
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
char *line, int line_size, int *print_prefix)
{
AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
line[0] = 0;
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, line_size, "[%s @ %p] ",
(*parent)->item_name(parent), parent);
}
}
snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ",
avc->item_name(ptr), ptr);
}
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) void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
{ {
static int print_prefix = 1; static int print_prefix = 1;
@ -99,33 +122,17 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
static char prev[1024]; static char prev[1024];
char line[1024]; char line[1024];
static int is_atty; static int is_atty;
AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
if (level > av_log_level) if (level > av_log_level)
return; return;
line[0] = 0; av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
#undef fprintf
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] ",
(*parent)->item_name(parent), parent);
}
}
snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ",
avc->item_name(ptr), ptr);
}
vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
#if HAVE_ISATTY #if HAVE_ISATTY
if (!is_atty) if (!is_atty)
is_atty = isatty(2) ? 1 : -1; is_atty = isatty(2) ? 1 : -1;
#endif #endif
#undef fprintf
if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
count++; count++;
if (is_atty == 1) if (is_atty == 1)

View File

@ -147,6 +147,16 @@ void av_log_set_callback(void (*)(void*, int, const char*, va_list));
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl);
const char* av_default_item_name(void* ctx); 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 * av_dlog macros
* Useful to print debug messages that shouldn't get compiled in normally. * Useful to print debug messages that shouldn't get compiled in normally.