Commit 3e605479 authored by Julian Rother's avatar Julian Rother
Browse files

avlogbuf: Collapse repeating messages

parent 22d0d3a1
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
static char *logbuffer; static char *logbuffer;
static size_t logsize; static size_t logsize;
static FILE *logstream; static FILE *logstream;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static char prevbuf[200] = "";
static int repeats = 0;
void init_avlogbuf(void) void init_avlogbuf(void)
{ {
...@@ -20,21 +23,39 @@ void avlogbuf_callback(void *class, int level, const char *fmt, va_list ap) ...@@ -20,21 +23,39 @@ void avlogbuf_callback(void *class, int level, const char *fmt, va_list ap)
{ {
int print_prefix; int print_prefix;
char buf[200]; char buf[200];
if (level >= AV_LOG_VERBOSE) if (level > AV_LOG_WARNING)
return; return;
print_prefix = 1; print_prefix = 1;
av_log_format_line(class, level, fmt, ap, BL(buf), &print_prefix); av_log_format_line(class, level, fmt, ap, BL(buf), &print_prefix);
if (pthread_mutex_lock(&mutex))
return;
if (!strcmp(buf, prevbuf))
{
repeats ++;
pthread_mutex_unlock(&mutex);
return;
}
if (repeats)
fprintf(logstream, "Last message repeated %d times\n", repeats);
repeats = 0;
strcpy(prevbuf, buf);
fputs(buf, logstream); fputs(buf, logstream);
pthread_mutex_unlock(&mutex);
} }
char *get_avlogbuf(void) char *get_avlogbuf(void)
{ {
char *p; char *p, *tmp;
if (!logstream) if (!logstream)
return ""; return "";
fclose(logstream); fclose(logstream);
p = logbuffer; p = logbuffer;
init_avlogbuf(); init_avlogbuf();
fputs(p, logstream); fputs(p, logstream);
if (repeats)
{
tmp = mprintf("%sLast message repeated %d times\n", p, repeats);
free(p); p = tmp;
}
return p; return p;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment