FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/fftools/textformat/tf_default.c
Date: 2026-08-26 01:27:24
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 6729 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 46360 times.
✓ Branch 1 taken 6729 times.
✓ Branch 2 taken 46360 times.
✗ Branch 3 not taken.
53089 for (i = 0; src[i] && i < dst_size - 1; i++)
61 46360 dst[i] = (char)av_toupper(src[i]);
62 6729 dst[i] = 0;
63 6729 return dst;
64 }
65
66 4572 static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
67 {
68 4572 DefaultContext *def = wctx->priv;
69 char buf[32];
70 4572 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
71 4572 const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
72
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4572 times.
4572 if (!section)
74 1133 return;
75
76 4572 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
77
2/2
✓ Branch 0 taken 4357 times.
✓ Branch 1 taken 215 times.
4572 if (parent_section &&
78
2/2
✓ Branch 0 taken 1109 times.
✓ Branch 1 taken 3248 times.
4357 !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) {
79 1109 def->nested_section[wctx->level] = 1;
80 1109 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
81 1109 wctx->section_pbuf[wctx->level - 1].str,
82 upcase_string(buf, sizeof(buf),
83 1109 av_x_if_null(section->element_name, section->name)));
84 }
85
86
4/4
✓ Branch 0 taken 4548 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1109 times.
✓ Branch 3 taken 3439 times.
4572 if (def->noprint_wrappers || def->nested_section[wctx->level])
87 1133 return;
88
89
2/2
✓ Branch 0 taken 2810 times.
✓ Branch 1 taken 629 times.
3439 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
90 2810 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
91 }
92
93 4572 static void default_print_section_footer(AVTextFormatContext *wctx)
94 {
95 4572 DefaultContext *def = wctx->priv;
96 4572 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 4572 times.
4572 if (!section)
101 1133 return;
102
103
4/4
✓ Branch 0 taken 4548 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 1109 times.
✓ Branch 3 taken 3439 times.
4572 if (def->noprint_wrappers || def->nested_section[wctx->level])
104 1133 return;
105
106
2/2
✓ Branch 0 taken 2810 times.
✓ Branch 1 taken 629 times.
3439 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
107 2810 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
108 }
109
110 12152 static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
111 {
112 12152 DefaultContext *def = wctx->priv;
113
114
2/2
✓ Branch 0 taken 12115 times.
✓ Branch 1 taken 37 times.
12152 if (!def->nokey)
115 12115 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
116 12152 writer_printf(wctx, "%s\n", value);
117 12152 }
118
119 12217 static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
120 {
121 12217 DefaultContext *def = wctx->priv;
122
123
1/2
✓ Branch 0 taken 12217 times.
✗ Branch 1 not taken.
12217 if (!def->nokey)
124 12217 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
125 12217 writer_printf(wctx, "%"PRId64"\n", value);
126 12217 }
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