• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavutil/log.c

Go to the documentation of this file.
00001 /*
00002  * log functions
00003  * Copyright (c) 2003 Michel Bardiaux
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 }

Generated on Tue Nov 4 2014 12:59:24 for ffmpeg by  doxygen 1.7.1