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 <limits.h> | ||
22 | #include <stdarg.h> | ||
23 | #include <stdint.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "avtextformat.h" | ||
28 | #include "libavutil/bprint.h" | ||
29 | #include "libavutil/opt.h" | ||
30 | #include "tf_internal.h" | ||
31 | |||
32 | /* Default output */ | ||
33 | |||
34 | typedef struct DefaultContext { | ||
35 | const AVClass *class; | ||
36 | int nokey; | ||
37 | int noprint_wrappers; | ||
38 | int nested_section[SECTION_MAX_NB_LEVELS]; | ||
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 | 4744 | static inline char *upcase_string(char *dst, size_t dst_size, const char *src) | |
56 | { | ||
57 | unsigned i; | ||
58 | |||
59 |
3/4✓ Branch 0 taken 33318 times.
✓ Branch 1 taken 4744 times.
✓ Branch 2 taken 33318 times.
✗ Branch 3 not taken.
|
38062 | for (i = 0; src[i] && i < dst_size - 1; i++) |
60 | 33318 | dst[i] = (char)av_toupper(src[i]); | |
61 | 4744 | dst[i] = 0; | |
62 | 4744 | return dst; | |
63 | } | ||
64 | |||
65 | 3114 | static void default_print_section_header(AVTextFormatContext *wctx, const void *data) | |
66 | { | ||
67 | 3114 | DefaultContext *def = wctx->priv; | |
68 | char buf[32]; | ||
69 | 3114 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | |
70 | 3114 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); | |
71 | |||
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3114 times.
|
3114 | if (!section) |
73 | 868 | return; | |
74 | |||
75 | 3114 | av_bprint_clear(&wctx->section_pbuf[wctx->level]); | |
76 |
2/2✓ Branch 0 taken 3004 times.
✓ Branch 1 taken 110 times.
|
3114 | if (parent_section && |
77 |
2/2✓ Branch 0 taken 850 times.
✓ Branch 1 taken 2154 times.
|
3004 | !(parent_section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) { |
78 | 850 | def->nested_section[wctx->level] = 1; | |
79 | 850 | av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:", | |
80 | 850 | wctx->section_pbuf[wctx->level - 1].str, | |
81 | upcase_string(buf, sizeof(buf), | ||
82 | 850 | av_x_if_null(section->element_name, section->name))); | |
83 | } | ||
84 | |||
85 |
4/4✓ Branch 0 taken 3096 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 850 times.
✓ Branch 3 taken 2246 times.
|
3114 | if (def->noprint_wrappers || def->nested_section[wctx->level]) |
86 | 868 | return; | |
87 | |||
88 |
2/2✓ Branch 0 taken 1947 times.
✓ Branch 1 taken 299 times.
|
2246 | if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) |
89 | 1947 | writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name)); | |
90 | } | ||
91 | |||
92 | 3114 | static void default_print_section_footer(AVTextFormatContext *wctx) | |
93 | { | ||
94 | 3114 | DefaultContext *def = wctx->priv; | |
95 | 3114 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | |
96 | |||
97 | char buf[32]; | ||
98 | |||
99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3114 times.
|
3114 | if (!section) |
100 | 868 | return; | |
101 | |||
102 |
4/4✓ Branch 0 taken 3096 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 850 times.
✓ Branch 3 taken 2246 times.
|
3114 | if (def->noprint_wrappers || def->nested_section[wctx->level]) |
103 | 868 | return; | |
104 | |||
105 |
2/2✓ Branch 0 taken 1947 times.
✓ Branch 1 taken 299 times.
|
2246 | if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER | AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY))) |
106 | 1947 | writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name)); | |
107 | } | ||
108 | |||
109 | 8861 | static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value) | |
110 | { | ||
111 | 8861 | DefaultContext *def = wctx->priv; | |
112 | |||
113 |
2/2✓ Branch 0 taken 8855 times.
✓ Branch 1 taken 6 times.
|
8861 | if (!def->nokey) |
114 | 8855 | writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); | |
115 | 8861 | writer_printf(wctx, "%s\n", value); | |
116 | 8861 | } | |
117 | |||
118 | 8941 | static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) | |
119 | { | ||
120 | 8941 | DefaultContext *def = wctx->priv; | |
121 | |||
122 |
1/2✓ Branch 0 taken 8941 times.
✗ Branch 1 not taken.
|
8941 | if (!def->nokey) |
123 | 8941 | writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key); | |
124 | 8941 | writer_printf(wctx, "%"PRId64"\n", value); | |
125 | 8941 | } | |
126 | |||
127 | const AVTextFormatter avtextformatter_default = { | ||
128 | .name = "default", | ||
129 | .priv_size = sizeof(DefaultContext), | ||
130 | .print_section_header = default_print_section_header, | ||
131 | .print_section_footer = default_print_section_footer, | ||
132 | .print_integer = default_print_int, | ||
133 | .print_string = default_print_str, | ||
134 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS, | ||
135 | .priv_class = &default_class, | ||
136 | }; | ||
137 |