Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__H264__App
comparison libavutil/log.c @ 9:ea1ba68cf0ed
update to match api changes + add sscc produced source
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Wed, 05 Jun 2013 14:43:26 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:125e45125b3c |
|---|---|
| 1 /* | |
| 2 * log functions | |
| 3 * Copyright (c) 2003 Michel Bardiaux | |
| 4 * | |
| 5 * This file is part of FFmpeg. | |
| 6 * | |
| 7 * FFmpeg is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 2.1 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * FFmpeg is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with FFmpeg; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /** | |
| 23 * @file | |
| 24 * logging functions | |
| 25 */ | |
| 26 #include "error.h" | |
| 27 #include <unistd.h> | |
| 28 #include <stdlib.h> | |
| 29 #include "log.h" | |
| 30 | |
| 31 | |
| 32 static int av_log_level = AV_LOG_INFO; | |
| 33 | |
| 34 static int use_ansi_color=-1; | |
| 35 | |
| 36 #undef fprintf | |
| 37 static void colored_fputs(int color, const char *str){ | |
| 38 if(use_ansi_color<0){ | |
| 39 #if HAVE_ISATTY && !defined(_WIN32) | |
| 40 use_ansi_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); | |
| 41 #else | |
| 42 use_ansi_color= 0; | |
| 43 #endif | |
| 44 } | |
| 45 | |
| 46 if(use_ansi_color){ | |
| 47 fprintf(stderr, "\033[%d;3%dm", color>>4, color&15); | |
| 48 } | |
| 49 fputs(str, stderr); | |
| 50 if(use_ansi_color){ | |
| 51 fprintf(stderr, "\033[0m"); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 void av_log_default_callback(int level, const char* fmt, va_list vl) | |
| 56 { | |
| 57 static int print_prefix=1; | |
| 58 static int count; | |
| 59 static char line[1024], prev[1024]; | |
| 60 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; | |
| 61 | |
| 62 if(level>av_log_level) | |
| 63 return; | |
| 64 #undef fprintf | |
| 65 | |
| 66 line[0]=0; | |
| 67 | |
| 68 vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); | |
| 69 | |
| 70 print_prefix= line[strlen(line)-1] == '\n'; | |
| 71 if(print_prefix && !strcmp(line, prev)){ | |
| 72 count++; | |
| 73 return; | |
| 74 } | |
| 75 if(count>0){ | |
| 76 fprintf(stderr, " Last message repeated %d times\n", count); | |
| 77 count=0; | |
| 78 } | |
| 79 colored_fputs(color[av_clip(level>>3, 0, 6)], line); | |
| 80 strcpy(prev, line); | |
| 81 } | |
| 82 | |
| 83 static void (*av_log_callback)(int, const char*, va_list) = av_log_default_callback; | |
| 84 | |
| 85 void av_log(int level, const char *fmt, ...) | |
| 86 { | |
| 87 va_list vl; | |
| 88 va_start(vl, fmt); | |
| 89 av_vlog(level, fmt, vl); | |
| 90 va_end(vl); | |
| 91 } | |
| 92 | |
| 93 void av_vlog(int level, const char *fmt, va_list vl) | |
| 94 { | |
| 95 av_log_callback(level, fmt, vl); | |
| 96 } | |
| 97 | |
| 98 int av_log_get_level(void) | |
| 99 { | |
| 100 return av_log_level; | |
| 101 } | |
| 102 | |
| 103 void av_log_set_level(int level) | |
| 104 { | |
| 105 av_log_level = level; | |
| 106 } | |
| 107 | |
| 108 void av_log_set_callback(void (*callback)(int, const char*, va_list)) | |
| 109 { | |
| 110 av_log_callback = callback; | |
| 111 } |
