FFmpeg
opt.c
Go to the documentation of this file.
1 /*
2  * AVOptions
3  * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * AVOptions
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27 
28 #include "avutil.h"
29 #include "avassert.h"
30 #include "avstring.h"
31 #include "channel_layout.h"
32 #include "dict.h"
33 #include "eval.h"
34 #include "log.h"
35 #include "mem.h"
36 #include "parseutils.h"
37 #include "pixdesc.h"
38 #include "mathematics.h"
39 #include "opt.h"
40 #include "samplefmt.h"
41 #include "bprint.h"
42 #include "version.h"
43 
44 #include <float.h>
45 
46 #define TYPE_BASE(type) ((type) & ~AV_OPT_TYPE_FLAG_ARRAY)
47 
48 const AVOption *av_opt_next(const void *obj, const AVOption *last)
49 {
50  const AVClass *class;
51  if (!obj)
52  return NULL;
53  class = *(const AVClass**)obj;
54  if (!last && class && class->option && class->option[0].name)
55  return class->option;
56  if (last && last[1].name)
57  return ++last;
58  return NULL;
59 }
60 
61 static const size_t opt_elem_size[] = {
62  [AV_OPT_TYPE_FLAGS] = sizeof(unsigned),
63  [AV_OPT_TYPE_INT] = sizeof(int),
64  [AV_OPT_TYPE_INT64] = sizeof(int64_t),
65  [AV_OPT_TYPE_UINT64] = sizeof(uint64_t),
66  [AV_OPT_TYPE_DOUBLE] = sizeof(double),
67  [AV_OPT_TYPE_FLOAT] = sizeof(float),
68  [AV_OPT_TYPE_STRING] = sizeof(char *),
69  [AV_OPT_TYPE_RATIONAL] = sizeof(AVRational),
70  [AV_OPT_TYPE_BINARY] = sizeof(uint8_t *),
71  [AV_OPT_TYPE_DICT] = sizeof(AVDictionary *),
72  [AV_OPT_TYPE_IMAGE_SIZE] = sizeof(int[2]),
74  [AV_OPT_TYPE_PIXEL_FMT] = sizeof(int),
75  [AV_OPT_TYPE_SAMPLE_FMT] = sizeof(int),
76  [AV_OPT_TYPE_DURATION] = sizeof(int64_t),
77  [AV_OPT_TYPE_COLOR] = sizeof(uint8_t[4]),
79  [AV_OPT_TYPE_BOOL] = sizeof(int),
80 };
81 
82 // option is plain old data
83 static int opt_is_pod(enum AVOptionType type)
84 {
85  switch (type) {
86  case AV_OPT_TYPE_FLAGS:
87  case AV_OPT_TYPE_INT:
88  case AV_OPT_TYPE_INT64:
89  case AV_OPT_TYPE_DOUBLE:
90  case AV_OPT_TYPE_FLOAT:
92  case AV_OPT_TYPE_UINT64:
98  case AV_OPT_TYPE_COLOR:
99  case AV_OPT_TYPE_BOOL:
100  return 1;
101  }
102  return 0;
103 }
104 
105 static uint8_t opt_array_sep(const AVOption *o)
106 {
107  const AVOptionArrayDef *d = o->default_val.arr;
109  return (d && d->sep) ? d->sep : ',';
110 }
111 
112 static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx)
113 {
115  return (uint8_t *)array + idx * opt_elem_size[TYPE_BASE(o->type)];
116 }
117 
118 static unsigned *opt_array_pcount(const void *parray)
119 {
120  return (unsigned *)((const void * const *)parray + 1);
121 }
122 
123 static void opt_free_elem(const AVOption *o, void *ptr)
124 {
125  switch (TYPE_BASE(o->type)) {
126  case AV_OPT_TYPE_STRING:
127  case AV_OPT_TYPE_BINARY:
128  av_freep(ptr);
129  break;
130 
131  case AV_OPT_TYPE_DICT:
132  av_dict_free((AVDictionary **)ptr);
133  break;
134 
137  break;
138 
139  default:
140  break;
141  }
142 }
143 
144 static void opt_free_array(const AVOption *o, void *parray, unsigned *count)
145 {
146  for (unsigned i = 0; i < *count; i++)
147  opt_free_elem(o, opt_array_pelem(o, *(void **)parray, i));
148 
149  av_freep(parray);
150  *count = 0;
151 }
152 
153 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
154 {
155  switch (o->type) {
156  case AV_OPT_TYPE_FLAGS:
157  *intnum = *(unsigned int*)dst;
158  return 0;
160  *intnum = *(enum AVPixelFormat *)dst;
161  return 0;
163  *intnum = *(enum AVSampleFormat *)dst;
164  return 0;
165  case AV_OPT_TYPE_BOOL:
166  case AV_OPT_TYPE_INT:
167  *intnum = *(int *)dst;
168  return 0;
170  case AV_OPT_TYPE_INT64:
171  case AV_OPT_TYPE_UINT64:
172  *intnum = *(int64_t *)dst;
173  return 0;
174  case AV_OPT_TYPE_FLOAT:
175  *num = *(float *)dst;
176  return 0;
177  case AV_OPT_TYPE_DOUBLE:
178  *num = *(double *)dst;
179  return 0;
181  *intnum = ((AVRational *)dst)->num;
182  *den = ((AVRational *)dst)->den;
183  return 0;
184  case AV_OPT_TYPE_CONST:
185  *intnum = o->default_val.i64;
186  return 0;
187  }
188  return AVERROR(EINVAL);
189 }
190 
191 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
192 {
193  const enum AVOptionType type = TYPE_BASE(o->type);
194 
195  if (type != AV_OPT_TYPE_FLAGS &&
196  (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
197  num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
198  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
199  num, o->name, o->min, o->max);
200  return AVERROR(ERANGE);
201  }
202  if (type == AV_OPT_TYPE_FLAGS) {
203  double d = num*intnum/den;
204  if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) {
205  av_log(obj, AV_LOG_ERROR,
206  "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
207  num*intnum/den, o->name);
208  return AVERROR(ERANGE);
209  }
210  }
211 
212  switch (type) {
214  *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
215  break;
217  *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
218  break;
219  case AV_OPT_TYPE_BOOL:
220  case AV_OPT_TYPE_FLAGS:
221  case AV_OPT_TYPE_INT:
222  *(int *)dst = llrint(num / den) * intnum;
223  break;
225  case AV_OPT_TYPE_INT64:{
226  double d = num / den;
227  if (intnum == 1 && d == (double)INT64_MAX) {
228  *(int64_t *)dst = INT64_MAX;
229  } else
230  *(int64_t *)dst = llrint(d) * intnum;
231  break;}
232  case AV_OPT_TYPE_UINT64:{
233  double d = num / den;
234  // We must special case uint64_t here as llrint() does not support values
235  // outside the int64_t range and there is no portable function which does
236  // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double
237  // while INT64_MAX is not
238  if (intnum == 1 && d == (double)UINT64_MAX) {
239  *(uint64_t *)dst = UINT64_MAX;
240  } else if (d > INT64_MAX + 1ULL) {
241  *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum;
242  } else {
243  *(uint64_t *)dst = llrint(d) * intnum;
244  }
245  break;}
246  case AV_OPT_TYPE_FLOAT:
247  *(float *)dst = num * intnum / den;
248  break;
249  case AV_OPT_TYPE_DOUBLE:
250  *(double *)dst = num * intnum / den;
251  break;
254  if ((int) num == num)
255  *(AVRational *)dst = (AVRational) { num *intnum, den };
256  else
257  *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
258  break;
259  default:
260  return AVERROR(EINVAL);
261  }
262  return 0;
263 }
264 
265 static int hexchar2int(char c) {
266  if (c >= '0' && c <= '9')
267  return c - '0';
268  if (c >= 'a' && c <= 'f')
269  return c - 'a' + 10;
270  if (c >= 'A' && c <= 'F')
271  return c - 'A' + 10;
272  return -1;
273 }
274 
275 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
276 {
277  int *lendst = (int *)(dst + 1);
278  uint8_t *bin, *ptr;
279  int len;
280 
281  av_freep(dst);
282  *lendst = 0;
283 
284  if (!val || !(len = strlen(val)))
285  return 0;
286 
287  if (len & 1)
288  return AVERROR(EINVAL);
289  len /= 2;
290 
291  ptr = bin = av_malloc(len);
292  if (!ptr)
293  return AVERROR(ENOMEM);
294  while (*val) {
295  int a = hexchar2int(*val++);
296  int b = hexchar2int(*val++);
297  if (a < 0 || b < 0) {
298  av_free(bin);
299  return AVERROR(EINVAL);
300  }
301  *ptr++ = (a << 4) | b;
302  }
303  *dst = bin;
304  *lendst = len;
305 
306  return 0;
307 }
308 
309 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
310 {
311  av_freep(dst);
312  if (!val)
313  return 0;
314  *dst = av_strdup(val);
315  return *dst ? 0 : AVERROR(ENOMEM);
316 }
317 
318 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
319  opt->type == AV_OPT_TYPE_UINT64 || \
320  opt->type == AV_OPT_TYPE_CONST || \
321  opt->type == AV_OPT_TYPE_FLAGS || \
322  opt->type == AV_OPT_TYPE_INT) \
323  ? opt->default_val.i64 \
324  : opt->default_val.dbl)
325 
326 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
327 {
328  const enum AVOptionType type = TYPE_BASE(o->type);
329  int ret = 0;
330 
332  int num, den;
333  char c;
334  if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
335  if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
336  return ret;
337  ret = 0;
338  }
339  }
340 
341  for (;;) {
342  int i = 0;
343  char buf[256];
344  int cmd = 0;
345  double d;
346  int64_t intnum = 1;
347 
348  if (type == AV_OPT_TYPE_FLAGS) {
349  if (*val == '+' || *val == '-')
350  cmd = *(val++);
351  for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
352  buf[i] = val[i];
353  buf[i] = 0;
354  }
355 
356  {
357  int res;
358  int ci = 0;
359  double const_values[64];
360  const char * const_names[64];
361  int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0;
362  const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags);
363  if (o_named && o_named->type == AV_OPT_TYPE_CONST) {
364  d = DEFAULT_NUMVAL(o_named);
365  if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
366  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n",
367  o_named->name, o_named->help);
368  } else {
369  if (o->unit) {
370  for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
371  if (o_named->type == AV_OPT_TYPE_CONST &&
372  o_named->unit &&
373  !strcmp(o_named->unit, o->unit)) {
374  if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
375  av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
376  return AVERROR_PATCHWELCOME;
377  }
378  const_names [ci ] = o_named->name;
379  const_values[ci++] = DEFAULT_NUMVAL(o_named);
380  }
381  }
382  }
383  const_names [ci ] = "default";
384  const_values[ci++] = DEFAULT_NUMVAL(o);
385  const_names [ci ] = "max";
386  const_values[ci++] = o->max;
387  const_names [ci ] = "min";
388  const_values[ci++] = o->min;
389  const_names [ci ] = "none";
390  const_values[ci++] = 0;
391  const_names [ci ] = "all";
392  const_values[ci++] = ~0;
393  const_names [ci] = NULL;
394  const_values[ci] = 0;
395 
396  res = av_expr_parse_and_eval(&d, i ? buf : val, const_names,
397  const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
398  if (res < 0) {
399  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
400  return res;
401  }
402  }
403  }
404  if (type == AV_OPT_TYPE_FLAGS) {
405  intnum = *(unsigned int*)dst;
406  if (cmd == '+')
407  d = intnum | (int64_t)d;
408  else if (cmd == '-')
409  d = intnum &~(int64_t)d;
410  }
411 
412  if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
413  return ret;
414  val += i;
415  if (!i || !*val)
416  return 0;
417  }
418 }
419 
420 static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
421 {
422  int ret;
423 
424  if (!val || !strcmp(val, "none")) {
425  dst[0] =
426  dst[1] = 0;
427  return 0;
428  }
429  ret = av_parse_video_size(dst, dst + 1, val);
430  if (ret < 0)
431  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
432  return ret;
433 }
434 
435 static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
436 {
437  int ret = av_parse_video_rate(dst, val);
438  if (ret < 0)
439  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
440  return ret;
441 }
442 
443 static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
444 {
445  int ret;
446 
447  if (!val) {
448  return 0;
449  } else {
450  ret = av_parse_color(dst, val, -1, obj);
451  if (ret < 0)
452  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val);
453  return ret;
454  }
455  return 0;
456 }
457 
458 static const char *get_bool_name(int val)
459 {
460  if (val < 0)
461  return "auto";
462  return val ? "true" : "false";
463 }
464 
465 static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
466 {
467  int n;
468 
469  if (!val)
470  return 0;
471 
472  if (!strcmp(val, "auto")) {
473  n = -1;
474  } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
475  n = 1;
476  } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
477  n = 0;
478  } else {
479  char *end = NULL;
480  n = strtol(val, &end, 10);
481  if (val + strlen(val) != end)
482  goto fail;
483  }
484 
485  if (n < o->min || n > o->max)
486  goto fail;
487 
488  *dst = n;
489  return 0;
490 
491 fail:
492  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val);
493  return AVERROR(EINVAL);
494 }
495 
496 static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
497  int fmt_nb, int ((*get_fmt)(const char *)), const char *desc)
498 {
499  int fmt, min, max;
500 
501  if (!val || !strcmp(val, "none")) {
502  fmt = -1;
503  } else {
504  fmt = get_fmt(val);
505  if (fmt == -1) {
506  char *tail;
507  fmt = strtol(val, &tail, 0);
508  if (*tail || (unsigned)fmt >= fmt_nb) {
509  av_log(obj, AV_LOG_ERROR,
510  "Unable to parse option value \"%s\" as %s\n", val, desc);
511  return AVERROR(EINVAL);
512  }
513  }
514  }
515 
516  min = FFMAX(o->min, -1);
517  max = FFMIN(o->max, fmt_nb-1);
518 
519  // hack for compatibility with old ffmpeg
520  if(min == 0 && max == 0) {
521  min = -1;
522  max = fmt_nb-1;
523  }
524 
525  if (fmt < min || fmt > max) {
526  av_log(obj, AV_LOG_ERROR,
527  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
528  fmt, o->name, desc, min, max);
529  return AVERROR(ERANGE);
530  }
531 
532  *(int *)dst = fmt;
533  return 0;
534 }
535 
536 static int get_pix_fmt(const char *name)
537 {
538  return av_get_pix_fmt(name);
539 }
540 
541 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
542 {
543  return set_string_fmt(obj, o, val, dst,
544  AV_PIX_FMT_NB, get_pix_fmt, "pixel format");
545 }
546 
547 static int get_sample_fmt(const char *name)
548 {
549  return av_get_sample_fmt(name);
550 }
551 
552 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
553 {
554  return set_string_fmt(obj, o, val, dst,
555  AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format");
556 }
557 
558 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
559 {
561 
562  if (val) {
563  int ret = av_dict_parse_string(&options, val, "=", ":", 0);
564  if (ret < 0) {
566  return ret;
567  }
568  }
569 
570  av_dict_free((AVDictionary **)dst);
571  *dst = (uint8_t *)options;
572 
573  return 0;
574 }
575 
576 static int set_string_channel_layout(void *obj, const AVOption *o,
577  const char *val, void *dst)
578 {
579  AVChannelLayout *channel_layout = dst;
580  av_channel_layout_uninit(channel_layout);
581  if (!val)
582  return 0;
583  return av_channel_layout_from_string(channel_layout, val);
584 }
585 
586 static int opt_set_elem(void *obj, void *target_obj, const AVOption *o,
587  const char *val, void *dst)
588 {
589  const enum AVOptionType type = TYPE_BASE(o->type);
590  int ret;
591 
592  if (!val && (type != AV_OPT_TYPE_STRING &&
597  return AVERROR(EINVAL);
598 
599  switch (type) {
600  case AV_OPT_TYPE_BOOL:
601  return set_string_bool(obj, o, val, dst);
602  case AV_OPT_TYPE_STRING:
603  return set_string(obj, o, val, dst);
604  case AV_OPT_TYPE_BINARY:
605  return set_string_binary(obj, o, val, dst);
606  case AV_OPT_TYPE_FLAGS:
607  case AV_OPT_TYPE_INT:
608  case AV_OPT_TYPE_INT64:
609  case AV_OPT_TYPE_UINT64:
610  case AV_OPT_TYPE_FLOAT:
611  case AV_OPT_TYPE_DOUBLE:
613  return set_string_number(obj, target_obj, o, val, dst);
615  return set_string_image_size(obj, o, val, dst);
616  case AV_OPT_TYPE_VIDEO_RATE: {
617  AVRational tmp;
618  ret = set_string_video_rate(obj, o, val, &tmp);
619  if (ret < 0)
620  return ret;
621  return write_number(obj, o, dst, 1, tmp.den, tmp.num);
622  }
624  return set_string_pixel_fmt(obj, o, val, dst);
626  return set_string_sample_fmt(obj, o, val, dst);
628  {
629  int64_t usecs = 0;
630  if (val) {
631  if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
632  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
633  return ret;
634  }
635  }
636  if (usecs < o->min || usecs > o->max) {
637  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
638  usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
639  return AVERROR(ERANGE);
640  }
641  *(int64_t *)dst = usecs;
642  return 0;
643  }
644  case AV_OPT_TYPE_COLOR:
645  return set_string_color(obj, o, val, dst);
647  ret = set_string_channel_layout(obj, o, val, dst);
648  if (ret < 0) {
649  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
650  ret = AVERROR(EINVAL);
651  }
652  return ret;
653  case AV_OPT_TYPE_DICT:
654  return set_string_dict(obj, o, val, dst);
655  }
656 
657  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
658  return AVERROR(EINVAL);
659 }
660 
661 static int opt_set_array(void *obj, void *target_obj, const AVOption *o,
662  const char *val, void *dst)
663 {
664  const AVOptionArrayDef *arr = o->default_val.arr;
665  const size_t elem_size = opt_elem_size[TYPE_BASE(o->type)];
666  const uint8_t sep = opt_array_sep(o);
667  uint8_t *str = NULL;
668 
669  void *elems = NULL;
670  unsigned nb_elems = 0;
671  int ret;
672 
673  if (val && *val) {
674  str = av_malloc(strlen(val) + 1);
675  if (!str)
676  return AVERROR(ENOMEM);
677  }
678 
679  // split and unescape the string
680  while (val && *val) {
681  uint8_t *p = str;
682  void *tmp;
683 
684  if (arr && arr->size_max && nb_elems >= arr->size_max) {
685  av_log(obj, AV_LOG_ERROR,
686  "Cannot assign more than %u elements to array option %s\n",
687  arr->size_max, o->name);
688  ret = AVERROR(EINVAL);
689  goto fail;
690  }
691 
692  for (; *val; val++, p++) {
693  if (*val == '\\' && val[1])
694  val++;
695  else if (*val == sep) {
696  val++;
697  break;
698  }
699  *p = *val;
700  }
701  *p = 0;
702 
703  tmp = av_realloc_array(elems, nb_elems + 1, elem_size);
704  if (!tmp) {
705  ret = AVERROR(ENOMEM);
706  goto fail;
707  }
708  elems = tmp;
709 
710  tmp = opt_array_pelem(o, elems, nb_elems);
711  memset(tmp, 0, elem_size);
712 
713  ret = opt_set_elem(obj, target_obj, o, str, tmp);
714  if (ret < 0)
715  goto fail;
716  nb_elems++;
717  }
718  av_freep(&str);
719 
720  opt_free_array(o, dst, opt_array_pcount(dst));
721 
722  if (arr && nb_elems < arr->size_min) {
723  av_log(obj, AV_LOG_ERROR,
724  "Cannot assign fewer than %u elements to array option %s\n",
725  arr->size_min, o->name);
726  ret = AVERROR(EINVAL);
727  goto fail;
728  }
729 
730  *((void **)dst) = elems;
731  *opt_array_pcount(dst) = nb_elems;
732 
733  return 0;
734 fail:
735  av_freep(&str);
736  opt_free_array(o, &elems, &nb_elems);
737  return ret;
738 }
739 
740 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
741 {
742  void *dst, *target_obj;
743  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
744  if (!o || !target_obj)
746 
747  if (o->flags & AV_OPT_FLAG_READONLY)
748  return AVERROR(EINVAL);
749 
750  if (o->flags & AV_OPT_FLAG_DEPRECATED)
751  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
752 
753  dst = ((uint8_t *)target_obj) + o->offset;
754 
755  return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
756  opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst);
757 }
758 
759 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
760 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
761  const char *val, vartype *name ## _out) \
762 { \
763  if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
764  return AVERROR(EINVAL); \
765  return set_string_number(obj, obj, o, val, name ## _out); \
766 }
767 
770 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
771 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
772 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
774 
775 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
776  int search_flags)
777 {
778  void *dst, *target_obj;
779  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
780 
781  if (!o || !target_obj)
783 
785  return AVERROR(EINVAL);
786 
787  dst = ((uint8_t *)target_obj) + o->offset;
788  return write_number(obj, o, dst, num, den, intnum);
789 }
790 
791 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
792 {
793  return set_number(obj, name, 1, 1, val, search_flags);
794 }
795 
796 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
797 {
798  return set_number(obj, name, val, 1, 1, search_flags);
799 }
800 
801 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
802 {
803  return set_number(obj, name, val.num, val.den, 1, search_flags);
804 }
805 
806 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
807 {
808  void *target_obj;
809  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
810  uint8_t *ptr;
811  uint8_t **dst;
812  int *lendst;
813 
814  if (!o || !target_obj)
816 
818  return AVERROR(EINVAL);
819 
820  ptr = len ? av_malloc(len) : NULL;
821  if (len && !ptr)
822  return AVERROR(ENOMEM);
823 
824  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
825  lendst = (int *)(dst + 1);
826 
827  av_free(*dst);
828  *dst = ptr;
829  *lendst = len;
830  if (len)
831  memcpy(ptr, val, len);
832 
833  return 0;
834 }
835 
836 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
837 {
838  void *target_obj;
839  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
840 
841  if (!o || !target_obj)
843  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
844  av_log(obj, AV_LOG_ERROR,
845  "The value set by option '%s' is not an image size.\n", o->name);
846  return AVERROR(EINVAL);
847  }
848  if (w<0 || h<0) {
849  av_log(obj, AV_LOG_ERROR,
850  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
851  return AVERROR(EINVAL);
852  }
853  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
854  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
855  return 0;
856 }
857 
858 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
859 {
860  void *target_obj;
861  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
862 
863  if (!o || !target_obj)
865  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
866  av_log(obj, AV_LOG_ERROR,
867  "The value set by option '%s' is not a video rate.\n",
868  o->name);
869  return AVERROR(EINVAL);
870  }
871  if (val.num <= 0 || val.den <= 0)
872  return AVERROR(EINVAL);
873  return set_number(obj, name, val.num, val.den, 1, search_flags);
874 }
875 
876 static int set_format(void *obj, const char *name, int fmt, int search_flags,
877  enum AVOptionType type, const char *desc, int nb_fmts)
878 {
879  void *target_obj;
880  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
881  search_flags, &target_obj);
882  int min, max;
883 
884  if (!o || !target_obj)
886  if (o->type != type) {
887  av_log(obj, AV_LOG_ERROR,
888  "The value set by option '%s' is not a %s format", name, desc);
889  return AVERROR(EINVAL);
890  }
891 
892  min = FFMAX(o->min, -1);
893  max = FFMIN(o->max, nb_fmts-1);
894 
895  if (fmt < min || fmt > max) {
896  av_log(obj, AV_LOG_ERROR,
897  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
898  fmt, name, desc, min, max);
899  return AVERROR(ERANGE);
900  }
901  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
902  return 0;
903 }
904 
905 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
906 {
907  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
908 }
909 
910 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
911 {
912  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
913 }
914 
915 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
916  int search_flags)
917 {
918  void *target_obj;
919  AVDictionary **dst;
920  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
921 
922  if (!o || !target_obj)
924  if (o->flags & AV_OPT_FLAG_READONLY)
925  return AVERROR(EINVAL);
926 
927  dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
928  av_dict_free(dst);
929  av_dict_copy(dst, val, 0);
930 
931  return 0;
932 }
933 
934 int av_opt_set_chlayout(void *obj, const char *name,
935  const AVChannelLayout *channel_layout,
936  int search_flags)
937 {
938  void *target_obj;
939  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
940  AVChannelLayout *dst;
941 
942  if (!o || !target_obj)
944 
945  dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
946 
947  return av_channel_layout_copy(dst, channel_layout);
948 }
949 
950 static void format_duration(char *buf, size_t size, int64_t d)
951 {
952  char *e;
953 
954  av_assert0(size >= 25);
955  if (d < 0 && d != INT64_MIN) {
956  *(buf++) = '-';
957  size--;
958  d = -d;
959  }
960  if (d == INT64_MAX)
961  snprintf(buf, size, "INT64_MAX");
962  else if (d == INT64_MIN)
963  snprintf(buf, size, "INT64_MIN");
964  else if (d > (int64_t)3600*1000000)
965  snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
966  (int)((d / 60000000) % 60),
967  (int)((d / 1000000) % 60),
968  (int)(d % 1000000));
969  else if (d > 60*1000000)
970  snprintf(buf, size, "%d:%02d.%06d",
971  (int)(d / 60000000),
972  (int)((d / 1000000) % 60),
973  (int)(d % 1000000));
974  else
975  snprintf(buf, size, "%d.%06d",
976  (int)(d / 1000000),
977  (int)(d % 1000000));
978  e = buf + strlen(buf);
979  while (e > buf && e[-1] == '0')
980  *(--e) = 0;
981  if (e > buf && e[-1] == '.')
982  *(--e) = 0;
983 }
984 
985 static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
986  void *dst, int search_flags)
987 {
988  int ret;
989 
990  switch (TYPE_BASE(o->type)) {
991  case AV_OPT_TYPE_BOOL:
992  ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
993  break;
994  case AV_OPT_TYPE_FLAGS:
995  ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
996  break;
997  case AV_OPT_TYPE_INT:
998  ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
999  break;
1000  case AV_OPT_TYPE_INT64:
1001  ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
1002  break;
1003  case AV_OPT_TYPE_UINT64:
1004  ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
1005  break;
1006  case AV_OPT_TYPE_FLOAT:
1007  ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
1008  break;
1009  case AV_OPT_TYPE_DOUBLE:
1010  ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
1011  break;
1013  case AV_OPT_TYPE_RATIONAL:
1014  ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
1015  break;
1016  case AV_OPT_TYPE_CONST:
1017  ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
1018  break;
1019  case AV_OPT_TYPE_STRING:
1020  if (*(uint8_t **)dst) {
1021  *pbuf = av_strdup(*(uint8_t **)dst);
1022  } else if (search_flags & AV_OPT_ALLOW_NULL) {
1023  *pbuf = NULL;
1024  return 0;
1025  } else {
1026  *pbuf = av_strdup("");
1027  }
1028  return *pbuf ? 0 : AVERROR(ENOMEM);
1029  case AV_OPT_TYPE_BINARY: {
1030  const uint8_t *bin;
1031  int len;
1032 
1033  if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1034  *pbuf = NULL;
1035  return 0;
1036  }
1037  len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
1038  if ((uint64_t)len * 2 + 1 > INT_MAX)
1039  return AVERROR(EINVAL);
1040  if (!(*pbuf = av_malloc(len * 2 + 1)))
1041  return AVERROR(ENOMEM);
1042  if (!len) {
1043  *pbuf[0] = '\0';
1044  return 0;
1045  }
1046  bin = *(uint8_t **)dst;
1047  for (int i = 0; i < len; i++)
1048  snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
1049  return 0;
1050  }
1052  ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
1053  break;
1054  case AV_OPT_TYPE_PIXEL_FMT:
1055  ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
1056  break;
1058  ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
1059  break;
1060  case AV_OPT_TYPE_DURATION: {
1061  int64_t i64 = *(int64_t *)dst;
1062  format_duration(*pbuf, buf_len, i64);
1063  ret = strlen(*pbuf); // no overflow possible, checked by an assert
1064  break;
1065  }
1066  case AV_OPT_TYPE_COLOR:
1067  ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
1068  (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
1069  (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
1070  break;
1071  case AV_OPT_TYPE_CHLAYOUT:
1072  ret = av_channel_layout_describe(dst, *pbuf, buf_len);
1073  break;
1074  case AV_OPT_TYPE_DICT:
1075  if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1076  *pbuf = NULL;
1077  return 0;
1078  }
1079  return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
1080  default:
1081  return AVERROR(EINVAL);
1082  }
1083 
1084  return ret;
1085 }
1086 
1087 static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
1088 {
1089  const unsigned count = *opt_array_pcount(dst);
1090  const uint8_t sep = opt_array_sep(o);
1091 
1092  uint8_t *str = NULL;
1093  size_t str_len = 0;
1094  int ret;
1095 
1096  *out_val = NULL;
1097 
1098  for (unsigned i = 0; i < count; i++) {
1099  uint8_t buf[128], *out = buf;
1100  size_t out_len;
1101 
1102  ret = opt_get_elem(o, &out, sizeof(buf),
1103  opt_array_pelem(o, *(void **)dst, i), 0);
1104  if (ret < 0)
1105  goto fail;
1106 
1107  out_len = strlen(out);
1108  if (out_len > SIZE_MAX / 2 - !!i ||
1109  !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
1110  ret = AVERROR(ERANGE);
1111  goto fail;
1112  }
1113 
1114  // terminator escaping separator
1115  // ↓ ↓ ↓
1116  ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
1117  if (ret < 0)
1118  goto fail;
1119 
1120  // add separator if needed
1121  if (i)
1122  str[str_len++] = sep;
1123 
1124  // escape the element
1125  for (unsigned j = 0; j < out_len; j++) {
1126  uint8_t val = out[j];
1127  if (val == sep || val == '\\')
1128  str[str_len++] = '\\';
1129  str[str_len++] = val;
1130  }
1131  str[str_len] = 0;
1132 
1133 fail:
1134  if (out != buf)
1135  av_freep(&out);
1136  if (ret < 0) {
1137  av_freep(&str);
1138  return ret;
1139  }
1140  }
1141 
1142  *out_val = str;
1143 
1144  return 0;
1145 }
1146 
1147 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
1148 {
1149  void *dst, *target_obj;
1150  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1151  uint8_t *out, buf[128];
1152  int ret;
1153 
1154  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
1155  return AVERROR_OPTION_NOT_FOUND;
1156 
1157  if (o->flags & AV_OPT_FLAG_DEPRECATED)
1158  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
1159 
1160  dst = (uint8_t *)target_obj + o->offset;
1161 
1162  if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
1163  ret = opt_get_array(o, dst, out_val);
1164  if (ret < 0)
1165  return ret;
1166  if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) {
1167  *out_val = av_strdup("");
1168  if (!*out_val)
1169  return AVERROR(ENOMEM);
1170  }
1171  return 0;
1172  }
1173 
1174  buf[0] = 0;
1175  out = buf;
1176  ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
1177  if (ret < 0)
1178  return ret;
1179  if (out != buf) {
1180  *out_val = out;
1181  return 0;
1182  }
1183 
1184  if (ret >= sizeof(buf))
1185  return AVERROR(EINVAL);
1186  *out_val = av_strdup(out);
1187  return *out_val ? 0 : AVERROR(ENOMEM);
1188 }
1189 
1190 static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
1191  int search_flags)
1192 {
1193  void *dst, *target_obj;
1194  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1195  if (!o || !target_obj)
1196  return AVERROR_OPTION_NOT_FOUND;
1197  if (o->type & AV_OPT_TYPE_FLAG_ARRAY)
1198  return AVERROR(EINVAL);
1199 
1200  dst = ((uint8_t *)target_obj) + o->offset;
1201 
1202  return read_number(o, dst, num, den, intnum);
1203 }
1204 
1205 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
1206 {
1207  int64_t intnum = 1;
1208  double num = 1;
1209  int ret, den = 1;
1210 
1211  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1212  return ret;
1213  if (num == den)
1214  *out_val = intnum;
1215  else
1216  *out_val = num * intnum / den;
1217  return 0;
1218 }
1219 
1220 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
1221 {
1222  int64_t intnum = 1;
1223  double num = 1;
1224  int ret, den = 1;
1225 
1226  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1227  return ret;
1228  *out_val = num * intnum / den;
1229  return 0;
1230 }
1231 
1232 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1233 {
1234  int64_t intnum = 1;
1235  double num = 1;
1236  int ret, den = 1;
1237 
1238  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1239  return ret;
1240 
1241  if (num == 1.0 && (int)intnum == intnum)
1242  *out_val = (AVRational){intnum, den};
1243  else
1244  *out_val = av_d2q(num*intnum/den, 1<<24);
1245  return 0;
1246 }
1247 
1248 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1249 {
1250  void *dst, *target_obj;
1251  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1252  if (!o || !target_obj)
1253  return AVERROR_OPTION_NOT_FOUND;
1254  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1255  av_log(obj, AV_LOG_ERROR,
1256  "The value for option '%s' is not a image size.\n", name);
1257  return AVERROR(EINVAL);
1258  }
1259 
1260  dst = ((uint8_t*)target_obj) + o->offset;
1261  if (w_out) *w_out = *(int *)dst;
1262  if (h_out) *h_out = *((int *)dst+1);
1263  return 0;
1264 }
1265 
1266 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1267 {
1268  int64_t intnum = 1;
1269  double num = 1;
1270  int ret, den = 1;
1271 
1272  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1273  return ret;
1274 
1275  if (num == 1.0 && (int)intnum == intnum)
1276  *out_val = (AVRational) { intnum, den };
1277  else
1278  *out_val = av_d2q(num * intnum / den, 1 << 24);
1279  return 0;
1280 }
1281 
1282 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
1283  enum AVOptionType type, const char *desc)
1284 {
1285  void *dst, *target_obj;
1286  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1287  if (!o || !target_obj)
1288  return AVERROR_OPTION_NOT_FOUND;
1289  if (o->type != type) {
1290  av_log(obj, AV_LOG_ERROR,
1291  "The value for option '%s' is not a %s format.\n", desc, name);
1292  return AVERROR(EINVAL);
1293  }
1294 
1295  dst = ((uint8_t*)target_obj) + o->offset;
1296  *out_fmt = *(int *)dst;
1297  return 0;
1298 }
1299 
1300 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1301 {
1302  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1303 }
1304 
1305 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1306 {
1307  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1308 }
1309 
1310 int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1311 {
1312  void *dst, *target_obj;
1313  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1314  if (!o || !target_obj)
1315  return AVERROR_OPTION_NOT_FOUND;
1316  if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1317  av_log(obj, AV_LOG_ERROR,
1318  "The value for option '%s' is not a channel layout.\n", name);
1319  return AVERROR(EINVAL);
1320  }
1321 
1322  dst = ((uint8_t*)target_obj) + o->offset;
1323  return av_channel_layout_copy(cl, dst);
1324 }
1325 
1326 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1327 {
1328  void *target_obj;
1329  AVDictionary *src;
1330  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1331 
1332  if (!o || !target_obj)
1333  return AVERROR_OPTION_NOT_FOUND;
1334  if (o->type != AV_OPT_TYPE_DICT)
1335  return AVERROR(EINVAL);
1336 
1337  src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1338  av_dict_copy(out_val, src, 0);
1339 
1340  return 0;
1341 }
1342 
1343 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1344 {
1345  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1346  const AVOption *flag = av_opt_find(obj, flag_name,
1347  field ? field->unit : NULL, 0, 0);
1348  int64_t res;
1349 
1350  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1351  av_opt_get_int(obj, field_name, 0, &res) < 0)
1352  return 0;
1353  return res & flag->default_val.i64;
1354 }
1355 
1356 static void log_int_value(void *av_log_obj, int level, int64_t i)
1357 {
1358  if (i == INT_MAX) {
1359  av_log(av_log_obj, level, "INT_MAX");
1360  } else if (i == INT_MIN) {
1361  av_log(av_log_obj, level, "INT_MIN");
1362  } else if (i == UINT32_MAX) {
1363  av_log(av_log_obj, level, "UINT32_MAX");
1364  } else if (i == INT64_MAX) {
1365  av_log(av_log_obj, level, "I64_MAX");
1366  } else if (i == INT64_MIN) {
1367  av_log(av_log_obj, level, "I64_MIN");
1368  } else {
1369  av_log(av_log_obj, level, "%"PRId64, i);
1370  }
1371 }
1372 
1373 static void log_value(void *av_log_obj, int level, double d)
1374 {
1375  if (d == INT_MAX) {
1376  av_log(av_log_obj, level, "INT_MAX");
1377  } else if (d == INT_MIN) {
1378  av_log(av_log_obj, level, "INT_MIN");
1379  } else if (d == UINT32_MAX) {
1380  av_log(av_log_obj, level, "UINT32_MAX");
1381  } else if (d == (double)INT64_MAX) {
1382  av_log(av_log_obj, level, "I64_MAX");
1383  } else if (d == INT64_MIN) {
1384  av_log(av_log_obj, level, "I64_MIN");
1385  } else if (d == FLT_MAX) {
1386  av_log(av_log_obj, level, "FLT_MAX");
1387  } else if (d == FLT_MIN) {
1388  av_log(av_log_obj, level, "FLT_MIN");
1389  } else if (d == -FLT_MAX) {
1390  av_log(av_log_obj, level, "-FLT_MAX");
1391  } else if (d == -FLT_MIN) {
1392  av_log(av_log_obj, level, "-FLT_MIN");
1393  } else if (d == DBL_MAX) {
1394  av_log(av_log_obj, level, "DBL_MAX");
1395  } else if (d == DBL_MIN) {
1396  av_log(av_log_obj, level, "DBL_MIN");
1397  } else if (d == -DBL_MAX) {
1398  av_log(av_log_obj, level, "-DBL_MAX");
1399  } else if (d == -DBL_MIN) {
1400  av_log(av_log_obj, level, "-DBL_MIN");
1401  } else {
1402  av_log(av_log_obj, level, "%g", d);
1403  }
1404 }
1405 
1406 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1407 {
1408  const AVOption *opt = NULL;
1409 
1410  if (!unit)
1411  return NULL;
1412  while ((opt = av_opt_next(obj, opt)))
1413  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1414  opt->default_val.i64 == value)
1415  return opt->name;
1416  return NULL;
1417 }
1418 
1419 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1420 {
1421  const AVOption *opt = NULL;
1422  char flags[512];
1423 
1424  flags[0] = 0;
1425  if (!unit)
1426  return NULL;
1427  while ((opt = av_opt_next(obj, opt))) {
1428  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1429  opt->default_val.i64 & value) {
1430  if (flags[0])
1431  av_strlcatf(flags, sizeof(flags), "+");
1432  av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1433  }
1434  }
1435  if (flags[0])
1436  return av_strdup(flags);
1437  return NULL;
1438 }
1439 
1440 static void log_type(void *av_log_obj, const AVOption *o,
1441  enum AVOptionType parent_type)
1442 {
1443  const char *desc[] = {
1444  [AV_OPT_TYPE_FLAGS] = "<flags>",
1445  [AV_OPT_TYPE_INT] = "<int>",
1446  [AV_OPT_TYPE_INT64] = "<int64>",
1447  [AV_OPT_TYPE_UINT64] = "<uint64>",
1448  [AV_OPT_TYPE_DOUBLE] = "<double>",
1449  [AV_OPT_TYPE_FLOAT] = "<float>",
1450  [AV_OPT_TYPE_STRING] = "<string>",
1451  [AV_OPT_TYPE_RATIONAL] = "<rational>",
1452  [AV_OPT_TYPE_BINARY] = "<binary>",
1453  [AV_OPT_TYPE_DICT] = "<dictionary>",
1454  [AV_OPT_TYPE_IMAGE_SIZE] = "<image_size>",
1455  [AV_OPT_TYPE_VIDEO_RATE] = "<video_rate>",
1456  [AV_OPT_TYPE_PIXEL_FMT] = "<pix_fmt>",
1457  [AV_OPT_TYPE_SAMPLE_FMT] = "<sample_fmt>",
1458  [AV_OPT_TYPE_DURATION] = "<duration>",
1459  [AV_OPT_TYPE_COLOR] = "<color>",
1460  [AV_OPT_TYPE_CHLAYOUT] = "<channel_layout>",
1461  [AV_OPT_TYPE_BOOL] = "<boolean>",
1462  };
1463  const enum AVOptionType type = TYPE_BASE(o->type);
1464 
1465  if (o->type == AV_OPT_TYPE_CONST && TYPE_BASE(parent_type) == AV_OPT_TYPE_INT)
1466  av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
1467  else if (type < FF_ARRAY_ELEMS(desc) && desc[type]) {
1468  if (o->type & AV_OPT_TYPE_FLAG_ARRAY)
1469  av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", desc[type]);
1470  else
1471  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[type]);
1472  }
1473  else
1474  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1475 }
1476 
1477 static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
1478 {
1479  if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY)
1480  return;
1481  if ((opt->type == AV_OPT_TYPE_COLOR ||
1482  opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1483  opt->type == AV_OPT_TYPE_STRING ||
1484  opt->type == AV_OPT_TYPE_DICT ||
1485  opt->type == AV_OPT_TYPE_CHLAYOUT ||
1486  opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1487  !opt->default_val.str)
1488  return;
1489 
1490  if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1491  const AVOptionArrayDef *arr = opt->default_val.arr;
1492  if (arr && arr->def)
1493  av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def);
1494  return;
1495  }
1496 
1497  av_log(av_log_obj, AV_LOG_INFO, " (default ");
1498  switch (opt->type) {
1499  case AV_OPT_TYPE_BOOL:
1500  av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64));
1501  break;
1502  case AV_OPT_TYPE_FLAGS: {
1503  char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1504  if (def_flags) {
1505  av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1506  av_freep(&def_flags);
1507  } else {
1508  av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1509  }
1510  break;
1511  }
1512  case AV_OPT_TYPE_DURATION: {
1513  char buf[25];
1514  format_duration(buf, sizeof(buf), opt->default_val.i64);
1515  av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1516  break;
1517  }
1518  case AV_OPT_TYPE_INT:
1519  case AV_OPT_TYPE_UINT64:
1520  case AV_OPT_TYPE_INT64: {
1521  const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1522  if (def_const)
1523  av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1524  else
1525  log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1526  break;
1527  }
1528  case AV_OPT_TYPE_DOUBLE:
1529  case AV_OPT_TYPE_FLOAT:
1530  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1531  break;
1532  case AV_OPT_TYPE_RATIONAL: {
1533  AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1534  av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1535  break;
1536  case AV_OPT_TYPE_PIXEL_FMT:
1537  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1538  break;
1540  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1541  break;
1542  case AV_OPT_TYPE_COLOR:
1544  case AV_OPT_TYPE_STRING:
1545  case AV_OPT_TYPE_DICT:
1547  case AV_OPT_TYPE_CHLAYOUT:
1548  av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1549  break;
1550  }
1551  av_log(av_log_obj, AV_LOG_INFO, ")");
1552 }
1553 
1554 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1555  int req_flags, int rej_flags, enum AVOptionType parent_type)
1556 {
1557  const AVOption *opt = NULL;
1558  AVOptionRanges *r;
1559  int i;
1560 
1561  while ((opt = av_opt_next(obj, opt))) {
1562  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1563  continue;
1564 
1565  /* Don't print CONST's on level one.
1566  * Don't print anything but CONST's on level two.
1567  * Only print items from the requested unit.
1568  */
1569  if (!unit && opt->type == AV_OPT_TYPE_CONST)
1570  continue;
1571  else if (unit && opt->type != AV_OPT_TYPE_CONST)
1572  continue;
1573  else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1574  continue;
1575  else if (unit && opt->type == AV_OPT_TYPE_CONST)
1576  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1577  else
1578  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1579  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1580  opt->name);
1581 
1582  log_type(av_log_obj, opt, parent_type);
1583 
1584  av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1585  (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1586  (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1587  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1588  (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1589  (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1590  (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1591  (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1592  (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1593  (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1594  (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1595  (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1596 
1597  if (opt->help)
1598  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1599 
1600  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1601  switch (opt->type) {
1602  case AV_OPT_TYPE_INT:
1603  case AV_OPT_TYPE_INT64:
1604  case AV_OPT_TYPE_UINT64:
1605  case AV_OPT_TYPE_DOUBLE:
1606  case AV_OPT_TYPE_FLOAT:
1607  case AV_OPT_TYPE_RATIONAL:
1608  for (i = 0; i < r->nb_ranges; i++) {
1609  av_log(av_log_obj, AV_LOG_INFO, " (from ");
1610  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1611  av_log(av_log_obj, AV_LOG_INFO, " to ");
1612  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1613  av_log(av_log_obj, AV_LOG_INFO, ")");
1614  }
1615  break;
1616  }
1618  }
1619 
1620  log_default(obj, av_log_obj, opt);
1621 
1622  av_log(av_log_obj, AV_LOG_INFO, "\n");
1623  if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1624  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1625  }
1626 }
1627 
1628 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1629 {
1630  if (!obj)
1631  return -1;
1632 
1633  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1634 
1635  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1636 
1637  return 0;
1638 }
1639 
1641 {
1642  av_opt_set_defaults2(s, 0, 0);
1643 }
1644 
1645 void av_opt_set_defaults2(void *s, int mask, int flags)
1646 {
1647  const AVOption *opt = NULL;
1648  while ((opt = av_opt_next(s, opt))) {
1649  void *dst = ((uint8_t*)s) + opt->offset;
1650 
1651  if ((opt->flags & mask) != flags)
1652  continue;
1653 
1654  if (opt->flags & AV_OPT_FLAG_READONLY)
1655  continue;
1656 
1657  if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1658  const AVOptionArrayDef *arr = opt->default_val.arr;
1659  const char sep = opt_array_sep(opt);
1660 
1661  av_assert0(sep && sep != '\\' &&
1662  (sep < 'a' || sep > 'z') &&
1663  (sep < 'A' || sep > 'Z') &&
1664  (sep < '0' || sep > '9'));
1665 
1666  if (arr && arr->def)
1667  opt_set_array(s, s, opt, arr->def, dst);
1668 
1669  continue;
1670  }
1671 
1672  switch (opt->type) {
1673  case AV_OPT_TYPE_CONST:
1674  /* Nothing to be done here */
1675  break;
1676  case AV_OPT_TYPE_BOOL:
1677  case AV_OPT_TYPE_FLAGS:
1678  case AV_OPT_TYPE_INT:
1679  case AV_OPT_TYPE_INT64:
1680  case AV_OPT_TYPE_UINT64:
1681  case AV_OPT_TYPE_DURATION:
1682  case AV_OPT_TYPE_PIXEL_FMT:
1684  write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1685  break;
1686  case AV_OPT_TYPE_DOUBLE:
1687  case AV_OPT_TYPE_FLOAT: {
1688  double val;
1689  val = opt->default_val.dbl;
1690  write_number(s, opt, dst, val, 1, 1);
1691  }
1692  break;
1693  case AV_OPT_TYPE_RATIONAL: {
1694  AVRational val;
1695  val = av_d2q(opt->default_val.dbl, INT_MAX);
1696  write_number(s, opt, dst, 1, val.den, val.num);
1697  }
1698  break;
1699  case AV_OPT_TYPE_COLOR:
1700  set_string_color(s, opt, opt->default_val.str, dst);
1701  break;
1702  case AV_OPT_TYPE_STRING:
1703  set_string(s, opt, opt->default_val.str, dst);
1704  break;
1706  set_string_image_size(s, opt, opt->default_val.str, dst);
1707  break;
1709  set_string_video_rate(s, opt, opt->default_val.str, dst);
1710  break;
1711  case AV_OPT_TYPE_BINARY:
1712  set_string_binary(s, opt, opt->default_val.str, dst);
1713  break;
1714  case AV_OPT_TYPE_CHLAYOUT:
1715  set_string_channel_layout(s, opt, opt->default_val.str, dst);
1716  break;
1717  case AV_OPT_TYPE_DICT:
1718  set_string_dict(s, opt, opt->default_val.str, dst);
1719  break;
1720  default:
1721  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1722  opt->type, opt->name);
1723  }
1724  }
1725 }
1726 
1727 /**
1728  * Store the value in the field in ctx that is named like key.
1729  * ctx must be an AVClass context, storing is done using AVOptions.
1730  *
1731  * @param buf the string to parse, buf will be updated to point at the
1732  * separator just after the parsed key/value pair
1733  * @param key_val_sep a 0-terminated list of characters used to
1734  * separate key from value
1735  * @param pairs_sep a 0-terminated list of characters used to separate
1736  * two pairs from each other
1737  * @return 0 if the key/value pair has been successfully parsed and
1738  * set, or a negative value corresponding to an AVERROR code in case
1739  * of error:
1740  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1741  * the error code issued by av_opt_set() if the key/value pair
1742  * cannot be set
1743  */
1744 static int parse_key_value_pair(void *ctx, const char **buf,
1745  const char *key_val_sep, const char *pairs_sep)
1746 {
1747  char *key = av_get_token(buf, key_val_sep);
1748  char *val;
1749  int ret;
1750 
1751  if (!key)
1752  return AVERROR(ENOMEM);
1753 
1754  if (*key && strspn(*buf, key_val_sep)) {
1755  (*buf)++;
1756  val = av_get_token(buf, pairs_sep);
1757  if (!val) {
1758  av_freep(&key);
1759  return AVERROR(ENOMEM);
1760  }
1761  } else {
1762  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1763  av_free(key);
1764  return AVERROR(EINVAL);
1765  }
1766 
1767  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1768 
1771  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1772 
1773  av_free(key);
1774  av_free(val);
1775  return ret;
1776 }
1777 
1778 int av_set_options_string(void *ctx, const char *opts,
1779  const char *key_val_sep, const char *pairs_sep)
1780 {
1781  int ret, count = 0;
1782 
1783  if (!opts)
1784  return 0;
1785 
1786  while (*opts) {
1787  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1788  return ret;
1789  count++;
1790 
1791  if (*opts)
1792  opts++;
1793  }
1794 
1795  return count;
1796 }
1797 
1798 #define WHITESPACES " \n\t\r"
1799 
1800 static int is_key_char(char c)
1801 {
1802  return (unsigned)((c | 32) - 'a') < 26 ||
1803  (unsigned)(c - '0') < 10 ||
1804  c == '-' || c == '_' || c == '/' || c == '.';
1805 }
1806 
1807 /**
1808  * Read a key from a string.
1809  *
1810  * The key consists of is_key_char characters and must be terminated by a
1811  * character from the delim string; spaces are ignored.
1812  *
1813  * @return 0 for success (even with ellipsis), <0 for failure
1814  */
1815 static int get_key(const char **ropts, const char *delim, char **rkey)
1816 {
1817  const char *opts = *ropts;
1818  const char *key_start, *key_end;
1819 
1820  key_start = opts += strspn(opts, WHITESPACES);
1821  while (is_key_char(*opts))
1822  opts++;
1823  key_end = opts;
1824  opts += strspn(opts, WHITESPACES);
1825  if (!*opts || !strchr(delim, *opts))
1826  return AVERROR(EINVAL);
1827  opts++;
1828  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1829  return AVERROR(ENOMEM);
1830  memcpy(*rkey, key_start, key_end - key_start);
1831  (*rkey)[key_end - key_start] = 0;
1832  *ropts = opts;
1833  return 0;
1834 }
1835 
1836 int av_opt_get_key_value(const char **ropts,
1837  const char *key_val_sep, const char *pairs_sep,
1838  unsigned flags,
1839  char **rkey, char **rval)
1840 {
1841  int ret;
1842  char *key = NULL, *val;
1843  const char *opts = *ropts;
1844 
1845  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1847  return AVERROR(EINVAL);
1848  if (!(val = av_get_token(&opts, pairs_sep))) {
1849  av_free(key);
1850  return AVERROR(ENOMEM);
1851  }
1852  *ropts = opts;
1853  *rkey = key;
1854  *rval = val;
1855  return 0;
1856 }
1857 
1858 int av_opt_set_from_string(void *ctx, const char *opts,
1859  const char *const *shorthand,
1860  const char *key_val_sep, const char *pairs_sep)
1861 {
1862  int ret, count = 0;
1863  const char *dummy_shorthand = NULL;
1864  const char *key;
1865 
1866  if (!opts)
1867  return 0;
1868  if (!shorthand)
1869  shorthand = &dummy_shorthand;
1870 
1871  while (*opts) {
1872  char *parsed_key, *value;
1873  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1874  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1875  &parsed_key, &value);
1876  if (ret < 0) {
1877  if (ret == AVERROR(EINVAL))
1878  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1879  else
1880  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1881  av_err2str(ret));
1882  return ret;
1883  }
1884  if (*opts)
1885  opts++;
1886  if (parsed_key) {
1887  key = parsed_key;
1888  while (*shorthand) /* discard all remaining shorthand */
1889  shorthand++;
1890  } else {
1891  key = *(shorthand++);
1892  }
1893 
1894  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1895  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1897  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1898  av_free(value);
1899  av_free(parsed_key);
1900  return ret;
1901  }
1902 
1903  av_free(value);
1904  av_free(parsed_key);
1905  count++;
1906  }
1907  return count;
1908 }
1909 
1910 void av_opt_free(void *obj)
1911 {
1912  const AVOption *o = NULL;
1913  while ((o = av_opt_next(obj, o))) {
1914  void *pitem = (uint8_t *)obj + o->offset;
1915 
1917  opt_free_array(o, pitem, opt_array_pcount(pitem));
1918  else
1919  opt_free_elem(o, pitem);
1920  }
1921 }
1922 
1923 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1924 {
1925  const AVDictionaryEntry *t = NULL;
1926  AVDictionary *tmp = NULL;
1927  int ret;
1928 
1929  if (!options)
1930  return 0;
1931 
1932  while ((t = av_dict_iterate(*options, t))) {
1933  ret = av_opt_set(obj, t->key, t->value, search_flags);
1936  if (ret < 0) {
1937  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1938  av_dict_free(&tmp);
1939  return ret;
1940  }
1941  }
1943  *options = tmp;
1944  return 0;
1945 }
1946 
1948 {
1949  return av_opt_set_dict2(obj, options, 0);
1950 }
1951 
1952 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1953  int opt_flags, int search_flags)
1954 {
1955  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1956 }
1957 
1958 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1959  int opt_flags, int search_flags, void **target_obj)
1960 {
1961  const AVClass *c;
1962  const AVOption *o = NULL;
1963 
1964  if(!obj)
1965  return NULL;
1966 
1967  c= *(AVClass**)obj;
1968 
1969  if (!c)
1970  return NULL;
1971 
1972  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1973  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1974  void *iter = NULL;
1975  const AVClass *child;
1976  while (child = av_opt_child_class_iterate(c, &iter))
1977  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1978  return o;
1979  } else {
1980  void *child = NULL;
1981  while (child = av_opt_child_next(obj, child))
1982  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1983  return o;
1984  }
1985  }
1986 
1987  while (o = av_opt_next(obj, o)) {
1988  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1989  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1990  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1991  if (target_obj) {
1992  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1993  *target_obj = obj;
1994  else
1995  *target_obj = NULL;
1996  }
1997  return o;
1998  }
1999  }
2000  return NULL;
2001 }
2002 
2003 void *av_opt_child_next(void *obj, void *prev)
2004 {
2005  const AVClass *c = *(AVClass **)obj;
2006  if (c->child_next)
2007  return c->child_next(obj, prev);
2008  return NULL;
2009 }
2010 
2011 const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
2012 {
2013  if (parent->child_class_iterate)
2014  return parent->child_class_iterate(iter);
2015  return NULL;
2016 }
2017 
2018 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
2019 {
2020  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
2021 
2022  // no direct access to array-type options
2023  if (!opt || (opt->type & AV_OPT_TYPE_FLAG_ARRAY))
2024  return NULL;
2025  return (uint8_t*)obj + opt->offset;
2026 }
2027 
2028 static int opt_copy_elem(void *logctx, enum AVOptionType type,
2029  void *dst, const void *src)
2030 {
2031  if (type == AV_OPT_TYPE_STRING) {
2032  const char *src_str = *(const char *const *)src;
2033  char **dstp = (char **)dst;
2034  if (*dstp != src_str)
2035  av_freep(dstp);
2036  if (src_str) {
2037  *dstp = av_strdup(src_str);
2038  if (!*dstp)
2039  return AVERROR(ENOMEM);
2040  }
2041  } else if (type == AV_OPT_TYPE_BINARY) {
2042  const uint8_t *const *src8 = (const uint8_t *const *)src;
2043  uint8_t **dst8 = (uint8_t **)dst;
2044  int len = *(const int *)(src8 + 1);
2045  if (*dst8 != *src8)
2046  av_freep(dst8);
2047  *dst8 = av_memdup(*src8, len);
2048  if (len && !*dst8) {
2049  *(int *)(dst8 + 1) = 0;
2050  return AVERROR(ENOMEM);
2051  }
2052  *(int *)(dst8 + 1) = len;
2053  } else if (type == AV_OPT_TYPE_CONST) {
2054  // do nothing
2055  } else if (type == AV_OPT_TYPE_DICT) {
2056  const AVDictionary *sdict = *(const AVDictionary * const *)src;
2057  AVDictionary **ddictp = (AVDictionary **)dst;
2058  if (sdict != *ddictp)
2059  av_dict_free(ddictp);
2060  *ddictp = NULL;
2061  return av_dict_copy(ddictp, sdict, 0);
2062  } else if (type == AV_OPT_TYPE_CHLAYOUT) {
2063  if (dst != src)
2064  return av_channel_layout_copy(dst, src);
2065  } else if (opt_is_pod(type)) {
2066  size_t size = opt_elem_size[type];
2067  memcpy(dst, src, size);
2068  } else {
2069  av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type);
2070  return AVERROR(EINVAL);
2071  }
2072 
2073  return 0;
2074 }
2075 
2076 static int opt_copy_array(void *logctx, const AVOption *o,
2077  void **pdst, const void * const *psrc)
2078 {
2079  unsigned nb_elems = *opt_array_pcount(psrc);
2080  void *dst = NULL;
2081  int ret;
2082 
2083  if (*pdst == *psrc) {
2084  *pdst = NULL;
2085  *opt_array_pcount(pdst) = 0;
2086  }
2087 
2088  opt_free_array(o, pdst, opt_array_pcount(pdst));
2089 
2090  dst = av_calloc(nb_elems, opt_elem_size[TYPE_BASE(o->type)]);
2091  if (!dst)
2092  return AVERROR(ENOMEM);
2093 
2094  for (unsigned i = 0; i < nb_elems; i++) {
2095  ret = opt_copy_elem(logctx, TYPE_BASE(o->type),
2096  opt_array_pelem(o, dst, i),
2097  opt_array_pelem(o, *(void**)psrc, i));
2098  if (ret < 0) {
2099  opt_free_array(o, &dst, &nb_elems);
2100  return ret;
2101  }
2102  }
2103 
2104  *pdst = dst;
2105  *opt_array_pcount(pdst) = nb_elems;
2106 
2107  return 0;
2108 }
2109 
2110 int av_opt_copy(void *dst, const void *src)
2111 {
2112  const AVOption *o = NULL;
2113  const AVClass *c;
2114  int ret = 0;
2115 
2116  if (!src)
2117  return AVERROR(EINVAL);
2118 
2119  c = *(AVClass **)src;
2120  if (!c || c != *(AVClass **)dst)
2121  return AVERROR(EINVAL);
2122 
2123  while ((o = av_opt_next(src, o))) {
2124  void *field_dst = (uint8_t *)dst + o->offset;
2125  void *field_src = (uint8_t *)src + o->offset;
2126 
2127  int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
2128  opt_copy_array(dst, o, field_dst, field_src) :
2129  opt_copy_elem (dst, o->type, field_dst, field_src);
2130  if (err < 0)
2131  ret = err;
2132  }
2133  return ret;
2134 }
2135 
2136 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2137 {
2138  int ret;
2139  const AVClass *c = *(AVClass**)obj;
2140  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
2141 
2142  if (!callback)
2144 
2145  ret = callback(ranges_arg, obj, key, flags);
2146  if (ret >= 0) {
2148  ret = 1;
2149  (*ranges_arg)->nb_components = ret;
2150  }
2151  return ret;
2152 }
2153 
2154 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2155 {
2156  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
2157  AVOptionRange **range_array = av_mallocz(sizeof(void*));
2158  AVOptionRange *range = av_mallocz(sizeof(*range));
2159  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
2160  int ret;
2161 
2162  *ranges_arg = NULL;
2163 
2164  if (!ranges || !range || !range_array || !field) {
2165  ret = AVERROR(ENOMEM);
2166  goto fail;
2167  }
2168 
2169  ranges->range = range_array;
2170  ranges->range[0] = range;
2171  ranges->nb_ranges = 1;
2172  ranges->nb_components = 1;
2173  range->is_range = 1;
2174  range->value_min = field->min;
2175  range->value_max = field->max;
2176 
2177  switch (field->type) {
2178  case AV_OPT_TYPE_BOOL:
2179  case AV_OPT_TYPE_INT:
2180  case AV_OPT_TYPE_INT64:
2181  case AV_OPT_TYPE_UINT64:
2182  case AV_OPT_TYPE_PIXEL_FMT:
2184  case AV_OPT_TYPE_FLOAT:
2185  case AV_OPT_TYPE_DOUBLE:
2186  case AV_OPT_TYPE_DURATION:
2187  case AV_OPT_TYPE_COLOR:
2188  break;
2189  case AV_OPT_TYPE_STRING:
2190  range->component_min = 0;
2191  range->component_max = 0x10FFFF; // max unicode value
2192  range->value_min = -1;
2193  range->value_max = INT_MAX;
2194  break;
2195  case AV_OPT_TYPE_RATIONAL:
2196  range->component_min = INT_MIN;
2197  range->component_max = INT_MAX;
2198  break;
2200  range->component_min = 0;
2201  range->component_max = INT_MAX/128/8;
2202  range->value_min = 0;
2203  range->value_max = INT_MAX/8;
2204  break;
2206  range->component_min = 1;
2207  range->component_max = INT_MAX;
2208  range->value_min = 1;
2209  range->value_max = INT_MAX;
2210  break;
2211  default:
2212  ret = AVERROR(ENOSYS);
2213  goto fail;
2214  }
2215 
2216  *ranges_arg = ranges;
2217  return 1;
2218 fail:
2219  av_free(ranges);
2220  av_free(range);
2221  av_free(range_array);
2222  return ret;
2223 }
2224 
2226 {
2227  int i;
2228  AVOptionRanges *ranges = *rangesp;
2229 
2230  if (!ranges)
2231  return;
2232 
2233  for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
2234  AVOptionRange *range = ranges->range[i];
2235  if (range) {
2236  av_freep(&range->str);
2237  av_freep(&ranges->range[i]);
2238  }
2239  }
2240  av_freep(&ranges->range);
2241  av_freep(rangesp);
2242 }
2243 
2244 int av_opt_is_set_to_default(void *obj, const AVOption *o)
2245 {
2246  int64_t i64;
2247  double d;
2248  AVRational q;
2249  int ret, w, h;
2250  char *str;
2251  void *dst;
2252 
2253  if (!o || !obj)
2254  return AVERROR(EINVAL);
2255 
2256  dst = ((uint8_t*)obj) + o->offset;
2257 
2258  if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
2259  const char *def = o->default_val.arr ? o->default_val.arr->def : NULL;
2260  uint8_t *val;
2261 
2262  ret = opt_get_array(o, dst, &val);
2263  if (ret < 0)
2264  return ret;
2265 
2266  if (!!val != !!def)
2267  ret = 0;
2268  else if (val)
2269  ret = !strcmp(val, def);
2270 
2271  av_freep(&val);
2272 
2273  return ret;
2274  }
2275 
2276  switch (o->type) {
2277  case AV_OPT_TYPE_CONST:
2278  return 1;
2279  case AV_OPT_TYPE_BOOL:
2280  case AV_OPT_TYPE_FLAGS:
2281  case AV_OPT_TYPE_PIXEL_FMT:
2283  case AV_OPT_TYPE_INT:
2284  case AV_OPT_TYPE_DURATION:
2285  case AV_OPT_TYPE_INT64:
2286  case AV_OPT_TYPE_UINT64:
2287  read_number(o, dst, NULL, NULL, &i64);
2288  return o->default_val.i64 == i64;
2289  case AV_OPT_TYPE_CHLAYOUT: {
2290  AVChannelLayout ch_layout = { 0 };
2291  if (o->default_val.str) {
2292  if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
2293  return ret;
2294  }
2295  return !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout);
2296  }
2297  case AV_OPT_TYPE_STRING:
2298  str = *(char **)dst;
2299  if (str == o->default_val.str) //2 NULLs
2300  return 1;
2301  if (!str || !o->default_val.str) //1 NULL
2302  return 0;
2303  return !strcmp(str, o->default_val.str);
2304  case AV_OPT_TYPE_DOUBLE:
2305  d = *(double *)dst;
2306  return o->default_val.dbl == d;
2307  case AV_OPT_TYPE_FLOAT:
2308  d = *(float *)dst;
2309  return (float)o->default_val.dbl == d;
2310  case AV_OPT_TYPE_RATIONAL:
2311  q = av_d2q(o->default_val.dbl, INT_MAX);
2312  return !av_cmp_q(*(AVRational*)dst, q);
2313  case AV_OPT_TYPE_BINARY: {
2314  struct {
2315  uint8_t *data;
2316  int size;
2317  } tmp = {0};
2318  int opt_size = *(int *)((void **)dst + 1);
2319  void *opt_ptr = *(void **)dst;
2320  if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
2321  return 1;
2322  if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
2323  return 0;
2324  if (opt_size != strlen(o->default_val.str) / 2)
2325  return 0;
2326  ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
2327  if (!ret)
2328  ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2329  av_free(tmp.data);
2330  return ret;
2331  }
2332  case AV_OPT_TYPE_DICT: {
2333  AVDictionary *dict1 = NULL;
2334  AVDictionary *dict2 = *(AVDictionary **)dst;
2335  const AVDictionaryEntry *en1 = NULL;
2336  const AVDictionaryEntry *en2 = NULL;
2337  ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2338  if (ret < 0) {
2339  av_dict_free(&dict1);
2340  return ret;
2341  }
2342  do {
2343  en1 = av_dict_iterate(dict1, en1);
2344  en2 = av_dict_iterate(dict2, en2);
2345  } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2346  av_dict_free(&dict1);
2347  return (!en1 && !en2);
2348  }
2350  if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2351  w = h = 0;
2352  else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2353  return ret;
2354  return (w == *(int *)dst) && (h == *((int *)dst+1));
2356  q = (AVRational){0, 0};
2357  if (o->default_val.str) {
2358  if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2359  return ret;
2360  }
2361  return !av_cmp_q(*(AVRational*)dst, q);
2362  case AV_OPT_TYPE_COLOR: {
2363  uint8_t color[4] = {0, 0, 0, 0};
2364  if (o->default_val.str) {
2365  if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2366  return ret;
2367  }
2368  return !memcmp(color, dst, sizeof(color));
2369  }
2370  default:
2371  av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2372  break;
2373  }
2374  return AVERROR_PATCHWELCOME;
2375 }
2376 
2377 int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2378 {
2379  const AVOption *o;
2380  void *target;
2381  if (!obj)
2382  return AVERROR(EINVAL);
2383  o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2384  if (!o)
2385  return AVERROR_OPTION_NOT_FOUND;
2386  return av_opt_is_set_to_default(target, o);
2387 }
2388 
2389 int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2390  const char key_val_sep, const char pairs_sep)
2391 {
2392  const AVOption *o = NULL;
2393  uint8_t *buf;
2394  AVBPrint bprint;
2395  int ret, cnt = 0;
2396  const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2397 
2398  if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2399  pairs_sep == '\\' || key_val_sep == '\\') {
2400  av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2401  return AVERROR(EINVAL);
2402  }
2403 
2404  if (!obj || !buffer)
2405  return AVERROR(EINVAL);
2406 
2407  *buffer = NULL;
2409 
2410  while (o = av_opt_next(obj, o)) {
2411  if (o->type == AV_OPT_TYPE_CONST)
2412  continue;
2413  if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2414  continue;
2415  else if (((o->flags & opt_flags) != opt_flags))
2416  continue;
2418  continue;
2419  if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2420  av_bprint_finalize(&bprint, NULL);
2421  return ret;
2422  }
2423  if (buf) {
2424  if (cnt++)
2425  av_bprint_append_data(&bprint, &pairs_sep, 1);
2426  av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2427  av_bprint_append_data(&bprint, &key_val_sep, 1);
2428  av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2429  av_freep(&buf);
2430  }
2431  }
2432  ret = av_bprint_finalize(&bprint, buffer);
2433  if (ret < 0)
2434  return ret;
2435  return 0;
2436 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:522
set_string_bool
static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:465
OPT_EVAL_NUMBER
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition: opt.c:759
av_opt_get_dict_val
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
Definition: opt.c:1326
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
av_opt_set_image_size
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
Definition: opt.c:836
AVOption::i64
int64_t i64
Definition: opt.h:369
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
log_default
static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
Definition: opt.c:1477
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
log_int_value
static void log_int_value(void *av_log_obj, int level, int64_t i)
Definition: opt.c:1356
level
uint8_t level
Definition: svq3.c:205
AVOptionRanges::nb_components
int nb_components
Number of componentes.
Definition: opt.h:464
INFINITY
#define INFINITY
Definition: mathematics.h:118
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:1640
opt_free_elem
static void opt_free_elem(const AVOption *o, void *ptr)
Definition: opt.c:123
r
const char * r
Definition: vf_curves.c:127
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
opt.h
av_opt_flag_is_set
int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
Check whether a particular flag is set in a flags field.
Definition: opt.c:1343
AV_OPT_TYPE_SAMPLE_FMT
@ AV_OPT_TYPE_SAMPLE_FMT
Definition: opt.h:247
get_pix_fmt
static int get_pix_fmt(const char *name)
Definition: opt.c:536
av_opt_child_class_iterate
const AVClass * av_opt_child_class_iterate(const AVClass *parent, void **iter)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:2011
out
FILE * out
Definition: movenc.c:55
color
Definition: vf_paletteuse.c:512
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
AVOptionType
AVOptionType
Definition: opt.h:233
AVOptionArrayDef
May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
Definition: opt.h:312
set_string_sample_fmt
static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:552
av_parse_color
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition: parseutils.c:356
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:248
AVOption::arr
const AVOptionArrayDef * arr
Used for AV_OPT_TYPE_FLAG_ARRAY options.
Definition: opt.h:381
get_opt_const_name
static const char * get_opt_const_name(void *obj, const char *unit, int64_t value)
Definition: opt.c:1406
AVOptionRanges::nb_ranges
int nb_ranges
Number of ranges per component.
Definition: opt.h:460
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
av_opt_set_double
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:796
av_opt_set_from_string
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
Definition: opt.c:1858
AVOption
AVOption.
Definition: opt.h:346
is_key_char
static int is_key_char(char c)
Definition: opt.c:1800
b
#define b
Definition: input.c:41
set_string_channel_layout
static int set_string_channel_layout(void *obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:576
data
const char data[16]
Definition: mxf.c:148
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:249
av_opt_find2
const AVOption * av_opt_find2(void *obj, const char *name, const char *unit, int opt_flags, int search_flags, void **target_obj)
Look for an option in an object.
Definition: opt.c:1958
AVOption::help
const char * help
short English help text
Definition: opt.h:353
float.h
AVOption::flags
int flags
A combination of AV_OPT_FLAG_*.
Definition: opt.h:389
max
#define max(a, b)
Definition: cuda_runtime.h:33
AVClass::child_class_iterate
const struct AVClass *(* child_class_iterate)(void **iter)
Iterate over the AVClasses corresponding to potential AVOptions-enabled children.
Definition: log.h:146
mathematics.h
AVDictionary
Definition: dict.c:34
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
opt_copy_array
static int opt_copy_array(void *logctx, const AVOption *o, void **pdst, const void *const *psrc)
Definition: opt.c:2076
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:240
opt_array_pcount
static unsigned * opt_array_pcount(const void *parray)
Definition: opt.c:118
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:103
av_opt_serialize
int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, const char key_val_sep, const char pairs_sep)
Serialize object's options.
Definition: opt.c:2389
const_values
static const double const_values[]
Definition: eval.c:28
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
AV_PIX_FMT_NB
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:442
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:241
av_opt_is_set_to_default
int av_opt_is_set_to_default(void *obj, const AVOption *o)
Check if given option is set to its default value.
Definition: opt.c:2244
fail
#define fail()
Definition: checkasm.h:179
AVOption::offset
int offset
Native access only.
Definition: opt.h:361
av_opt_get_key_value
int av_opt_get_key_value(const char **ropts, const char *key_val_sep, const char *pairs_sep, unsigned flags, char **rkey, char **rval)
Extract a key-value pair from the beginning of a string.
Definition: opt.c:1836
get_bool_name
static const char * get_bool_name(int val)
Definition: opt.c:458
samplefmt.h
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1910
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
val
static double val(void *priv, double ch)
Definition: aeval.c:78
type
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 type
Definition: writing_filters.txt:86
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:740
AV_OPT_SERIALIZE_SKIP_DEFAULTS
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS
Serialize options that are not set to default values only.
Definition: opt.h:930
AVRational::num
int num
Numerator.
Definition: rational.h:59
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:274
opt_free_array
static void opt_free_array(const AVOption *o, void *parray, unsigned *count)
Definition: opt.c:144
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
mask
static const uint16_t mask[17]
Definition: lzw.c:38
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:645
class
#define class
Definition: math.h:25
AVOptionArrayDef::def
const char * def
Native access only.
Definition: opt.h:319
s
#define s(width, name)
Definition: cbs_vp9.c:198
opt_copy_elem
static int opt_copy_elem(void *logctx, enum AVOptionType type, void *dst, const void *src)
Definition: opt.c:2028
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
AVDictionaryEntry::key
char * key
Definition: dict.h:90
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:237
AV_OPT_FLAG_CHILD_CONSTS
#define AV_OPT_FLAG_CHILD_CONSTS
Set if option constants can also reside in child objects.
Definition: opt.h:307
av_opt_set_dict_val
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
Definition: opt.c:915
av_opt_set_pixel_fmt
int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
Definition: opt.c:905
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:236
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
av_set_options_string
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition: opt.c:1778
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:49
WHITESPACES
#define WHITESPACES
Definition: opt.c:1798
field
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 field
Definition: writing_filters.txt:78
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
key
const char * key
Definition: hwcontext_opencl.c:189
NAN
#define NAN
Definition: mathematics.h:115
AV_OPT_FLAG_BSF_PARAM
#define AV_OPT_FLAG_BSF_PARAM
A generic parameter which can be set by the user for bit stream filtering.
Definition: opt.h:289
av_opt_get_pixel_fmt
int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
Definition: opt.c:1300
callback
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition: dshow.c:342
av_opt_get_video_rate
int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:1266
if
if(ret)
Definition: filter_design.txt:179
AVOptionArrayDef::size_max
unsigned size_max
Maximum number of elements in the array, 0 when unlimited.
Definition: opt.h:329
opts
AVDictionary * opts
Definition: movenc.c:51
log_type
static void log_type(void *av_log_obj, const AVOption *o, enum AVOptionType parent_type)
Definition: opt.c:1440
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
av_opt_set_video_rate
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:858
NULL
#define NULL
Definition: coverity.c:32
av_opt_set_bin
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition: opt.c:806
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV_DICT_MULTIKEY
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition: dict.h:84
opt_set_elem
static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:586
log_value
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:1373
av_bprint_escape
void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape the content in src and append it to dstbuf.
Definition: bprint.c:268
av_opt_get_double
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition: opt.c:1220
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
set_format
static int set_format(void *obj, const char *name, int fmt, int search_flags, enum AVOptionType type, const char *desc, int nb_fmts)
Definition: opt.c:876
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:250
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:245
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:242
parseutils.h
av_opt_get_sample_fmt
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition: opt.c:1305
set_number
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:775
AV_OPT_SEARCH_FAKE_OBJ
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() is fake – only a double pointer to AVClass instead of a required poin...
Definition: opt.h:530
double
double
Definition: af_crystalizer.c:131
av_parse_time
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
Definition: parseutils.c:589
AVOptionRanges::range
AVOptionRange ** range
Array of option ranges.
Definition: opt.h:456
opt_list
static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags, enum AVOptionType parent_type)
Definition: opt.c:1554
AVOption::min
double min
minimum valid value for the option
Definition: opt.h:383
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Definition: opt.h:252
av_opt_get_int
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:1205
AVOption::default_val
union AVOption::@390 default_val
Native access only, except when documented otherwise.
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:269
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
av_opt_set_int
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:791
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:2110
opt_is_pod
static int opt_is_pod(enum AVOptionType type)
Definition: opt.c:83
options
const OptionDef options[]
eval.h
AV_OPT_FLAG_FILTERING_PARAM
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition: opt.h:298
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1952
AVOptionRange
A single allowed range of values, or a single allowed value.
Definition: opt.h:402
AV_SAMPLE_FMT_NB
@ AV_SAMPLE_FMT_NB
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:71
av_expr_parse_and_eval
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
Definition: eval.c:803
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
AV_OPT_TYPE_FLAG_ARRAY
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition: opt.h:263
av_opt_set_chlayout
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition: opt.c:934
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:121
size
int size
Definition: twinvq_data.h:10344
av_reallocp
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:188
set_string_fmt
static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst, int fmt_nb, int((*get_fmt)(const char *)), const char *desc)
Definition: opt.c:496
read_number
static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
Definition: opt.c:153
parse_key_value_pair
static int parse_key_value_pair(void *ctx, const char **buf, const char *key_val_sep, const char *pairs_sep)
Store the value in the field in ctx that is named like key.
Definition: opt.c:1744
hexchar2int
static int hexchar2int(char c)
Definition: opt.c:265
AVOption::name
const char * name
Definition: opt.h:347
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2557
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
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:223
av_opt_show2
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:1628
av_parse_video_size
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition: parseutils.c:150
set_string_video_rate
static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
Definition: opt.c:435
get_sample_fmt
static int get_sample_fmt(const char *name)
Definition: opt.c:547
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:801
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
DEFAULT_NUMVAL
#define DEFAULT_NUMVAL(opt)
Definition: opt.c:318
av_opt_ptr
void * av_opt_ptr(const AVClass *class, void *obj, const char *name)
Gets a pointer to the requested field in a struct.
Definition: opt.c:2018
opt_array_pelem
static void * opt_array_pelem(const AVOption *o, void *array, unsigned idx)
Definition: opt.c:112
get_number
static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, int search_flags)
Definition: opt.c:1190
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:238
AV_OPT_FLAG_READONLY
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:285
flag
#define flag(name)
Definition: cbs_av1.c:466
av_parse_video_rate
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:181
AV_OPT_FLAG_DEPRECATED
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
Definition: opt.h:303
av_opt_next
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:48
av_channel_layout_from_string
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
Definition: channel_layout.c:303
bprint.h
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
set_string_pixel_fmt
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:541
av_opt_set_dict2
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition: opt.c:1923
av_get_sample_fmt
enum AVSampleFormat av_get_sample_fmt(const char *name)
Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE on error.
Definition: samplefmt.c:58
AV_OPT_FLAG_SUBTITLE_PARAM
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:276
get_opt_flags_string
static char * get_opt_flags_string(void *obj, const char *unit, int64_t value)
Definition: opt.c:1419
AVOption::str
const char * str
Definition: opt.h:371
opt_elem_size
static const size_t opt_elem_size[]
Definition: opt.c:61
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
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
AV_OPT_FLAG_IMPLICIT_KEY
@ AV_OPT_FLAG_IMPLICIT_KEY
Accept to parse a value without a key; the key will then be returned as NULL.
Definition: opt.h:635
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
class_name
class_name
Definition: libkvazaar.c:318
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:275
set_string
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:309
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
AV_OPT_MULTI_COMPONENT_RANGE
#define AV_OPT_MULTI_COMPONENT_RANGE
Allows av_opt_query_ranges and av_opt_query_ranges_default to return more than one component for cert...
Definition: opt.h:543
len
int len
Definition: vorbis_enc_data.h:426
AVOptionRanges
List of AVOptionRange structs.
Definition: opt.h:425
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
get_key
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition: opt.c:1815
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
version.h
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:111
ret
ret
Definition: filter_design.txt:187
AVOption::dbl
double dbl
Definition: opt.h:370
set_string_color
static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:443
dict.h
AVOption::type
enum AVOptionType type
Definition: opt.h:362
const_names
static const char *const const_names[]
Definition: eval.c:34
set_string_dict
static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:558
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2897
TYPE_BASE
#define TYPE_BASE(type)
Definition: opt.c:46
opt_array_sep
static uint8_t opt_array_sep(const AVOption *o)
Definition: opt.c:105
opt_get_elem
static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, void *dst, int search_flags)
Definition: opt.c:985
set_string_binary
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:275
channel_layout.h
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_FLAG_RUNTIME_PARAM
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition: opt.h:294
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
av_get_token
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:143
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:433
av_match_name
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition: avstring.c:345
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:200
av_opt_get_chlayout
int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
Definition: opt.c:1310
AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
Serialize options that exactly match opt_flags only.
Definition: opt.h:931
av_opt_child_next
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition: opt.c:2003
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Definition: opt.h:246
av_opt_set_defaults2
void av_opt_set_defaults2(void *s, int mask, int flags)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1645
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:440
av_opt_query_ranges_default
int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
Get a default list of allowed ranges for the given option.
Definition: opt.c:2154
av_opt_query_ranges
int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
Get a list of allowed ranges for the given option.
Definition: opt.c:2136
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition: opt.h:273
desc
const char * desc
Definition: libsvtav1.c:75
AVOptionArrayDef::size_min
unsigned size_min
Minimum number of elements in the array.
Definition: opt.h:325
avutil.h
mem.h
AV_OPT_ALLOW_NULL
#define AV_OPT_ALLOW_NULL
In av_opt_get, return NULL if the option has a pointer type and is set to NULL, rather than returning...
Definition: opt.h:536
AVOption::unit
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:396
llrint
#define llrint(x)
Definition: libm.h:394
av_opt_freep_ranges
void av_opt_freep_ranges(AVOptionRanges **rangesp)
Free an AVOptionRanges struct and set it to NULL.
Definition: opt.c:2225
set_string_number
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:326
opt_set_array
static int opt_set_array(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:661
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
AV_OPT_FLAG_EXPORT
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:280
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:251
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:88
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
av_dict_get_string
int av_dict_get_string(const AVDictionary *m, char **buffer, const char key_val_sep, const char pairs_sep)
Get dictionary entries as a string.
Definition: dict.c:250
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:237
format_duration
static void format_duration(char *buf, size_t size, int64_t d)
Definition: opt.c:950
AV_ESCAPE_MODE_BACKSLASH
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Definition: avstring.h:316
d
d
Definition: ffmpeg_filter.c:424
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:234
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
set_string_image_size
static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:420
av_opt_get
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:1147
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2038
av_opt_set_dict
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1947
AVDictionaryEntry::value
char * value
Definition: dict.h:91
av_opt_get_image_size
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
Definition: opt.c:1248
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:239
av_opt_set_q
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:801
int
int
Definition: ffmpeg_filter.c:424
av_opt_set_sample_fmt
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition: opt.c:910
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
AVOption::max
double max
maximum valid value for the option
Definition: opt.h:384
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
snprintf
#define snprintf
Definition: snprintf.h:34
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
av_opt_is_set_to_default_by_name
int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
Check if given option is set to its default value.
Definition: opt.c:2377
av_x_if_null
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:312
get_format
static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, enum AVOptionType type, const char *desc)
Definition: opt.c:1282
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2885
opt_get_array
static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
Definition: opt.c:1087
min
float min
Definition: vorbis_enc_data.h:429
write_number
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
Definition: opt.c:191
AV_OPT_TYPE_UINT64
@ AV_OPT_TYPE_UINT64
Definition: opt.h:243
av_opt_get_q
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:1232