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
35typedef struct DefaultContext {
36 const AVClass *class;
37 int nokey;
40
41#undef OFFSET
42#define OFFSET(x) offsetof(DefaultContext, x)
43
44static 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
53
54/* lame uppercasing routine, assumes the string is lower case ASCII */
55static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
56{
57 unsigned i;
58
59 for (i = 0; src[i] && i < dst_size - 1; i++)
60 dst[i] = (char)av_toupper(src[i]);
61 dst[i] = 0;
62 return dst;
63}
64
66{
67 const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
68
69 return parent_section &&
71}
72
74{
75 DefaultContext *def = wctx->priv;
76 char buf[32];
77 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
78 int nested = default_is_nested(wctx);
79
80 if (!section)
81 return;
82
83 av_bprint_clear(&wctx->section_pbuf[wctx->level]);
84 if (nested)
85 av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
86 wctx->section_pbuf[wctx->level - 1].str,
87 upcase_string(buf, sizeof(buf),
88 av_x_if_null(section->element_name, section->name)));
89
90 if (def->noprint_wrappers || nested)
91 return;
92
94 writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
95}
96
98{
99 DefaultContext *def = wctx->priv;
100 const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
101
102 char buf[32];
103
104 if (!section)
105 return;
106
107 if (def->noprint_wrappers || default_is_nested(wctx))
108 return;
109
111 writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
112}
113
114static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
115{
116 DefaultContext *def = wctx->priv;
117
118 if (!def->nokey)
119 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
120 writer_printf(wctx, "%s\n", value);
121}
122
123static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
124{
125 DefaultContext *def = wctx->priv;
126
127 if (!def->nokey)
128 writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
129 writer_printf(wctx, "%"PRId64"\n", value);
130}
131
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,
140 .priv_class = &default_class,
141};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
#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:132
#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:121
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:356
@ 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:226
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
#define src
Definition vp8dsp.c:248
static int default_is_nested(AVTextFormatContext *wctx)
Definition tf_default.c:65
static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
Definition tf_default.c:114
static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
Definition tf_default.c:123
static const AVOption default_options[]
Definition tf_default.c:44
static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
Definition tf_default.c:73
static void default_print_section_footer(AVTextFormatContext *wctx)
Definition tf_default.c:97
#define OFFSET(x)
Definition tf_default.c:42
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition tf_default.c:55
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