FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/log.c
Date: 2026-10-20 16:15:15
Exec Total Coverage
Lines: 159 209 76.1%
Functions: 20 25 80.0%
Branches: 107 148 72.3%

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 win_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 #endif
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 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 9279 static void check_color_terminal(void)
155 {
156 9279 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 9279 times.
9279 if (getenv("AV_LOG_FORCE_NOCOLOR")) {
172 ✗ use_color = 0;
173
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9279 times.
9279 } 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 9279 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 9279 times.
9279 use_color = (term && isatty(2));
180 #else
181 use_color = 0;
182 #endif
183 }
184
185
3/6
✓ Branch 1 taken 9279 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9279 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 9279 times.
✗ Branch 6 not taken.
9279 if (getenv("AV_LOG_FORCE_256COLOR") || term && strstr(term, "256color"))
186 9279 use_color *= 256;
187 9279 }
188
189 653223 static void ansi_fputs(int level, int tint, const char *str, int local_use_color)
190 {
191
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 653208 times.
653223 if (local_use_color == 1) {
192 15 uint32_t intensity = (color[level] >> 4) & 15;
193 15 uint32_t fg = color[level] & 15;
194 #if defined(_WIN32)
195 /* Piped stderr is 8-color ANSI. Linux keeps 0;33m; Windows console
196 * already uses win_color 14 (bright yellow), so match that here. */
197 if (level == AV_LOG_WARNING / 8)
198 intensity = 1;
199 #endif
200 15 fprintf(stderr,
201 "\033[%"PRIu32";3%"PRIu32"m%s\033[0m",
202 intensity, fg, str);
203
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 653193 times.
✓ Branch 2 taken 7 times.
✓ Branch 3 taken 8 times.
653208 } else if (tint && use_color == 256) {
204 7 fprintf(stderr,
205 "\033[48;5;%"PRIu32"m\033[38;5;%dm%s\033[0m",
206 7 (color[level] >> 16) & 0xff,
207 tint,
208 str);
209
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 653192 times.
653201 } else if (local_use_color == 256) {
210 9 fprintf(stderr,
211 "\033[48;5;%"PRIu32"m\033[38;5;%"PRIu32"m%s\033[0m",
212 9 (color[level] >> 16) & 0xff,
213 9 (color[level] >> 8) & 0xff,
214 str);
215 } else
216 653192 fputs(str, stderr);
217 653223 }
218
219 2964740 static void colored_fputs(int level, int tint, const char *str)
220 {
221 int local_use_color;
222
2/2
✓ Branch 0 taken 2311517 times.
✓ Branch 1 taken 653223 times.
2964740 if (!*str)
223 2311517 return;
224
225
2/2
✓ Branch 0 taken 9278 times.
✓ Branch 1 taken 643945 times.
653223 if (use_color < 0)
226 9278 check_color_terminal();
227
228
2/2
✓ Branch 0 taken 453079 times.
✓ Branch 1 taken 200144 times.
653223 if (level == AV_LOG_INFO/8) local_use_color = 0;
229 200144 else local_use_color = use_color;
230
231 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
232 if (con != INVALID_HANDLE_VALUE) {
233 if (local_use_color)
234 SetConsoleTextAttribute(con, background | win_color[level]);
235 win_console_puts(str);
236 if (local_use_color)
237 SetConsoleTextAttribute(con, attr_orig);
238 } else {
239 ansi_fputs(level, tint, str, local_use_color);
240 }
241 #else
242 653223 ansi_fputs(level, tint, str, local_use_color);
243 #endif
244
245 }
246
247 2222 const char *av_default_item_name(void *ptr)
248 {
249 2222 return (*(AVClass **) ptr)->class_name;
250 }
251
252 ✗ AVClassCategory av_default_get_category(void *ptr)
253 {
254 ✗ return (*(AVClass **) ptr)->category;
255 }
256
257 2964740 static void sanitize(uint8_t *line){
258
2/2
✓ Branch 0 taken 28008620 times.
✓ Branch 1 taken 2964740 times.
30973360 while(*line){
259
5/6
✓ Branch 0 taken 28008620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 27674176 times.
✓ Branch 3 taken 334444 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 27674162 times.
28008620 if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
260 14 *line='?';
261 28008620 line++;
262 }
263 2964740 }
264
265 80615 static int get_category(void *ptr){
266 80615 AVClass *avc = *(AVClass **) ptr;
267
1/2
✓ Branch 0 taken 80615 times.
✗ Branch 1 not taken.
80615 if( !avc
268
1/2
✓ Branch 0 taken 80615 times.
✗ Branch 1 not taken.
80615 || (avc->version&0xFF)<100
269
1/2
✓ Branch 0 taken 80615 times.
✗ Branch 1 not taken.
80615 || avc->version < (51 << 16 | 59 << 8)
270
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80615 times.
80615 || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16;
271
272
2/2
✓ Branch 0 taken 6387 times.
✓ Branch 1 taken 74228 times.
80615 if(avc->get_category)
273 6387 return avc->get_category(ptr) + 16;
274
275 74228 return avc->category + 16;
276 }
277
278 ✗ static const char *get_level_str(int level)
279 {
280 ✗ switch (level) {
281 ✗ case AV_LOG_QUIET:
282 ✗ return "quiet";
283 ✗ case AV_LOG_DEBUG:
284 ✗ return "debug";
285 ✗ case AV_LOG_TRACE:
286 ✗ return "trace";
287 ✗ case AV_LOG_VERBOSE:
288 ✗ return "verbose";
289 ✗ case AV_LOG_INFO:
290 ✗ return "info";
291 ✗ case AV_LOG_WARNING:
292 ✗ return "warning";
293 ✗ case AV_LOG_ERROR:
294 ✗ return "error";
295 ✗ case AV_LOG_FATAL:
296 ✗ return "fatal";
297 ✗ case AV_LOG_PANIC:
298 ✗ return "panic";
299 ✗ default:
300 ✗ return "";
301 }
302 }
303
304 80615 static const char *item_name(void *obj, const AVClass *cls)
305 {
306
1/2
✓ Branch 0 taken 80615 times.
✗ Branch 1 not taken.
80615 return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
307 }
308
309 ✗ static void format_date_now(AVBPrint* bp_time, int include_date)
310 {
311 struct tm *ptm, tmbuf;
312 ✗ const int64_t time_us = av_gettime();
313 ✗ const int64_t time_ms = time_us / 1000;
314 ✗ const time_t time_s = time_ms / 1000;
315 ✗ const int millisec = time_ms - (time_s * 1000);
316 ✗ ptm = localtime_r(&time_s, &tmbuf);
317 ✗ if (ptm) {
318 ✗ if (include_date)
319 ✗ av_bprint_strftime(bp_time, "%Y-%m-%d ", ptm);
320
321 ✗ av_bprint_strftime(bp_time, "%H:%M:%S", ptm);
322 ✗ av_bprintf(bp_time, ".%03d ", millisec);
323 }
324 ✗ }
325
326 595047 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
327 AVBPrint part[5], int *print_prefix, int type[2])
328 {
329
2/2
✓ Branch 0 taken 79855 times.
✓ Branch 1 taken 515192 times.
595047 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
330 595047 av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC);
331 595047 av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC);
332 595047 av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);
333 595047 av_bprint_init(part+3, 0, 65536);
334 595047 av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC);
335 595047 int flags = atomic_load_explicit(&av_log_flags, memory_order_relaxed);
336
337
2/2
✓ Branch 0 taken 595044 times.
✓ Branch 1 taken 3 times.
595047 if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
338
4/4
✓ Branch 0 taken 353838 times.
✓ Branch 1 taken 241209 times.
✓ Branch 2 taken 79620 times.
✓ Branch 3 taken 274218 times.
595047 if (*print_prefix && avc) {
339
2/2
✓ Branch 0 taken 57809 times.
✓ Branch 1 taken 21811 times.
79620 if (avc->parent_log_context_offset) {
340 57809 AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
341 57809 avc->parent_log_context_offset);
342
3/4
✓ Branch 0 taken 995 times.
✓ Branch 1 taken 56814 times.
✓ Branch 2 taken 995 times.
✗ Branch 3 not taken.
57809 if (parent && *parent) {
343 995 av_bprintf(part+0, "[%s @ %p] ",
344 item_name(parent, *parent), parent);
345
1/2
✓ Branch 0 taken 995 times.
✗ Branch 1 not taken.
995 if(type) type[0] = get_category(parent);
346 }
347 }
348 79620 av_bprintf(part+1, "[%s @ %p] ",
349 item_name(avcl, avc), avcl);
350
1/2
✓ Branch 0 taken 79620 times.
✗ Branch 1 not taken.
79620 if(type) type[1] = get_category(avcl);
351 }
352
353
5/6
✓ Branch 0 taken 353838 times.
✓ Branch 1 taken 241209 times.
✓ Branch 2 taken 335959 times.
✓ Branch 3 taken 17879 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 335959 times.
595047 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME)))
354 ✗ format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME);
355
356
5/6
✓ Branch 0 taken 353838 times.
✓ Branch 1 taken 241209 times.
✓ Branch 2 taken 335959 times.
✓ Branch 3 taken 17879 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 335959 times.
595047 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))
357 ✗ av_bprintf(part+2, "[%s] ", get_level_str(level));
358
359 595047 av_vbprintf(part+3, fmt, vl);
360
361
7/8
✓ Branch 0 taken 594052 times.
✓ Branch 1 taken 995 times.
✓ Branch 2 taken 515427 times.
✓ Branch 3 taken 78625 times.
✓ Branch 4 taken 515427 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 497246 times.
✓ Branch 7 taken 18181 times.
595047 if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
362
2/4
✓ Branch 0 taken 576866 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 576866 times.
✗ Branch 3 not taken.
576866 char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0;
363
4/4
✓ Branch 0 taken 240941 times.
✓ Branch 1 taken 335925 times.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 240910 times.
576866 *print_prefix = lastc == '\n' || lastc == '\r';
364 }
365 595047 }
366
367 ✗ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
368 char *line, int line_size, int *print_prefix)
369 {
370 ✗ av_log_format_line2(ptr, level, fmt, vl, line, line_size, print_prefix);
371 ✗ }
372
373 3 int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
374 char *line, int line_size, int *print_prefix)
375 {
376 AVBPrint part[5];
377 int ret;
378
379 3 format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
380 3 ret = snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
381 3 av_bprint_finalize(part+3, NULL);
382 3 return ret;
383 }
384
385 43750163 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
386 {
387 static int print_prefix = 1;
388 static int count;
389 static char prev[LINE_SZ];
390 AVBPrint part[5];
391 char line[LINE_SZ];
392 static int is_atty;
393 int type[2];
394 43750163 unsigned tint = 0;
395
396
2/2
✓ Branch 0 taken 43732281 times.
✓ Branch 1 taken 17882 times.
43750163 if (level >= 0) {
397 43732281 tint = level & 0xff00;
398 43732281 level &= 0xff;
399 }
400
401
2/2
✓ Branch 0 taken 43155119 times.
✓ Branch 1 taken 595044 times.
43750163 if (level > atomic_load_explicit(&av_log_level, memory_order_relaxed))
402 43155119 return;
403 595044 ff_mutex_lock(&mutex);
404
405 595044 format_line(ptr, level, fmt, vl, part, &print_prefix, type);
406 595044 snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
407
408 #if HAVE_ISATTY
409
2/2
✓ Branch 0 taken 9328 times.
✓ Branch 1 taken 585716 times.
595044 if (!is_atty)
410
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9328 times.
9328 is_atty = isatty(2) ? 1 : -1;
411 #endif
412
413
6/6
✓ Branch 0 taken 353835 times.
✓ Branch 1 taken 241209 times.
✓ Branch 2 taken 242298 times.
✓ Branch 3 taken 111537 times.
✓ Branch 4 taken 2194 times.
✓ Branch 5 taken 240104 times.
595044 if (print_prefix && (atomic_load_explicit(&av_log_flags, memory_order_relaxed) & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) &&
414
3/4
✓ Branch 0 taken 2096 times.
✓ Branch 1 taken 98 times.
✓ Branch 2 taken 2096 times.
✗ Branch 3 not taken.
2194 *line && line[strlen(line) - 1] != '\r'){
415 2096 count++;
416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2096 times.
2096 if (is_atty == 1)
417 ✗ fprintf(stderr, " Last message repeated %d times\r", count);
418 2096 goto end;
419 }
420
2/2
✓ Branch 0 taken 387 times.
✓ Branch 1 taken 592561 times.
592948 if (count > 0) {
421 387 fprintf(stderr, " Last message repeated %d times\n", count);
422 387 count = 0;
423 }
424 592948 strcpy(prev, line);
425
426 592948 sanitize(part[4].str);
427 592948 colored_fputs(7, 0, part[4].str);
428 592948 sanitize(part[0].str);
429 592948 colored_fputs(type[0], 0, part[0].str);
430 592948 sanitize(part[1].str);
431 592948 colored_fputs(type[1], 0, part[1].str);
432 592948 sanitize(part[2].str);
433 592948 colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[2].str);
434 592948 sanitize(part[3].str);
435 592948 colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[3].str);
436
437 #if CONFIG_VALGRIND_BACKTRACE
438
2/2
✓ Branch 0 taken 462137 times.
✓ Branch 1 taken 130811 times.
592948 if (level <= BACKTRACE_LOGLEVEL)
439 130811 VALGRIND_PRINTF_BACKTRACE("%s", "");
440 #endif
441 462137 end:
442 595044 av_bprint_finalize(part+3, NULL);
443 595044 ff_mutex_unlock(&mutex);
444 }
445
446 static void (*_Atomic av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
447
448 46483991 void av_log(void* avcl, int level, const char *fmt, ...)
449 {
450 va_list vl;
451 46483991 va_start(vl, fmt);
452 46483991 av_vlog(avcl, level, fmt, vl);
453 46483991 va_end(vl);
454 46483991 }
455
456 6030 void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...)
457 {
458 va_list vl;
459 6030 va_start(vl, fmt);
460
2/2
✓ Branch 0 taken 5899 times.
✓ Branch 1 taken 131 times.
6030 av_vlog(avcl, *state ? subsequent_level : initial_level, fmt, vl);
461 6030 va_end(vl);
462 6030 *state = 1;
463 6030 }
464
465 46490195 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
466 {
467
2/2
✓ Branch 0 taken 42326788 times.
✓ Branch 1 taken 4163407 times.
46490195 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
468 46490195 void (*log_callback)(void*, int, const char*, va_list) =
469 46490195 atomic_load_explicit(&av_log_callback, memory_order_relaxed);
470
3/4
✓ Branch 0 taken 42326788 times.
✓ Branch 1 taken 4163407 times.
✓ Branch 2 taken 42326788 times.
✗ Branch 3 not taken.
46490195 if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
471
3/4
✓ Branch 0 taken 500923 times.
✓ Branch 1 taken 41825865 times.
✓ Branch 2 taken 500923 times.
✗ Branch 3 not taken.
42326788 avc->log_level_offset_offset && level >= AV_LOG_FATAL)
472 500923 level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);
473
2/2
✓ Branch 0 taken 46490192 times.
✓ Branch 1 taken 3 times.
46490195 if (log_callback)
474 46490192 log_callback(avcl, level, fmt, vl);
475 46490195 }
476
477 2928122 int av_log_get_level(void)
478 {
479 2928122 return atomic_load_explicit(&av_log_level, memory_order_relaxed);
480 }
481
482 8933 void av_log_set_level(int level)
483 {
484 8933 atomic_store_explicit(&av_log_level, level, memory_order_relaxed);
485 8933 }
486
487 9486 void av_log_set_flags(int arg)
488 {
489 9486 atomic_store_explicit(&av_log_flags, arg, memory_order_relaxed);
490 9486 }
491
492 432 int av_log_get_flags(void)
493 {
494 432 return atomic_load_explicit(&av_log_flags, memory_order_relaxed);
495 }
496
497 108 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
498 {
499 108 atomic_store_explicit(&av_log_callback, callback, memory_order_relaxed);
500 108 }
501
502 14 static void missing_feature_sample(int sample, void *avc, const char *msg,
503 va_list argument_list)
504 {
505 14 av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
506 14 av_log(avc, AV_LOG_WARNING, " is not implemented. Update your FFmpeg "
507 "version to the newest one from Git. If the problem still "
508 "occurs, it means that your file has a feature which has not "
509 "been implemented.\n");
510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (sample)
511 ✗ av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
512 "of this file to https://streams.videolan.org/upload/ "
513 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
514 14 }
515
516 ✗ void avpriv_request_sample(void *avc, const char *msg, ...)
517 {
518 va_list argument_list;
519
520 ✗ va_start(argument_list, msg);
521 ✗ missing_feature_sample(1, avc, msg, argument_list);
522 ✗ va_end(argument_list);
523 ✗ }
524
525 14 void avpriv_report_missing_feature(void *avc, const char *msg, ...)
526 {
527 va_list argument_list;
528
529 14 va_start(argument_list, msg);
530 14 missing_feature_sample(0, avc, msg, argument_list);
531 14 va_end(argument_list);
532 14 }
533