FFmpeg
avtextformat.h
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 #ifndef FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H
22 #define FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H
23 
24 #include <stdint.h>
25 #include "libavutil/dict.h"
26 #include "libavformat/avio.h"
27 #include "libavutil/bprint.h"
28 #include "libavutil/rational.h"
29 #include "libavutil/hash.h"
30 #include "avtextwriters.h"
31 
32 #define SECTION_MAX_NB_CHILDREN 11
33 
35  char *context_id;
36  const char *context_type;
39 
40 
41 typedef struct AVTextFormatSection {
42  int id; ///< unique id identifying a section
43  const char *name;
44 
45 #define AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
46 #define AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
47 #define AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
48  /// For these sections the element_name field is mandatory.
49 #define AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE 8 ///< the section contains a type to distinguish multiple nested elements
50 #define AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type
51 #define AV_TEXTFORMAT_SECTION_FLAG_IS_SHAPE 32 ///< ...
52 #define AV_TEXTFORMAT_SECTION_FLAG_HAS_LINKS 64 ///< ...
53 #define AV_TEXTFORMAT_SECTION_PRINT_TAGS 128 ///< ...
54 #define AV_TEXTFORMAT_SECTION_FLAG_IS_SUBGRAPH 256 ///< ...
55 
56  int flags;
57  const int children_ids[SECTION_MAX_NB_CHILDREN + 1]; ///< list of children section IDS, terminated by -1
58  const char *element_name; ///< name of the contained element, if provided
59  const char *unique_name; ///< unique section name, in case the name is ambiguous
60  const char *(*get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
61  const char *id_key; ///< name of the key to be used as the id
62  const char *src_id_key; ///< name of the key to be used as the source id for diagram connections
63  const char *dest_id_key; ///< name of the key to be used as the target id for diagram connections
64  const char *linktype_key; ///< name of the key to be used as the link type for diagram connections (AVTextFormatLinkType)
66 
68 
69 #define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS 1
70 #define AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT 2
71 #define AV_TEXTFORMAT_FLAG_IS_DIAGRAM_FORMATTER 4
72 
73 typedef enum {
79 
80 typedef enum {
91 
92 typedef enum {
96 
97 typedef struct AVTextFormatter {
98  const AVClass *priv_class; ///< private class of the formatter, if any
99  int priv_size; ///< private size for the formatter context
100  const char *name;
101 
102  int (*init) (AVTextFormatContext *tctx);
104 
105  void (*print_section_header)(AVTextFormatContext *tctx, const void *data);
107  void (*print_integer) (AVTextFormatContext *tctx, const char *, int64_t);
108  void (*print_string) (AVTextFormatContext *tctx, const char *, const char *);
109  int flags; ///< a combination or AV_TEXTFORMAT__FLAG_*
111 
112 #define SECTION_MAX_NB_LEVELS 12
113 #define SECTION_MAX_NB_SECTIONS 100
114 
115 typedef struct AVTextFormatOptions {
116  /**
117  * Callback to discard certain elements based upon the key used.
118  * It is called before any element with a key is printed.
119  * If this callback is unset, all elements are printed.
120  *
121  * @retval 1 if the element is supposed to be printed
122  * @retval 0 if the element is supposed to be discarded
123  */
124  int (*is_key_selected)(struct AVTextFormatContext *tctx, const char *key);
132 
134  const AVClass *class; ///< class of the formatter
135  const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance
136  AVTextWriterContext *writer; ///< the AVTextWriterContext
137 
138  char *name; ///< name of this formatter instance
139  void *priv; ///< private data for use by the filter
140 
141  const AVTextFormatSection *sections; ///< array containing all sections
142  int nb_sections; ///< number of sections
143 
144  int level; ///< current level, starting from 0
145 
146  /** number of the item printed in the given section, starting from 0 */
149 
150  /** section per each level */
152  AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
153  /// used by various formatters
154 
156 
158 
162 };
163 
164 #define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
165 #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
166 
167 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
168  const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash);
169 
171 
172 
173 void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id);
174 
176 
177 void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val, int flags);
178 
179 int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags);
180 
181 void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, const char *unit);
182 
183 void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep);
184 
185 void avtext_print_time(AVTextFormatContext *tctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration);
186 
187 void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration);
188 
189 void avtext_print_data(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size);
190 
191 void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size);
192 
194 
204 
205 #endif /* FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H */
flags
const SwsFlags flags[]
Definition: swscale.c:61
AVTextFormatOptions::use_value_prefix
int use_value_prefix
Definition: avtextformat.h:127
name
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 minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AV_TEXTFORMAT_LINKTYPE_SRCDEST
@ AV_TEXTFORMAT_LINKTYPE_SRCDEST
Definition: avtextformat.h:81
AVTextFormatContext::opts
AVTextFormatOptions opts
Definition: avtextformat.h:155
AV_TEXTFORMAT_LINKTYPE_DESTSRC
@ AV_TEXTFORMAT_LINKTYPE_DESTSRC
Definition: avtextformat.h:82
AVTextFormatContext::nb_item_type
unsigned int nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS]
Definition: avtextformat.h:148
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
AVTextFormatSection::src_id_key
const char * src_id_key
name of the key to be used as the source id for diagram connections
Definition: avtextformat.h:62
AVTextFormatSectionContext::context_type
const char * context_type
Definition: avtextformat.h:36
avtextformatter_compact
const AVTextFormatter avtextformatter_compact
Definition: tf_compact.c:239
AV_TEXTFORMAT_STRING_VALIDATION_NB
@ AV_TEXTFORMAT_STRING_VALIDATION_NB
Definition: avtextformat.h:77
data
const char data[16]
Definition: mxf.c:149
AVTextFormatContext::name
char * name
name of this formatter instance
Definition: avtextformat.h:138
AVTextWriterContext
Definition: avtextwriters.h:42
AVTextFormatContext
Definition: avtextformat.h:133
AV_TEXTFORMAT_LINKTYPE_ONETOMANY
@ AV_TEXTFORMAT_LINKTYPE_ONETOMANY
Definition: avtextformat.h:86
avtext_print_section_footer
void avtext_print_section_footer(AVTextFormatContext *tctx)
Definition: avtextformat.c:266
AVTextFormatDataDump
AVTextFormatDataDump
Definition: avtextformat.h:92
AVTextFormatSection::id
int id
unique id identifying a section
Definition: avtextformat.h:42
avtextformatter_mermaid
const AVTextFormatter avtextformatter_mermaid
Definition: tf_mermaid.c:651
AV_TEXTFORMAT_LINKTYPE_BIDIR
@ AV_TEXTFORMAT_LINKTYPE_BIDIR
Definition: avtextformat.h:83
AVTextFormatContext::level
int level
current level, starting from 0
Definition: avtextformat.h:144
AVTextFormatSection::name
const char * name
Definition: avtextformat.h:43
AVTextFormatLinkType
AVTextFormatLinkType
Definition: avtextformat.h:80
AV_TEXTFORMAT_LINKTYPE_MANYTOONE
@ AV_TEXTFORMAT_LINKTYPE_MANYTOONE
Definition: avtextformat.h:87
AV_TEXTFORMAT_DATADUMP_BASE64
@ AV_TEXTFORMAT_DATADUMP_BASE64
Definition: avtextformat.h:94
val
static double val(void *priv, double ch)
Definition: aeval.c:77
avtext_get_formatter_by_name
const AVTextFormatter * avtext_get_formatter_by_name(const char *name)
Definition: avtextformat.c:684
AVTextFormatSectionContext
Definition: avtextformat.h:34
AVTextFormatContext::writer
AVTextWriterContext * writer
the AVTextWriterContext
Definition: avtextformat.h:136
AVTextFormatOptions::data_dump_format
AVTextFormatDataDump data_dump_format
Definition: avtextformat.h:130
avtext_context_close
int avtext_context_close(AVTextFormatContext **tctx)
Definition: avtextformat.c:102
AVTextFormatSection::flags
int flags
Definition: avtextformat.h:56
AVTextFormatOptions::is_key_selected
int(* is_key_selected)(struct AVTextFormatContext *tctx, const char *key)
Callback to discard certain elements based upon the key used.
Definition: avtextformat.h:124
SECTION_MAX_NB_CHILDREN
#define SECTION_MAX_NB_CHILDREN
Definition: avtextformat.h:32
AVTextFormatSection::element_name
const char * element_name
name of the contained element, if provided
Definition: avtextformat.h:58
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:127
AVTextFormatter::print_string
void(* print_string)(AVTextFormatContext *tctx, const char *, const char *)
Definition: avtextformat.h:108
AVTextFormatter
Definition: avtextformat.h:97
SECTION_MAX_NB_SECTIONS
#define SECTION_MAX_NB_SECTIONS
Definition: avtextformat.h:113
AVTextFormatSection
Definition: avtextformat.h:41
avtextformatter_ini
const AVTextFormatter avtextformatter_ini
Definition: tf_ini.c:141
AV_TEXTFORMAT_DATADUMP_XXD
@ AV_TEXTFORMAT_DATADUMP_XXD
Definition: avtextformat.h:93
AVTextFormatContext::priv
void * priv
private data for use by the filter
Definition: avtextformat.h:139
avtext_print_section_header
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
Definition: avtextformat.c:248
key
const char * key
Definition: hwcontext_opencl.c:189
avtext_print_time
void avtext_print_time(AVTextFormatContext *tctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
Definition: avtextformat.c:488
AVTextFormatter::priv_size
int priv_size
private size for the formatter context
Definition: avtextformat.h:99
avtext_print_rational
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
Definition: avtextformat.c:481
AVTextFormatSection::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition: avtextformat.h:59
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
AVTextFormatContext::section
const AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:151
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_TEXTFORMAT_LINKTYPE_MANYTOMANY
@ AV_TEXTFORMAT_LINKTYPE_MANYTOMANY
Definition: avtextformat.h:89
StringValidation
StringValidation
Definition: avtextformat.h:73
options
Definition: swscale.c:43
AVTextFormatter::print_section_header
void(* print_section_header)(AVTextFormatContext *tctx, const void *data)
Definition: avtextformat.h:105
AV_TEXTFORMAT_STRING_VALIDATION_IGNORE
@ AV_TEXTFORMAT_STRING_VALIDATION_IGNORE
Definition: avtextformat.h:76
AVTextFormatContext::formatter
const AVTextFormatter * formatter
the AVTextFormatter of which this is an instance
Definition: avtextformat.h:135
avtext_print_integer
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val, int flags)
Definition: avtextformat.c:287
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:112
avtext_print_data
void avtext_print_data(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
Definition: avtextformat.c:549
avtextformatter_flat
const AVTextFormatter avtextformatter_flat
Definition: tf_flat.c:151
AV_TEXTFORMAT_STRING_VALIDATION_FAIL
@ AV_TEXTFORMAT_STRING_VALIDATION_FAIL
Definition: avtextformat.h:74
AVTextFormatter::name
const char * name
Definition: avtextformat.h:100
size
int size
Definition: twinvq_data.h:10344
avio.h
AVTextFormatContext::section_pbuf
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various formatters
Definition: avtextformat.h:152
avtext_context_open
int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args, const AVTextFormatSection *sections, int nb_sections, AVTextFormatOptions options, char *show_data_hash)
Definition: avtextformat.c:127
avtext_print_ts
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
Definition: avtextformat.c:504
AVTextFormatter::flags
int flags
a combination or AV_TEXTFORMAT__FLAG_*
Definition: avtextformat.h:109
AVHashContext
Definition: hash.c:66
AVTextFormatSection::linktype_key
const char * linktype_key
name of the key to be used as the link type for diagram connections (AVTextFormatLinkType)
Definition: avtextformat.h:64
AVTextFormatContext::sections
const AVTextFormatSection * sections
array containing all sections
Definition: avtextformat.h:141
avtext_print_string
int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
Definition: avtextformat.c:439
bprint.h
AVTextFormatSectionContext::context_id
char * context_id
Definition: avtextformat.h:35
avtextformatter_xml
const AVTextFormatter avtextformatter_xml
Definition: tf_xml.c:202
AVTextFormatSectionContext::context_flags
int context_flags
Definition: avtextformat.h:37
AVTextFormatter::uninit
int(* uninit)(AVTextFormatContext *tctx)
Definition: avtextformat.h:103
AVTextFormatContext::string_validation_utf8_flags
unsigned int string_validation_utf8_flags
Definition: avtextformat.h:161
AV_TEXTFORMAT_LINKTYPE_ONETOONE
@ AV_TEXTFORMAT_LINKTYPE_ONETOONE
Definition: avtextformat.h:88
avtextformatter_json
const AVTextFormatter avtextformatter_json
Definition: tf_json.c:203
AVTextFormatter::print_section_footer
void(* print_section_footer)(AVTextFormatContext *tctx)
Definition: avtextformat.h:106
AVTextFormatOptions::use_value_sexagesimal_format
int use_value_sexagesimal_format
Definition: avtextformat.h:129
avtext_print_data_hash
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
Definition: avtextformat.c:568
AVTextFormatSection::dest_id_key
const char * dest_id_key
name of the key to be used as the target id for diagram connections
Definition: avtextformat.h:63
dict.h
hash.h
AVTextFormatter::priv_class
const AVClass * priv_class
private class of the formatter, if any
Definition: avtextformat.h:98
AVTextFormatter::print_integer
void(* print_integer)(AVTextFormatContext *tctx, const char *, int64_t)
Definition: avtextformat.h:107
AVTextFormatSection::children_ids
const int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition: avtextformat.h:57
AV_TEXTFORMAT_LINKTYPE_HIDDEN
@ AV_TEXTFORMAT_LINKTYPE_HIDDEN
Definition: avtextformat.h:85
AVTextFormatOptions::show_optional_fields
int show_optional_fields
Definition: avtextformat.h:125
AVTextFormatContext::string_validation
int string_validation
Definition: avtextformat.h:159
AVTextFormatOptions
Definition: avtextformat.h:115
sections
static const AVTextFormatSection sections[]
Definition: ffprobe.c:256
AVTextFormatter::init
int(* init)(AVTextFormatContext *tctx)
Definition: avtextformat.h:102
avtextwriters.h
AVTextFormatOptions::show_value_unit
int show_value_unit
Definition: avtextformat.h:126
avtextformatter_csv
const AVTextFormatter avtextformatter_csv
Definition: tf_compact.c:270
AVTextFormatSection::id_key
const char * id_key
name of the key to be used as the id
Definition: avtextformat.h:61
AVTextFormatContext::nb_item
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
number of the item printed in the given section, starting from 0
Definition: avtextformat.h:147
avtext_print_unit_integer
void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, const char *unit)
Definition: avtextformat.c:429
AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
@ AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
Definition: avtextformat.h:75
AV_TEXTFORMAT_LINKTYPE_NONDIR
@ AV_TEXTFORMAT_LINKTYPE_NONDIR
Definition: avtextformat.h:84
show_data_hash
static char * show_data_hash
Definition: ffprobe.c:146
avtextformatter_mermaidhtml
const AVTextFormatter avtextformatter_mermaidhtml
Definition: tf_mermaid.c:665
AVTextFormatOptions::use_byte_value_binary_prefix
int use_byte_value_binary_prefix
Definition: avtextformat.h:128
AVTextFormatContext::nb_sections
int nb_sections
number of sections
Definition: avtextformat.h:142
AVTextFormatContext::hash
struct AVHashContext * hash
Definition: avtextformat.h:157
AVTextFormatContext::string_validation_replacement
char * string_validation_replacement
Definition: avtextformat.h:160