FFmpeg
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 <inttypes.h>
22 #include <limits.h>
23 #include <math.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <string.h>
27 
28 #include "libavutil/mem.h"
29 #include "libavutil/avassert.h"
30 #include "libavutil/avutil.h"
31 #include "libavutil/base64.h"
32 #include "libavutil/bprint.h"
33 #include "libavutil/common.h"
34 #include "libavutil/error.h"
35 #include "libavutil/hash.h"
36 #include "libavutil/macros.h"
37 #include "libavutil/opt.h"
38 #include "avtextformat.h"
39 
40 #define SECTION_ID_NONE (-1)
41 
42 #define SHOW_OPTIONAL_FIELDS_AUTO (-1)
43 #define SHOW_OPTIONAL_FIELDS_NEVER 0
44 #define SHOW_OPTIONAL_FIELDS_ALWAYS 1
45 
46 static const struct {
47  double bin_val;
48  double dec_val;
49  char bin_str[4];
50  char dec_str[4];
51 } si_prefixes[] = {
52  { 1.0, 1.0, "", "" },
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" },
58 };
59 
60 static const char *textcontext_get_formatter_name(void *p)
61 {
62  AVTextFormatContext *tctx = p;
63  return tctx->formatter->name;
64 }
65 
66 #define OFFSET(x) offsetof(AVTextFormatContext, x)
67 
68 static const AVOption textcontext_options[] = {
69  { "string_validation", "set string validation mode",
70  OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
71  { "sv", "set string validation mode",
72  OFFSET(string_validation), AV_OPT_TYPE_INT, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, 0, AV_TEXTFORMAT_STRING_VALIDATION_NB - 1, .unit = "sv" },
73  { "ignore", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_IGNORE }, .unit = "sv" },
74  { "replace", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_REPLACE }, .unit = "sv" },
75  { "fail", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_TEXTFORMAT_STRING_VALIDATION_FAIL }, .unit = "sv" },
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" } },
78  { NULL }
79 };
80 
81 static void *textcontext_child_next(void *obj, void *prev)
82 {
83  AVTextFormatContext *ctx = obj;
84  if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
85  return ctx->priv;
86  return NULL;
87 }
88 
89 static const AVClass textcontext_class = {
90  .class_name = "AVTextContext",
91  .item_name = textcontext_get_formatter_name,
92  .option = textcontext_options,
93  .version = LIBAVUTIL_VERSION_INT,
94  .child_next = textcontext_child_next,
95 };
96 
97 static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
98 {
99  av_bprintf(bp, "0X");
100  for (unsigned i = 0; i < ubuf_size; i++)
101  av_bprintf(bp, "%02X", ubuf[i]);
102 }
103 
105 {
106  AVTextFormatContext *tctx = *ptctx;
107  int ret = 0;
108 
109  if (!tctx)
110  return AVERROR(EINVAL);
111 
112  av_hash_freep(&tctx->hash);
113 
114  if (tctx->formatter) {
115  if (tctx->formatter->uninit)
116  ret = tctx->formatter->uninit(tctx);
117  if (tctx->formatter->priv_class)
118  av_opt_free(tctx->priv);
119  }
120  for (int i = 0; i < SECTION_MAX_NB_LEVELS; i++)
122  av_freep(&tctx->priv);
123  av_opt_free(tctx);
124  av_freep(ptctx);
125  return ret;
126 }
127 
128 
129 int avtext_context_open(AVTextFormatContext **ptctx, const AVTextFormatter *formatter, AVTextWriterContext *writer_context, const char *args,
131 {
132  AVTextFormatContext *tctx;
133  int ret = 0;
134 
135  av_assert0(ptctx && formatter);
136 
137  if (!(tctx = av_mallocz(sizeof(AVTextFormatContext)))) {
138  ret = AVERROR(ENOMEM);
139  goto fail;
140  }
141 
142  for (int i = 0; i < SECTION_MAX_NB_LEVELS; i++)
144 
145  tctx->class = &textcontext_class;
146  av_opt_set_defaults(tctx);
147 
148  if (!(tctx->priv = av_mallocz(formatter->priv_size))) {
149  ret = AVERROR(ENOMEM);
150  goto fail;
151  }
152 
153  tctx->opts = options;
154 
155  if (nb_sections > SECTION_MAX_NB_SECTIONS) {
156  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);
157  ret = AVERROR(EINVAL);
158  goto fail;
159  }
160 
161  tctx->formatter = formatter;
162  tctx->level = -1;
163  tctx->sections = sections;
164  tctx->nb_sections = nb_sections;
165  tctx->writer = writer_context;
166 
167  if (formatter->priv_class) {
168  void *priv_ctx = tctx->priv;
169  *(const AVClass **)priv_ctx = formatter->priv_class;
170  av_opt_set_defaults(priv_ctx);
171  }
172 
173  /* convert options to dictionary */
174  if (args) {
176  const AVDictionaryEntry *opt = NULL;
177 
178  if ((ret = av_dict_parse_string(&opts, args, "=", ":", 0)) < 0) {
179  av_log(tctx, AV_LOG_ERROR, "Failed to parse option string '%s' provided to textformat context\n", args);
180  av_dict_free(&opts);
181  goto fail;
182  }
183 
184  while ((opt = av_dict_iterate(opts, opt))) {
185  if ((ret = av_opt_set(tctx, opt->key, opt->value, AV_OPT_SEARCH_CHILDREN)) < 0) {
186  av_log(tctx, AV_LOG_ERROR, "Failed to set option '%s' with value '%s' provided to textformat context\n",
187  opt->key, opt->value);
188  av_dict_free(&opts);
189  goto fail;
190  }
191  }
192 
193  av_dict_free(&opts);
194  }
195 
196  if (show_data_hash) {
197  if ((ret = av_hash_alloc(&tctx->hash, show_data_hash)) < 0) {
198  if (ret == AVERROR(EINVAL)) {
199  const char *n;
200  av_log(NULL, AV_LOG_ERROR, "Unknown hash algorithm '%s'\nKnown algorithms:", show_data_hash);
201  for (unsigned i = 0; (n = av_hash_names(i)); i++)
202  av_log(NULL, AV_LOG_ERROR, " %s", n);
203  av_log(NULL, AV_LOG_ERROR, "\n");
204  }
205  goto fail;
206  }
207  }
208 
209  /* validate replace string */
210  {
211  const uint8_t *p = (uint8_t *)tctx->string_validation_replacement;
212  const uint8_t *endp = p + strlen((const char *)p);
213  while (*p) {
214  const uint8_t *p0 = p;
215  int32_t code;
217  if (ret < 0) {
218  AVBPrint bp;
220  bprint_bytes(&bp, p0, p - p0);
221  av_log(tctx, AV_LOG_ERROR,
222  "Invalid UTF8 sequence %s found in string validation replace '%s'\n",
223  bp.str, tctx->string_validation_replacement);
224  goto fail;
225  }
226  }
227  }
228 
229  if (tctx->formatter->init)
230  ret = tctx->formatter->init(tctx);
231  if (ret < 0)
232  goto fail;
233 
234  *ptctx = tctx;
235 
236  return 0;
237 
238 fail:
239  avtext_context_close(&tctx);
240  return ret;
241 }
242 
243 static const char unit_second_str[] = "s";
244 
245 void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
246 {
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);
249  return;
250  }
251 
252  tctx->level++;
254 
255  tctx->nb_item[tctx->level] = 0;
256  memset(tctx->nb_item_type[tctx->level], 0, sizeof(tctx->nb_item_type[tctx->level]));
257  tctx->section[tctx->level] = &tctx->sections[section_id];
258 
259  if (tctx->formatter->print_section_header)
260  tctx->formatter->print_section_header(tctx, data);
261 }
262 
264 {
265  if (tctx->level < 0 || tctx->level >= SECTION_MAX_NB_LEVELS) {
266  av_log(tctx, AV_LOG_ERROR, "Invalid level for section_footer: %d\n", tctx->level);
267  return;
268  }
269 
270  int section_id = tctx->section[tctx->level]->id;
271  int parent_section_id = tctx->level ?
272  tctx->section[tctx->level - 1]->id : SECTION_ID_NONE;
273 
274  if (parent_section_id != SECTION_ID_NONE) {
275  tctx->nb_item[tctx->level - 1]++;
276  tctx->nb_item_type[tctx->level - 1][section_id]++;
277  }
278 
279  if (tctx->formatter->print_section_footer)
280  tctx->formatter->print_section_footer(tctx);
281  tctx->level--;
282 }
283 
285 {
286  av_assert0(tctx);
287 
289  return;
290 
294  return;
295 
296  av_assert0(key && tctx->level >= 0 && tctx->level < SECTION_MAX_NB_LEVELS);
297 
298  if (!tctx->opts.is_key_selected || tctx->opts.is_key_selected(tctx, key)) {
299  tctx->formatter->print_integer(tctx, key, val);
300  tctx->nb_item[tctx->level]++;
301  }
302 }
303 
304 static inline int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
305 {
306  const uint8_t *p, *endp, *srcp = (const uint8_t *)src;
307  AVBPrint dstbuf;
308  AVBPrint invalid_seq;
309  int invalid_chars_nb = 0, ret = 0;
310 
311  *dstp = NULL;
313  av_bprint_init(&invalid_seq, 0, AV_BPRINT_SIZE_UNLIMITED);
314 
315  endp = srcp + strlen(src);
316  for (p = srcp; *p;) {
317  int32_t code;
318  int invalid = 0;
319  const uint8_t *p0 = p;
320 
321  if (av_utf8_decode(&code, &p, endp, tctx->string_validation_utf8_flags) < 0) {
322 
323  av_bprint_clear(&invalid_seq);
324 
325  bprint_bytes(&invalid_seq, p0, p - p0);
326 
327  av_log(tctx, AV_LOG_DEBUG, "Invalid UTF-8 sequence '%s' found in string '%s'\n", invalid_seq.str, src);
328  invalid = 1;
329  }
330 
331  if (invalid) {
332  invalid_chars_nb++;
333 
334  switch (tctx->string_validation) {
336  av_log(tctx, AV_LOG_ERROR, "Invalid UTF-8 sequence found in string '%s'\n", src);
338  goto end;
339 
341  av_bprintf(&dstbuf, "%s", tctx->string_validation_replacement);
342  break;
343  }
344  }
345 
347  av_bprint_append_data(&dstbuf, p0, p-p0);
348  }
349 
350  if (invalid_chars_nb && tctx->string_validation == AV_TEXTFORMAT_STRING_VALIDATION_REPLACE)
351  av_log(tctx, AV_LOG_WARNING,
352  "%d invalid UTF-8 sequence(s) found in string '%s', replaced with '%s'\n",
353  invalid_chars_nb, src, tctx->string_validation_replacement);
354 
355 end:
356  av_bprint_finalize(&dstbuf, dstp);
357  av_bprint_finalize(&invalid_seq, NULL);
358  return ret;
359 }
360 
361 struct unit_value {
362  union {
363  double d;
365  } val;
366 
368  const char *unit;
369 };
370 
371 static const char float_fmt_full[] = "%f";
372 static const char float_fmt_singledigit[] = "%.1f";
373 static char *value_string(const AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
374 {
375  double vald;
376  int64_t vali = 0;
377  const char *float_fmt = 0;
378 
380  vald = 20 * log10(uv.val.d);
381  float_fmt = float_fmt_singledigit;
382  } else if (uv.fmt >= AV_TEXTFORMAT_VALUE_FMT_DOUBLE) {
383  vald = uv.val.d;
384  float_fmt = float_fmt_full;
385  } else {
386  vald = (double)uv.val.i;
387  vali = uv.val.i;
388  }
389 
391  double secs;
392  int hours, mins;
393  secs = vald;
394  mins = (int)secs / 60;
395  secs = secs - mins * 60;
396  hours = mins / 60;
397  mins %= 60;
398  snprintf(buf, buf_size, "%d:%02d:%09.6f", hours, mins, secs);
399  } else {
400  const char *prefix_string = "";
401 
402  if (tctx->opts.use_value_prefix && vald > 1) {
403  int64_t index;
404 
406  index = (int64_t)(log2(vald) / 10);
408  vald /= si_prefixes[index].bin_val;
409  prefix_string = si_prefixes[index].bin_str;
410  } else {
411  index = (int64_t)(log10(vald) / 3);
413  vald /= si_prefixes[index].dec_val;
414  prefix_string = si_prefixes[index].dec_str;
415  }
416  vali = (int64_t)vald;
417  }
418 
419  if (float_fmt || (tctx->opts.use_value_prefix && vald != (int64_t)vald))
420  snprintf(buf, buf_size, float_fmt ? float_fmt : "%f", vald);
421  else
422  snprintf(buf, buf_size, "%"PRId64, vali);
423 
424  av_strlcatf(buf, buf_size, "%s%s%s", *prefix_string || tctx->opts.show_value_unit && uv.unit && *uv.unit ? " " : "",
425  prefix_string, tctx->opts.show_value_unit && uv.unit ? uv.unit : "");
426  }
427 
428  return buf;
429 }
430 
431 
432 void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, AVTextFormatValueFormat fmt, const char *unit)
433 {
434  char val_str[128];
435  struct unit_value uv;
436 
438 
439  uv.val.i = val;
440  uv.fmt = fmt;
441  uv.unit = unit;
442  avtext_print_string(tctx, key, value_string(tctx, val_str, sizeof(val_str), uv), 0);
443 }
444 
445 
447 {
448  char val_str[128];
449  struct unit_value uv;
450 
452 
453  uv.val.d = val;
454  uv.fmt = fmt;
455  uv.unit = unit;
456  avtext_print_string(tctx, key, value_string(tctx, val_str, sizeof(val_str), uv), 0);
457 }
458 
459 int avtext_print_string(AVTextFormatContext *tctx, const char *key, const char *val, int flags)
460 {
461  const AVTextFormatSection *section;
462  int ret = 0;
463 
464  av_assert0(key && val && tctx->level >= 0 && tctx->level < SECTION_MAX_NB_LEVELS);
465 
466  section = tctx->section[tctx->level];
467 
469  return 0;
470 
474  return 0;
475 
476  if (!tctx->opts.is_key_selected || tctx->opts.is_key_selected(tctx, key)) {
478  char *key1 = NULL, *val1 = NULL;
479  ret = validate_string(tctx, &key1, key);
480  if (ret < 0) goto end;
481  ret = validate_string(tctx, &val1, val);
482  if (ret < 0) goto end;
483  tctx->formatter->print_string(tctx, key1, val1);
484  end:
485  if (ret < 0)
486  av_log(tctx, AV_LOG_ERROR,
487  "Invalid key=value string combination %s=%s in section %s\n",
488  key, val, section->unique_name);
489  av_free(key1);
490  av_free(val1);
491  } else {
492  tctx->formatter->print_string(tctx, key, val);
493  }
494 
495  tctx->nb_item[tctx->level]++;
496  }
497 
498  return ret;
499 }
500 
501 void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
502 {
503  char buf[44];
504  snprintf(buf, sizeof(buf), "%d%c%d", q.num, sep, q.den);
505  avtext_print_string(tctx, key, buf, 0);
506 }
507 
508 void avtext_print_time(AVTextFormatContext *tctx, const char *key,
509  int64_t ts, const AVRational *time_base, int is_duration)
510 {
511  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0)) {
513  } else {
514  char buf[128];
515  double d = av_q2d(*time_base) * ts;
516  struct unit_value uv;
517  uv.val.d = d;
519  uv.unit = unit_second_str;
520  value_string(tctx, buf, sizeof(buf), uv);
521  avtext_print_string(tctx, key, buf, 0);
522  }
523 }
524 
525 void avtext_print_ts(AVTextFormatContext *tctx, const char *key, int64_t ts, int is_duration)
526 {
527  if ((!is_duration && ts == AV_NOPTS_VALUE) || (is_duration && ts == 0))
529  else
530  avtext_print_integer(tctx, key, ts, 0);
531 }
532 
533 static void print_data_xxd(AVBPrint *bp, const uint8_t *data, int size)
534 {
535  unsigned offset = 0;
536  int i;
537 
538  av_bprintf(bp, "\n");
539  while (size) {
540  av_bprintf(bp, "%08x: ", offset);
541  int l = FFMIN(size, 16);
542  for (i = 0; i < l; i++) {
543  av_bprintf(bp, "%02x", data[i]);
544  if (i & 1)
545  av_bprintf(bp, " ");
546  }
547  av_bprint_chars(bp, ' ', 41 - 2 * i - i / 2);
548  for (i = 0; i < l; i++)
549  av_bprint_chars(bp, data[i] - 32U < 95 ? data[i] : '.', 1);
550  av_bprintf(bp, "\n");
551  offset += l;
552  data += l;
553  size -= l;
554  }
555 }
556 
557 static void print_data_base64(AVBPrint *bp, const uint8_t *data, int size)
558 {
559  char buf[AV_BASE64_SIZE(60)];
560 
561  av_bprintf(bp, "\n");
562  while (size) {
563  int l = FFMIN(size, 60);
564  av_base64_encode(buf, sizeof(buf), data, l);
565  av_bprintf(bp, "%s\n", buf);
566  data += l;
567  size -= l;
568  }
569 }
570 void avtext_print_data(AVTextFormatContext *tctx, const char *key,
571  const uint8_t *data, int size)
572 {
573  AVBPrint bp;
575  switch (tctx->opts.data_dump_format) {
577  print_data_xxd(&bp, data, size);
578  break;
580  print_data_base64(&bp, data, size);
581  break;
582  default:
583  av_unreachable("Invalid data dump type");
584  }
585  avtext_print_string(tctx, key, bp.str, 0);
586  av_bprint_finalize(&bp, NULL);
587 }
588 
590  const uint8_t *data, int size)
591 {
592  char buf[AV_HASH_MAX_SIZE * 2 + 64] = { 0 };
593  int len;
594 
595  if (!tctx->hash)
596  return;
597 
598  av_hash_init(tctx->hash);
599  av_hash_update(tctx->hash, data, size);
600  len = snprintf(buf, sizeof(buf), "%s:", av_hash_get_name(tctx->hash));
601  av_hash_final_hex(tctx->hash, (uint8_t *)&buf[len], (int)sizeof(buf) - len);
602  avtext_print_string(tctx, key, buf, 0);
603 }
604 
605 static const char *writercontext_get_writer_name(void *p)
606 {
607  AVTextWriterContext *wctx = p;
608  return wctx->writer->name;
609 }
610 
611 static void *writercontext_child_next(void *obj, void *prev)
612 {
613  AVTextFormatContext *ctx = obj;
614  if (!prev && ctx->formatter && ctx->formatter->priv_class && ctx->priv)
615  return ctx->priv;
616  return NULL;
617 }
618 
619 static const AVClass textwriter_class = {
620  .class_name = "AVTextWriterContext",
621  .item_name = writercontext_get_writer_name,
622  .version = LIBAVUTIL_VERSION_INT,
623  .child_next = writercontext_child_next,
624 };
625 
626 
628 {
629  AVTextWriterContext *wctx = *pwctx;
630  int ret = 0;
631 
632  if (!wctx)
633  return AVERROR(EINVAL);
634 
635  if (wctx->writer) {
636  if (wctx->writer->uninit)
637  ret = wctx->writer->uninit(wctx);
638  if (wctx->writer->priv_class)
639  av_opt_free(wctx->priv);
640  }
641  av_freep(&wctx->priv);
642  av_freep(pwctx);
643  return ret;
644 }
645 
646 
648 {
649  AVTextWriterContext *wctx;
650  int ret = 0;
651 
652  if (!pwctx || !writer)
653  return AVERROR(EINVAL);
654 
655  if (!((wctx = av_mallocz(sizeof(AVTextWriterContext))))) {
656  ret = AVERROR(ENOMEM);
657  goto fail;
658  }
659 
660  if (writer->priv_size && !((wctx->priv = av_mallocz(writer->priv_size)))) {
661  ret = AVERROR(ENOMEM);
662  goto fail;
663  }
664 
665  if (writer->priv_class) {
666  void *priv_ctx = wctx->priv;
667  *(const AVClass **)priv_ctx = writer->priv_class;
668  av_opt_set_defaults(priv_ctx);
669  }
670 
671  wctx->class = &textwriter_class;
672  wctx->writer = writer;
673 
674  av_opt_set_defaults(wctx);
675 
676 
677  if (wctx->writer->init)
678  ret = wctx->writer->init(wctx);
679  if (ret < 0)
680  goto fail;
681 
682  *pwctx = wctx;
683 
684  return 0;
685 
686 fail:
688  return ret;
689 }
690 
691 static const AVTextFormatter *const registered_formatters[] =
692 {
702  NULL
703 };
704 
706 {
707  for (int i = 0; registered_formatters[i]; i++) {
708  const char *end;
709  if (av_strstart(name, registered_formatters[i]->name, &end) &&
710  (*end == '\0' || *end == '='))
711  return registered_formatters[i];
712  }
713 
714  return NULL;
715 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:604
flags
const SwsFlags flags[]
Definition: swscale.c:85
AVTextFormatOptions::use_value_prefix
int use_value_prefix
Definition: avtextformat.h:127
value_string
static char * value_string(const AVTextFormatContext *tctx, char *buf, int buf_size, struct unit_value uv)
Definition: avtextformat.c:373
validate_string
static int validate_string(AVTextFormatContext *tctx, char **dstp, const char *src)
Definition: avtextformat.c:304
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:508
AVTextWriter::init
int(* init)(AVTextWriterContext *wctx)
Definition: avtextwriters.h:35
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:369
writercontext_get_writer_name
static const char * writercontext_get_writer_name(void *p)
Definition: avtextformat.c:605
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
AV_TEXTFORMAT_PRINT_STRING_OPTIONAL
#define AV_TEXTFORMAT_PRINT_STRING_OPTIONAL
Definition: avtextformat.h:172
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:525
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:1671
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:364
textcontext_options
static const AVOption textcontext_options[]
Definition: avtextformat.c:68
opt.h
AVTextFormatContext::opts
AVTextFormatOptions opts
Definition: avtextformat.h:155
AVTextWriter::priv_size
int priv_size
private size for the writer private class
Definition: avtextwriters.h:32
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:148
int64_t
long long int64_t
Definition: coverity.c:34
avtext_print_integer
void avtext_print_integer(AVTextFormatContext *tctx, const char *key, int64_t val, int flags)
Definition: avtextformat.c:284
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
AVOption
AVOption.
Definition: opt.h:428
data
const char data[16]
Definition: mxf.c:149
AVTextWriterContext
Definition: avtextwriters.h:42
avtextformat.h
AVTextFormatContext
Definition: avtextformat.h:133
dec_str
char dec_str[4]
Definition: avtextformat.c:50
AVTextWriterContext::priv
void * priv
private data for use by the writer
Definition: avtextwriters.h:46
AVDictionary
Definition: dict.c:32
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
AV_TEXTFORMAT_VALUE_FMT_SECOND
@ AV_TEXTFORMAT_VALUE_FMT_SECOND
Definition: avtextformat.h:168
textcontext_class
static const AVClass textcontext_class
Definition: avtextformat.c:89
AVTextFormatSection::id
int id
unique id identifying a section
Definition: avtextformat.h:42
avtextformatter_mermaid
const AVTextFormatter avtextformatter_mermaid
Definition: tf_mermaid.c:650
AVTextFormatContext::level
int level
current level, starting from 0
Definition: avtextformat.h:144
AVTextWriter::uninit
int(* uninit)(AVTextWriterContext *wctx)
Definition: avtextwriters.h:36
macros.h
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:60
AV_TEXTFORMAT_DATADUMP_BASE64
@ AV_TEXTFORMAT_DATADUMP_BASE64
Definition: avtextformat.h:94
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1942
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
val
static double val(void *priv, double ch)
Definition: aeval.c:77
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:824
AV_TEXTFORMAT_PRINT_STRING_VALIDATE
#define AV_TEXTFORMAT_PRINT_STRING_VALIDATE
Definition: avtextformat.h:173
AVRational::num
int num
Numerator.
Definition: rational.h:59
av_clip64
#define av_clip64
Definition: common.h:103
AVTextFormatContext::writer
AVTextWriterContext * writer
the AVTextWriterContext
Definition: avtextformat.h:136
AVTextFormatOptions::data_dump_format
AVTextFormatDataDump data_dump_format
Definition: avtextformat.h:130
avassert.h
SECTION_ID_NONE
#define SECTION_ID_NONE
Definition: avtextformat.c:40
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
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
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
registered_formatters
static const AVTextFormatter *const registered_formatters[]
Definition: avtextformat.c:691
float_fmt_full
static const char float_fmt_full[]
Definition: avtextformat.c:371
avtextformatter_default
const AVTextFormatter avtextformatter_default
Definition: tf_default.c:128
print_data_base64
static void print_data_base64(AVBPrint *bp, const uint8_t *data, int size)
Definition: avtextformat.c:557
AVTextFormatter::print_string
void(* print_string)(AVTextFormatContext *tctx, const char *, const char *)
Definition: avtextformat.h:108
textcontext_child_next
static void * textcontext_child_next(void *obj, void *prev)
Definition: avtextformat.c:81
AVTextFormatter
Definition: avtextformat.h:97
SECTION_MAX_NB_SECTIONS
#define SECTION_MAX_NB_SECTIONS
Definition: avtextformat.h:113
avtext_print_data_hash
void avtext_print_data_hash(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
Definition: avtextformat.c:589
AVTextWriterContext::class
const AVClass * class
class of the writer
Definition: avtextwriters.h:43
AVDictionaryEntry::key
char * key
Definition: dict.h:91
avtextwriter_context_close
int avtextwriter_context_close(AVTextWriterContext **pwctx)
Definition: avtextformat.c:627
AVTextFormatSection
Definition: avtextformat.h:41
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
unit_value::fmt
AVTextFormatValueFormat fmt
Definition: avtextformat.c:367
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
bin_str
char bin_str[4]
Definition: avtextformat.c:49
avtextformatter_ini
const AVTextFormatter avtextformatter_ini
Definition: tf_ini.c:140
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:129
limits.h
AVTextWriter::priv_class
const AVClass * priv_class
private class of the writer, if any
Definition: avtextwriters.h:31
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
key
const char * key
Definition: hwcontext_opencl.c:189
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
AVTextFormatter::priv_size
int priv_size
private size for the formatter context
Definition: avtextformat.h:99
dec_val
double dec_val
Definition: avtextformat.c:48
AVTextFormatSection::unique_name
const char * unique_name
unique section name, in case the name is ambiguous
Definition: avtextformat.h:59
fail
#define fail
Definition: test.h:478
opts
static 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:459
av_hash_names
const char * av_hash_names(int i)
Get the names of available hash algorithms.
Definition: hash.c:98
AVTextFormatContext::section
const AVTextFormatSection * section[SECTION_MAX_NB_LEVELS]
section per each level
Definition: avtextformat.h:151
unit_second_str
static const char unit_second_str[]
Definition: avtextformat.c:243
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:42
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:116
AV_TEXTFORMAT_VALUE_FMT_BYTE
@ AV_TEXTFORMAT_VALUE_FMT_BYTE
Definition: avtextformat.h:166
bprint_bytes
static void bprint_bytes(AVBPrint *bp, const uint8_t *ubuf, size_t ubuf_size)
Definition: avtextformat.c:97
AVTextWriter::name
const char * name
Definition: avtextwriters.h:33
AV_TEXTFORMAT_VALUE_FMT_DOUBLE
@ AV_TEXTFORMAT_VALUE_FMT_DOUBLE
Definition: avtextformat.h:167
options
Definition: swscale.c:50
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
double
double
Definition: af_crystalizer.c:132
AVTextFormatContext::formatter
const AVTextFormatter * formatter
the AVTextFormatter of which this is an instance
Definition: avtextformat.h:135
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:705
base64.h
index
int index
Definition: gxfenc.c:90
SECTION_MAX_NB_LEVELS
#define SECTION_MAX_NB_LEVELS
Definition: avtextformat.h:112
avtext_print_unit_double
void avtext_print_unit_double(AVTextFormatContext *tctx, const char *key, double val, AVTextFormatValueFormat fmt, const char *unit)
Definition: avtextformat.c:446
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
avtextformatter_flat
const AVTextFormatter avtextformatter_flat
Definition: tf_flat.c:150
options
const OptionDef options[]
avtextwriter_context_open
int avtextwriter_context_open(AVTextWriterContext **pwctx, const AVTextWriter *writer)
Definition: avtextformat.c:647
AVTextWriter
Definition: avtextwriters.h:30
AV_TEXTFORMAT_STRING_VALIDATION_FAIL
@ AV_TEXTFORMAT_STRING_VALIDATION_FAIL
Definition: avtextformat.h:74
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
AVTextFormatter::name
const char * name
Definition: avtextformat.h:100
avtext_print_section_footer
void avtext_print_section_footer(AVTextFormatContext *tctx)
Definition: avtextformat.c:263
AVTextWriterContext::writer
const AVTextWriter * writer
Definition: avtextwriters.h:44
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
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
unit_value
Definition: avtextformat.c:361
SHOW_OPTIONAL_FIELDS_NEVER
#define SHOW_OPTIONAL_FIELDS_NEVER
Definition: avtextformat.c:43
AVTextFormatter::flags
int flags
a combination or AV_TEXTFORMAT__FLAG_*
Definition: avtextformat.h:109
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
av_strstart
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:36
textwriter_class
static const AVClass textwriter_class
Definition: avtextformat.c:619
AVTextFormatContext::sections
const AVTextFormatSection * sections
array containing all sections
Definition: avtextformat.h:141
unit_value::val
union unit_value::@17 val
avtext_print_rational
void avtext_print_rational(AVTextFormatContext *tctx, const char *key, AVRational q, char sep)
Definition: avtextformat.c:501
unit_value::unit
const char * unit
Definition: avtextformat.c:368
AVTextFormatContext::class
const AVClass * class
class of the formatter
Definition: avtextformat.h:134
bprint.h
AV_BASE64_SIZE
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition: base64.h:66
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
common.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
avtextformatter_xml
const AVTextFormatter avtextformatter_xml
Definition: tf_xml.c:202
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
len
int len
Definition: vorbis_enc_data.h:426
writercontext_child_next
static void * writercontext_child_next(void *obj, void *prev)
Definition: avtextformat.c:611
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:106
AVTextFormatOptions::use_value_sexagesimal_format
int use_value_sexagesimal_format
Definition: avtextformat.h:129
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
avtext_print_unit_integer
void avtext_print_unit_integer(AVTextFormatContext *tctx, const char *key, int64_t val, AVTextFormatValueFormat fmt, const char *unit)
Definition: avtextformat.c:432
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:122
U
#define U(x)
Definition: vpx_arith.h:37
AVTextFormatValueFormat
AVTextFormatValueFormat
Definition: avtextformat.h:164
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
AVTextFormatOptions::show_optional_fields
int show_optional_fields
Definition: avtextformat.h:125
AVTextFormatContext::string_validation
int string_validation
Definition: avtextformat.h:159
AVRational::den
int den
Denominator.
Definition: rational.h:60
AVTextFormatOptions
Definition: avtextformat.h:115
float_fmt_singledigit
static const char float_fmt_singledigit[]
Definition: avtextformat.c:372
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:258
av_bprint_clear
void av_bprint_clear(AVBPrint *buf)
Reset the string to "" but keep internal allocated data.
Definition: bprint.c:227
sections
static const AVTextFormatSection sections[]
Definition: ffprobe.c: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
si_prefixes
static const struct @16 si_prefixes[]
AVTextFormatter::init
int(* init)(AVTextFormatContext *tctx)
Definition: avtextformat.h:102
av_base64_encode
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Definition: base64.c:147
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
AV_TEXTFORMAT_VALUE_FMT_DECIBEL
@ AV_TEXTFORMAT_VALUE_FMT_DECIBEL
Definition: avtextformat.h:169
AVTextFormatOptions::show_value_unit
int show_value_unit
Definition: avtextformat.h:126
avutil.h
print_data_xxd
static void print_data_xxd(AVBPrint *bp, const uint8_t *data, int size)
Definition: avtextformat.c:533
mem.h
avtextformatter_csv
const AVTextFormatter avtextformatter_csv
Definition: tf_compact.c:270
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:147
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:66
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
avtext_print_data
void avtext_print_data(AVTextFormatContext *tctx, const char *key, const uint8_t *data, int size)
Definition: avtextformat.c:570
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:130
AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
@ AV_TEXTFORMAT_STRING_VALIDATION_REPLACE
Definition: avtextformat.h:75
AVDictionaryEntry::value
char * value
Definition: dict.h:92
show_data_hash
static char * show_data_hash
Definition: ffprobe.c:147
bin_val
double bin_val
Definition: avtextformat.c:47
AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
#define AV_TEXTFORMAT_FLAG_SUPPORTS_OPTIONAL_FIELDS
Definition: avtextformat.h:69
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:275
unit_value::d
double d
Definition: avtextformat.c:363
avtext_context_close
int avtext_context_close(AVTextFormatContext **ptctx)
Definition: avtextformat.c:104
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:148
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:298
snprintf
#define snprintf
Definition: snprintf.h:34
avtextformatter_mermaidhtml
const AVTextFormatter avtextformatter_mermaidhtml
Definition: tf_mermaid.c:664
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
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
avtext_print_section_header
void avtext_print_section_header(AVTextFormatContext *tctx, const void *data, int section_id)
Definition: avtextformat.c:245
AVTextFormatContext::string_validation_replacement
char * string_validation_replacement
Definition: avtextformat.h:160