FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
avtextformat.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 "libavutil/mem.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/bprint.h"
30 #include "libavutil/error.h"
31 #include "libavutil/hash.h"
32 #include "libavutil/intreadwrite.h"
33 #include "libavutil/macros.h"
34 #include "libavutil/opt.h"
35 #include "avtextformat.h"
36 
37 #define SECTION_ID_NONE -1
38 
39 #define SHOW_OPTIONAL_FIELDS_AUTO -1
40 #define SHOW_OPTIONAL_FIELDS_NEVER 0
41 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
42 
43 static const struct {
44  double bin_val;
45  double dec_val;
46  const char *bin_str;
47  const char *dec_str;
48 } si_prefixes[] = {
49  { 1.0, 1.0, "", "" },
50  { 1.024e3, 1e3, "Ki", "K" },
51  { 1.048576e6, 1e6, "Mi", "M" },
52  { 1.073741824e9, 1e9, "Gi", "G" },
53  { 1.099511627776e12, 1e12, "Ti", "T" },
54  { 1.125899906842624e15, 1e15, "Pi", "P" },
55 };
56 
57 static const char *textcontext_get_formatter_name(void *p)
58 {
59  AVTextFormatContext *tctx = p;
60  return tctx->formatter->name;
61 }
62 
63 #define OFFSET(x) offsetof(AVTextFormatContext, x)
64 
65 static const AVOption textcontext_options[] = {
66  { "string_validation", "set string validation mode",
68  { "sv", "set string validation mode",
70  { "ignore", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE}, .unit = "sv" },
71  { "replace", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE}, .unit = "sv" },
72  { "fail", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL}, .unit = "sv" },
73  { "string_validation_replacement", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str=""}},
74  { "svr", "set string validation replacement string", OFFSET(string_validation_replacement), AV_OPT_TYPE_STRING, {.str="\xEF\xBF\xBD"}},
75  { NULL }
76 };
77 
78 static void *textcontext_child_next(void *obj, void *prev)
79 {
80  AVTextFormatContext *ctx = obj;
81  if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
82  return ctx->priv;
83  return NULL;
84 }
85 
86 static const AVClass textcontext_class = {
87  .class_name = "AVTextContext",
88  .item_name = textcontext_get_formatter_name,
89  .option = textcontext_options,
90  .version = LIBAVUTIL_VERSION_INT,
91  .child_next = textcontext_child_next,
92 };
93 
94 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
95 {
96  int i;
97  av_bprintf(bp, "0X");
98  for (i = 0; i < ubuf_size; i++)
99  av_bprintf(bp, "%02X", ubuf[i]);
100 }
101 
103 {
104  AVTextFormatContext *tctx = *ptctx;
105  int i;
106 
107  if (!tctx)
108  return;
109 
110  av_hash_freep(&tctx->hash);
111 
112  av_hash_freep(&tctx->hash);
113 
114  if (tctx->formatter) {
115  if (tctx->formatter->uninit)
116  tctx->formatter->uninit(tctx);
117  if (tctx->formatter->priv_class)
118  av_opt_free(tctx->priv);
119  }
120  for (i = 0; i < SECTION_MAX_NB_LEVELS; i++)
122  av_freep(&tctx->priv);
123  av_opt_free(tctx);
124  av_freep(ptctx);
125 }
126 
127 
128 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
129  const struct AVTextFormatSection *sections, int nb_sections,
130  int show_value_unit,
131  int use_value_prefix,
135  char *show_data_hash)
136 {
137  AVTextFormatContext *tctx;
138  int i, ret = 0;
139 
140  if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) {
141  ret = AVERROR(ENOMEM);
142  goto fail;
143  }
144 
145  for (int i = 0; i < SECTION_MAX_NB_LEVELS; i++)
147 
148  tctx->class = &textcontext_class;
149  av_opt_set_defaults(tctx);
150 
151  if (!(tctx->priv = av_mallocz(formatter->priv_size))) {
152  ret = AVERROR(ENOMEM);
153  goto fail;
154  }
155 
161 
162  if (nb_sections > SECTION_MAX_NB_SECTIONS) {
163  av_log(tctx, AV_LOG_ERROR, "The number of section definitions (%d) is larger than the maximum allowed (%d)\n", nb_sections, SECTION_MAX_NB_SECTIONS);
164  ret = AVERROR(EINVAL);
165  goto fail;
166  }
167 
168  tctx->formatter = formatter;
169  tctx->level = -1;
170  tctx->sections = sections;
171  tctx->nb_sections = nb_sections;
172  tctx->writer = writer_context;
173 
174  if (formatter->priv_class) {
175  void *priv_ctx = tctx->priv;
176  *(const AVClass **)priv_ctx = formatter->priv_class;
177  av_opt_set_defaults(priv_ctx);
178  }
179 
180  /* convert options to dictionary */
181  if (args) {
183  const AVDictionaryEntry *opt = NULL;
184 
185  if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
186  av_log(tctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to textformat context\n", args);
187  av_dict_free(&opts);
188  goto fail;
189  }
190 
191  while ((opt = av_dict_iterate(opts, opt))) {
192  if ((ret = av_opt_set(tctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
193  av_log(tctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to textformat context\n",
194  opt->key, opt->value);
195  av_dict_free(&opts);
196  goto fail;
197  }
198  }
199 
200  av_dict_free(&opts);
201  }
202 
203  if (show_data_hash) {
204  if ((ret = av_hash_alloc(&tctx->hash, show_data_hash)) < 0) {
205  if (ret == AVERROR(EINVAL)) {
206  const char *n;
207  av_log(NULL, AV_LOG_ERROR, "Unknown hash algorithm '%s'\nKnown algorithms:", show_data_hash);
208  for (i = 0; (n = av_hash_names(i)); i++)
209  av_log(NULL, AV_LOG_ERROR, " %s", n);
210  av_log(NULL, AV_LOG_ERROR, "\n");
211  }
212  return ret;
213  }
214  }
215 
216  /* validate replace string */
217  {
218  const uint8_t *p = tctx->string_validation_replacement;
219  const uint8_t *endp = p + strlen(p);
220  while (*p) {
221  const uint8_t *p0 = p;
222  int32_t code;
224  if (ret < 0) {
225  AVBPrint bp;
227  bprint_bytes(&bp, p0, p-p0),
228  av_log(tctx, AV_LOG_ERROR,
229  "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
230  bp.str, tctx->string_validation_replacement);
231  return ret;
232  }
233  }
234  }
235 
236  if (tctx->formatter->init)
237  ret = tctx->formatter->init(tctx);
238  if (ret < 0)
239  goto fail;
240 
241  *ptctx = tctx;
242 
243  return 0;
244 
245 fail:
246  avtext_context_close(&tctx);
247  return ret;
248 }
249 
250 /* Temporary definitions during refactoring */
251 static const char unit_second_str[] = "s" ;
252 static const char unit_hertz_str[] = "Hz" ;
253 static const char unit_byte_str[] = "byte" ;
254 static const char unit_bit_per_second_str[] = "bit/s";
255 
256 
258  const void *data,
259  int section_id)
260 {
261  tctx->level++;
263 
264  tctx->nb_item[tctx->level] = 0;
265  memset(tctx->nb_item_type[tctx->level], 0, sizeof(tctx->nb_item_type[tctx->level]));
266  tctx->section[tctx->level] = &tctx->sections[section_id];
267 
268  if (tctx->formatter->print_section_header)
269  tctx->formatter->print_section_header(tctx, data);
270 }
271 
273 {
274  int section_id = tctx->section[tctx->level]->id;
275  int parent_section_id = tctx->level ?
276  tctx->section[tctx->level-1]->id : SECTION_ID_NONE;
277 
278  if (parent_section_id != SECTION_ID_NONE) {
279  tctx->nb_item[tctx->level - 1]++;
280  tctx->nb_item_type[tctx->level - 1][section_id]++;
281  }
282 
283  if (tctx->formatter->print_section_footer)
284  tctx->formatter->print_section_footer(tctx);
285  tctx->level--;
286 }
287 
289  const char *key, int64_t val)
290 {
291  const struct AVTextFormatSection *section = tctx->section[tctx->level];
292 
293  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
294  tctx->formatter->print_integer(tctx, key, val);
295  tctx->nb_item[tctx->level]++;
296  }
297 }
298 
299 static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
300 {
301  const uint8_t *p, *endp;
302  AVBPrint dstbuf;
303  int invalid_chars_nb = 0, ret = 0;
304 
306 
307  endp = src + strlen(src);
308  for (p = src; *p;) {
309  uint32_t code;
310  int invalid = 0;
311  const uint8_t *p0 = p;
312 
313  if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {
314  AVBPrint bp;
316  bprint_bytes(&bp, p0, p-p0);
317  av_log(tctx, AV_LOG_DEBUG,
318  "Invalid UTF-8 sequence %s found in string '%s'\n", bp.str, src);
319  invalid = 1;
320  }
321 
322  if (invalid) {
323  invalid_chars_nb++;
324 
325  switch (tctx->string_validation) {
327  av_log(tctx, AV_LOG_ERROR,
328  "Invalid UTF-8 sequence found in string '%s'\n", src);
330  goto end;
331  break;
332 
334  av_bprintf(&dstbuf, "%s", tctx->string_validation_replacement);
335  break;
336  }
337  }
338 
340  av_bprint_append_data(&dstbuf, p0, p-p0);
341  }
342 
343  if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE) {
344  av_log(tctx, AV_LOG_WARNING,
345  "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
346  invalid_chars_nb, src, tctx->string_validation_replacement);
347  }
348 
349 end:
350  av_bprint_finalize(&dstbuf, dstp);
351  return ret;
352 }
353 
354 struct unit_value {
355  union { double d; int64_t i; } val;
356  const char *unit;
357 };
358 
359 static char *value_string(AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
360 {
361  double vald;
362  int64_t vali;
363  int show_float = 0;
364 
365  if (uv.unit == unit_second_str) {
366  vald = uv.val.d;
367  show_float = 1;
368  } else {
369  vald = vali = uv.val.i;
370  }
371 
373  double secs;
374  int hours, mins;
375  secs = vald;
376  mins = (int)secs / 60;
377  secs = secs - mins * 60;
378  hours = mins / 60;
379  mins %= 60;
380  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
381  } else {
382  const char *prefix_string = "";
383 
384  if (tctx->use_value_prefix && vald > 1) {
385  int64_t index;
386 
387  if (uv.unit == unit_byte_str && tctx->use_byte_value_binary_prefix) {
388  index = (int64_t) (log2(vald)) / 10;
390  vald /= si_prefixes[index].bin_val;
391  prefix_string = si_prefixes[index].bin_str;
392  } else {
393  index = (int64_t) (log10(vald)) / 3;
395  vald /= si_prefixes[index].dec_val;
396  prefix_string = si_prefixes[index].dec_str;
397  }
398  vali = vald;
399  }
400 
401  if (show_float || (tctx->use_value_prefix && vald != (int64_t)vald))
402  snprintf(buf, buf_size, "%f", vald);
403  else
404  snprintf(buf, buf_size, "%"PRId64, vali);
405  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->show_value_unit ? " " : "",
406  prefix_string, tctx->show_value_unit ? uv.unit : "");
407  }
408 
409  return buf;
410 }
411 
412 
413 void avtext_print_unit_int(AVTextFormatContext *tctx, const char *key, int value, const char *unit)
414 {
415  char val_str[128];
416  struct unit_value uv;
417  uv.val.i = value;
418  uv.unit = unit;
419  avtext_print_string(tctx, key, value_string(tctx, val_str, sizeof(val_str), uv), 0);
420 }
421 
422 
423 int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
424 {
425  const struct AVTextFormatSection *section = tctx->section[tctx->level];
426  int ret = 0;
427 
432  return 0;
433 
434  if (section->show_all_entries || av_dict_get(section->entries_to_show, key, NULL, 0)) {
436  char *key1 = NULL, *val1 = NULL;
437  ret = validate_string(tctx, &key1, key);
438  if (ret < 0) goto end;
439  ret = validate_string(tctx, &val1, val);
440  if (ret < 0) goto end;
441  tctx->formatter->print_string(tctx, key1, val1);
442  end:
443  if (ret < 0) {
444  av_log(tctx, AV_LOG_ERROR,
445  "Invalid key=value string combination %s=%s in section %s\n",
446  key, val, section->unique_name);
447  }
448  av_free(key1);
449  av_free(val1);
450  } else {
451  tctx->formatter->print_string(tctx, key, val);
452  }
453 
454  tctx->nb_item[tctx->level]++;
455  }
456 
457  return ret;
458 }
459 
461  const char *key, AVRational q, char sep)
462 {
463  char buf[44];
464  snprintf(buf, sizeof(buf), "%d%c%d", q.num, sep, q.den);
465  avtext_print_string(tctx, key, buf, 0);
466 }
467 
468 void avtext_print_time(AVTextFormatContext *tctx, const char *key,
469  int64_t ts, const AVRational *time_base, int is_duration)
470 {
471  char buf[128];
472 
473  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
475  } else {
476  double d = ts * av_q2d(*time_base);
477  struct unit_value uv;
478  uv.val.d = d;
479  uv.unit = unit_second_str;
480  value_string(tctx, buf, sizeof(buf), uv);
481  avtext_print_string(tctx, key, buf, 0);
482  }
483 }
484 
485 void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
486 {
487  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
489  } else {
490  avtext_print_integer(tctx, key, ts);
491  }
492 }
493 
495  const uint8_t *data, int size)
496 {
497  AVBPrint bp;
498  int offset = 0, l, i;
499 
501  av_bprintf(&bp, "\n");
502  while (size) {
503  av_bprintf(&bp, "%08x: ", offset);
504  l = FFMIN(size, 16);
505  for (i = 0; i < l; i++) {
506  av_bprintf(&bp, "%02x", data[i]);
507  if (i & 1)
508  av_bprintf(&bp, " ");
509  }
510  av_bprint_chars(&bp, ' ', 41 - 2 * i - i / 2);
511  for (i = 0; i < l; i++)
512  av_bprint_chars(&bp, data[i] - 32U < 95 ? data[i] : '.', 1);
513  av_bprintf(&bp, "\n");
514  offset += l;
515  data += l;
516  size -= l;
517  }
518  avtext_print_string(tctx, name, bp.str, 0);
519  av_bprint_finalize(&bp, NULL);
520 }
521 
523  const uint8_t *data, int size)
524 {
525  char *p, buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
526 
527  if (!tctx->hash)
528  return;
529  av_hash_init(tctx->hash);
530  av_hash_update(tctx->hash, data, size);
531  snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash));
532  p = buf + strlen(buf);
533  av_hash_final_hex(tctx->hash, p, buf + sizeof(buf) - p);
534  avtext_print_string(tctx, name, buf, 0);
535 }
536 
538  uint8_t *data, int size, const char *format,
539  int columns, int bytes, int offset_add)
540 {
541  AVBPrint bp;
542  int offset = 0, l, i;
543 
545  av_bprintf(&bp, "\n");
546  while (size) {
547  av_bprintf(&bp, "%08x: ", offset);
548  l = FFMIN(size, columns);
549  for (i = 0; i < l; i++) {
550  if (bytes == 1) av_bprintf(&bp, format, *data);
551  else if (bytes == 2) av_bprintf(&bp, format, AV_RN16(data));
552  else if (bytes == 4) av_bprintf(&bp, format, AV_RN32(data));
553  data += bytes;
554  size --;
555  }
556  av_bprintf(&bp, "\n");
557  offset += offset_add;
558  }
559  avtext_print_string(tctx, name, bp.str, 0);
560  av_bprint_finalize(&bp, NULL);
561 }
562 
563 static const char *writercontext_get_writer_name(void *p)
564 {
565  AVTextWriterContext *wctx = p;
566  return wctx->writer->name;
567 }
568 
569 static void *writercontext_child_next(void *obj, void *prev)
570 {
571  AVTextFormatContext *ctx = obj;
572  if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
573  return ctx->priv;
574  return NULL;
575 }
576 
577 static const AVClass textwriter_class = {
578  .class_name = "AVTextWriterContext",
579  .item_name = writercontext_get_writer_name,
580  .version = LIBAVUTIL_VERSION_INT,
581  .child_next = writercontext_child_next,
582 };
583 
584 
586 {
587  AVTextWriterContext *wctx = *pwctx;
588 
589  if (!wctx)
590  return;
591 
592  if (wctx->writer) {
593  if (wctx->writer->uninit)
594  wctx->writer->uninit(wctx);
595  if (wctx->writer->priv_class)
596  av_opt_free(wctx->priv);
597  }
598  av_freep(&wctx->priv);
599  av_freep(pwctx);
600 }
601 
602 
604 {
605  AVTextWriterContext *wctx;
606  int ret = 0;
607 
608  if (!(wctx = av_mallocz(sizeof(AVTextWriterContext)))) {
609  ret = AVERROR(ENOMEM);
610  goto fail;
611  }
612 
613  if (!(wctx->priv = av_mallocz(writer->priv_size))) {
614  ret = AVERROR(ENOMEM);
615  goto fail;
616  }
617 
618  if (writer->priv_class) {
619  void *priv_ctx = wctx->priv;
620  *(const AVClass **)priv_ctx = writer->priv_class;
621  av_opt_set_defaults(priv_ctx);
622  }
623 
624  wctx->class = &textwriter_class;
625  wctx->writer = writer;
626 
627  av_opt_set_defaults(wctx);
628 
629 
630  if (wctx->writer->init)
631  ret = wctx->writer->init(wctx);
632  if (ret < 0)
633  goto fail;
634 
635  *pwctx = wctx;
636 
637  return 0;
638 
639 fail:
641  return ret;
642 }
643 
645 static void formatters_register_all(void)
646 {
647  static int initialized;
648 
649  if (initialized)
650  return;
651  initialized = 1;
652 
660 }
661 
663 {
665 
666  for (int i = 0; registered_formatters[i]; i++)
667  if (!strcmp(registered_formatters[i]->name, name))
668  return registered_formatters[i];
669 
670  return NULL;
671 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:605
flags
const SwsFlags flags[]
Definition: swscale.c:61
validate_string
static int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
Definition: avtextformat.c:299
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:468
AVTextWriter::init
int(* init)(AVTextWriterContext *wctx)
Definition: avtextwriters.h:40
av_utf8_decode
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...
Definition: avstring.c:368
writercontext_get_writer_name
static const char * writercontext_get_writer_name(void *p)
Definition: avtextformat.c:563
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
use_byte_value_binary_prefix
static int use_byte_value_binary_prefix
Definition: ffprobe.c:131
AV_TEXTFORMAT_PRINT_STRING_OPTIONAL
#define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL
Definition: avtextformat.h:123
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
avtext_print_ts
void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
Definition: avtextformat.c:485
av_clip
#define av_clip
Definition: common.h:100
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1678
AVTextFormatSection::entries_to_show
AVDictionary * entries_to_show
Definition: avtextformat.h:52
AVERROR
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 they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
unit_value::i
int64_t i
Definition: avtextformat.c:355
textcontext_options
static const AVOption textcontext_options[]
Definition: avtextformat.c:65
opt.h
AVTextFormatContext::section
const struct AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:106
AVTextWriter::priv_size
int priv_size
private size for the writer private class
Definition: avtextwriters.h:37
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
AV_HASH_MAX_SIZE
#define AV_HASH_MAX_SIZE
Maximum value that av_hash_get_size() will currently return.
Definition: hash.h:156
AVTextFormatContext::nb_item_type
unsigned int nb_item_type[SECTION_MAX_NB_LEVELS][SECTION_MAX_NB_SECTIONS]
Definition: avtextformat.h:103
int64_t
long long int64_t
Definition: coverity.c:34
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:356
avtextformatter_compact
const AVTextFormatter avtextformatter_compact
Definition: tf_compact.c:238
AV_TEXTFORMAT_STRING_VALIDATION_NB
@ AV_TEXTFORMAT_STRING_VALIDATION_NB
Definition: avtextformat.h:66
avtext_print_data_hash
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size)
Definition: avtextformat.c:522
AVOption
AVOption.
Definition: opt.h:429
data
const char data[16]
Definition: mxf.c:149
AVTextFormatContext::show_value_unit
int show_value_unit
Definition: avtextformat.h:111
AVTextWriterContext
Definition: avtextwriters.h:47
avtextformat.h
AVTextFormatContext
Definition: avtextformat.h:88
AVTextWriterContext::priv
void * priv
private data for use by the writer
Definition: avtextwriters.h:51
AVDictionary
Definition: dict.c:32
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
textcontext_class
static const AVClass textcontext_class
Definition: avtextformat.c:86
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
show_optional_fields
static int show_optional_fields
Definition: ffprobe.c:138
macros.h
fail
#define fail()
Definition: checkasm.h:194
av_hash_get_name
const char * av_hash_get_name(const AVHashContext *ctx)
Definition: hash.c:104
textcontext_get_formatter_name
static const char * textcontext_get_formatter_name(void *p)
Definition: avtextformat.c:57
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1949
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
val
static double val(void *priv, double ch)
Definition: aeval.c:77
si_prefixes
static const struct @11 si_prefixes[]
AVTextFormatSection::show_all_entries
int show_all_entries
Definition: avtextformat.h:54
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:835
AV_TEXTFORMAT_PRINT_STRING_VALIDATE
#define AV_TEXTFORMAT_PRINT_STRING_VALIDATE
Definition: avtextformat.h:124
AVRational::num
int num
Numerator.
Definition: rational.h:59
avtext_print_integer
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val)
Definition: avtextformat.c:288
AVTextFormatContext::writer
AVTextWriterContext * writer
the AVTextWriterContext
Definition: avtextformat.h:91
avassert.h
SECTION_ID_NONE
#define SECTION_ID_NONE
Definition: avtextformat.c:37
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:134
unit_bit_per_second_str
static const char unit_bit_per_second_str[]
Definition: avtextformat.c:254
AVTextFormatContext::sections
const struct AVTextFormatSection * sections
array containing all sections
Definition: avtextformat.h:96
initialized
static int initialized
Definition: vaapi_transcode.c:43
AVTextFormatter::print_string
void(* print_string)(AVTextFormatContext *tctx, const char *, const char *)
Definition: avtextformat.h:81
textcontext_child_next
static void * textcontext_child_next(void *obj, void *prev)
Definition: avtextformat.c:78
intreadwrite.h
AVTextFormatter
Definition: avtextformat.h:69
SECTION_MAX_NB_SECTIONS
#define SECTION_MAX_NB_SECTIONS
Definition: avtextformat.h:86
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
AVTextWriterContext::class
const AVClass * class
class of the writer
Definition: avtextwriters.h:48
AVDictionaryEntry::key
char * key
Definition: dict.h:91
AVTextFormatSection
Definition: avtextformat.h:37
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
av_hash_alloc
int av_hash_alloc(AVHashContext **ctx, const char *name)
Allocate a hash context for the algorithm specified by name.
Definition: hash.c:114
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
avtextformatter_ini
const AVTextFormatter avtextformatter_ini
Definition: tf_ini.c:151
limits.h
value_string
static char * value_string(AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
Definition: avtextformat.c:359
AVTextWriter::priv_class
const AVClass * priv_class
private class of the writer, if any
Definition: avtextwriters.h:36
AVTextFormatContext::priv
void * priv
private data for use by the filter
Definition: avtextformat.h:94
key
const char * key
Definition: hwcontext_opencl.c:189
bin_str
const char * bin_str
Definition: avtextformat.c:46
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
dec_val
double dec_val
Definition: avtextformat.c:45
AVTextFormatSection::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition: avtextformat.h:51
opts
AVDictionary * opts
Definition: movenc.c:51
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
NULL
#define NULL
Definition: coverity.c:32
avtext_print_string
int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
Definition: avtextformat.c:423
av_hash_names
const char * av_hash_names(int i)
Get the names of available hash algorithms.
Definition: hash.c:98
unit_second_str
static const char unit_second_str[]
Definition: avtextformat.c:251
av_hash_init
void av_hash_init(AVHashContext *ctx)
Initialize or reset a hash context.
Definition: hash.c:151
SHOW_OPTIONAL_FIELDS_AUTO
#define SHOW_OPTIONAL_FIELDS_AUTO
Definition: avtextformat.c:39
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
bprint_bytes
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
Definition: avtextformat.c:94
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:360
AVTextWriter::name
const char * name
Definition: avtextwriters.h:38
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
av_hash_update
void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
Update a hash context with additional data.
Definition: hash.c:172
avtext_get_formatter_by_name
const AVTextFormatter * avtext_get_formatter_by_name(const char *name)
Definition: avtextformat.c:662
index
int index
Definition: gxfenc.c:90
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:85
av_hash_freep
void av_hash_freep(AVHashContext **ctx)
Free hash context and set hash context pointer to NULL.
Definition: hash.c:248
error.h
formatters_register_all
static void formatters_register_all(void)
Definition: avtextformat.c:645
show_value_unit
static int show_value_unit
Definition: ffprobe.c:129
dec_str
const char * dec_str
Definition: avtextformat.c:47
avtextformatter_flat
const AVTextFormatter avtextformatter_flat
Definition: tf_flat.c:162
avtextwriter_context_open
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
Definition: avtextformat.c:603
AVTextWriter
Definition: avtextwriters.h:35
unit_hertz_str
static const char unit_hertz_str[]
Definition: avtextformat.c:252
AV_TEXTFORMAT_STRING_VALIDATION_FAIL
@ AV_TEXTFORMAT_STRING_VALIDATION_FAIL
Definition: avtextformat.h:63
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
AVTextFormatter::name
const char * name
Definition: avtextformat.h:72
avtext_print_section_footer
void avtext_print_section_footer(AVTextFormatContext *tctx)
Definition: avtextformat.c:272
AVTextWriterContext::writer
const AVTextWriter * writer
Definition: avtextwriters.h:49
size
int size
Definition: twinvq_data.h:10344
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
AVTextFormatContext::use_value_sexagesimal_format
int use_value_sexagesimal_format
Definition: avtextformat.h:114
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
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
unit_value
Definition: avtextformat.c:354
SHOW_OPTIONAL_FIELDS_NEVER
#define SHOW_OPTIONAL_FIELDS_NEVER
Definition: avtextformat.c:40
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
offset
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 offset
Definition: writing_filters.txt:86
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:233
textwriter_class
static const AVClass textwriter_class
Definition: avtextformat.c:577
avtext_print_rational
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
Definition: avtextformat.c:460
unit_value::unit
const char * unit
Definition: avtextformat.c:356
AVTextFormatContext::class
const AVClass * class
class of the formatter
Definition: avtextformat.h:89
bprint.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
registered_formatters
static const AVTextFormatter * registered_formatters[7+1]
Definition: avtextformat.c:644
unit_value::val
union unit_value::@12 val
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
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
avtextformatter_xml
const AVTextFormatter avtextformatter_xml
Definition: tf_xml.c:207
AVTextFormatter::uninit
void(* uninit)(AVTextFormatContext *tctx)
Definition: avtextformat.h:75
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVTextWriter::uninit
void(* uninit)(AVTextWriterContext *wctx)
Definition: avtextwriters.h:41
AVTextFormatContext::string_validation_utf8_flags
unsigned int string_validation_utf8_flags
Definition: avtextformat.h:120
avtextwriter_context_close
void avtextwriter_context_close(AVTextWriterContext **pwctx)
Definition: avtextformat.c:585
writercontext_child_next
static void * writercontext_child_next(void *obj, void *prev)
Definition: avtextformat.c:569
use_value_sexagesimal_format
static int use_value_sexagesimal_format
Definition: ffprobe.c:132
avtextformatter_json
const AVTextFormatter avtextformatter_json
Definition: tf_json.c:202
log2
#define log2(x)
Definition: libm.h:406
AVTextFormatter::print_section_footer
void(* print_section_footer)(AVTextFormatContext *tctx)
Definition: avtextformat.h:78
sections
static struct AVTextFormatSection sections[]
Definition: ffprobe.c:251
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:81
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:99
U
#define U(x)
Definition: vpx_arith.h:37
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
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:537
AVTextFormatContext::string_validation
int string_validation
Definition: avtextformat.h:118
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
av_dict_parse_string
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.
Definition: dict.c:210
AVTextFormatter::init
int(* init)(AVTextFormatContext *tctx)
Definition: avtextformat.h:74
unit_byte_str
static const char unit_byte_str[]
Definition: avtextformat.c:253
AVTextFormatContext::use_value_prefix
int use_value_prefix
Definition: avtextformat.h:112
mem.h
avtextformatter_csv
const AVTextFormatter avtextformatter_csv
Definition: tf_compact.c:269
av_hash_final_hex
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...
Definition: hash.c:225
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
avtext_context_close
void avtext_context_close(AVTextFormatContext **ptctx)
Definition: avtextformat.c:102
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:90
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
int32_t
int32_t
Definition: audioconvert.c:56
OFFSET
#define OFFSET(x)
Definition: avtextformat.c:63
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
av_bprint_chars
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
Definition: bprint.c:145
AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
@ AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
Definition: avtextformat.h:64
AVDictionaryEntry::value
char * value
Definition: dict.h:92
show_data_hash
static char * show_data_hash
Definition: ffprobe.c:142
bin_val
double bin_val
Definition: avtextformat.c:44
AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
Definition: avtextformat.h:59
AV_OPT_TYPE_STRING
@ 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...
Definition: opt.h:276
avtext_print_unit_int
void avtext_print_unit_int(AVTextFormatContext *tctx, const char *key, int value, const char *unit)
Definition: avtextformat.c:413
unit_value::d
double d
Definition: avtextformat.c:355
av_bprint_append_data
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:163
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
snprintf
#define snprintf
Definition: snprintf.h:34
avtext_print_data
void avtext_print_data(AVTextFormatContext *tctx, const char *name, const uint8_t *data, int size)
Definition: avtextformat.c:494
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:42
src
#define src
Definition: vp8dsp.c:248
AVTextFormatContext::nb_sections
int nb_sections
number of sections
Definition: avtextformat.h:97
AVTextFormatContext::hash
struct AVHashContext * hash
Definition: avtextformat.h:116
avtext_print_section_header
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
Definition: avtextformat.c:257
AVTextFormatContext::string_validation_replacement
char * string_validation_replacement
Definition: avtextformat.h:119