FFmpeg
Loading...
Searching...
No Matches
tf_default.c
Go to the documentation of this file.
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
41
42#undef OFFSET
43#define OFFSET(x) offsetof(DefaultContext, x)
44
45static 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
54
55/* lame uppercasing routine, assumes the string is lower case ASCII */
56static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
57{
58 unsigned i;
59
60 for (i = 0; src[i] && i < dst_size - 1; i++)
61 dst[i] = (char)av_toupper(src[i]);
62 dst[i] = 0;
63 return dst;
64}
65
67{
68 DefaultContext *def = wctx->priv;
69 char buf[32];
70 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
71 const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
72
73 if (!section)
74 return;
75
76 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
77 if (parent_section &&
79 def->nested_section[wctx->level] = 1;
80 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
81 wctx->section_pbuf[wctx->level - 1].str,
82 upcase_string(buf, sizeof(buf),
83 av_x_if_null(section->element_name, section->name)));
84 }
85
86 if (def->noprint_wrappers || def->nested_section[wctx->level])
87 return;
88
90 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
91}
92
94{
95 DefaultContext *def = wctx->priv;
96 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
97
98 char buf[32];
99
100 if (!section)
101 return;
102
103 if (def->noprint_wrappers || def->nested_section[wctx->level])
104 return;
105
107 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
108}
109
110static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
111{
112 DefaultContext *def = wctx->priv;
113
114 if (!def->nokey)
115 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
116 writer_printf(wctx, "%s\n", value);
117}
118
119static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
120{
121 DefaultContext *def = wctx->priv;
122
123 if (!def->nokey)
124 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
125 writer_printf(wctx, "%"PRId64"\n", value);
126}
127
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,
136 .priv_class = &default_class,
137};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define SECTION_MAX_NB_LEVELS
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
#define AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
const AVTextFormatter avtextformatter_default
Definition tf_default.c:128
#define AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Convenience header that includes libavutil's core.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition bprint.c:122
AVBPrint public header.
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
double value
Definition eval.c:102
const char * key
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition graphprint.c:161
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition bprint.c:227
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition avutil.h:311
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition avstring.h:227
const char data[16]
Definition mxf.c:149
AVOptions.
Describe the class of an AVClass context structure.
Definition log.h:76
AVOption.
Definition opt.h:428
void * priv
private data for use by the filter
int level
current level, starting from 0
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various formatters
const char * element_name
name of the contained element, if provided
const char * name
int nested_section[SECTION_MAX_NB_LEVELS]
Definition tf_default.c:39
#define src
Definition vp8dsp.c:248
static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
Definition tf_default.c:110
static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
Definition tf_default.c:119
static const AVOption default_options[]
Definition tf_default.c:45
static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
Definition tf_default.c:66
static void default_print_section_footer(AVTextFormatContext *wctx)
Definition tf_default.c:93
#define OFFSET(x)
Definition tf_default.c:43
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition tf_default.c:56
Internal utilities for text formatters.
static const AVTextFormatSection * tf_get_section(AVTextFormatContext *tfc, int level)
Safely validate and access a section at a given level.
Definition tf_internal.h:42
static const AVTextFormatSection * tf_get_parent_section(AVTextFormatContext *tfc, int level)
Safely access the parent section.
Definition tf_internal.h:55
#define DEFINE_FORMATTER_CLASS(name)
Definition tf_internal.h:31
static void writer_printf(AVTextFormatContext *wctx, const char *fmt,...)
Definition tf_internal.h:73