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 <stddef.h>
25 #include <stdint.h>
26 #include "libavutil/attributes.h"
27 #include "libavutil/dict.h"
28 #include "libavformat/avio.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/rational.h"
31 #include "libavutil/hash.h"
32 #include "avtextwriters.h"
33 
34 #define SECTION_MAX_NB_CHILDREN 11
35 
36 
37 typedef struct AVTextFormatSection {
38  int id; ///< unique id identifying a section
39  const char *name;
40 
41 #define AV_TEXTFORMAT_SECTION_FLAG_IS_WRAPPER 1 ///< the section only contains other sections, but has no data at its own level
42 #define AV_TEXTFORMAT_SECTION_FLAG_IS_ARRAY 2 ///< the section contains an array of elements of the same type
43 #define AV_TEXTFORMAT_SECTION_FLAG_HAS_VARIABLE_FIELDS 4 ///< the section may contain a variable number of fields with variable keys.
44  /// For these sections the element_name field is mandatory.
45 #define AV_TEXTFORMAT_SECTION_FLAG_HAS_TYPE 8 ///< the section contains a type to distinguish multiple nested elements
46 #define AV_TEXTFORMAT_SECTION_FLAG_NUMBERING_BY_TYPE 16 ///< the items in this array section should be numbered individually by type
47 
48  int flags;
49  const int children_ids[SECTION_MAX_NB_CHILDREN+1]; ///< list of children section IDS, terminated by -1
50  const char *element_name; ///< name of the contained element, if provided
51  const char *unique_name; ///< unique section name, in case the name is ambiguous
53  const char *(* get_type)(const void *data); ///< function returning a type if defined, must be defined when SECTION_FLAG_HAS_TYPE is defined
56 
58 
59 #define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS 1
60 #define AV_TEXTFORMAT_FLAG_SUPPORTS_MIXED_ARRAY_CONTENT 2
61 
62 typedef enum {
68 
69 typedef struct AVTextFormatter {
70  const AVClass *priv_class; ///< private class of the formatter, if any
71  int priv_size; ///< private size for the formatter context
72  const char *name;
73 
74  int (*init) (AVTextFormatContext *tctx);
75  void (*uninit)(AVTextFormatContext *tctx);
76 
77  void (*print_section_header)(AVTextFormatContext *tctx, const void *data);
79  void (*print_integer) (AVTextFormatContext *tctx, const char *, int64_t);
80  void (*print_rational) (AVTextFormatContext *tctx, AVRational *q, char *sep);
81  void (*print_string) (AVTextFormatContext *tctx, const char *, const char *);
82  int flags; ///< a combination or AV_TEXTFORMAT__FLAG_*
84 
85 #define SECTION_MAX_NB_LEVELS 12
86 #define SECTION_MAX_NB_SECTIONS 100
87 
89  const AVClass *class; ///< class of the formatter
90  const AVTextFormatter *formatter; ///< the AVTextFormatter of which this is an instance
91  AVTextWriterContext *writer; ///< the AVTextWriterContext
92 
93  char *name; ///< name of this formatter instance
94  void *priv; ///< private data for use by the filter
95 
96  const struct AVTextFormatSection *sections; ///< array containing all sections
97  int nb_sections; ///< number of sections
98 
99  int level; ///< current level, starting from 0
100 
101  /** number of the item printed in the given section, starting from 0 */
104 
105  /** section per each level */
107  AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]; ///< generic print buffer dedicated to each section,
108  /// used by various formatters
109 
115 
117 
121 };
122 
123 #define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL 1
124 #define AV_TEXTFORMAT_PRINT_STRING_VALIDATE 2
125 
126 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
127  const struct AVTextFormatSection *sections, int nb_sections,
128  int show_value_unit,
129  int use_value_prefix,
133  char *show_data_hash);
134 
136 
137 
138 void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id);
139 
141 
142 void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val);
143 
144 int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags);
145 
146 void avtext_print_unit_int(AVTextFormatContext *tctx, const char *key, int value, const char *unit);
147 
148 void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep);
149 
150 void avtext_print_time(AVTextFormatContext *tctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration);
151 
152 void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration);
153 
154 void avtext_print_data(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size);
155 
156 void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size);
157 
158 void avtext_print_integers(AVTextFormatContext *tctx, const char *name, uint8_t *data, int size,
159  const char *format, int columns, int bytes, int offset_add);
160 
162 
170 
171 #endif /* FFTOOLS_TEXTFORMAT_AVTEXTFORMAT_H */
flags
const SwsFlags flags[]
Definition: swscale.c:61
use_byte_value_binary_prefix
static int use_byte_value_binary_prefix
Definition: ffprobe.c:131
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
AVTextFormatSection::entries_to_show
AVDictionary * entries_to_show
Definition: avtextformat.h:52
AVTextFormatContext::section
const struct AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:106
AVTextFormatContext::nb_item_type
unsigned int nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS]
Definition: avtextformat.h:103
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
avtextformatter_compact
const AVTextFormatter avtextformatter_compact
Definition: tf_compact.c:241
AV_TEXTFORMAT_STRING_VALIDATION_NB
@ AV_TEXTFORMAT_STRING_VALIDATION_NB
Definition: avtextformat.h:66
data
const char data[16]
Definition: mxf.c:149
AVTextFormatContext::show_value_unit
int show_value_unit
Definition: avtextformat.h:111
AVTextFormatContext::name
char * name
name of this formatter instance
Definition: avtextformat.h:93
AVTextWriterContext
Definition: avtextwriters.h:47
AVTextFormatContext
Definition: avtextformat.h:88
AVDictionary
Definition: dict.c:32
avtext_print_section_footer
void avtext_print_section_footer(AVTextFormatContext *tctx)
Definition: avtextformat.c:272
AVTextFormatSection::id
int id
unique id identifying a section
Definition: avtextformat.h:38
AVTextFormatContext::level
int level
current level, starting from 0
Definition: avtextformat.h:99
AVTextFormatSection::name
const char * name
Definition: avtextformat.h:39
show_optional_fields
static int show_optional_fields
Definition: ffprobe.c:138
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AVTextFormatSection::show_all_entries
int show_all_entries
Definition: avtextformat.h:54
avtext_get_formatter_by_name
const AVTextFormatter * avtext_get_formatter_by_name(const char *name)
Definition: avtextformat.c:663
AVTextFormatContext::writer
AVTextWriterContext * writer
the AVTextWriterContext
Definition: avtextformat.h:91
avtext_context_close
int avtext_context_close(AVTextFormatContext **tctx)
Definition: avtextformat.c:102
AVTextFormatSection::flags
int flags
Definition: avtextformat.h:48
SECTION_MAX_NB_CHILDREN
#define SECTION_MAX_NB_CHILDREN
Definition: avtextformat.h:34
AVTextFormatSection::element_name
const char * element_name
name of the contained element, if provided
Definition: avtextformat.h:50
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:136
AVTextFormatContext::sections
const struct AVTextFormatSection * sections
array containing all sections
Definition: avtextformat.h:96
AVTextFormatter::print_string
void(* print_string)(AVTextFormatContext *tctx, const char *, const char *)
Definition: avtextformat.h:81
AVTextFormatter
Definition: avtextformat.h:69
SECTION_MAX_NB_SECTIONS
#define SECTION_MAX_NB_SECTIONS
Definition: avtextformat.h:86
avtext_print_data_hash
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size)
Definition: avtextformat.c:523
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
AVTextFormatSection
Definition: avtextformat.h:37
avtext_print_data
void avtext_print_data(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size)
Definition: avtextformat.c:495
avtextformatter_ini
const AVTextFormatter avtextformatter_ini
Definition: tf_ini.c:152
avtext_print_integers
void avtext_print_integers(AVTextFormatContext *tctx, const char *name, uint8_t *data, int size, const char *format, int columns, int bytes, int offset_add)
Definition: avtextformat.c:538
AVTextFormatContext::priv
void * priv
private data for use by the filter
Definition: avtextformat.h:94
avtext_print_section_header
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
Definition: avtextformat.c:257
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:469
AVTextFormatter::priv_size
int priv_size
private size for the formatter context
Definition: avtextformat.h:71
AVTextFormatContext::use_byte_value_binary_prefix
int use_byte_value_binary_prefix
Definition: avtextformat.h:113
avtext_print_rational
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
Definition: avtextformat.c:460
AVTextFormatSection::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition: avtextformat.h:51
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
StringValidation
StringValidation
Definition: avtextformat.h:62
AVTextFormatter::print_section_header
void(* print_section_header)(AVTextFormatContext *tctx, const void *data)
Definition: avtextformat.h:77
AV_TEXTFORMAT_STRING_VALIDATION_IGNORE
@ AV_TEXTFORMAT_STRING_VALIDATION_IGNORE
Definition: avtextformat.h:65
AVTextFormatContext::formatter
const AVTextFormatter * formatter
the AVTextFormatter of which this is an instance
Definition: avtextformat.h:90
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:85
show_value_unit
static int show_value_unit
Definition: ffprobe.c:129
avtext_print_unit_int
void avtext_print_unit_int(AVTextFormatContext *tctx, const char *key, int value, const char *unit)
Definition: avtextformat.c:413
avtextformatter_flat
const AVTextFormatter avtextformatter_flat
Definition: tf_flat.c:165
AV_TEXTFORMAT_STRING_VALIDATION_FAIL
@ AV_TEXTFORMAT_STRING_VALIDATION_FAIL
Definition: avtextformat.h:63
AVTextFormatter::name
const char * name
Definition: avtextformat.h:72
size
int size
Definition: twinvq_data.h:10344
AVTextFormatContext::use_value_sexagesimal_format
int use_value_sexagesimal_format
Definition: avtextformat.h:114
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:107
use_value_prefix
static int use_value_prefix
Definition: ffprobe.c:130
avtext_print_ts
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
Definition: avtextformat.c:486
AVTextFormatContext::show_optional_fields
int show_optional_fields
Definition: avtextformat.h:110
AVTextFormatter::flags
int flags
a combination or AV_TEXTFORMAT__FLAG_*
Definition: avtextformat.h:82
AVTextFormatter::print_rational
void(* print_rational)(AVTextFormatContext *tctx, AVRational *q, char *sep)
Definition: avtextformat.h:80
AVHashContext
Definition: hash.c:66
attributes.h
avtext_print_string
int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
Definition: avtextformat.c:423
bprint.h
avtext_print_integer
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val)
Definition: avtextformat.c:288
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
avtextformatter_xml
const AVTextFormatter avtextformatter_xml
Definition: tf_xml.c:210
AVTextFormatter::uninit
void(* uninit)(AVTextFormatContext *tctx)
Definition: avtextformat.h:75
AVTextFormatContext::string_validation_utf8_flags
unsigned int string_validation_utf8_flags
Definition: avtextformat.h:120
use_value_sexagesimal_format
static int use_value_sexagesimal_format
Definition: ffprobe.c:132
avtextformatter_json
const AVTextFormatter avtextformatter_json
Definition: tf_json.c:204
AVTextFormatter::print_section_footer
void(* print_section_footer)(AVTextFormatContext *tctx)
Definition: avtextformat.h:78
sections
static struct AVTextFormatSection sections[]
Definition: ffprobe.c:251
dict.h
hash.h
AVTextFormatter::priv_class
const AVClass * priv_class
private class of the formatter, if any
Definition: avtextformat.h:70
AVTextFormatter::print_integer
void(* print_integer)(AVTextFormatContext *tctx, const char *, int64_t)
Definition: avtextformat.h:79
AVTextFormatSection::children_ids
const int children_ids[SECTION_MAX_NB_CHILDREN+1]
list of children section IDS, terminated by -1
Definition: avtextformat.h:49
AVTextFormatContext::string_validation
int string_validation
Definition: avtextformat.h:118
AVTextFormatter::init
int(* init)(AVTextFormatContext *tctx)
Definition: avtextformat.h:74
AVTextFormatContext::use_value_prefix
int use_value_prefix
Definition: avtextformat.h:112
avtextwriters.h
avtextformatter_csv
const AVTextFormatter avtextformatter_csv
Definition: tf_compact.c:272
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:102
AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
@ AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
Definition: avtextformat.h:64
show_data_hash
static char * show_data_hash
Definition: ffprobe.c:142
AVTextFormatContext::nb_sections
int nb_sections
number of sections
Definition: avtextformat.h:97
AVTextFormatContext::hash
struct AVHashContext * hash
Definition: avtextformat.h:116
AVTextFormatContext::string_validation_replacement
char * string_validation_replacement
Definition: avtextformat.h:119
avtext_context_open
int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args, const struct AVTextFormatSection *sections, int nb_sections, int show_value_unit, int use_value_prefix, int use_byte_value_binary_prefix, int use_value_sexagesimal_format, int show_optional_fields, char *show_data_hash)
Definition: avtextformat.c:128