FFmpeg
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 <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;
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 static 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 
65 static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
66 {
67  DefaultContext *def = wctx->priv;
68  char buf[32];
69  const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
70  const AVTextFormatSection *parent_section = tf_get_parent_section(wctx, wctx->level);
71 
72  if (!section)
73  return;
74 
75  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
76  if (parent_section &&
78  def->nested_section[wctx->level] = 1;
79  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
80  wctx->section_pbuf[wctx->level - 1].str,
81  upcase_string(buf, sizeof(buf),
82  av_x_if_null(section->element_name, section->name)));
83  }
84 
85  if (def->noprint_wrappers || def->nested_section[wctx->level])
86  return;
87 
89  writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
90 }
91 
93 {
94  DefaultContext *def = wctx->priv;
95  const AVTextFormatSection *section = tf_get_section(wctx, wctx->level);
96 
97  char buf[32];
98 
99  if (!section)
100  return;
101 
102  if (def->noprint_wrappers || def->nested_section[wctx->level])
103  return;
104 
106  writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
107 }
108 
109 static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
110 {
111  DefaultContext *def = wctx->priv;
112 
113  if (!def->nokey)
114  writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
115  writer_printf(wctx, "%s\n", value);
116 }
117 
118 static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
119 {
120  DefaultContext *def = wctx->priv;
121 
122  if (!def->nokey)
123  writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
124  writer_printf(wctx, "%"PRId64"\n", value);
125 }
126 
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,
135  .priv_class = &default_class,
136 };
flags
const SwsFlags flags[]
Definition: swscale.c:61
opt.h
int64_t
long long int64_t
Definition: coverity.c:34
DefaultContext
Definition: tf_default.c:34
default_print_str
static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
Definition: tf_default.c:109
writer_printf
static void writer_printf(AVTextFormatContext *wctx, const char *fmt,...)
Definition: tf_internal.h:73
AVOption
AVOption.
Definition: opt.h:429
data
const char data[16]
Definition: mxf.c:149
avtextformat.h
AVTextFormatContext
Definition: avtextformat.h:112
DefaultContext::nokey
int nokey
Definition: tf_default.c:36
AVTextFormatContext::level
int level
current level, starting from 0
Definition: avtextformat.h:123
AVTextFormatSection::name
const char * name
Definition: avtextformat.h:43
upcase_string
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition: tf_default.c:55
AVTextFormatSection::flags
int flags
Definition: avtextformat.h:56
AVTextFormatSection::element_name
const char * element_name
name of the contained element, if provided
Definition: avtextformat.h:58
AVTextFormatter
Definition: avtextformat.h:94
AVTextFormatSection
Definition: avtextformat.h:41
limits.h
AVTextFormatContext::priv
void * priv
private data for use by the filter
Definition: avtextformat.h:118
key
const char * key
Definition: hwcontext_opencl.c:189
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
tf_get_parent_section
static const AVTextFormatSection * tf_get_parent_section(AVTextFormatContext *tfc, int level)
Safely access the parent section.
Definition: tf_internal.h:55
OFFSET
#define OFFSET(x)
Definition: tf_default.c:42
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:109
DefaultContext::noprint_wrappers
int noprint_wrappers
Definition: tf_default.c:37
default_print_section_footer
static void default_print_section_footer(AVTextFormatContext *wctx)
Definition: tf_default.c:92
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:127
AVTextFormatter::name
const char * name
Definition: avtextformat.h:97
AVTextFormatContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various formatters
Definition: avtextformat.h:131
tf_internal.h
DEFINE_FORMATTER_CLASS
DEFINE_FORMATTER_CLASS(default)
DefaultContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: tf_default.c:38
bprint.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
default_print_int
static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
Definition: tf_default.c:118
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
av_toupper
static av_const int av_toupper(int c)
Locale-independent conversion of ASCII characters to uppercase.
Definition: avstring.h:227
default_print_section_header
static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
Definition: tf_default.c:65
AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER
#define AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER
the section only contains other sections, but has no data at its own level
Definition: avtextformat.h:45
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:232
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
default_options
static const AVOption default_options[]
Definition: tf_default.c:44
tf_get_section
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
AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
Definition: avtextformat.h:71
AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY
#define AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY
the section contains an array of elements of the same type
Definition: avtextformat.h:46
src
#define src
Definition: vp8dsp.c:248
av_x_if_null
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