avutil/log: Use bprint for part

This should fix the issue with strings longer than 1024

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/37/head
Michael Niedermayer 12 years ago
parent 112c970ca6
commit 148310ca16
  1. 45
      libavutil/log.c

@ -35,6 +35,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include "avutil.h" #include "avutil.h"
#include "bprint.h"
#include "common.h" #include "common.h"
#include "internal.h" #include "internal.h"
#include "log.h" #include "log.h"
@ -168,30 +169,33 @@ static int get_category(void *ptr){
} }
static void format_line(void *ptr, int level, const char *fmt, va_list vl, static void format_line(void *ptr, int level, const char *fmt, va_list vl,
char part[3][LINE_SZ], int part_size, int *print_prefix, int type[2]) AVBPrint part[3], int *print_prefix, int type[2])
{ {
AVClass* avc = ptr ? *(AVClass **) ptr : NULL; AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
part[0][0] = part[1][0] = part[2][0] = 0; av_bprint_init(part+0, 0, 1);
av_bprint_init(part+1, 0, 1);
av_bprint_init(part+2, 0, 65536);
if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
if (*print_prefix && avc) { if (*print_prefix && avc) {
if (avc->parent_log_context_offset) { if (avc->parent_log_context_offset) {
AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
avc->parent_log_context_offset); avc->parent_log_context_offset);
if (parent && *parent) { if (parent && *parent) {
snprintf(part[0], part_size, "[%s @ %p] ", av_bprintf(part+0, "[%s @ %p] ",
(*parent)->item_name(parent), parent); (*parent)->item_name(parent), parent);
if(type) type[0] = get_category(parent); if(type) type[0] = get_category(parent);
} }
} }
snprintf(part[1], part_size, "[%s @ %p] ", av_bprintf(part+1, "[%s @ %p] ",
avc->item_name(ptr), ptr); avc->item_name(ptr), ptr);
if(type) type[1] = get_category(ptr); if(type) type[1] = get_category(ptr);
} }
vsnprintf(part[2], part_size, fmt, vl); av_vbprintf(part+2, fmt, vl);
if(*part[0] || *part[1] || *part[2]) { if(*part[0].str || *part[1].str || *part[2].str) {
char lastc = strlen(part[2]) ? part[2][strlen(part[2]) - 1] : 0; char lastc = part[2].len ? part[2].str[part[2].len - 1] : 0;
*print_prefix = lastc == '\n' || lastc == '\r'; *print_prefix = lastc == '\n' || lastc == '\r';
} }
} }
@ -199,9 +203,10 @@ static void format_line(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, void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
char *line, int line_size, int *print_prefix) char *line, int line_size, int *print_prefix)
{ {
char part[3][LINE_SZ]; AVBPrint part[3];
format_line(ptr, level, fmt, vl, part, sizeof(part[0]), print_prefix, NULL); format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
snprintf(line, line_size, "%s%s%s", part[0], part[1], part[2]); snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str);
av_bprint_finalize(part+2, NULL);
} }
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)
@ -209,15 +214,15 @@ 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;
static int count; static int count;
static char prev[LINE_SZ]; static char prev[LINE_SZ];
char part[3][LINE_SZ]; AVBPrint part[3];
char line[LINE_SZ]; char line[LINE_SZ];
static int is_atty; static int is_atty;
int type[2]; int type[2];
if (level > av_log_level) if (level > av_log_level)
return; return;
format_line(ptr, level, fmt, vl, part, sizeof(part[0]), &print_prefix, type); format_line(ptr, level, fmt, vl, part, &print_prefix, type);
snprintf(line, sizeof(line), "%s%s%s", part[0], part[1], part[2]); snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str);
#if HAVE_ISATTY #if HAVE_ISATTY
if (!is_atty) if (!is_atty)
@ -229,6 +234,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count++; count++;
if (is_atty == 1) if (is_atty == 1)
fprintf(stderr, " Last message repeated %d times\r", count); fprintf(stderr, " Last message repeated %d times\r", count);
av_bprint_finalize(part+2, NULL);
return; return;
} }
if (count > 0) { if (count > 0) {
@ -236,12 +242,13 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
count = 0; count = 0;
} }
strcpy(prev, line); strcpy(prev, line);
sanitize(part[0]); sanitize(part[0].str);
colored_fputs(type[0], part[0]); colored_fputs(type[0], part[0].str);
sanitize(part[1]); sanitize(part[1].str);
colored_fputs(type[1], part[1]); colored_fputs(type[1], part[1].str);
sanitize(part[2]); sanitize(part[2].str);
colored_fputs(av_clip(level >> 3, 0, 6), part[2]); colored_fputs(av_clip(level >> 3, 0, 6), part[2].str);
av_bprint_finalize(part+2, NULL);
} }
static void (*av_log_callback)(void*, int, const char*, va_list) = static void (*av_log_callback)(void*, int, const char*, va_list) =

Loading…
Cancel
Save