FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavutil/log.c
Date: 2025-04-25 22:50:00
Exec Total Coverage
Lines: 144 207 69.6%
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 <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_DEVICE_VIDEO_OUTPUT ] = 213 << 8 | 0x15,
118 [16+AV_CLASS_CATEGORY_DEVICE_VIDEO_INPUT ] = 207 << 8 | 0x05,
119 [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT ] = 213 << 8 | 0x15,
120 [16+AV_CLASS_CATEGORY_DEVICE_AUDIO_INPUT ] = 207 << 8 | 0x05,
121 [16+AV_CLASS_CATEGORY_DEVICE_OUTPUT ] = 213 << 8 | 0x15,
122 [16+AV_CLASS_CATEGORY_DEVICE_INPUT ] = 207 << 8 | 0x05,
123 };
124
125 #endif
126 static int use_color = -1;
127
128 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
129 static void win_console_puts(const char *str)
130 {
131 const uint8_t *q = str;
132 uint16_t line[LINE_SZ];
133
134 while (*q) {
135 uint16_t *buf = line;
136 DWORD nb_chars = 0;
137 DWORD written;
138
139 while (*q && nb_chars < LINE_SZ - 1) {
140 uint32_t ch;
141 uint16_t tmp;
142
143 GET_UTF8(ch, *q ? *q++ : 0, ch = 0xfffd; goto continue_on_invalid;)
144 continue_on_invalid:
145 PUT_UTF16(ch, tmp, *buf++ = tmp; nb_chars++;)
146 }
147
148 WriteConsoleW(con, line, nb_chars, &written, NULL);
149 }
150 }
151 #endif
152
153 8475 static void check_color_terminal(void)
154 {
155 8475 char *term = getenv("TERM");
156
157 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
158 CONSOLE_SCREEN_BUFFER_INFO con_info;
159 DWORD dummy;
160 con = GetStdHandle(STD_ERROR_HANDLE);
161 if (con != INVALID_HANDLE_VALUE && !GetConsoleMode(con, &dummy))
162 con = INVALID_HANDLE_VALUE;
163 if (con != INVALID_HANDLE_VALUE) {
164 GetConsoleScreenBufferInfo(con, &con_info);
165 attr_orig = con_info.wAttributes;
166 background = attr_orig & 0xF0;
167 }
168 #endif
169
170
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8475 times.
8475 if (getenv("AV_LOG_FORCE_NOCOLOR")) {
171 use_color = 0;
172
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8475 times.
8475 } else if (getenv("AV_LOG_FORCE_COLOR")) {
173 use_color = 1;
174 } else {
175 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
176 use_color = (con != INVALID_HANDLE_VALUE);
177 #elif HAVE_ISATTY
178
2/4
✓ Branch 0 taken 8475 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8475 times.
8475 use_color = (term && isatty(2));
179 #else
180 use_color = 0;
181 #endif
182 }
183
184
3/6
✓ Branch 1 taken 8475 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8475 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 8475 times.
✗ Branch 6 not taken.
8475 if (getenv("AV_LOG_FORCE_256COLOR") || term && strstr(term, "256color"))
185 8475 use_color *= 256;
186 8475 }
187
188 452657 static void ansi_fputs(int level, int tint, const char *str, int local_use_color)
189 {
190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 452657 times.
452657 if (local_use_color == 1) {
191 fprintf(stderr,
192 "\033[%"PRIu32";3%"PRIu32"m%s\033[0m",
193 (color[level] >> 4) & 15,
194 color[level] & 15,
195 str);
196
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 452657 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
452657 } else if (tint && use_color == 256) {
197 fprintf(stderr,
198 "\033[48;5;%"PRIu32"m\033[38;5;%dm%s\033[0m",
199 (color[level] >> 16) & 0xff,
200 tint,
201 str);
202
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 452657 times.
452657 } else if (local_use_color == 256) {
203 fprintf(stderr,
204 "\033[48;5;%"PRIu32"m\033[38;5;%"PRIu32"m%s\033[0m",
205 (color[level] >> 16) & 0xff,
206 (color[level] >> 8) & 0xff,
207 str);
208 } else
209 452657 fputs(str, stderr);
210 452657 }
211
212 2240155 static void colored_fputs(int level, int tint, const char *str)
213 {
214 int local_use_color;
215
2/2
✓ Branch 0 taken 1787498 times.
✓ Branch 1 taken 452657 times.
2240155 if (!*str)
216 1787498 return;
217
218
2/2
✓ Branch 0 taken 8475 times.
✓ Branch 1 taken 444182 times.
452657 if (use_color < 0)
219 8475 check_color_terminal();
220
221
2/2
✓ Branch 0 taken 419553 times.
✓ Branch 1 taken 33104 times.
452657 if (level == AV_LOG_INFO/8) local_use_color = 0;
222 33104 else local_use_color = use_color;
223
224 #if defined(_WIN32) && HAVE_SETCONSOLETEXTATTRIBUTE && HAVE_GETSTDHANDLE
225 if (con != INVALID_HANDLE_VALUE) {
226 if (local_use_color)
227 SetConsoleTextAttribute(con, background | color[level]);
228 win_console_puts(str);
229 if (local_use_color)
230 SetConsoleTextAttribute(con, attr_orig);
231 } else {
232 ansi_fputs(level, tint, str, local_use_color);
233 }
234 #else
235 452657 ansi_fputs(level, tint, str, local_use_color);
236 #endif
237
238 }
239
240 2229 const char *av_default_item_name(void *ptr)
241 {
242 2229 return (*(AVClass **) ptr)->class_name;
243 }
244
245 AVClassCategory av_default_get_category(void *ptr)
246 {
247 return (*(AVClass **) ptr)->category;
248 }
249
250 2240155 static void sanitize(uint8_t *line){
251
2/2
✓ Branch 0 taken 14399119 times.
✓ Branch 1 taken 2240155 times.
16639274 while(*line){
252
5/6
✓ Branch 0 taken 14399119 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14185499 times.
✓ Branch 3 taken 213620 times.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 14185485 times.
14399119 if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
253 14 *line='?';
254 14399119 line++;
255 }
256 2240155 }
257
258 23596 static int get_category(void *ptr){
259 23596 AVClass *avc = *(AVClass **) ptr;
260
1/2
✓ Branch 0 taken 23596 times.
✗ Branch 1 not taken.
23596 if( !avc
261
1/2
✓ Branch 0 taken 23596 times.
✗ Branch 1 not taken.
23596 || (avc->version&0xFF)<100
262
1/2
✓ Branch 0 taken 23596 times.
✗ Branch 1 not taken.
23596 || avc->version < (51 << 16 | 59 << 8)
263
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23596 times.
23596 || avc->category >= AV_CLASS_CATEGORY_NB) return AV_CLASS_CATEGORY_NA + 16;
264
265
2/2
✓ Branch 0 taken 6017 times.
✓ Branch 1 taken 17579 times.
23596 if(avc->get_category)
266 6017 return avc->get_category(ptr) + 16;
267
268 17579 return avc->category + 16;
269 }
270
271 static const char *get_level_str(int level)
272 {
273 switch (level) {
274 case AV_LOG_QUIET:
275 return "quiet";
276 case AV_LOG_DEBUG:
277 return "debug";
278 case AV_LOG_TRACE:
279 return "trace";
280 case AV_LOG_VERBOSE:
281 return "verbose";
282 case AV_LOG_INFO:
283 return "info";
284 case AV_LOG_WARNING:
285 return "warning";
286 case AV_LOG_ERROR:
287 return "error";
288 case AV_LOG_FATAL:
289 return "fatal";
290 case AV_LOG_PANIC:
291 return "panic";
292 default:
293 return "";
294 }
295 }
296
297 23596 static const char *item_name(void *obj, const AVClass *cls)
298 {
299
1/2
✓ Branch 0 taken 23596 times.
✗ Branch 1 not taken.
23596 return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
300 }
301
302 static void format_date_now(AVBPrint* bp_time, int include_date)
303 {
304 struct tm *ptm, tmbuf;
305 const int64_t time_us = av_gettime();
306 const int64_t time_ms = time_us / 1000;
307 const time_t time_s = time_ms / 1000;
308 const int millisec = time_ms - (time_s * 1000);
309 ptm = localtime_r(&time_s, &tmbuf);
310 if (ptm) {
311 if (include_date)
312 av_bprint_strftime(bp_time, "%Y-%m-%d ", ptm);
313
314 av_bprint_strftime(bp_time, "%H:%M:%S", ptm);
315 av_bprintf(bp_time, ".%03d ", millisec);
316 }
317 }
318
319 450130 static void format_line(void *avcl, int level, const char *fmt, va_list vl,
320 AVBPrint part[5], int *print_prefix, int type[2])
321 {
322
2/2
✓ Branch 0 taken 22724 times.
✓ Branch 1 taken 427406 times.
450130 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
323 450130 av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC);
324 450130 av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC);
325 450130 av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);
326 450130 av_bprint_init(part+3, 0, 65536);
327 450130 av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC);
328
329
1/2
✓ Branch 0 taken 450130 times.
✗ Branch 1 not taken.
450130 if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
330
4/4
✓ Branch 0 taken 231696 times.
✓ Branch 1 taken 218434 times.
✓ Branch 2 taken 22610 times.
✓ Branch 3 taken 209086 times.
450130 if (*print_prefix && avc) {
331
2/2
✓ Branch 0 taken 3489 times.
✓ Branch 1 taken 19121 times.
22610 if (avc->parent_log_context_offset) {
332 3489 AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) +
333 3489 avc->parent_log_context_offset);
334
3/4
✓ Branch 0 taken 986 times.
✓ Branch 1 taken 2503 times.
✓ Branch 2 taken 986 times.
✗ Branch 3 not taken.
3489 if (parent && *parent) {
335 986 av_bprintf(part+0, "[%s @ %p] ",
336 item_name(parent, *parent), parent);
337
1/2
✓ Branch 0 taken 986 times.
✗ Branch 1 not taken.
986 if(type) type[0] = get_category(parent);
338 }
339 }
340 22610 av_bprintf(part+1, "[%s @ %p] ",
341 item_name(avcl, avc), avcl);
342
1/2
✓ Branch 0 taken 22610 times.
✗ Branch 1 not taken.
22610 if(type) type[1] = get_category(avcl);
343 }
344
345
5/6
✓ Branch 0 taken 231696 times.
✓ Branch 1 taken 218434 times.
✓ Branch 2 taken 215221 times.
✓ Branch 3 taken 16475 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 215221 times.
450130 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME)))
346 format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME);
347
348
5/6
✓ Branch 0 taken 231696 times.
✓ Branch 1 taken 218434 times.
✓ Branch 2 taken 215221 times.
✓ Branch 3 taken 16475 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 215221 times.
450130 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))
349 av_bprintf(part+2, "[%s] ", get_level_str(level));
350
351 450130 av_vbprintf(part+3, fmt, vl);
352
353
7/8
✓ Branch 0 taken 449144 times.
✓ Branch 1 taken 986 times.
✓ Branch 2 taken 427520 times.
✓ Branch 3 taken 21624 times.
✓ Branch 4 taken 427520 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 410743 times.
✓ Branch 7 taken 16777 times.
450130 if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
354
2/4
✓ Branch 0 taken 433353 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 433353 times.
✗ Branch 3 not taken.
433353 char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0;
355
4/4
✓ Branch 0 taken 218155 times.
✓ Branch 1 taken 215198 times.
✓ Branch 2 taken 23 times.
✓ Branch 3 taken 218132 times.
433353 *print_prefix = lastc == '\n' || lastc == '\r';
356 }
357 450130 }
358
359 void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
360 char *line, int line_size, int *print_prefix)
361 {
362 av_log_format_line2(ptr, level, fmt, vl, line, line_size, print_prefix);
363 }
364
365 int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
366 char *line, int line_size, int *print_prefix)
367 {
368 AVBPrint part[5];
369 int ret;
370
371 format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
372 ret = snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
373 av_bprint_finalize(part+3, NULL);
374 return ret;
375 }
376
377 16098915 void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
378 {
379 static int print_prefix = 1;
380 static int count;
381 static char prev[LINE_SZ];
382 AVBPrint part[5];
383 char line[LINE_SZ];
384 static int is_atty;
385 int type[2];
386 16098915 unsigned tint = 0;
387
388
2/2
✓ Branch 0 taken 16082440 times.
✓ Branch 1 taken 16475 times.
16098915 if (level >= 0) {
389 16082440 tint = level & 0xff00;
390 16082440 level &= 0xff;
391 }
392
393
2/2
✓ Branch 0 taken 15648785 times.
✓ Branch 1 taken 450130 times.
16098915 if (level > av_log_level)
394 15648785 return;
395 450130 ff_mutex_lock(&mutex);
396
397 450130 format_line(ptr, level, fmt, vl, part, &print_prefix, type);
398 450130 snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
399
400 #if HAVE_ISATTY
401
2/2
✓ Branch 0 taken 8475 times.
✓ Branch 1 taken 441655 times.
450130 if (!is_atty)
402
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 8475 times.
8475 is_atty = isatty(2) ? 1 : -1;
403 #endif
404
405
6/6
✓ Branch 0 taken 231696 times.
✓ Branch 1 taken 218434 times.
✓ Branch 2 taken 228874 times.
✓ Branch 3 taken 2822 times.
✓ Branch 4 taken 2099 times.
✓ Branch 5 taken 226775 times.
450130 if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev) &&
406
2/4
✓ Branch 0 taken 2099 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2099 times.
✗ Branch 3 not taken.
2099 *line && line[strlen(line) - 1] != '\r'){
407 2099 count++;
408
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2099 times.
2099 if (is_atty == 1)
409 fprintf(stderr, " Last message repeated %d times\r", count);
410 2099 goto end;
411 }
412
2/2
✓ Branch 0 taken 382 times.
✓ Branch 1 taken 447649 times.
448031 if (count > 0) {
413 382 fprintf(stderr, " Last message repeated %d times\n", count);
414 382 count = 0;
415 }
416 448031 strcpy(prev, line);
417
418 448031 sanitize(part[4].str);
419 448031 colored_fputs(7, 0, part[4].str);
420 448031 sanitize(part[0].str);
421 448031 colored_fputs(type[0], 0, part[0].str);
422 448031 sanitize(part[1].str);
423 448031 colored_fputs(type[1], 0, part[1].str);
424 448031 sanitize(part[2].str);
425 448031 colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[2].str);
426 448031 sanitize(part[3].str);
427 448031 colored_fputs(av_clip(level >> 3, 0, NB_LEVELS - 1), tint >> 8, part[3].str);
428
429 #if CONFIG_VALGRIND_BACKTRACE
430
2/2
✓ Branch 0 taken 427360 times.
✓ Branch 1 taken 20671 times.
448031 if (level <= BACKTRACE_LOGLEVEL)
431 20671 VALGRIND_PRINTF_BACKTRACE("%s", "");
432 #endif
433 427360 end:
434 450130 av_bprint_finalize(part+3, NULL);
435 450130 ff_mutex_unlock(&mutex);
436 }
437
438 static void (*av_log_callback)(void*, int, const char*, va_list) =
439 av_log_default_callback;
440
441 16099243 void av_log(void* avcl, int level, const char *fmt, ...)
442 {
443 va_list vl;
444 16099243 va_start(vl, fmt);
445 16099243 av_vlog(avcl, level, fmt, vl);
446 16099243 va_end(vl);
447 16099243 }
448
449 39 void av_log_once(void* avcl, int initial_level, int subsequent_level, int *state, const char *fmt, ...)
450 {
451 va_list vl;
452 39 va_start(vl, fmt);
453
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 5 times.
39 av_vlog(avcl, *state ? subsequent_level : initial_level, fmt, vl);
454 39 va_end(vl);
455 39 *state = 1;
456 39 }
457
458 16099436 void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
459 {
460
2/2
✓ Branch 0 taken 14893415 times.
✓ Branch 1 taken 1206021 times.
16099436 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
461 16099436 void (*log_callback)(void*, int, const char*, va_list) = av_log_callback;
462
4/4
✓ Branch 0 taken 14893415 times.
✓ Branch 1 taken 1206021 times.
✓ Branch 2 taken 14893375 times.
✓ Branch 3 taken 40 times.
16099436 if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) &&
463
3/4
✓ Branch 0 taken 406429 times.
✓ Branch 1 taken 14486946 times.
✓ Branch 2 taken 406429 times.
✗ Branch 3 not taken.
14893375 avc->log_level_offset_offset && level >= AV_LOG_FATAL)
464 406429 level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset);
465
2/2
✓ Branch 0 taken 16099433 times.
✓ Branch 1 taken 3 times.
16099436 if (log_callback)
466 16099433 log_callback(avcl, level, fmt, vl);
467 16099436 }
468
469 58360 int av_log_get_level(void)
470 {
471 58360 return av_log_level;
472 }
473
474 3752 void av_log_set_level(int level)
475 {
476 3752 av_log_level = level;
477 3752 }
478
479 8426 void av_log_set_flags(int arg)
480 {
481 8426 flags = arg;
482 8426 }
483
484 64 int av_log_get_flags(void)
485 {
486 64 return flags;
487 }
488
489 86 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
490 {
491 86 av_log_callback = callback;
492 86 }
493
494 14 static void missing_feature_sample(int sample, void *avc, const char *msg,
495 va_list argument_list)
496 {
497 14 av_vlog(avc, AV_LOG_WARNING, msg, argument_list);
498 14 av_log(avc, AV_LOG_WARNING, " is not implemented. Update your FFmpeg "
499 "version to the newest one from Git. If the problem still "
500 "occurs, it means that your file has a feature which has not "
501 "been implemented.\n");
502
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (sample)
503 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
504 "of this file to https://streams.videolan.org/upload/ "
505 "and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)\n");
506 14 }
507
508 void avpriv_request_sample(void *avc, const char *msg, ...)
509 {
510 va_list argument_list;
511
512 va_start(argument_list, msg);
513 missing_feature_sample(1, avc, msg, argument_list);
514 va_end(argument_list);
515 }
516
517 14 void avpriv_report_missing_feature(void *avc, const char *msg, ...)
518 {
519 va_list argument_list;
520
521 14 va_start(argument_list, msg);
522 14 missing_feature_sample(0, avc, msg, argument_list);
523 14 va_end(argument_list);
524 14 }
525