Rev 4349 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4349 | Rev 5370 | ||
---|---|---|---|
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. |
11 | * |
11 | * |
12 | * FFmpeg is distributed in the hope that it will be useful, |
12 | * FFmpeg is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. |
15 | * Lesser General Public License for more details. |
16 | * |
16 | * |
17 | * You should have received a copy of the GNU Lesser General Public |
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 |
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 |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | */ |
20 | */ |
21 | 21 | ||
22 | /** |
22 | /** |
23 | * @file |
23 | * @file |
24 | * logging functions |
24 | * logging functions |
25 | */ |
25 | */ |
26 | 26 | ||
27 | #include "config.h" |
27 | #include "config.h" |
28 | 28 | ||
29 | #if HAVE_UNISTD_H |
29 | #if HAVE_UNISTD_H |
30 | #include |
30 | #include |
31 | #endif |
31 | #endif |
32 | #include |
32 | #include |
33 | #include |
33 | #include |
34 | #include "avutil.h" |
34 | #include "avutil.h" |
35 | #include "bprint.h" |
35 | #include "bprint.h" |
36 | #include "common.h" |
36 | #include "common.h" |
37 | #include "internal.h" |
37 | #include "internal.h" |
38 | #include "log.h" |
38 | #include "log.h" |
39 | 39 | ||
40 | #if HAVE_PTHREADS |
40 | #if HAVE_PTHREADS |
41 | #include |
41 | #include |
42 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
42 | static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; |
43 | #endif |
43 | #endif |
44 | 44 | ||
45 | #define LINE_SZ 1024 |
45 | #define LINE_SZ 1024 |
46 | 46 | ||
47 | static int av_log_level = AV_LOG_INFO; |
47 | static int av_log_level = AV_LOG_INFO; |
48 | static int flags; |
48 | static int flags; |
49 | 49 | ||
50 | #define HAVE_SETCONSOLETEXTATTRIBUTE 0 |
50 | #define HAVE_SETCONSOLETEXTATTRIBUTE 0 |
51 | 51 | ||
52 | #if HAVE_SETCONSOLETEXTATTRIBUTE |
52 | #if HAVE_SETCONSOLETEXTATTRIBUTE |
53 | #include |
53 | #include |
54 | static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { |
54 | static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { |
55 | [AV_LOG_PANIC /8] = 12, |
55 | [AV_LOG_PANIC /8] = 12, |
56 | [AV_LOG_FATAL /8] = 12, |
56 | [AV_LOG_FATAL /8] = 12, |
57 | [AV_LOG_ERROR /8] = 12, |
57 | [AV_LOG_ERROR /8] = 12, |
58 | [AV_LOG_WARNING/8] = 14, |
58 | [AV_LOG_WARNING/8] = 14, |
59 | [AV_LOG_INFO /8] = 7, |
59 | [AV_LOG_INFO /8] = 7, |
60 | [AV_LOG_VERBOSE/8] = 10, |
60 | [AV_LOG_VERBOSE/8] = 10, |
61 | [AV_LOG_DEBUG /8] = 10, |
61 | [AV_LOG_DEBUG /8] = 10, |
62 | [16+AV_CLASS_CATEGORY_NA ] = 7, |
62 | [16+AV_CLASS_CATEGORY_NA ] = 7, |
63 | [16+AV_CLASS_CATEGORY_INPUT ] = 13, |
63 | [16+AV_CLASS_CATEGORY_INPUT ] = 13, |
64 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 5, |
64 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 5, |
65 | [16+AV_CLASS_CATEGORY_MUXER ] = 13, |
65 | [16+AV_CLASS_CATEGORY_MUXER ] = 13, |
66 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 5, |
66 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 5, |
67 | [16+AV_CLASS_CATEGORY_ENCODER ] = 11, |
67 | [16+AV_CLASS_CATEGORY_ENCODER ] = 11, |
68 | [16+AV_CLASS_CATEGORY_DECODER ] = 3, |
68 | [16+AV_CLASS_CATEGORY_DECODER ] = 3, |
69 | [16+AV_CLASS_CATEGORY_FILTER ] = 10, |
69 | [16+AV_CLASS_CATEGORY_FILTER ] = 10, |
70 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 9, |
70 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 9, |
71 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 7, |
71 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 7, |
72 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 7, |
72 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 7, |
73 | }; |
73 | }; |
74 | 74 | ||
75 | static int16_t background, attr_orig; |
75 | static int16_t background, attr_orig; |
76 | static HANDLE con; |
76 | static HANDLE con; |
77 | #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) |
77 | #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) |
78 | #define set_256color set_color |
78 | #define set_256color set_color |
79 | #define reset_color() SetConsoleTextAttribute(con, attr_orig) |
79 | #define reset_color() SetConsoleTextAttribute(con, attr_orig) |
80 | #else |
80 | #else |
81 | 81 | ||
82 | static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { |
82 | static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { |
83 | [AV_LOG_PANIC /8] = 52 << 16 | 196 << 8 | 0x41, |
83 | [AV_LOG_PANIC /8] = 52 << 16 | 196 << 8 | 0x41, |
84 | [AV_LOG_FATAL /8] = 208 << 8 | 0x41, |
84 | [AV_LOG_FATAL /8] = 208 << 8 | 0x41, |
85 | [AV_LOG_ERROR /8] = 196 << 8 | 0x11, |
85 | [AV_LOG_ERROR /8] = 196 << 8 | 0x11, |
86 | [AV_LOG_WARNING/8] = 226 << 8 | 0x03, |
86 | [AV_LOG_WARNING/8] = 226 << 8 | 0x03, |
87 | [AV_LOG_INFO /8] = 253 << 8 | 0x09, |
87 | [AV_LOG_INFO /8] = 253 << 8 | 0x09, |
88 | [AV_LOG_VERBOSE/8] = 40 << 8 | 0x02, |
88 | [AV_LOG_VERBOSE/8] = 40 << 8 | 0x02, |
89 | [AV_LOG_DEBUG /8] = 34 << 8 | 0x02, |
89 | [AV_LOG_DEBUG /8] = 34 << 8 | 0x02, |
90 | [16+AV_CLASS_CATEGORY_NA ] = 250 << 8 | 0x09, |
90 | [16+AV_CLASS_CATEGORY_NA ] = 250 << 8 | 0x09, |
91 | [16+AV_CLASS_CATEGORY_INPUT ] = 219 << 8 | 0x15, |
91 | [16+AV_CLASS_CATEGORY_INPUT ] = 219 << 8 | 0x15, |
92 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 201 << 8 | 0x05, |
92 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 201 << 8 | 0x05, |
93 | [16+AV_CLASS_CATEGORY_MUXER ] = 213 << 8 | 0x15, |
93 | [16+AV_CLASS_CATEGORY_MUXER ] = 213 << 8 | 0x15, |
94 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 207 << 8 | 0x05, |
94 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 207 << 8 | 0x05, |
95 | [16+AV_CLASS_CATEGORY_ENCODER ] = 51 << 8 | 0x16, |
95 | [16+AV_CLASS_CATEGORY_ENCODER ] = 51 << 8 | 0x16, |
96 | [16+AV_CLASS_CATEGORY_DECODER ] = 39 << 8 | 0x06, |
96 | [16+AV_CLASS_CATEGORY_DECODER ] = 39 << 8 | 0x06, |
97 | [16+AV_CLASS_CATEGORY_FILTER ] = 155 << 8 | 0x12, |
97 | [16+AV_CLASS_CATEGORY_FILTER ] = 155 << 8 | 0x12, |
98 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 192 << 8 | 0x14, |
98 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 192 << 8 | 0x14, |
99 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 153 << 8 | 0x14, |
99 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 153 << 8 | 0x14, |
100 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 147 << 8 | 0x14, |
100 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 147 << 8 | 0x14, |
101 | }; |
101 | }; |
102 | 102 | ||
103 | #define set_color(x) fprintf(stderr, "\033[%d;3%dm", (color[x] >> 4) & 15, color[x] & 15) |
103 | #define set_color(x) fprintf(stderr, "\033[%d;3%dm", (color[x] >> 4) & 15, color[x] & 15) |
104 | #define set_256color(x) fprintf(stderr, "\033[48;5;%dm\033[38;5;%dm", (color[x] >> 16) & 0xff, (color[x] >> 8) & 0xff) |
104 | #define set_256color(x) fprintf(stderr, "\033[48;5;%dm\033[38;5;%dm", (color[x] >> 16) & 0xff, (color[x] >> 8) & 0xff) |
105 | #define reset_color() fprintf(stderr, "\033[0m") |
105 | #define reset_color() fprintf(stderr, "\033[0m") |
106 | #endif |
106 | #endif |
107 | static int use_color = -1; |
107 | static int use_color = 0; |
108 | 108 | ||
109 | static void colored_fputs(int level, const char *str) |
109 | static void colored_fputs(int level, const char *str) |
110 | { |
110 | { |
111 | if (use_color < 0) { |
111 | if (use_color < 0) { |
112 | #if HAVE_SETCONSOLETEXTATTRIBUTE |
112 | #if HAVE_SETCONSOLETEXTATTRIBUTE |
113 | CONSOLE_SCREEN_BUFFER_INFO con_info; |
113 | CONSOLE_SCREEN_BUFFER_INFO con_info; |
114 | con = GetStdHandle(STD_ERROR_HANDLE); |
114 | con = GetStdHandle(STD_ERROR_HANDLE); |
115 | use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && |
115 | use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && |
116 | !getenv("AV_LOG_FORCE_NOCOLOR"); |
116 | !getenv("AV_LOG_FORCE_NOCOLOR"); |
117 | if (use_color) { |
117 | if (use_color) { |
118 | GetConsoleScreenBufferInfo(con, &con_info); |
118 | GetConsoleScreenBufferInfo(con, &con_info); |
119 | attr_orig = con_info.wAttributes; |
119 | attr_orig = con_info.wAttributes; |
120 | background = attr_orig & 0xF0; |
120 | background = attr_orig & 0xF0; |
121 | } |
121 | } |
122 | #elif HAVE_ISATTY |
122 | #elif HAVE_ISATTY |
123 | // use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && |
123 | // use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && |
124 | // (getenv("TERM") && isatty(2) || |
124 | // (getenv("TERM") && isatty(2) || |
125 | // getenv("AV_LOG_FORCE_COLOR")); |
125 | // getenv("AV_LOG_FORCE_COLOR")); |
126 | #else |
126 | #else |
127 | // use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && |
127 | // use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && |
128 | // !getenv("AV_LOG_FORCE_NOCOLOR"); |
128 | // !getenv("AV_LOG_FORCE_NOCOLOR"); |
129 | #endif |
129 | #endif |
130 | } |
130 | } |
131 | 131 | ||
132 | if (use_color == 1) { |
132 | if (use_color == 1) { |
133 | set_color(level); |
133 | set_color(level); |
134 | } else if (use_color == 256) |
134 | } else if (use_color == 256) |
135 | set_256color(level); |
135 | set_256color(level); |
136 | fputs(str, stderr); |
136 | fputs(str, stderr); |
137 | if (use_color) { |
137 | if (use_color) { |
138 | reset_color(); |
138 | reset_color(); |
139 | } |
139 | } |
140 | } |
140 | } |
141 | 141 | ||
142 | const char *av_default_item_name(void *ptr) |
142 | const char *av_default_item_name(void *ptr) |
143 | { |
143 | { |
144 | return (*(AVClass **) ptr)->class_name; |
144 | return (*(AVClass **) ptr)->class_name; |
145 | } |
145 | } |
146 | 146 | ||
147 | AVClassCategory av_default_get_category(void *ptr) |
147 | AVClassCategory av_default_get_category(void *ptr) |
148 | { |
148 | { |
149 | return (*(AVClass **) ptr)->category; |
149 | return (*(AVClass **) ptr)->category; |
150 | } |
150 | } |
151 | 151 | ||
152 | static void sanitize(uint8_t *line){ |
152 | static void sanitize(uint8_t *line){ |
153 | while(*line){ |
153 | while(*line){ |
154 | if(*line < 0x08 || (*line > 0x0D && *line < 0x20)) |
154 | if(*line < 0x08 || (*line > 0x0D && *line < 0x20)) |
155 | *line='?'; |
155 | *line='?'; |
156 | line++; |
156 | line++; |
157 | } |
157 | } |
158 | } |
158 | } |
159 | 159 | ||
160 | static int get_category(void *ptr){ |
160 | static int get_category(void *ptr){ |
161 | AVClass *avc = *(AVClass **) ptr; |
161 | AVClass *avc = *(AVClass **) ptr; |
162 | if( !avc |
162 | if( !avc |
163 | || (avc->version&0xFF)<100 |
163 | || (avc->version&0xFF)<100 |
164 | || avc->version < (51 << 16 | 59 << 8) |
164 | || avc->version < (51 << 16 | 59 << 8) |
165 | || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16; |
165 | || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16; |
166 | 166 | ||
167 | if(avc->get_category) |
167 | if(avc->get_category) |
168 | return avc->get_category(ptr) + 16; |
168 | return avc->get_category(ptr) + 16; |
169 | 169 | ||
170 | return avc->category + 16; |
170 | return avc->category + 16; |
171 | } |
171 | } |
172 | 172 | ||
173 | static void format_line(void *ptr, int level, const char *fmt, va_list vl, |
173 | static void format_line(void *ptr, int level, const char *fmt, va_list vl, |
174 | AVBPrint part[3], int *print_prefix, int type[2]) |
174 | AVBPrint part[3], int *print_prefix, int type[2]) |
175 | { |
175 | { |
176 | AVClass* avc = ptr ? *(AVClass **) ptr : NULL; |
176 | AVClass* avc = ptr ? *(AVClass **) ptr : NULL; |
177 | av_bprint_init(part+0, 0, 1); |
177 | av_bprint_init(part+0, 0, 1); |
178 | av_bprint_init(part+1, 0, 1); |
178 | av_bprint_init(part+1, 0, 1); |
179 | av_bprint_init(part+2, 0, 65536); |
179 | av_bprint_init(part+2, 0, 65536); |
180 | 180 | ||
181 | if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; |
181 | if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; |
182 | if (*print_prefix && avc) { |
182 | if (*print_prefix && avc) { |
183 | if (avc->parent_log_context_offset) { |
183 | if (avc->parent_log_context_offset) { |
184 | AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + |
184 | AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + |
185 | avc->parent_log_context_offset); |
185 | avc->parent_log_context_offset); |
186 | if (parent && *parent) { |
186 | if (parent && *parent) { |
187 | av_bprintf(part+0, "[%s @ %p] ", |
187 | av_bprintf(part+0, "[%s @ %p] ", |
188 | (*parent)->item_name(parent), parent); |
188 | (*parent)->item_name(parent), parent); |
189 | if(type) type[0] = get_category(parent); |
189 | if(type) type[0] = get_category(parent); |
190 | } |
190 | } |
191 | } |
191 | } |
192 | av_bprintf(part+1, "[%s @ %p] ", |
192 | av_bprintf(part+1, "[%s @ %p] ", |
193 | avc->item_name(ptr), ptr); |
193 | avc->item_name(ptr), ptr); |
194 | if(type) type[1] = get_category(ptr); |
194 | if(type) type[1] = get_category(ptr); |
195 | } |
195 | } |
196 | 196 | ||
197 | av_vbprintf(part+2, fmt, vl); |
197 | av_vbprintf(part+2, fmt, vl); |
198 | 198 | ||
199 | if(*part[0].str || *part[1].str || *part[2].str) { |
199 | if(*part[0].str || *part[1].str || *part[2].str) { |
200 | char lastc = part[2].len ? part[2].str[part[2].len - 1] : 0; |
200 | char lastc = part[2].len ? part[2].str[part[2].len - 1] : 0; |
201 | *print_prefix = lastc == '\n' || lastc == '\r'; |
201 | *print_prefix = lastc == '\n' || lastc == '\r'; |
202 | } |
202 | } |
203 | } |
203 | } |
204 | 204 | ||
205 | void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, |
205 | void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, |
206 | char *line, int line_size, int *print_prefix) |
206 | char *line, int line_size, int *print_prefix) |
207 | { |
207 | { |
208 | AVBPrint part[3]; |
208 | AVBPrint part[3]; |
209 | format_line(ptr, level, fmt, vl, part, print_prefix, NULL); |
209 | format_line(ptr, level, fmt, vl, part, print_prefix, NULL); |
210 | snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str); |
210 | snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str); |
211 | av_bprint_finalize(part+2, NULL); |
211 | av_bprint_finalize(part+2, NULL); |
212 | } |
212 | } |
213 | 213 | ||
214 | void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) |
214 | void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) |
215 | { |
215 | { |
216 | static int print_prefix = 1; |
216 | static int print_prefix = 1; |
217 | static int count; |
217 | static int count; |
218 | static char prev[LINE_SZ]; |
218 | static char prev[LINE_SZ]; |
219 | AVBPrint part[3]; |
219 | AVBPrint part[3]; |
220 | char line[LINE_SZ]; |
220 | char line[LINE_SZ]; |
221 | static int is_atty; |
221 | static int is_atty; |
222 | int type[2]; |
222 | int type[2]; |
223 | 223 | ||
224 | if (level > av_log_level) |
224 | if (level > av_log_level) |
225 | return; |
225 | return; |
226 | #if HAVE_PTHREADS |
226 | #if HAVE_PTHREADS |
227 | pthread_mutex_lock(&mutex); |
227 | pthread_mutex_lock(&mutex); |
228 | #endif |
228 | #endif |
229 | 229 | ||
230 | format_line(ptr, level, fmt, vl, part, &print_prefix, type); |
230 | format_line(ptr, level, fmt, vl, part, &print_prefix, type); |
231 | snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str); |
231 | snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str); |
232 | 232 | ||
233 | 233 | ||
234 | if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) && |
234 | if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) && |
235 | *line && line[strlen(line) - 1] != '\r'){ |
235 | *line && line[strlen(line) - 1] != '\r'){ |
236 | count++; |
236 | count++; |
237 | if (is_atty == 1) |
237 | if (is_atty == 1) |
238 | fprintf(stderr, " Last message repeated %d times\r", count); |
238 | fprintf(stderr, " Last message repeated %d times\r", count); |
239 | goto end; |
239 | goto end; |
240 | } |
240 | } |
241 | if (count > 0) { |
241 | if (count > 0) { |
242 | fprintf(stderr, " Last message repeated %d times\n", count); |
242 | fprintf(stderr, " Last message repeated %d times\n", count); |
243 | count = 0; |
243 | count = 0; |
244 | } |
244 | } |
245 | strcpy(prev, line); |
245 | strcpy(prev, line); |
246 | sanitize(part[0].str); |
246 | sanitize(part[0].str); |
247 | colored_fputs(type[0], part[0].str); |
247 | colored_fputs(type[0], part[0].str); |
248 | sanitize(part[1].str); |
248 | sanitize(part[1].str); |
249 | colored_fputs(type[1], part[1].str); |
249 | colored_fputs(type[1], part[1].str); |
250 | sanitize(part[2].str); |
250 | sanitize(part[2].str); |
251 | colored_fputs(av_clip(level >> 3, 0, 6), part[2].str); |
251 | colored_fputs(av_clip(level >> 3, 0, 6), part[2].str); |
252 | end: |
252 | end: |
253 | av_bprint_finalize(part+2, NULL); |
253 | av_bprint_finalize(part+2, NULL); |
254 | #if HAVE_PTHREADS |
254 | #if HAVE_PTHREADS |
255 | pthread_mutex_unlock(&mutex); |
255 | pthread_mutex_unlock(&mutex); |
256 | #endif |
256 | #endif |
257 | } |
257 | } |
258 | 258 | ||
259 | static void (*av_log_callback)(void*, int, const char*, va_list) = |
259 | static void (*av_log_callback)(void*, int, const char*, va_list) = |
260 | av_log_default_callback; |
260 | av_log_default_callback; |
261 | 261 | ||
262 | void av_log(void* avcl, int level, const char *fmt, ...) |
262 | void av_log(void* avcl, int level, const char *fmt, ...) |
263 | { |
263 | { |
264 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
264 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
265 | va_list vl; |
265 | va_list vl; |
266 | va_start(vl, fmt); |
266 | va_start(vl, fmt); |
267 | if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) && |
267 | if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) && |
268 | avc->log_level_offset_offset && level >= AV_LOG_FATAL) |
268 | avc->log_level_offset_offset && level >= AV_LOG_FATAL) |
269 | level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset); |
269 | level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset); |
270 | av_vlog(avcl, level, fmt, vl); |
270 | av_vlog(avcl, level, fmt, vl); |
271 | va_end(vl); |
271 | va_end(vl); |
272 | } |
272 | } |
273 | 273 | ||
274 | void av_vlog(void* avcl, int level, const char *fmt, va_list vl) |
274 | void av_vlog(void* avcl, int level, const char *fmt, va_list vl) |
275 | { |
275 | { |
276 | void (*log_callback)(void*, int, const char*, va_list) = av_log_callback; |
276 | void (*log_callback)(void*, int, const char*, va_list) = av_log_callback; |
277 | if (log_callback) |
277 | if (log_callback) |
278 | log_callback(avcl, level, fmt, vl); |
278 | log_callback(avcl, level, fmt, vl); |
279 | } |
279 | } |
280 | 280 | ||
281 | int av_log_get_level(void) |
281 | int av_log_get_level(void) |
282 | { |
282 | { |
283 | return av_log_level; |
283 | return av_log_level; |
284 | } |
284 | } |
285 | 285 | ||
286 | void av_log_set_level(int level) |
286 | void av_log_set_level(int level) |
287 | { |
287 | { |
288 | av_log_level = level; |
288 | av_log_level = level; |
289 | } |
289 | } |
290 | 290 | ||
291 | void av_log_set_flags(int arg) |
291 | void av_log_set_flags(int arg) |
292 | { |
292 | { |
293 | flags = arg; |
293 | flags = arg; |
294 | } |
294 | } |
295 | 295 | ||
296 | void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) |
296 | void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) |
297 | { |
297 | { |
298 | av_log_callback = callback; |
298 | av_log_callback = callback; |
299 | } |
299 | } |
300 | 300 | ||
301 | static void missing_feature_sample(int sample, void *avc, const char *msg, |
301 | static void missing_feature_sample(int sample, void *avc, const char *msg, |
302 | va_list argument_list) |
302 | va_list argument_list) |
303 | { |
303 | { |
304 | av_vlog(avc, AV_LOG_WARNING, msg, argument_list); |
304 | av_vlog(avc, AV_LOG_WARNING, msg, argument_list); |
305 | av_log(avc, AV_LOG_WARNING, " is not implemented. Update your FFmpeg " |
305 | av_log(avc, AV_LOG_WARNING, " is not implemented. Update your FFmpeg " |
306 | "version to the newest one from Git. If the problem still " |
306 | "version to the newest one from Git. If the problem still " |
307 | "occurs, it means that your file has a feature which has not " |
307 | "occurs, it means that your file has a feature which has not " |
308 | "been implemented.\n"); |
308 | "been implemented.\n"); |
309 | if (sample) |
309 | if (sample) |
310 | av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample " |
310 | av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample " |
311 | "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ " |
311 | "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ " |
312 | "and contact the ffmpeg-devel mailing list.\n"); |
312 | "and contact the ffmpeg-devel mailing list.\n"); |
313 | } |
313 | } |
314 | 314 | ||
315 | void avpriv_request_sample(void *avc, const char *msg, ...) |
315 | void avpriv_request_sample(void *avc, const char *msg, ...) |
316 | { |
316 | { |
317 | va_list argument_list; |
317 | va_list argument_list; |
318 | 318 | ||
319 | va_start(argument_list, msg); |
319 | va_start(argument_list, msg); |
320 | missing_feature_sample(1, avc, msg, argument_list); |
320 | missing_feature_sample(1, avc, msg, argument_list); |
321 | va_end(argument_list); |
321 | va_end(argument_list); |
322 | } |
322 | } |
323 | 323 | ||
324 | void avpriv_report_missing_feature(void *avc, const char *msg, ...) |
324 | void avpriv_report_missing_feature(void *avc, const char *msg, ...) |
325 | { |
325 | { |
326 | va_list argument_list; |
326 | va_list argument_list; |
327 | 327 | ||
328 | va_start(argument_list, msg); |
328 | va_start(argument_list, msg); |
329 | missing_feature_sample(0, avc, msg, argument_list); |
329 | missing_feature_sample(0, avc, msg, argument_list); |
330 | va_end(argument_list); |
330 | va_end(argument_list); |
331 | }><>><>><>><>>100 |
331 | }><>><>><>><>>100 |
332 | >>>>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><> |
332 | >>>>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><>><> |