Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
diff libavutil/log.c @ 2:897f711a7157
rearrange to work with autoconf
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Tue, 25 Sep 2012 15:55:33 +0200 |
| parents | |
| children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libavutil/log.c Tue Sep 25 15:55:33 2012 +0200 1.3 @@ -0,0 +1,111 @@ 1.4 +/* 1.5 + * log functions 1.6 + * Copyright (c) 2003 Michel Bardiaux 1.7 + * 1.8 + * This file is part of FFmpeg. 1.9 + * 1.10 + * FFmpeg is free software; you can redistribute it and/or 1.11 + * modify it under the terms of the GNU Lesser General Public 1.12 + * License as published by the Free Software Foundation; either 1.13 + * version 2.1 of the License, or (at your option) any later version. 1.14 + * 1.15 + * FFmpeg is distributed in the hope that it will be useful, 1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1.18 + * Lesser General Public License for more details. 1.19 + * 1.20 + * You should have received a copy of the GNU Lesser General Public 1.21 + * License along with FFmpeg; if not, write to the Free Software 1.22 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 1.23 + */ 1.24 + 1.25 +/** 1.26 + * @file 1.27 + * logging functions 1.28 + */ 1.29 +#include "error.h" 1.30 +#include <unistd.h> 1.31 +#include <stdlib.h> 1.32 +#include "log.h" 1.33 + 1.34 + 1.35 +static int av_log_level = AV_LOG_INFO; 1.36 + 1.37 +static int use_ansi_color=-1; 1.38 + 1.39 +#undef fprintf 1.40 +static void colored_fputs(int color, const char *str){ 1.41 + if(use_ansi_color<0){ 1.42 +#if HAVE_ISATTY && !defined(_WIN32) 1.43 + use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); 1.44 +#else 1.45 + use_ansi_color= 0; 1.46 +#endif 1.47 + } 1.48 + 1.49 + if(use_ansi_color){ 1.50 + fprintf(stderr, "\033[%d;3%dm", color>>4, color&15); 1.51 + } 1.52 + fputs(str, stderr); 1.53 + if(use_ansi_color){ 1.54 + fprintf(stderr, "\033[0m"); 1.55 + } 1.56 +} 1.57 + 1.58 +void av_log_default_callback(int level, const char* fmt, va_list vl) 1.59 +{ 1.60 + static int print_prefix=1; 1.61 + static int count; 1.62 + static char line[1024], prev[1024]; 1.63 + static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; 1.64 + 1.65 + if(level>av_log_level) 1.66 + return; 1.67 +#undef fprintf 1.68 + 1.69 + line[0]=0; 1.70 + 1.71 + vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); 1.72 + 1.73 + print_prefix= line[strlen(line)-1] == '\n'; 1.74 + if(print_prefix && !strcmp(line, prev)){ 1.75 + count++; 1.76 + return; 1.77 + } 1.78 + if(count>0){ 1.79 + fprintf(stderr, " Last message repeated %d times\n", count); 1.80 + count=0; 1.81 + } 1.82 + colored_fputs(color[av_clip(level>>3, 0, 6)], line); 1.83 + strcpy(prev, line); 1.84 +} 1.85 + 1.86 +static void (*av_log_callback)(int, const char*, va_list) = av_log_default_callback; 1.87 + 1.88 +void av_log(int level, const char *fmt, ...) 1.89 +{ 1.90 + va_list vl; 1.91 + va_start(vl, fmt); 1.92 + av_vlog(level, fmt, vl); 1.93 + va_end(vl); 1.94 +} 1.95 + 1.96 +void av_vlog(int level, const char *fmt, va_list vl) 1.97 +{ 1.98 + av_log_callback(level, fmt, vl); 1.99 +} 1.100 + 1.101 +int av_log_get_level(void) 1.102 +{ 1.103 + return av_log_level; 1.104 +} 1.105 + 1.106 +void av_log_set_level(int level) 1.107 +{ 1.108 + av_log_level = level; 1.109 +} 1.110 + 1.111 +void av_log_set_callback(void (*callback)(int, const char*, va_list)) 1.112 +{ 1.113 + av_log_callback = callback; 1.114 +}
