FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/log.c
Date: 2026-04-22 18:56:46
Exec Total Coverage
Lines: 146 209 69.9%
Functions: 19 25 76.0%
Branches: 101 148 68.2%

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