| 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 | |||
| 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 | /* INI format output */ | ||
| 43 | |||
| 44 | typedef struct INIContext { | ||
| 45 | const AVClass *class; | ||
| 46 | int hierarchical; | ||
| 47 | } INIContext; | ||
| 48 | |||
| 49 | #undef OFFSET | ||
| 50 | #define OFFSET(x) offsetof(INIContext, x) | ||
| 51 | |||
| 52 | static const AVOption ini_options[] = { | ||
| 53 | { "hierarchical", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 }, | ||
| 54 | { "h", "specify if the section specification should be hierarchical", OFFSET(hierarchical), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1 }, | ||
| 55 | { NULL }, | ||
| 56 | }; | ||
| 57 | |||
| 58 | DEFINE_FORMATTER_CLASS(ini); | ||
| 59 | |||
| 60 | 740 | static char *ini_escape_str(AVBPrint *dst, const char *src) | |
| 61 | { | ||
| 62 | 740 | int i = 0; | |
| 63 | char c; | ||
| 64 | |||
| 65 |
2/2✓ Branch 0 taken 6309 times.
✓ Branch 1 taken 740 times.
|
7049 | while ((c = src[i++])) { |
| 66 |
2/7✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
✓ Branch 6 taken 6295 times.
|
6309 | switch (c) { |
| 67 | ✗ | case '\b': av_bprintf(dst, "%s", "\\b"); break; | |
| 68 | ✗ | case '\f': av_bprintf(dst, "%s", "\\f"); break; | |
| 69 | ✗ | case '\n': av_bprintf(dst, "%s", "\\n"); break; | |
| 70 | ✗ | case '\r': av_bprintf(dst, "%s", "\\r"); break; | |
| 71 | ✗ | case '\t': av_bprintf(dst, "%s", "\\t"); break; | |
| 72 | 14 | case '\\': | |
| 73 | case '#': | ||
| 74 | case '=': | ||
| 75 | case ':': | ||
| 76 | 14 | av_bprint_chars(dst, '\\', 1); | |
| 77 | /* fallthrough */ | ||
| 78 | 6309 | default: | |
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6309 times.
|
6309 | if ((unsigned char)c < 32) |
| 80 | ✗ | av_bprintf(dst, "\\x00%02x", (unsigned char)c); | |
| 81 | else | ||
| 82 | 6309 | av_bprint_chars(dst, c, 1); | |
| 83 | 6309 | break; | |
| 84 | } | ||
| 85 | } | ||
| 86 | 740 | return dst->str; | |
| 87 | } | ||
| 88 | |||
| 89 | 42 | static void ini_print_section_header(AVTextFormatContext *wctx, const void *data) | |
| 90 | { | ||
| 91 | 42 | INIContext *ini = wctx->priv; | |
| 92 | 42 | AVBPrint *buf = &wctx->section_pbuf[wctx->level]; | |
| 93 | 42 | const AVTextFormatSection *section = tf_get_section(wctx, wctx->level); | |
| 94 | 42 | const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level); | |
| 95 | |||
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (!section) |
| 97 | ✗ | return; | |
| 98 | |||
| 99 | 42 | av_bprint_clear(buf); | |
| 100 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 41 times.
|
42 | if (!parent_section) { |
| 101 | 1 | writer_put_str(wctx, "# ffprobe output\n\n"); | |
| 102 | 1 | return; | |
| 103 | } | ||
| 104 | |||
| 105 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3 times.
|
41 | if (wctx->nb_item[wctx->level - 1]) |
| 106 | 38 | writer_w8(wctx, '\n'); | |
| 107 | |||
| 108 | 41 | av_bprintf(buf, "%s", wctx->section_pbuf[wctx->level - 1].str); | |
| 109 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if (ini->hierarchical || |
| 110 | ✗ | !(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) { | |
| 111 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 3 times.
|
41 | av_bprintf(buf, "%s%s", buf->str[0] ? "." : "", wctx->section[wctx->level]->name); |
| 112 | |||
| 113 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 10 times.
|
41 | if (parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY) { |
| 114 | 62 | unsigned n = parent_section->flags & AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE | |
| 115 | 28 | ? wctx->nb_item_type[wctx->level - 1][section->id] | |
| 116 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 3 times.
|
31 | : wctx->nb_item[wctx->level - 1]; |
| 117 | 31 | av_bprintf(buf, ".%u", n); | |
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 2 times.
|
41 | if (!(section->flags & (AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY | AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER))) |
| 122 | 39 | writer_printf(wctx, "[%s]\n", buf->str); | |
| 123 | } | ||
| 124 | |||
| 125 | 370 | static void ini_print_str(AVTextFormatContext *wctx, const char *key, const char *value) | |
| 126 | { | ||
| 127 | AVBPrint buf; | ||
| 128 | |||
| 129 | 370 | av_bprint_init(&buf, 1, AV_BPRINT_SIZE_UNLIMITED); | |
| 130 | 370 | writer_printf(wctx, "%s=", ini_escape_str(&buf, key)); | |
| 131 | 370 | av_bprint_clear(&buf); | |
| 132 | 370 | writer_printf(wctx, "%s\n", ini_escape_str(&buf, value)); | |
| 133 | 370 | av_bprint_finalize(&buf, NULL); | |
| 134 | 370 | } | |
| 135 | |||
| 136 | 316 | static void ini_print_int(AVTextFormatContext *wctx, const char *key, int64_t value) | |
| 137 | { | ||
| 138 | 316 | writer_printf(wctx, "%s=%"PRId64"\n", key, value); | |
| 139 | 316 | } | |
| 140 | |||
| 141 | const AVTextFormatter avtextformatter_ini = { | ||
| 142 | .name = "ini", | ||
| 143 | .priv_size = sizeof(INIContext), | ||
| 144 | .print_section_header = ini_print_section_header, | ||
| 145 | .print_integer = ini_print_int, | ||
| 146 | .print_string = ini_print_str, | ||
| 147 | .flags = AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS | AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT, | ||
| 148 | .priv_class = &ini_class, | ||
| 149 | }; | ||
| 150 |