avlogbuf.c 737 Bytes
Newer Older
Julian Rother's avatar
Julian Rother committed
1
2
3
4
5
#include <pthread.h>
#include <libavutil/log.h>

#include "../util.h"

Julian Rother's avatar
Julian Rother committed
6
7
8
9
10
11
12
13
14
15
16
17
static char *logbuffer;
static size_t logsize;
static FILE *logstream;

void init_avlogbuf(void)
{
	logbuffer = 0;
	logsize = 0;
	if (!(logstream = open_memstream(&logbuffer, &logsize)))
		exit(99);
	av_log_set_callback(avlogbuf_callback);
}
Julian Rother's avatar
Julian Rother committed
18
19
20

void avlogbuf_callback(void *class, int level, const char *fmt, va_list ap)
{
Julian Rother's avatar
Julian Rother committed
21
22
	int print_prefix;
	char buf[200];
Julian Rother's avatar
Julian Rother committed
23
24
25
	if (level >= AV_LOG_VERBOSE)
		return;
	print_prefix = 1;
Julian Rother's avatar
Julian Rother committed
26
27
	av_log_format_line(class, level, fmt, ap, BL(buf), &print_prefix);
	fputs(buf, logstream);
Julian Rother's avatar
Julian Rother committed
28
29
30
31
}

char *get_avlogbuf(void)
{
Julian Rother's avatar
Julian Rother committed
32
33
34
35
36
37
38
39
	char *p;
	if (!logstream)
		return "";
	fclose(logstream);
	p = logbuffer;
	init_avlogbuf();
	fputs(p, logstream);
	return p;
Julian Rother's avatar
Julian Rother committed
40
}