40#define SECTION_ID_NONE (-1)
42#define SHOW_OPTIONAL_FIELDS_AUTO (-1)
43#define SHOW_OPTIONAL_FIELDS_NEVER 0
44#define SHOW_OPTIONAL_FIELDS_ALWAYS 1
53 { 1.024e3, 1e3,
"Ki",
"K" },
54 { 1.048576e6, 1e6,
"Mi",
"M" },
55 { 1.073741824e9, 1e9,
"Gi",
"G" },
56 { 1.099511627776e12, 1e12,
"Ti",
"T" },
57 { 1.125899906842624e15, 1e15,
"Pi",
"P" },
66#define OFFSET(x) offsetof(AVTextFormatContext, x)
69 {
"string_validation",
"set string validation mode",
71 {
"sv",
"set string validation mode",
76 {
"string_validation_replacement",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, { .str =
"" } },
77 {
"svr",
"set string validation replacement string",
OFFSET(string_validation_replacement),
AV_OPT_TYPE_STRING, { .str =
"\xEF\xBF\xBD" } },
84 if (!prev &&
ctx->formatter &&
ctx->formatter->priv_class &&
ctx->priv)
90 .class_name =
"AVTextContext",
97static void bprint_bytes(AVBPrint *bp,
const uint8_t *ubuf,
size_t ubuf_size)
100 for (
unsigned i = 0;
i < ubuf_size;
i++)
165 tctx->
writer = writer_context;
168 void *priv_ctx = tctx->
priv;
179 av_log(tctx,
AV_LOG_ERROR,
"Failed to parse option string '%s' provided to textformat context\n", args);
186 av_log(tctx,
AV_LOG_ERROR,
"Failed to set option '%s' with value '%s' provided to textformat context\n",
212 const uint8_t *endp = p + strlen((
const char *)p);
214 const uint8_t *p0 = p;
222 "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
247 if (section_id < 0 || section_id >= tctx->
nb_sections) {
248 av_log(tctx,
AV_LOG_ERROR,
"Invalid section_id for section_header: %d\n", section_id);
271 int parent_section_id = tctx->
level ?
306 const uint8_t *p, *endp, *srcp = (
const uint8_t *)
src;
308 AVBPrint invalid_seq;
309 int invalid_chars_nb = 0, ret = 0;
315 endp = srcp + strlen(
src);
316 for (p = srcp; *p;) {
319 const uint8_t *p0 = p;
327 av_log(tctx,
AV_LOG_DEBUG,
"Invalid UTF-8 sequence '%s' found in string '%s'\n", invalid_seq.str,
src);
352 "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
377 const char *float_fmt = 0;
380 vald = 20 * log10(uv.
val.
d);
394 mins = (int)secs / 60;
395 secs = secs - mins * 60;
398 snprintf(buf, buf_size,
"%d:%02d:%09.6f", hours, mins, secs);
400 const char *prefix_string =
"";
420 snprintf(buf, buf_size, float_fmt ? float_fmt :
"%f", vald);
422 snprintf(buf, buf_size,
"%"PRId64, vali);
480 if (ret < 0)
goto end;
482 if (ret < 0)
goto end;
487 "Invalid key=value string combination %s=%s in section %s\n",
511 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
515 double d =
av_q2d(*time_base) * ts;
527 if ((!is_duration && ts ==
AV_NOPTS_VALUE) || (is_duration && ts == 0))
542 for (
i = 0;
i < l;
i++) {
548 for (
i = 0;
i < l;
i++)
614 if (!prev &&
ctx->formatter &&
ctx->formatter->priv_class &&
ctx->priv)
620 .class_name =
"AVTextWriterContext",
652 if (!pwctx || !writer)
666 void *priv_ctx = wctx->
priv;
710 (*end ==
'\0' || *end ==
'='))
static double val(void *priv, double ch)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
static const AVClass textwriter_class
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val, int flags)
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
static const char unit_second_str[]
static char * value_string(const AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, AVTextFormatValueFormat fmt, const char *unit)
static const struct @105000147377261105311001355164026305374075040210 si_prefixes[]
static void * writercontext_child_next(void *obj, void *prev)
static const char * writercontext_get_writer_name(void *p)
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
void avtext_print_unit_double(AVTextFormatContext *tctx, const char *key, double val, AVTextFormatValueFormat fmt, const char *unit)
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)
void avtext_print_data(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
static const AVClass textcontext_class
static void * textcontext_child_next(void *obj, void *prev)
static void print_data_xxd(AVBPrint *bp, const uint8_t *data, int size)
static const char * textcontext_get_formatter_name(void *p)
int avtext_context_close(AVTextFormatContext **ptctx)
static const AVOption textcontext_options[]
static void print_data_base64(AVBPrint *bp, const uint8_t *data, int size)
void avtext_print_time(AVTextFormatContext *tctx, const char *key, int64_t ts, const AVRational *time_base, int is_duration)
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
static const AVTextFormatter *const registered_formatters[]
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
static const char float_fmt_singledigit[]
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
void avtext_print_section_footer(AVTextFormatContext *tctx)
const AVTextFormatter * avtext_get_formatter_by_name(const char *name)
static const char float_fmt_full[]
static int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
int avtextwriter_context_close(AVTextWriterContext **pwctx)
const AVTextFormatter avtextformatter_compact
@ AV_TEXTFORMAT_DATADUMP_BASE64
@ AV_TEXTFORMAT_DATADUMP_XXD
#define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL
#define SECTION_MAX_NB_LEVELS
const AVTextFormatter avtextformatter_ini
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
const AVTextFormatter avtextformatter_csv
#define SECTION_MAX_NB_SECTIONS
@ AV_TEXTFORMAT_VALUE_FMT_DOUBLE
@ AV_TEXTFORMAT_VALUE_FMT_DECIBEL
@ AV_TEXTFORMAT_VALUE_FMT_SECOND
@ AV_TEXTFORMAT_VALUE_FMT_BYTE
const AVTextFormatter avtextformatter_default
@ AV_TEXTFORMAT_STRING_VALIDATION_NB
@ AV_TEXTFORMAT_STRING_VALIDATION_FAIL
@ AV_TEXTFORMAT_STRING_VALIDATION_IGNORE
@ AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
#define AV_TEXTFORMAT_PRINT_STRING_VALIDATE
const AVTextFormatter avtextformatter_mermaid
const AVTextFormatter avtextformatter_json
const AVTextFormatter avtextformatter_flat
const AVTextFormatter avtextformatter_mermaidhtml
const AVTextFormatter avtextformatter_xml
Convenience header that includes libavutil's core.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_AUTOMATIC
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
static char * show_data_hash
#define SHOW_OPTIONAL_FIELDS_AUTO
static const AVTextFormatSection sections[]
#define SHOW_OPTIONAL_FIELDS_NEVER
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_hash_freep(AVHashContext **ctx)
Free hash context and set hash context pointer to NULL.
void av_hash_final_hex(struct AVHashContext *ctx, uint8_t *dst, int size)
Finalize a hash context and store the hexadecimal representation of the actual hash value as a string...
void av_hash_init(AVHashContext *ctx)
Initialize or reset a hash context.
void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
Update a hash context with additional data.
int av_hash_alloc(AVHashContext **ctx, const char *name)
Allocate a hash context for the algorithm specified by name.
const char * av_hash_names(int i)
Get the names of available hash algorithms.
#define AV_HASH_MAX_SIZE
Maximum value that av_hash_get_size() will currently return.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static double av_q2d(AVRational a)
Convert an AVRational to a double.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
int av_utf8_decode(int32_t *codep, const uint8_t **bufp, const uint8_t *buf_end, unsigned int flags)
Read and decode a single UTF-8 code point (character) from the buffer in *buf, and update *buf to poi...
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define LIBAVUTIL_VERSION_INT
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
void av_opt_free(void *obj)
Free all allocated objects in obj.
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
const char * av_hash_get_name(const AVHashContext *ctx)
Utility Preprocessor macros.
Memory handling functions.
#define FF_ARRAY_ELEMS(a)
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
unsigned int nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS]
struct AVHashContext * hash
void * priv
private data for use by the filter
const AVClass * class
class of the formatter
const AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
char * string_validation_replacement
int level
current level, starting from 0
unsigned int nb_item[SECTION_MAX_NB_LEVELS]
number of the item printed in the given section, starting from 0
unsigned int string_validation_utf8_flags
AVTextWriterContext * writer
the AVTextWriterContext
AVBPrint section_pbuf[SECTION_MAX_NB_LEVELS]
generic print buffer dedicated to each section, used by various formatters
const AVTextFormatSection * sections
array containing all sections
const AVTextFormatter * formatter
the AVTextFormatter of which this is an instance
int nb_sections
number of sections
int(* is_key_selected)(struct AVTextFormatContext *tctx, const char *key)
Callback to discard certain elements based upon the key used.
int use_byte_value_binary_prefix
int use_value_sexagesimal_format
AVTextFormatDataDump data_dump_format
const char * unique_name
unique section name, in case the name is ambiguous
int id
unique id identifying a section
int(* uninit)(AVTextFormatContext *tctx)
int priv_size
private size for the formatter context
int flags
a combination or AV_TEXTFORMAT__FLAG_*
void(* print_string)(AVTextFormatContext *tctx, const char *, const char *)
void(* print_section_header)(AVTextFormatContext *tctx, const void *data)
const AVClass * priv_class
private class of the formatter, if any
void(* print_integer)(AVTextFormatContext *tctx, const char *, int64_t)
void(* print_section_footer)(AVTextFormatContext *tctx)
int(* init)(AVTextFormatContext *tctx)
void * priv
private data for use by the writer
const AVTextWriter * writer
const AVClass * class
class of the writer
int priv_size
private size for the writer private class
int(* uninit)(AVTextWriterContext *wctx)
int(* init)(AVTextWriterContext *wctx)
const AVClass * priv_class
private class of the writer, if any
union unit_value::@153353126176234320255222000327105263006301132050 val
AVTextFormatValueFormat fmt
static AVFormatContext * ctx
static AVDictionary * opts