00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027 #include "avutil.h"
00028 #include "log.h"
00029
00030 int av_log_level = AV_LOG_INFO;
00031
00032 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
00033 {
00034 static int print_prefix=1;
00035 static int count;
00036 static char line[1024], prev[1024];
00037 AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
00038 if(level>av_log_level)
00039 return;
00040 #undef fprintf
00041 if(print_prefix && avc) {
00042 snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr);
00043 }else
00044 line[0]=0;
00045
00046 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
00047
00048 print_prefix= line[strlen(line)-1] == '\n';
00049 if(print_prefix && !strcmp(line, prev)){
00050 count++;
00051 return;
00052 }
00053 if(count>0){
00054 fprintf(stderr, " Last message repeated %d times\n", count);
00055 count=0;
00056 }
00057 fputs(line, stderr);
00058 strcpy(prev, line);
00059 }
00060
00061 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
00062
00063 void av_log(void* avcl, int level, const char *fmt, ...)
00064 {
00065 va_list vl;
00066 va_start(vl, fmt);
00067 av_vlog(avcl, level, fmt, vl);
00068 va_end(vl);
00069 }
00070
00071 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
00072 {
00073 av_log_callback(avcl, level, fmt, vl);
00074 }
00075
00076 int av_log_get_level(void)
00077 {
00078 return av_log_level;
00079 }
00080
00081 void av_log_set_level(int level)
00082 {
00083 av_log_level = level;
00084 }
00085
00086 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
00087 {
00088 av_log_callback = callback;
00089 }