FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/textformat/tf_default.c
Date: 2026-07-21 08:37:06
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 5 5 100.0%
Branches: 24 28 85.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) The FFmpeg developers
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <inttypes.h>
22 #include <limits.h>
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26
27 #include "avtextformat.h"
28 #include "libavutil/avutil.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/opt.h"
31 #include "tf_internal.h"
32
33 /* Default output */
34
35 typedef struct DefaultContext {
36 const AVClass *class;
37 int nokey;
38 int noprint_wrappers;
39 int nested_section[SECTION_MAX_NB_LEVELS];
40 } DefaultContext;
41
42 #undef OFFSET
43 #define OFFSET(x) offsetof(DefaultContext, x)
44
45 static const AVOption default_options[] = {
46 { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
47 { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
48 { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
49 { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
50 { NULL },
51 };
52
53 DEFINE_FORMATTER_CLASS(default);
54
55 /* lame uppercasing routine, assumes the string is lower case ASCII */
56 6705 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
57 {
58 unsigned i;
59
60
3/4
✓ Branch 0 taken 46206 times.
✓ Branch 1 taken 6705 times.
✓ Branch 2 taken 46206 times.
✗ Branch 3 not taken.
52911 for (i = 0; src[i] && i < dst_size - 1; i++)
61 46206 dst[i] = (char)av_toupper(src[i]);
62 6705 dst[i] = 0;
63 6705 return dst;
64 }
65
66 4528 static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
67 {
68 4528 DefaultContext *def = wctx->priv;
69 char buf[32];
70 4528 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
71 4528 const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
72
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4528 times.
4528 if (!section)
74 1131 return;
75
76 4528 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
77
2/2
✓ Branch 0 taken 4322 times.
✓ Branch 1 taken 206 times.
4528 if (parent_section &&
78
2/2
✓ Branch 0 taken 1107 times.
✓ Branch 1 taken 3215 times.
4322 !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) {
79 1107 def->nested_section[wctx->level] = 1;
80 1107 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
81 1107 wctx->section_pbuf[wctx->level - 1].str,
82 upcase_string(buf, sizeof(buf),
83 1107 av_x_if_null(section->element_name, section->name)));
84 }
85
86
4/4
✓ Branch 0 taken 4504 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1107 times.
✓ Branch 3 taken 3397 times.
4528 if (def->noprint_wrappers || def->nested_section[wctx->level])
87 1131 return;
88
89
2/2
✓ Branch 0 taken 2799 times.
✓ Branch 1 taken 598 times.
3397 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
90 2799 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
91 }
92
93 4528 static void default_print_section_footer(AVTextFormatContext *wctx)
94 {
95 4528 DefaultContext *def = wctx->priv;
96 4528 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
97
98 char buf[32];
99
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4528 times.
4528 if (!section)
101 1131 return;
102
103
4/4
✓ Branch 0 taken 4504 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1107 times.
✓ Branch 3 taken 3397 times.
4528 if (def->noprint_wrappers || def->nested_section[wctx->level])
104 1131 return;
105
106
2/2
✓ Branch 0 taken 2799 times.
✓ Branch 1 taken 598 times.
3397 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
107 2799 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
108 }
109
110 12113 static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
111 {
112 12113 DefaultContext *def = wctx->priv;
113
114
2/2
✓ Branch 0 taken 12076 times.
✓ Branch 1 taken 37 times.
12113 if (!def->nokey)
115 12076 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
116 12113 writer_printf(wctx, "%s\n", value);
117 12113 }
118
119 12211 static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
120 {
121 12211 DefaultContext *def = wctx->priv;
122
123
1/2
✓ Branch 0 taken 12211 times.
✗ Branch 1 not taken.
12211 if (!def->nokey)
124 12211 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
125 12211 writer_printf(wctx, "%"PRId64"\n", value);
126 12211 }
127
128 const AVTextFormatter avtextformatter_default = {
129 .name = "default",
130 .priv_size = sizeof(DefaultContext),
131 .print_section_header = default_print_section_header,
132 .print_section_footer = default_print_section_footer,
133 .print_integer = default_print_int,
134 .print_string = default_print_str,
135 .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS,
136 .priv_class = &default_class,
137 };
138