../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
45 / 45
100.0%
Branches:
27 / 30
90.0%
Functions:
6 / 6
100.0%

fftools/textformat/tf_default.c
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 } DefaultContext;
40
41 #undef OFFSET
42 #define OFFSET(x) offsetof(DefaultContext, x)
43
44 static const AVOption default_options[] = {
45 { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
46 { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
47 { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
48 { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1 },
49 { NULL },
50 };
51
52 DEFINE_FORMATTER_CLASS(default);
53
54 /* lame uppercasing routine, assumes the string is lower case ASCII */
55 7468 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
56 {
57 unsigned i;
58
59
3/4
✓ Branch 4 → 5 taken 51235 times.
✓ Branch 4 → 6 taken 7468 times.
✓ Branch 5 → 3 taken 51235 times.
✗ Branch 5 → 6 not taken.
58703 for (i = 0; src[i] && i < dst_size - 1; i++)
60 51235 dst[i] = (char)av_toupper(src[i]);
61 7468 dst[i] = 0;
62 7468 return dst;
63 }
64
65 9767 static int default_is_nested(AVTextFormatContext *wctx)
66 {
67 9767 const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
68
69
2/2
✓ Branch 3 → 4 taken 9267 times.
✓ Branch 3 → 6 taken 500 times.
19034 return parent_section &&
70
2/2
✓ Branch 4 → 5 taken 2430 times.
✓ Branch 4 → 6 taken 6837 times.
9267 !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY));
71 }
72
73 4932 static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
74 {
75 4932 DefaultContext *def = wctx->priv;
76 char buf[32];
77 4932 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
78 4932 int nested = default_is_nested(wctx);
79
80
1/2
✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 4932 times.
4932 if (!section)
81 1305 return;
82
83 4932 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
84
2/2
✓ Branch 7 → 8 taken 1222 times.
✓ Branch 7 → 11 taken 3710 times.
4932 if (nested)
85 1222 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
86 1222 wctx->section_pbuf[wctx->level - 1].str,
87 upcase_string(buf, sizeof(buf),
88 1222 av_x_if_null(section->element_name, section->name)));
89
90
4/4
✓ Branch 11 → 12 taken 4835 times.
✓ Branch 11 → 13 taken 97 times.
✓ Branch 12 → 13 taken 1208 times.
✓ Branch 12 → 14 taken 3627 times.
4932 if (def->noprint_wrappers || nested)
91 1305 return;
92
93
2/2
✓ Branch 14 → 15 taken 3123 times.
✓ Branch 14 → 17 taken 504 times.
3627 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
94 3123 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
95 }
96
97 4932 static void default_print_section_footer(AVTextFormatContext *wctx)
98 {
99 4932 DefaultContext *def = wctx->priv;
100 4932 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
101
102 char buf[32];
103
104
1/2
✗ Branch 3 → 4 not taken.
✓ Branch 3 → 5 taken 4932 times.
4932 if (!section)
105 1305 return;
106
107
4/4
✓ Branch 5 → 6 taken 4835 times.
✓ Branch 5 → 8 taken 97 times.
✓ Branch 7 → 8 taken 1208 times.
✓ Branch 7 → 9 taken 3627 times.
4932 if (def->noprint_wrappers || default_is_nested(wctx))
108 1305 return;
109
110
2/2
✓ Branch 9 → 10 taken 3123 times.
✓ Branch 9 → 12 taken 504 times.
3627 if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY)))
111 3123 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
112 }
113
114 12738 static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
115 {
116 12738 DefaultContext *def = wctx->priv;
117
118
2/2
✓ Branch 2 → 3 taken 12697 times.
✓ Branch 2 → 4 taken 41 times.
12738 if (!def->nokey)
119 12697 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
120 12738 writer_printf(wctx, "%s\n", value);
121 12738 }
122
123 12740 static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
124 {
125 12740 DefaultContext *def = wctx->priv;
126
127
2/2
✓ Branch 2 → 3 taken 12738 times.
✓ Branch 2 → 4 taken 2 times.
12740 if (!def->nokey)
128 12738 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
129 12740 writer_printf(wctx, "%"PRId64"\n", value);
130 12740 }
131
132 const AVTextFormatter avtextformatter_default = {
133 .name = "default",
134 .priv_size = sizeof(DefaultContext),
135 .print_section_header = default_print_section_header,
136 .print_section_footer = default_print_section_footer,
137 .print_integer = default_print_int,
138 .print_string = default_print_str,
139 .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS,
140 .priv_class = &default_class,
141 };
142