Line | Branch | Exec | Source |
---|---|---|---|
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 | |||
27 | #include "config.h" | ||
28 | |||
29 | #if HAVE_UNISTD_H | ||
30 | #include <unistd.h> | ||
31 | #endif | ||
32 | #if HAVE_IO_H | ||
33 | #include <io.h> | ||
34 | #endif | ||
35 | #include <inttypes.h> | ||
36 | #include <stdarg.h> | ||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <string.h> | ||
40 | #include "bprint.h" | ||
41 | #include "common.h" | ||
42 | #include "internal.h" | ||
43 | #include "log.h" | ||
44 | #include "thread.h" | ||
45 | #include "time.h" | ||
46 | #include "time_internal.h" | ||
47 | |||
48 | static AVMutex mutex = AV_MUTEX_INITIALIZER; | ||
49 | |||
50 | #define LINE_SZ 1024 | ||
51 | |||
52 | #if HAVE_VALGRIND_VALGRIND_H && CONFIG_VALGRIND_BACKTRACE | ||
53 | #include <valgrind/valgrind.h> | ||
54 | /* this is the log level at which valgrind will output a full backtrace */ | ||
55 | #define BACKTRACE_LOGLEVEL AV_LOG_ERROR | ||
56 | #endif | ||
57 | |||
58 | static int av_log_level = AV_LOG_INFO; | ||
59 | static int flags; | ||
60 | |||
61 | #define NB_LEVELS 8 | ||
62 | #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE | ||
63 | #include <windows.h> | ||
64 | static const uint8_t color[16 + AV_CLASS_CATEGORY_NB] = { | ||
65 | [AV_LOG_PANIC /8] = 12, | ||
66 | [AV_LOG_FATAL /8] = 12, | ||
67 | [AV_LOG_ERROR /8] = 12, | ||
68 | [AV_LOG_WARNING/8] = 14, | ||
69 | [AV_LOG_INFO /8] = 7, | ||
70 | [AV_LOG_VERBOSE/8] = 10, | ||
71 | [AV_LOG_DEBUG /8] = 10, | ||
72 | [AV_LOG_TRACE /8] = 8, | ||
73 | [16+AV_CLASS_CATEGORY_NA ] = 7, | ||
74 | [16+AV_CLASS_CATEGORY_INPUT ] = 13, | ||
75 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 5, | ||
76 | [16+AV_CLASS_CATEGORY_MUXER ] = 13, | ||
77 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 5, | ||
78 | [16+AV_CLASS_CATEGORY_ENCODER ] = 11, | ||
79 | [16+AV_CLASS_CATEGORY_DECODER ] = 3, | ||
80 | [16+AV_CLASS_CATEGORY_FILTER ] = 10, | ||
81 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 9, | ||
82 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 7, | ||
83 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 7, | ||
84 | [16+AV_CLASS_CATEGORY_HWDEVICE ] = 6, | ||
85 | [16+AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT ] = 13, | ||
86 | [16+AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ] = 5, | ||
87 | [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ] = 13, | ||
88 | [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ] = 5, | ||
89 | [16+AV_CLASS_CATEGORY_DEVICE_OUTPUT ] = 13, | ||
90 | [16+AV_CLASS_CATEGORY_DEVICE_INPUT ] = 5, | ||
91 | }; | ||
92 | |||
93 | static int16_t background, attr_orig; | ||
94 | static HANDLE con; | ||
95 | #else | ||
96 | |||
97 | static const uint32_t color[16 + AV_CLASS_CATEGORY_NB] = { | ||
98 | [AV_LOG_PANIC /8] = 52 << 16 | 196 << 8 | 0x41, | ||
99 | [AV_LOG_FATAL /8] = 208 << 8 | 0x41, | ||
100 | [AV_LOG_ERROR /8] = 196 << 8 | 0x11, | ||
101 | [AV_LOG_WARNING/8] = 226 << 8 | 0x03, | ||
102 | [AV_LOG_INFO /8] = 253 << 8 | 0x09, | ||
103 | [AV_LOG_VERBOSE/8] = 40 << 8 | 0x02, | ||
104 | [AV_LOG_DEBUG /8] = 34 << 8 | 0x02, | ||
105 | [AV_LOG_TRACE /8] = 34 << 8 | 0x07, | ||
106 | [16+AV_CLASS_CATEGORY_NA ] = 250 << 8 | 0x09, | ||
107 | [16+AV_CLASS_CATEGORY_INPUT ] = 219 << 8 | 0x15, | ||
108 | [16+AV_CLASS_CATEGORY_OUTPUT ] = 201 << 8 | 0x05, | ||
109 | [16+AV_CLASS_CATEGORY_MUXER ] = 213 << 8 | 0x15, | ||
110 | [16+AV_CLASS_CATEGORY_DEMUXER ] = 207 << 8 | 0x05, | ||
111 | [16+AV_CLASS_CATEGORY_ENCODER ] = 51 << 8 | 0x16, | ||
112 | [16+AV_CLASS_CATEGORY_DECODER ] = 39 << 8 | 0x06, | ||
113 | [16+AV_CLASS_CATEGORY_FILTER ] = 155 << 8 | 0x12, | ||
114 | [16+AV_CLASS_CATEGORY_BITSTREAM_FILTER] = 192 << 8 | 0x14, | ||
115 | [16+AV_CLASS_CATEGORY_SWSCALER ] = 153 << 8 | 0x14, | ||
116 | [16+AV_CLASS_CATEGORY_SWRESAMPLER ] = 147 << 8 | 0x14, | ||
117 | [16+AV_CLASS_CATEGORY_HWDEVICE ] = 214 << 8 | 0x13, | ||
118 | [16+AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT ] = 213 << 8 | 0x15, | ||
119 | [16+AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ] = 207 << 8 | 0x05, | ||
120 | [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ] = 213 << 8 | 0x15, | ||
121 | [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ] = 207 << 8 | 0x05, | ||
122 | [16+AV_CLASS_CATEGORY_DEVICE_OUTPUT ] = 213 << 8 | 0x15, | ||
123 | [16+AV_CLASS_CATEGORY_DEVICE_INPUT ] = 207 << 8 | 0x05, | ||
124 | }; | ||
125 | |||
126 | #endif | ||
127 | static int use_color = -1; | ||
128 | |||
129 | #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE | ||
130 | static void win_console_puts(const char *str) | ||
131 | { | ||
132 | const uint8_t *q = str; | ||
133 | uint16_t line[LINE_SZ]; | ||
134 | |||
135 | while (*q) { | ||
136 | uint16_t *buf = line; | ||
137 | DWORD nb_chars = 0; | ||
138 | DWORD written; | ||
139 | |||
140 | while (*q && nb_chars < LINE_SZ - 1) { | ||
141 | uint32_t ch; | ||
142 | uint16_t tmp; | ||
143 | |||
144 | GET_UTF8(ch, *q ? *q++ : 0, ch = 0xfffd; goto continue_on_invalid;) | ||
145 | continue_on_invalid: | ||
146 | PUT_UTF16(ch, tmp, *buf++ = tmp; nb_chars++;) | ||
147 | } | ||
148 | |||
149 | WriteConsoleW(con, line, nb_chars, &written, NULL); | ||
150 | } | ||
151 | } | ||
152 | #endif | ||
153 | |||
154 | 8636 | static void check_color_terminal(void) | |
155 | { | ||
156 | 8636 | char *term = getenv("TERM"); | |
157 | |||
158 | #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE | ||
159 | CONSOLE_SCREEN_BUFFER_INFO con_info; | ||
160 | DWORD dummy; | ||
161 | con = GetStdHandle(STD_ERROR_HANDLE); | ||
162 | if (con != INVALID_HANDLE_VALUE && !GetConsoleMode(con, &dummy)) | ||
163 | con = INVALID_HANDLE_VALUE; | ||
164 | if (con != INVALID_HANDLE_VALUE) { | ||
165 | GetConsoleScreenBufferInfo(con, &con_info); | ||
166 | attr_orig = con_info.wAttributes; | ||
167 | background = attr_orig & 0xF0; | ||
168 | } | ||
169 | #endif | ||
170 | |||
171 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8636 times.
|
8636 | if (getenv("AV_LOG_FORCE_NOCOLOR")) { |
172 | ✗ | use_color = 0; | |
173 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8636 times.
|
8636 | } else if (getenv("AV_LOG_FORCE_COLOR")) { |
174 | ✗ | use_color = 1; | |
175 | } else { | ||
176 | #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE | ||
177 | use_color = (con != INVALID_HANDLE_VALUE); | ||
178 | #elif HAVE_ISATTY | ||
179 |
2/4✓ Branch 0 taken 8636 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8636 times.
|
8636 | use_color = (term && isatty(2)); |
180 | #else | ||
181 | use_color = 0; | ||
182 | #endif | ||
183 | } | ||
184 | |||
185 |
3/6✓ Branch 1 taken 8636 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8636 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8636 times.
✗ Branch 6 not taken.
|
8636 | if (getenv("AV_LOG_FORCE_256COLOR") || term && strstr(term, "256color")) |
186 | 8636 | use_color *= 256; | |
187 | 8636 | } | |
188 | |||
189 | 452378 | static void ansi_fputs(int level, int tint, const char *str, int local_use_color) | |
190 | { | ||
191 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 452378 times.
|
452378 | if (local_use_color == 1) { |
192 | ✗ | fprintf(stderr, | |
193 | "\033[%"PRIu32";3%"PRIu32"m%s\033[0m", | ||
194 | ✗ | (color[level] >> 4) & 15, | |
195 | ✗ | color[level] & 15, | |
196 | str); | ||
197 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 452378 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
452378 | } else if (tint && use_color == 256) { |
198 | ✗ | fprintf(stderr, | |
199 | "\033[48;5;%"PRIu32"m\033[38;5;%dm%s\033[0m", | ||
200 | ✗ | (color[level] >> 16) & 0xff, | |
201 | tint, | ||
202 | str); | ||
203 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 452378 times.
|
452378 | } else if (local_use_color == 256) { |
204 | ✗ | fprintf(stderr, | |
205 | "\033[48;5;%"PRIu32"m\033[38;5;%"PRIu32"m%s\033[0m", | ||
206 | ✗ | (color[level] >> 16) & 0xff, | |
207 | ✗ | (color[level] >> 8) & 0xff, | |
208 | str); | ||
209 | } else | ||
210 | 452378 | fputs(str, stderr); | |
211 | 452378 | } | |
212 | |||
213 | 2239020 | static void colored_fputs(int level, int tint, const char *str) | |
214 | { | ||
215 | int local_use_color; | ||
216 |
2/2✓ Branch 0 taken 1786642 times.
✓ Branch 1 taken 452378 times.
|
2239020 | if (!*str) |
217 | 1786642 | return; | |
218 | |||
219 |
2/2✓ Branch 0 taken 8636 times.
✓ Branch 1 taken 443742 times.
|
452378 | if (use_color < 0) |
220 | 8636 | check_color_terminal(); | |
221 | |||
222 |
2/2✓ Branch 0 taken 418920 times.
✓ Branch 1 taken 33458 times.
|
452378 | if (level == AV_LOG_INFO/8) local_use_color = 0; |
223 | 33458 | else local_use_color = use_color; | |
224 | |||
225 | #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE | ||
226 | if (con != INVALID_HANDLE_VALUE) { | ||
227 | if (local_use_color) | ||
228 | SetConsoleTextAttribute(con, background | color[level]); | ||
229 | win_console_puts(str); | ||
230 | if (local_use_color) | ||
231 | SetConsoleTextAttribute(con, attr_orig); | ||
232 | } else { | ||
233 | ansi_fputs(level, tint, str, local_use_color); | ||
234 | } | ||
235 | #else | ||
236 | 452378 | ansi_fputs(level, tint, str, local_use_color); | |
237 | #endif | ||
238 | |||
239 | } | ||
240 | |||
241 | 2206 | const char *av_default_item_name(void *ptr) | |
242 | { | ||
243 | 2206 | return (*(AVClass **) ptr)->class_name; | |
244 | } | ||
245 | |||
246 | ✗ | AVClassCategory av_default_get_category(void *ptr) | |
247 | { | ||
248 | ✗ | return (*(AVClass **) ptr)->category; | |
249 | } | ||
250 | |||
251 | 2239020 | static void sanitize(uint8_t *line){ | |
252 |
2/2✓ Branch 0 taken 14469622 times.
✓ Branch 1 taken 2239020 times.
|
16708642 | while(*line){ |
253 |
5/6✓ Branch 0 taken 14469622 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14260704 times.
✓ Branch 3 taken 208918 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 14260690 times.
|
14469622 | if(*line < 0x08 || (*line > 0x0D && *line < 0x20)) |
254 | 14 | *line='?'; | |
255 | 14469622 | line++; | |
256 | } | ||
257 | 2239020 | } | |
258 | |||
259 | 23852 | static int get_category(void *ptr){ | |
260 | 23852 | AVClass *avc = *(AVClass **) ptr; | |
261 |
1/2✓ Branch 0 taken 23852 times.
✗ Branch 1 not taken.
|
23852 | if( !avc |
262 |
1/2✓ Branch 0 taken 23852 times.
✗ Branch 1 not taken.
|
23852 | || (avc->version&0xFF)<100 |
263 |
1/2✓ Branch 0 taken 23852 times.
✗ Branch 1 not taken.
|
23852 | || avc->version < (51 << 16 | 59 << 8) |
264 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 23852 times.
|
23852 | || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16; |
265 | |||
266 |
2/2✓ Branch 0 taken 6009 times.
✓ Branch 1 taken 17843 times.
|
23852 | if(avc->get_category) |
267 | 6009 | return avc->get_category(ptr) + 16; | |
268 | |||
269 | 17843 | return avc->category + 16; | |
270 | } | ||
271 | |||
272 | ✗ | static const char *get_level_str(int level) | |
273 | { | ||
274 | ✗ | switch (level) { | |
275 | ✗ | case AV_LOG_QUIET: | |
276 | ✗ | return "quiet"; | |
277 | ✗ | case AV_LOG_DEBUG: | |
278 | ✗ | return "debug"; | |
279 | ✗ | case AV_LOG_TRACE: | |
280 | ✗ | return "trace"; | |
281 | ✗ | case AV_LOG_VERBOSE: | |
282 | ✗ | return "verbose"; | |
283 | ✗ | case AV_LOG_INFO: | |
284 | ✗ | return "info"; | |
285 | ✗ | case AV_LOG_WARNING: | |
286 | ✗ | return "warning"; | |
287 | ✗ | case AV_LOG_ERROR: | |
288 | ✗ | return "error"; | |
289 | ✗ | case AV_LOG_FATAL: | |
290 | ✗ | return "fatal"; | |
291 | ✗ | case AV_LOG_PANIC: | |
292 | ✗ | return "panic"; | |
293 | ✗ | default: | |
294 | ✗ | return ""; | |
295 | } | ||
296 | } | ||
297 | |||
298 | 23852 | static const char *item_name(void *obj, const AVClass *cls) | |
299 | { | ||
300 |
1/2✓ Branch 0 taken 23852 times.
✗ Branch 1 not taken.
|
23852 | return (cls->item_name ? cls->item_name : av_default_item_name)(obj); |
301 | } | ||
302 | |||
303 | ✗ | static void format_date_now(AVBPrint* bp_time, int include_date) | |
304 | { | ||
305 | struct tm *ptm, tmbuf; | ||
306 | ✗ | const int64_t time_us = av_gettime(); | |
307 | ✗ | const int64_t time_ms = time_us / 1000; | |
308 | ✗ | const time_t time_s = time_ms / 1000; | |
309 | ✗ | const int millisec = time_ms - (time_s * 1000); | |
310 | ✗ | ptm = localtime_r(&time_s, &tmbuf); | |
311 | ✗ | if (ptm) { | |
312 | ✗ | if (include_date) | |
313 | ✗ | av_bprint_strftime(bp_time, "%Y-%m-%d ", ptm); | |
314 | |||
315 | ✗ | av_bprint_strftime(bp_time, "%H:%M:%S", ptm); | |
316 | ✗ | av_bprintf(bp_time, ".%03d ", millisec); | |
317 | } | ||
318 | ✗ | } | |
319 | |||
320 | 449905 | static void format_line(void *avcl, int level, const char *fmt, va_list vl, | |
321 | AVBPrint part[5], int *print_prefix, int type[2]) | ||
322 | { | ||
323 |
2/2✓ Branch 0 taken 22980 times.
✓ Branch 1 taken 426925 times.
|
449905 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
324 | 449905 | av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC); | |
325 | 449905 | av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC); | |
326 | 449905 | av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC); | |
327 | 449905 | av_bprint_init(part+3, 0, 65536); | |
328 | 449905 | av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC); | |
329 | |||
330 |
1/2✓ Branch 0 taken 449905 times.
✗ Branch 1 not taken.
|
449905 | if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; |
331 |
4/4✓ Branch 0 taken 227312 times.
✓ Branch 1 taken 222593 times.
✓ Branch 2 taken 22865 times.
✓ Branch 3 taken 204447 times.
|
449905 | if (*print_prefix && avc) { |
332 |
2/2✓ Branch 0 taken 3490 times.
✓ Branch 1 taken 19375 times.
|
22865 | if (avc->parent_log_context_offset) { |
333 | 3490 | AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) + | |
334 | 3490 | avc->parent_log_context_offset); | |
335 |
3/4✓ Branch 0 taken 987 times.
✓ Branch 1 taken 2503 times.
✓ Branch 2 taken 987 times.
✗ Branch 3 not taken.
|
3490 | if (parent && *parent) { |
336 | 987 | av_bprintf(part+0, "[%s @ %p] ", | |
337 | item_name(parent, *parent), parent); | ||
338 |
1/2✓ Branch 0 taken 987 times.
✗ Branch 1 not taken.
|
987 | if(type) type[0] = get_category(parent); |
339 | } | ||
340 | } | ||
341 | 22865 | av_bprintf(part+1, "[%s @ %p] ", | |
342 | item_name(avcl, avc), avcl); | ||
343 |
1/2✓ Branch 0 taken 22865 times.
✗ Branch 1 not taken.
|
22865 | if(type) type[1] = get_category(avcl); |
344 | } | ||
345 | |||
346 |
5/6✓ Branch 0 taken 227312 times.
✓ Branch 1 taken 222593 times.
✓ Branch 2 taken 210531 times.
✓ Branch 3 taken 16781 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 210531 times.
|
449905 | if (*print_prefix && (level > AV_LOG_QUIET) && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME))) |
347 | ✗ | format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME); | |
348 | |||
349 |
5/6✓ Branch 0 taken 227312 times.
✓ Branch 1 taken 222593 times.
✓ Branch 2 taken 210531 times.
✓ Branch 3 taken 16781 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 210531 times.
|
449905 | if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL)) |
350 | ✗ | av_bprintf(part+2, "[%s] ", get_level_str(level)); | |
351 | |||
352 | 449905 | av_vbprintf(part+3, fmt, vl); | |
353 | |||
354 |
7/8✓ Branch 0 taken 448918 times.
✓ Branch 1 taken 987 times.
✓ Branch 2 taken 427040 times.
✓ Branch 3 taken 21878 times.
✓ Branch 4 taken 427040 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 409957 times.
✓ Branch 7 taken 17083 times.
|
449905 | if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) { |
355 |
2/4✓ Branch 0 taken 432822 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 432822 times.
✗ Branch 3 not taken.
|
432822 | char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0; |
356 |
4/4✓ Branch 0 taken 222314 times.
✓ Branch 1 taken 210508 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 222291 times.
|
432822 | *print_prefix = lastc == '\n' || lastc == '\r'; |
357 | } | ||
358 | 449905 | } | |
359 | |||
360 | ✗ | void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, | |
361 | char *line, int line_size, int *print_prefix) | ||
362 | { | ||
363 | ✗ | av_log_format_line2(ptr, level, fmt, vl, line, line_size, print_prefix); | |
364 | ✗ | } | |
365 | |||
366 | ✗ | int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, | |
367 | char *line, int line_size, int *print_prefix) | ||
368 | { | ||
369 | AVBPrint part[5]; | ||
370 | int ret; | ||
371 | |||
372 | ✗ | format_line(ptr, level, fmt, vl, part, print_prefix, NULL); | |
373 | ✗ | ret = snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str); | |
374 | ✗ | av_bprint_finalize(part+3, NULL); | |
375 | ✗ | return ret; | |
376 | } | ||
377 | |||
378 | 16162007 | void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) | |
379 | { | ||
380 | static int print_prefix = 1; | ||
381 | static int count; | ||
382 | static char prev[LINE_SZ]; | ||
383 | AVBPrint part[5]; | ||
384 | char line[LINE_SZ]; | ||
385 | static int is_atty; | ||
386 | int type[2]; | ||
387 | 16162007 | unsigned tint = 0; | |
388 | |||
389 |
2/2✓ Branch 0 taken 16145226 times.
✓ Branch 1 taken 16781 times.
|
16162007 | if (level >= 0) { |
390 | 16145226 | tint = level & 0xff00; | |
391 | 16145226 | level &= 0xff; | |
392 | } | ||
393 | |||
394 |
2/2✓ Branch 0 taken 15712102 times.
✓ Branch 1 taken 449905 times.
|
16162007 | if (level > av_log_level) |
395 | 15712102 | return; | |
396 | 449905 | ff_mutex_lock(&mutex); | |
397 | |||
398 | 449905 | format_line(ptr, level, fmt, vl, part, &print_prefix, type); | |
399 | 449905 | snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str); | |
400 | |||
401 | #if HAVE_ISATTY | ||
402 |
2/2✓ Branch 0 taken 8636 times.
✓ Branch 1 taken 441269 times.
|
449905 | if (!is_atty) |
403 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8636 times.
|
8636 | is_atty = isatty(2) ? 1 : -1; |
404 | #endif | ||
405 | |||
406 |
6/6✓ Branch 0 taken 227312 times.
✓ Branch 1 taken 222593 times.
✓ Branch 2 taken 224453 times.
✓ Branch 3 taken 2859 times.
✓ Branch 4 taken 2101 times.
✓ Branch 5 taken 222352 times.
|
449905 | if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) && |
407 |
2/4✓ Branch 0 taken 2101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2101 times.
✗ Branch 3 not taken.
|
2101 | *line && line[strlen(line) - 1] != '\r'){ |
408 | 2101 | count++; | |
409 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2101 times.
|
2101 | if (is_atty == 1) |
410 | ✗ | fprintf(stderr, " Last message repeated %d times\r", count); | |
411 | 2101 | goto end; | |
412 | } | ||
413 |
2/2✓ Branch 0 taken 380 times.
✓ Branch 1 taken 447424 times.
|
447804 | if (count > 0) { |
414 | 380 | fprintf(stderr, " Last message repeated %d times\n", count); | |
415 | 380 | count = 0; | |
416 | } | ||
417 | 447804 | strcpy(prev, line); | |
418 | |||
419 | 447804 | sanitize(part[4].str); | |
420 | 447804 | colored_fputs(7, 0, part[4].str); | |
421 | 447804 | sanitize(part[0].str); | |
422 | 447804 | colored_fputs(type[0], 0, part[0].str); | |
423 | 447804 | sanitize(part[1].str); | |
424 | 447804 | colored_fputs(type[1], 0, part[1].str); | |
425 | 447804 | sanitize(part[2].str); | |
426 | 447804 | colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[2].str); | |
427 | 447804 | sanitize(part[3].str); | |
428 | 447804 | colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[3].str); | |
429 | |||
430 | #if CONFIG_VALGRIND_BACKTRACE | ||
431 |
2/2✓ Branch 0 taken 426833 times.
✓ Branch 1 taken 20971 times.
|
447804 | if (level <= BACKTRACE_LOGLEVEL) |
432 | 20971 | VALGRIND_PRINTF_BACKTRACE("%s", ""); | |
433 | #endif | ||
434 | 426833 | end: | |
435 | 449905 | av_bprint_finalize(part+3, NULL); | |
436 | 449905 | ff_mutex_unlock(&mutex); | |
437 | } | ||
438 | |||
439 | static void (*av_log_callback)(void*, int, const char*, va_list) = | ||
440 | av_log_default_callback; | ||
441 | |||
442 | 16162335 | void av_log(void* avcl, int level, const char *fmt, ...) | |
443 | { | ||
444 | va_list vl; | ||
445 | 16162335 | va_start(vl, fmt); | |
446 | 16162335 | av_vlog(avcl, level, fmt, vl); | |
447 | 16162335 | va_end(vl); | |
448 | 16162335 | } | |
449 | |||
450 | 39 | void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...) | |
451 | { | ||
452 | va_list vl; | ||
453 | 39 | va_start(vl, fmt); | |
454 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 6 times.
|
39 | av_vlog(avcl, *state ? subsequent_level : initial_level, fmt, vl); |
455 | 39 | va_end(vl); | |
456 | 39 | *state = 1; | |
457 | 39 | } | |
458 | |||
459 | 16162528 | void av_vlog(void* avcl, int level, const char *fmt, va_list vl) | |
460 | { | ||
461 |
2/2✓ Branch 0 taken 14926432 times.
✓ Branch 1 taken 1236096 times.
|
16162528 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
462 | 16162528 | void (*log_callback)(void*, int, const char*, va_list) = av_log_callback; | |
463 |
3/4✓ Branch 0 taken 14926432 times.
✓ Branch 1 taken 1236096 times.
✓ Branch 2 taken 14926432 times.
✗ Branch 3 not taken.
|
16162528 | if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) && |
464 |
3/4✓ Branch 0 taken 410697 times.
✓ Branch 1 taken 14515735 times.
✓ Branch 2 taken 410697 times.
✗ Branch 3 not taken.
|
14926432 | avc->log_level_offset_offset && level >= AV_LOG_FATAL) |
465 | 410697 | level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset); | |
466 |
2/2✓ Branch 0 taken 16162525 times.
✓ Branch 1 taken 3 times.
|
16162528 | if (log_callback) |
467 | 16162525 | log_callback(avcl, level, fmt, vl); | |
468 | 16162528 | } | |
469 | |||
470 | 102795 | int av_log_get_level(void) | |
471 | { | ||
472 | 102795 | return av_log_level; | |
473 | } | ||
474 | |||
475 | 3752 | void av_log_set_level(int level) | |
476 | { | ||
477 | 3752 | av_log_level = level; | |
478 | 3752 | } | |
479 | |||
480 | 8584 | void av_log_set_flags(int arg) | |
481 | { | ||
482 | 8584 | flags = arg; | |
483 | 8584 | } | |
484 | |||
485 | 64 | int av_log_get_flags(void) | |
486 | { | ||
487 | 64 | return flags; | |
488 | } | ||
489 | |||
490 | 86 | void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) | |
491 | { | ||
492 | 86 | av_log_callback = callback; | |
493 | 86 | } | |
494 | |||
495 | 14 | static void missing_feature_sample(int sample, void *avc, const char *msg, | |
496 | va_list argument_list) | ||
497 | { | ||
498 | 14 | av_vlog(avc, AV_LOG_WARNING, msg, argument_list); | |
499 | 14 | av_log(avc, AV_LOG_WARNING, " is not implemented. Update your FFmpeg " | |
500 | "version to the newest one from Git. If the problem still " | ||
501 | "occurs, it means that your file has a feature which has not " | ||
502 | "been implemented.\n"); | ||
503 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (sample) |
504 | ✗ | av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample " | |
505 | "of this file to https://streams.videolan.org/upload/ " | ||
506 | "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n"); | ||
507 | 14 | } | |
508 | |||
509 | ✗ | void avpriv_request_sample(void *avc, const char *msg, ...) | |
510 | { | ||
511 | va_list argument_list; | ||
512 | |||
513 | ✗ | va_start(argument_list, msg); | |
514 | ✗ | missing_feature_sample(1, avc, msg, argument_list); | |
515 | ✗ | va_end(argument_list); | |
516 | ✗ | } | |
517 | |||
518 | 14 | void avpriv_report_missing_feature(void *avc, const char *msg, ...) | |
519 | { | ||
520 | va_list argument_list; | ||
521 | |||
522 | 14 | va_start(argument_list, msg); | |
523 | 14 | missing_feature_sample(0, avc, msg, argument_list); | |
524 | 14 | va_end(argument_list); | |
525 | 14 | } | |
526 |