FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
31 #define writer_w8(wctx_, b_) (wctx_)->writer->writer->writer_w8((wctx_)->writer, b_)
32 #define writer_put_str(wctx_, str_) (wctx_)->writer->writer->writer_put_str((wctx_)->writer, str_)
33 #define writer_printf(wctx_, fmt_, ...) (wctx_)->writer->writer->writer_printf((wctx_)->writer, fmt_, __VA_ARGS__)
34 
35 #define DEFINE_FORMATTER_CLASS(name) \
36 static const char *name##_get_name(void *ctx) \
37 { \
38  return #name ; \
39 } \
40 static const AVClass name##_class = { \
41  .class_name = #name, \
42  .item_name = name##_get_name, \
43  .option = name##_options \
44 }
45 
46 /* Default output */
47 
48 typedef struct DefaultContext {
49  const AVClass *class;
50  int nokey;
54 
55 #undef OFFSET
56 #define OFFSET(x) offsetof(DefaultContext, x)
57 
58 static const AVOption default_options[] = {
59  { "noprint_wrappers", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
60  { "nw", "do not print headers and footers", OFFSET(noprint_wrappers), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
61  { "nokey", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
62  { "nk", "force no key printing", OFFSET(nokey), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1 },
63  {NULL},
64 };
65 
66 DEFINE_FORMATTER_CLASS(default);
67 
68 /* lame uppercasing routine, assumes the string is lower case ASCII */
69 static inline char *upcase_string(char *dst, size_t dst_size, const char *src)
70 {
71  int i;
72  for (i = 0; src[i] && i < dst_size-1; i++)
73  dst[i] = av_toupper(src[i]);
74  dst[i] = 0;
75  return dst;
76 }
77 
78 static void default_print_section_header(AVTextFormatContext *wctx, const void *data)
79 {
80  DefaultContext *def = wctx->priv;
81  char buf[32];
82  const struct AVTextFormatSection *section = wctx->section[wctx->level];
83  const struct AVTextFormatSection *parent_section = wctx->level ?
84  wctx->section[wctx->level-1] : NULL;
85 
86  av_bprint_clear(&wctx->section_pbuf[wctx->level]);
87  if (parent_section &&
89  def->nested_section[wctx->level] = 1;
90  av_bprintf(&wctx->section_pbuf[wctx->level], "%s%s:",
91  wctx->section_pbuf[wctx->level-1].str,
92  upcase_string(buf, sizeof(buf),
93  av_x_if_null(section->element_name, section->name)));
94  }
95 
96  if (def->noprint_wrappers || def->nested_section[wctx->level])
97  return;
98 
100  writer_printf(wctx, "[%s]\n", upcase_string(buf, sizeof(buf), section->name));
101 }
102 
104 {
105  DefaultContext *def = wctx->priv;
106  const struct AVTextFormatSection *section = wctx->section[wctx->level];
107  char buf[32];
108 
109  if (def->noprint_wrappers || def->nested_section[wctx->level])
110  return;
111 
113  writer_printf(wctx, "[/%s]\n", upcase_string(buf, sizeof(buf), section->name));
114 }
115 
116 static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
117 {
118  DefaultContext *def = wctx->priv;
119 
120  if (!def->nokey)
121  writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
122  writer_printf(wctx, "%s\n", value);
123 }
124 
125 static void default_print_int(AVTextFormatContext *wctx, const char *key, int64_t value)
126 {
127  DefaultContext *def = wctx->priv;
128 
129  if (!def->nokey)
130  writer_printf(wctx, "%s%s=", wctx->section_pbuf[wctx->level].str, key);
131  writer_printf(wctx, "%"PRId64"\n", value);
132 }
133 
135  .name = "default",
136  .priv_size = sizeof(DefaultContext),
137  .print_section_header = default_print_section_header,
138  .print_section_footer = default_print_section_footer,
139  .print_integer = default_print_int,
140  .print_string = default_print_str,
142  .priv_class = &default_class,
143 };
flags
const SwsFlags flags[]
Definition: swscale.c:61
opt.h
AVTextFormatContext::section
const struct AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:106
int64_t
long long int64_t
Definition: coverity.c:34
DefaultContext
Definition: tf_default.c:48
default_print_str
static void default_print_str(AVTextFormatContext *wctx, const char *key, const char *value)
Definition: tf_default.c:116
AVOption
AVOption.
Definition: opt.h:429
data
const char data[16]
Definition: mxf.c:149
avtextformat.h
AVTextFormatContext
Definition: avtextformat.h:88
DefaultContext::nokey
int nokey
Definition: tf_default.c:50
AVTextFormatContext::level
int level
current level, starting from 0
Definition: avtextformat.h:99
AVTextFormatSection::name
const char * name
Definition: avtextformat.h:39
upcase_string
static char * upcase_string(char *dst, size_t dst_size, const char *src)
Definition: tf_default.c:69
AVTextFormatSection::flags
int flags
Definition: avtextformat.h:48
AVTextFormatSection::element_name
const char * element_name
name of the contained element, if provided
Definition: avtextformat.h:50
AVTextFormatter
Definition: avtextformat.h:69
AVTextFormatSection
Definition: avtextformat.h:37
limits.h
AVTextFormatContext::priv
void * priv
private data for use by the filter
Definition: avtextformat.h:94
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
OFFSET
#define OFFSET(x)
Definition: tf_default.c:56
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:85
DefaultContext::noprint_wrappers
int noprint_wrappers
Definition: tf_default.c:51
default_print_section_footer
static void default_print_section_footer(AVTextFormatContext *wctx)
Definition: tf_default.c:103
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:134
AVTextFormatter::name
const char * name
Definition: avtextformat.h:72
AVTextFormatContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various formatters
Definition: avtextformat.h:107
DefaultContext::nested_section
int nested_section[SECTION_MAX_NB_LEVELS]
Definition: tf_default.c:52
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:125
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:78
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:41
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
DEFINE_FORMATTER_CLASS
#define DEFINE_FORMATTER_CLASS(name)
Definition: tf_default.c:35
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:58
AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
Definition: avtextformat.h:59
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:42
src
#define src
Definition: vp8dsp.c:248
writer_printf
#define writer_printf(wctx_, fmt_,...)
Definition: tf_default.c:33
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:312