| OLD | NEW |
| 1 /* | 1 /* |
| 2 * log functions | 2 * log functions |
| 3 * Copyright (c) 2003 Michel Bardiaux | 3 * Copyright (c) 2003 Michel Bardiaux |
| 4 * | 4 * |
| 5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
| 6 * | 6 * |
| 7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include <unistd.h> | 27 #include <unistd.h> |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 #include "avutil.h" | 29 #include "avutil.h" |
| 30 #include "log.h" | 30 #include "log.h" |
| 31 | 31 |
| 32 #if LIBAVUTIL_VERSION_MAJOR > 50 | 32 #if LIBAVUTIL_VERSION_MAJOR > 50 |
| 33 static | 33 static |
| 34 #endif | 34 #endif |
| 35 int av_log_level = AV_LOG_INFO; | 35 int av_log_level = AV_LOG_INFO; |
| 36 | 36 |
| 37 #ifdef _WIN32 | 37 #if defined(_WIN32) && !defined(__MINGW32CE__) |
| 38 #include <windows.h> | 38 #include <windows.h> |
| 39 static const uint8_t color[] = {12,12,12,14,7,7,7}; | 39 static const uint8_t color[] = {12,12,12,14,7,7,7}; |
| 40 static int16_t background, attr_orig; | 40 static int16_t background, attr_orig; |
| 41 static HANDLE con; | 41 static HANDLE con; |
| 42 #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) | 42 #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) |
| 43 #define reset_color() SetConsoleTextAttribute(con, attr_orig) | 43 #define reset_color() SetConsoleTextAttribute(con, attr_orig) |
| 44 #else | 44 #else |
| 45 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; | 45 static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; |
| 46 #define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x]>>4, color[x]&15) | 46 #define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x]>>4, color[x]&15) |
| 47 #define reset_color() fprintf(stderr, "\033[0m") | 47 #define reset_color() fprintf(stderr, "\033[0m") |
| 48 #endif | 48 #endif |
| 49 static int use_color=-1; | 49 static int use_color=-1; |
| 50 | 50 |
| 51 #undef fprintf | 51 #undef fprintf |
| 52 static void colored_fputs(int level, const char *str){ | 52 static void colored_fputs(int level, const char *str){ |
| 53 if(use_color<0){ | 53 if(use_color<0){ |
| 54 #ifdef _WIN32 | 54 #if defined(_WIN32) && !defined(__MINGW32CE__) |
| 55 CONSOLE_SCREEN_BUFFER_INFO con_info; | 55 CONSOLE_SCREEN_BUFFER_INFO con_info; |
| 56 con = GetStdHandle(STD_ERROR_HANDLE); | 56 con = GetStdHandle(STD_ERROR_HANDLE); |
| 57 use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR"); | 57 use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR"); |
| 58 if (use_color) { | 58 if (use_color) { |
| 59 GetConsoleScreenBufferInfo(con, &con_info); | 59 GetConsoleScreenBufferInfo(con, &con_info); |
| 60 attr_orig = con_info.wAttributes; | 60 attr_orig = con_info.wAttributes; |
| 61 background = attr_orig & 0xF0; | 61 background = attr_orig & 0xF0; |
| 62 } | 62 } |
| 63 #elif HAVE_ISATTY | 63 #elif HAVE_ISATTY |
| 64 use_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); | 64 use_color= getenv("TERM") && !getenv("NO_COLOR") && isatty(2); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 140 |
| 141 void av_log_set_level(int level) | 141 void av_log_set_level(int level) |
| 142 { | 142 { |
| 143 av_log_level = level; | 143 av_log_level = level; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) | 146 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) |
| 147 { | 147 { |
| 148 av_log_callback = callback; | 148 av_log_callback = callback; |
| 149 } | 149 } |
| OLD | NEW |