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 "common.h"
33 #include "dict.h"
34 #include "eval.h"
35 #include "log.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  *dst = av_strdup(val);
313  return *dst ? 0 : AVERROR(ENOMEM);
314 }
315 
316 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
317  opt->type == AV_OPT_TYPE_UINT64 || \
318  opt->type == AV_OPT_TYPE_CONST || \
319  opt->type == AV_OPT_TYPE_FLAGS || \
320  opt->type == AV_OPT_TYPE_INT) \
321  ? opt->default_val.i64 \
322  : opt->default_val.dbl)
323 
324 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
325 {
326  const enum AVOptionType type = TYPE_BASE(o->type);
327  int ret = 0;
328 
330  int num, den;
331  char c;
332  if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
333  if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
334  return ret;
335  ret = 0;
336  }
337  }
338 
339  for (;;) {
340  int i = 0;
341  char buf[256];
342  int cmd = 0;
343  double d;
344  int64_t intnum = 1;
345 
346  if (type == AV_OPT_TYPE_FLAGS) {
347  if (*val == '+' || *val == '-')
348  cmd = *(val++);
349  for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
350  buf[i] = val[i];
351  buf[i] = 0;
352  }
353 
354  {
355  int res;
356  int ci = 0;
357  double const_values[64];
358  const char * const_names[64];
359  int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0;
360  const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags);
361  if (o_named && o_named->type == AV_OPT_TYPE_CONST) {
362  d = DEFAULT_NUMVAL(o_named);
363  if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
364  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n",
365  o_named->name, o_named->help);
366  } else {
367  if (o->unit) {
368  for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
369  if (o_named->type == AV_OPT_TYPE_CONST &&
370  o_named->unit &&
371  !strcmp(o_named->unit, o->unit)) {
372  if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
373  av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
374  return AVERROR_PATCHWELCOME;
375  }
376  const_names [ci ] = o_named->name;
377  const_values[ci++] = DEFAULT_NUMVAL(o_named);
378  }
379  }
380  }
381  const_names [ci ] = "default";
382  const_values[ci++] = DEFAULT_NUMVAL(o);
383  const_names [ci ] = "max";
384  const_values[ci++] = o->max;
385  const_names [ci ] = "min";
386  const_values[ci++] = o->min;
387  const_names [ci ] = "none";
388  const_values[ci++] = 0;
389  const_names [ci ] = "all";
390  const_values[ci++] = ~0;
391  const_names [ci] = NULL;
392  const_values[ci] = 0;
393 
394  res = av_expr_parse_and_eval(&d, i ? buf : val, const_names,
395  const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
396  if (res < 0) {
397  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
398  return res;
399  }
400  }
401  }
402  if (type == AV_OPT_TYPE_FLAGS) {
403  intnum = *(unsigned int*)dst;
404  if (cmd == '+')
405  d = intnum | (int64_t)d;
406  else if (cmd == '-')
407  d = intnum &~(int64_t)d;
408  }
409 
410  if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
411  return ret;
412  val += i;
413  if (!i || !*val)
414  return 0;
415  }
416 }
417 
418 static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
419 {
420  int ret;
421 
422  if (!val || !strcmp(val, "none")) {
423  dst[0] =
424  dst[1] = 0;
425  return 0;
426  }
427  ret = av_parse_video_size(dst, dst + 1, val);
428  if (ret < 0)
429  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
430  return ret;
431 }
432 
433 static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
434 {
435  int ret = av_parse_video_rate(dst, val);
436  if (ret < 0)
437  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
438  return ret;
439 }
440 
441 static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
442 {
443  int ret;
444 
445  if (!val) {
446  return 0;
447  } else {
448  ret = av_parse_color(dst, val, -1, obj);
449  if (ret < 0)
450  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val);
451  return ret;
452  }
453  return 0;
454 }
455 
456 static const char *get_bool_name(int val)
457 {
458  if (val < 0)
459  return "auto";
460  return val ? "true" : "false";
461 }
462 
463 static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
464 {
465  int n;
466 
467  if (!val)
468  return 0;
469 
470  if (!strcmp(val, "auto")) {
471  n = -1;
472  } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
473  n = 1;
474  } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
475  n = 0;
476  } else {
477  char *end = NULL;
478  n = strtol(val, &end, 10);
479  if (val + strlen(val) != end)
480  goto fail;
481  }
482 
483  if (n < o->min || n > o->max)
484  goto fail;
485 
486  *dst = n;
487  return 0;
488 
489 fail:
490  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val);
491  return AVERROR(EINVAL);
492 }
493 
494 static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
495  int fmt_nb, int ((*get_fmt)(const char *)), const char *desc)
496 {
497  int fmt, min, max;
498 
499  if (!val || !strcmp(val, "none")) {
500  fmt = -1;
501  } else {
502  fmt = get_fmt(val);
503  if (fmt == -1) {
504  char *tail;
505  fmt = strtol(val, &tail, 0);
506  if (*tail || (unsigned)fmt >= fmt_nb) {
507  av_log(obj, AV_LOG_ERROR,
508  "Unable to parse option value \"%s\" as %s\n", val, desc);
509  return AVERROR(EINVAL);
510  }
511  }
512  }
513 
514  min = FFMAX(o->min, -1);
515  max = FFMIN(o->max, fmt_nb-1);
516 
517  // hack for compatibility with old ffmpeg
518  if(min == 0 && max == 0) {
519  min = -1;
520  max = fmt_nb-1;
521  }
522 
523  if (fmt < min || fmt > max) {
524  av_log(obj, AV_LOG_ERROR,
525  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
526  fmt, o->name, desc, min, max);
527  return AVERROR(ERANGE);
528  }
529 
530  *(int *)dst = fmt;
531  return 0;
532 }
533 
534 static int get_pix_fmt(const char *name)
535 {
536  return av_get_pix_fmt(name);
537 }
538 
539 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
540 {
541  return set_string_fmt(obj, o, val, dst,
542  AV_PIX_FMT_NB, get_pix_fmt, "pixel format");
543 }
544 
545 static int get_sample_fmt(const char *name)
546 {
547  return av_get_sample_fmt(name);
548 }
549 
550 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
551 {
552  return set_string_fmt(obj, o, val, dst,
553  AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format");
554 }
555 
556 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
557 {
559 
560  if (val) {
561  int ret = av_dict_parse_string(&options, val, "=", ":", 0);
562  if (ret < 0) {
564  return ret;
565  }
566  }
567 
568  av_dict_free((AVDictionary **)dst);
569  *dst = (uint8_t *)options;
570 
571  return 0;
572 }
573 
574 static int set_string_channel_layout(void *obj, const AVOption *o,
575  const char *val, void *dst)
576 {
577  AVChannelLayout *channel_layout = dst;
578  av_channel_layout_uninit(channel_layout);
579  if (!val)
580  return 0;
581  return av_channel_layout_from_string(channel_layout, val);
582 }
583 
584 static int opt_set_elem(void *obj, void *target_obj, const AVOption *o,
585  const char *val, void *dst)
586 {
587  const enum AVOptionType type = TYPE_BASE(o->type);
588  int ret;
589 
590  if (!val && (type != AV_OPT_TYPE_STRING &&
595  return AVERROR(EINVAL);
596 
597  switch (type) {
598  case AV_OPT_TYPE_BOOL:
599  return set_string_bool(obj, o, val, dst);
600  case AV_OPT_TYPE_STRING:
601  return set_string(obj, o, val, dst);
602  case AV_OPT_TYPE_BINARY:
603  return set_string_binary(obj, o, val, dst);
604  case AV_OPT_TYPE_FLAGS:
605  case AV_OPT_TYPE_INT:
606  case AV_OPT_TYPE_INT64:
607  case AV_OPT_TYPE_UINT64:
608  case AV_OPT_TYPE_FLOAT:
609  case AV_OPT_TYPE_DOUBLE:
611  return set_string_number(obj, target_obj, o, val, dst);
613  return set_string_image_size(obj, o, val, dst);
614  case AV_OPT_TYPE_VIDEO_RATE: {
615  AVRational tmp;
616  ret = set_string_video_rate(obj, o, val, &tmp);
617  if (ret < 0)
618  return ret;
619  return write_number(obj, o, dst, 1, tmp.den, tmp.num);
620  }
622  return set_string_pixel_fmt(obj, o, val, dst);
624  return set_string_sample_fmt(obj, o, val, dst);
626  {
627  int64_t usecs = 0;
628  if (val) {
629  if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
630  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
631  return ret;
632  }
633  }
634  if (usecs < o->min || usecs > o->max) {
635  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
636  usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
637  return AVERROR(ERANGE);
638  }
639  *(int64_t *)dst = usecs;
640  return 0;
641  }
642  case AV_OPT_TYPE_COLOR:
643  return set_string_color(obj, o, val, dst);
645  ret = set_string_channel_layout(obj, o, val, dst);
646  if (ret < 0) {
647  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
648  ret = AVERROR(EINVAL);
649  }
650  return ret;
651  case AV_OPT_TYPE_DICT:
652  return set_string_dict(obj, o, val, dst);
653  }
654 
655  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
656  return AVERROR(EINVAL);
657 }
658 
659 static int opt_set_array(void *obj, void *target_obj, const AVOption *o,
660  const char *val, void *dst)
661 {
662  const AVOptionArrayDef *arr = o->default_val.arr;
663  const size_t elem_size = opt_elem_size[TYPE_BASE(o->type)];
664  const uint8_t sep = opt_array_sep(o);
665  uint8_t *str = NULL;
666 
667  void *elems = NULL;
668  unsigned nb_elems = 0;
669  int ret;
670 
671  if (val && *val) {
672  str = av_malloc(strlen(val) + 1);
673  if (!str)
674  return AVERROR(ENOMEM);
675  }
676 
677  // split and unescape the string
678  while (val && *val) {
679  uint8_t *p = str;
680  void *tmp;
681 
682  if (arr && arr->size_max && nb_elems >= arr->size_max) {
683  av_log(obj, AV_LOG_ERROR,
684  "Cannot assign more than %u elements to array option %s\n",
685  arr->size_max, o->name);
686  ret = AVERROR(EINVAL);
687  goto fail;
688  }
689 
690  for (; *val; val++, p++) {
691  if (*val == '\\' && val[1])
692  val++;
693  else if (*val == sep) {
694  val++;
695  break;
696  }
697  *p = *val;
698  }
699  *p = 0;
700 
701  tmp = av_realloc_array(elems, nb_elems + 1, elem_size);
702  if (!tmp) {
703  ret = AVERROR(ENOMEM);
704  goto fail;
705  }
706  elems = tmp;
707 
708  tmp = opt_array_pelem(o, elems, nb_elems);
709  memset(tmp, 0, elem_size);
710 
711  ret = opt_set_elem(obj, target_obj, o, str, tmp);
712  if (ret < 0)
713  goto fail;
714  nb_elems++;
715  }
716  av_freep(&str);
717 
718  opt_free_array(o, dst, opt_array_pcount(dst));
719 
720  if (arr && nb_elems < arr->size_min) {
721  av_log(obj, AV_LOG_ERROR,
722  "Cannot assign fewer than %u elements to array option %s\n",
723  arr->size_min, o->name);
724  ret = AVERROR(EINVAL);
725  goto fail;
726  }
727 
728  *((void **)dst) = elems;
729  *opt_array_pcount(dst) = nb_elems;
730 
731  return 0;
732 fail:
733  av_freep(&str);
734  opt_free_array(o, &elems, &nb_elems);
735  return ret;
736 }
737 
738 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
739 {
740  void *dst, *target_obj;
741  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
742  if (!o || !target_obj)
744 
745  if (o->flags & AV_OPT_FLAG_READONLY)
746  return AVERROR(EINVAL);
747 
748  if (o->flags & AV_OPT_FLAG_DEPRECATED)
749  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
750 
751  dst = ((uint8_t *)target_obj) + o->offset;
752 
753  return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
754  opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst);
755 }
756 
757 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
758 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
759  const char *val, vartype *name ## _out) \
760 { \
761  if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
762  return AVERROR(EINVAL); \
763  return set_string_number(obj, obj, o, val, name ## _out); \
764 }
765 
768 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
769 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
770 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
772 
773 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
774  int search_flags)
775 {
776  void *dst, *target_obj;
777  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
778 
779  if (!o || !target_obj)
781 
783  return AVERROR(EINVAL);
784 
785  dst = ((uint8_t *)target_obj) + o->offset;
786  return write_number(obj, o, dst, num, den, intnum);
787 }
788 
789 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
790 {
791  return set_number(obj, name, 1, 1, val, search_flags);
792 }
793 
794 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
795 {
796  return set_number(obj, name, val, 1, 1, search_flags);
797 }
798 
799 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
800 {
801  return set_number(obj, name, val.num, val.den, 1, search_flags);
802 }
803 
804 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
805 {
806  void *target_obj;
807  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
808  uint8_t *ptr;
809  uint8_t **dst;
810  int *lendst;
811 
812  if (!o || !target_obj)
814 
816  return AVERROR(EINVAL);
817 
818  ptr = len ? av_malloc(len) : NULL;
819  if (len && !ptr)
820  return AVERROR(ENOMEM);
821 
822  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
823  lendst = (int *)(dst + 1);
824 
825  av_free(*dst);
826  *dst = ptr;
827  *lendst = len;
828  if (len)
829  memcpy(ptr, val, len);
830 
831  return 0;
832 }
833 
834 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
835 {
836  void *target_obj;
837  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
838 
839  if (!o || !target_obj)
841  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
842  av_log(obj, AV_LOG_ERROR,
843  "The value set by option '%s' is not an image size.\n", o->name);
844  return AVERROR(EINVAL);
845  }
846  if (w<0 || h<0) {
847  av_log(obj, AV_LOG_ERROR,
848  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
849  return AVERROR(EINVAL);
850  }
851  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
852  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
853  return 0;
854 }
855 
856 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
857 {
858  void *target_obj;
859  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
860 
861  if (!o || !target_obj)
863  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
864  av_log(obj, AV_LOG_ERROR,
865  "The value set by option '%s' is not a video rate.\n",
866  o->name);
867  return AVERROR(EINVAL);
868  }
869  if (val.num <= 0 || val.den <= 0)
870  return AVERROR(EINVAL);
871  return set_number(obj, name, val.num, val.den, 1, search_flags);
872 }
873 
874 static int set_format(void *obj, const char *name, int fmt, int search_flags,
875  enum AVOptionType type, const char *desc, int nb_fmts)
876 {
877  void *target_obj;
878  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
879  search_flags, &target_obj);
880  int min, max;
881 
882  if (!o || !target_obj)
884  if (o->type != type) {
885  av_log(obj, AV_LOG_ERROR,
886  "The value set by option '%s' is not a %s format", name, desc);
887  return AVERROR(EINVAL);
888  }
889 
890  min = FFMAX(o->min, -1);
891  max = FFMIN(o->max, nb_fmts-1);
892 
893  if (fmt < min || fmt > max) {
894  av_log(obj, AV_LOG_ERROR,
895  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
896  fmt, name, desc, min, max);
897  return AVERROR(ERANGE);
898  }
899  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
900  return 0;
901 }
902 
903 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
904 {
905  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
906 }
907 
908 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
909 {
910  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
911 }
912 
913 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
914  int search_flags)
915 {
916  void *target_obj;
917  AVDictionary **dst;
918  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
919 
920  if (!o || !target_obj)
922  if (o->flags & AV_OPT_FLAG_READONLY)
923  return AVERROR(EINVAL);
924 
925  dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
926  av_dict_free(dst);
927  av_dict_copy(dst, val, 0);
928 
929  return 0;
930 }
931 
932 int av_opt_set_chlayout(void *obj, const char *name,
933  const AVChannelLayout *channel_layout,
934  int search_flags)
935 {
936  void *target_obj;
937  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
938  AVChannelLayout *dst;
939 
940  if (!o || !target_obj)
942 
943  dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
944 
945  return av_channel_layout_copy(dst, channel_layout);
946 }
947 
948 static void format_duration(char *buf, size_t size, int64_t d)
949 {
950  char *e;
951 
952  av_assert0(size >= 25);
953  if (d < 0 && d != INT64_MIN) {
954  *(buf++) = '-';
955  size--;
956  d = -d;
957  }
958  if (d == INT64_MAX)
959  snprintf(buf, size, "INT64_MAX");
960  else if (d == INT64_MIN)
961  snprintf(buf, size, "INT64_MIN");
962  else if (d > (int64_t)3600*1000000)
963  snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
964  (int)((d / 60000000) % 60),
965  (int)((d / 1000000) % 60),
966  (int)(d % 1000000));
967  else if (d > 60*1000000)
968  snprintf(buf, size, "%d:%02d.%06d",
969  (int)(d / 60000000),
970  (int)((d / 1000000) % 60),
971  (int)(d % 1000000));
972  else
973  snprintf(buf, size, "%d.%06d",
974  (int)(d / 1000000),
975  (int)(d % 1000000));
976  e = buf + strlen(buf);
977  while (e > buf && e[-1] == '0')
978  *(--e) = 0;
979  if (e > buf && e[-1] == '.')
980  *(--e) = 0;
981 }
982 
983 static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
984  void *dst, int search_flags)
985 {
986  int ret;
987 
988  switch (TYPE_BASE(o->type)) {
989  case AV_OPT_TYPE_BOOL:
990  ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
991  break;
992  case AV_OPT_TYPE_FLAGS:
993  ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
994  break;
995  case AV_OPT_TYPE_INT:
996  ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
997  break;
998  case AV_OPT_TYPE_INT64:
999  ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
1000  break;
1001  case AV_OPT_TYPE_UINT64:
1002  ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
1003  break;
1004  case AV_OPT_TYPE_FLOAT:
1005  ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
1006  break;
1007  case AV_OPT_TYPE_DOUBLE:
1008  ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
1009  break;
1011  case AV_OPT_TYPE_RATIONAL:
1012  ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
1013  break;
1014  case AV_OPT_TYPE_CONST:
1015  ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
1016  break;
1017  case AV_OPT_TYPE_STRING:
1018  if (*(uint8_t **)dst) {
1019  *pbuf = av_strdup(*(uint8_t **)dst);
1020  } else if (search_flags & AV_OPT_ALLOW_NULL) {
1021  *pbuf = NULL;
1022  return 0;
1023  } else {
1024  *pbuf = av_strdup("");
1025  }
1026  return *pbuf ? 0 : AVERROR(ENOMEM);
1027  case AV_OPT_TYPE_BINARY: {
1028  const uint8_t *bin;
1029  int len;
1030 
1031  if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1032  *pbuf = NULL;
1033  return 0;
1034  }
1035  len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
1036  if ((uint64_t)len * 2 + 1 > INT_MAX)
1037  return AVERROR(EINVAL);
1038  if (!(*pbuf = av_malloc(len * 2 + 1)))
1039  return AVERROR(ENOMEM);
1040  if (!len) {
1041  *pbuf[0] = '\0';
1042  return 0;
1043  }
1044  bin = *(uint8_t **)dst;
1045  for (int i = 0; i < len; i++)
1046  snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
1047  return 0;
1048  }
1050  ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
1051  break;
1052  case AV_OPT_TYPE_PIXEL_FMT:
1053  ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
1054  break;
1056  ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
1057  break;
1058  case AV_OPT_TYPE_DURATION: {
1059  int64_t i64 = *(int64_t *)dst;
1060  format_duration(*pbuf, buf_len, i64);
1061  ret = strlen(*pbuf); // no overflow possible, checked by an assert
1062  break;
1063  }
1064  case AV_OPT_TYPE_COLOR:
1065  ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
1066  (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
1067  (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
1068  break;
1069  case AV_OPT_TYPE_CHLAYOUT:
1070  ret = av_channel_layout_describe(dst, *pbuf, buf_len);
1071  break;
1072  case AV_OPT_TYPE_DICT:
1073  if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1074  *pbuf = NULL;
1075  return 0;
1076  }
1077  return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
1078  default:
1079  return AVERROR(EINVAL);
1080  }
1081 
1082  return ret;
1083 }
1084 
1085 static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
1086 {
1087  const unsigned count = *opt_array_pcount(dst);
1088  const uint8_t sep = opt_array_sep(o);
1089 
1090  uint8_t *str = NULL;
1091  size_t str_len = 0;
1092  int ret;
1093 
1094  *out_val = NULL;
1095 
1096  for (unsigned i = 0; i < count; i++) {
1097  uint8_t buf[128], *out = buf;
1098  size_t out_len;
1099 
1100  ret = opt_get_elem(o, &out, sizeof(buf),
1101  opt_array_pelem(o, *(void **)dst, i), 0);
1102  if (ret < 0)
1103  goto fail;
1104 
1105  out_len = strlen(out);
1106  if (out_len > SIZE_MAX / 2 - !!i ||
1107  !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
1108  ret = AVERROR(ERANGE);
1109  goto fail;
1110  }
1111 
1112  // terminator escaping separator
1113  // ↓ ↓ ↓
1114  ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
1115  if (ret < 0)
1116  goto fail;
1117 
1118  // add separator if needed
1119  if (i)
1120  str[str_len++] = sep;
1121 
1122  // escape the element
1123  for (unsigned j = 0; j < out_len; j++) {
1124  uint8_t val = out[j];
1125  if (val == sep || val == '\\')
1126  str[str_len++] = '\\';
1127  str[str_len++] = val;
1128  }
1129  str[str_len] = 0;
1130 
1131 fail:
1132  if (out != buf)
1133  av_freep(&out);
1134  if (ret < 0) {
1135  av_freep(&str);
1136  return ret;
1137  }
1138  }
1139 
1140  *out_val = str;
1141 
1142  return 0;
1143 }
1144 
1145 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
1146 {
1147  void *dst, *target_obj;
1148  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1149  uint8_t *out, buf[128];
1150  int ret;
1151 
1152  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
1153  return AVERROR_OPTION_NOT_FOUND;
1154 
1155  if (o->flags & AV_OPT_FLAG_DEPRECATED)
1156  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
1157 
1158  dst = (uint8_t *)target_obj + o->offset;
1159 
1160  if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
1161  ret = opt_get_array(o, dst, out_val);
1162  if (ret < 0)
1163  return ret;
1164  if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) {
1165  *out_val = av_strdup("");
1166  if (!*out_val)
1167  return AVERROR(ENOMEM);
1168  }
1169  return 0;
1170  }
1171 
1172  buf[0] = 0;
1173  out = buf;
1174  ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
1175  if (ret < 0)
1176  return ret;
1177  if (out != buf) {
1178  *out_val = out;
1179  return 0;
1180  }
1181 
1182  if (ret >= sizeof(buf))
1183  return AVERROR(EINVAL);
1184  *out_val = av_strdup(out);
1185  return *out_val ? 0 : AVERROR(ENOMEM);
1186 }
1187 
1188 static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
1189  int search_flags)
1190 {
1191  void *dst, *target_obj;
1192  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1193  if (!o || !target_obj)
1194  return AVERROR_OPTION_NOT_FOUND;
1195  if (o->type & AV_OPT_TYPE_FLAG_ARRAY)
1196  return AVERROR(EINVAL);
1197 
1198  dst = ((uint8_t *)target_obj) + o->offset;
1199 
1200  return read_number(o, dst, num, den, intnum);
1201 }
1202 
1203 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
1204 {
1205  int64_t intnum = 1;
1206  double num = 1;
1207  int ret, den = 1;
1208 
1209  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1210  return ret;
1211  if (num == den)
1212  *out_val = intnum;
1213  else
1214  *out_val = num * intnum / den;
1215  return 0;
1216 }
1217 
1218 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
1219 {
1220  int64_t intnum = 1;
1221  double num = 1;
1222  int ret, den = 1;
1223 
1224  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1225  return ret;
1226  *out_val = num * intnum / den;
1227  return 0;
1228 }
1229 
1230 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1231 {
1232  int64_t intnum = 1;
1233  double num = 1;
1234  int ret, den = 1;
1235 
1236  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1237  return ret;
1238 
1239  if (num == 1.0 && (int)intnum == intnum)
1240  *out_val = (AVRational){intnum, den};
1241  else
1242  *out_val = av_d2q(num*intnum/den, 1<<24);
1243  return 0;
1244 }
1245 
1246 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1247 {
1248  void *dst, *target_obj;
1249  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1250  if (!o || !target_obj)
1251  return AVERROR_OPTION_NOT_FOUND;
1252  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1253  av_log(obj, AV_LOG_ERROR,
1254  "The value for option '%s' is not a image size.\n", name);
1255  return AVERROR(EINVAL);
1256  }
1257 
1258  dst = ((uint8_t*)target_obj) + o->offset;
1259  if (w_out) *w_out = *(int *)dst;
1260  if (h_out) *h_out = *((int *)dst+1);
1261  return 0;
1262 }
1263 
1264 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1265 {
1266  int64_t intnum = 1;
1267  double num = 1;
1268  int ret, den = 1;
1269 
1270  if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1271  return ret;
1272 
1273  if (num == 1.0 && (int)intnum == intnum)
1274  *out_val = (AVRational) { intnum, den };
1275  else
1276  *out_val = av_d2q(num * intnum / den, 1 << 24);
1277  return 0;
1278 }
1279 
1280 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
1281  enum AVOptionType type, const char *desc)
1282 {
1283  void *dst, *target_obj;
1284  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1285  if (!o || !target_obj)
1286  return AVERROR_OPTION_NOT_FOUND;
1287  if (o->type != type) {
1288  av_log(obj, AV_LOG_ERROR,
1289  "The value for option '%s' is not a %s format.\n", desc, name);
1290  return AVERROR(EINVAL);
1291  }
1292 
1293  dst = ((uint8_t*)target_obj) + o->offset;
1294  *out_fmt = *(int *)dst;
1295  return 0;
1296 }
1297 
1298 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1299 {
1300  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1301 }
1302 
1303 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1304 {
1305  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1306 }
1307 
1308 int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1309 {
1310  void *dst, *target_obj;
1311  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1312  if (!o || !target_obj)
1313  return AVERROR_OPTION_NOT_FOUND;
1314  if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1315  av_log(obj, AV_LOG_ERROR,
1316  "The value for option '%s' is not a channel layout.\n", name);
1317  return AVERROR(EINVAL);
1318  }
1319 
1320  dst = ((uint8_t*)target_obj) + o->offset;
1321  return av_channel_layout_copy(cl, dst);
1322 }
1323 
1324 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1325 {
1326  void *target_obj;
1327  AVDictionary *src;
1328  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1329 
1330  if (!o || !target_obj)
1331  return AVERROR_OPTION_NOT_FOUND;
1332  if (o->type != AV_OPT_TYPE_DICT)
1333  return AVERROR(EINVAL);
1334 
1335  src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1336  av_dict_copy(out_val, src, 0);
1337 
1338  return 0;
1339 }
1340 
1341 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1342 {
1343  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1344  const AVOption *flag = av_opt_find(obj, flag_name,
1345  field ? field->unit : NULL, 0, 0);
1346  int64_t res;
1347 
1348  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1349  av_opt_get_int(obj, field_name, 0, &res) < 0)
1350  return 0;
1351  return res & flag->default_val.i64;
1352 }
1353 
1354 static void log_int_value(void *av_log_obj, int level, int64_t i)
1355 {
1356  if (i == INT_MAX) {
1357  av_log(av_log_obj, level, "INT_MAX");
1358  } else if (i == INT_MIN) {
1359  av_log(av_log_obj, level, "INT_MIN");
1360  } else if (i == UINT32_MAX) {
1361  av_log(av_log_obj, level, "UINT32_MAX");
1362  } else if (i == INT64_MAX) {
1363  av_log(av_log_obj, level, "I64_MAX");
1364  } else if (i == INT64_MIN) {
1365  av_log(av_log_obj, level, "I64_MIN");
1366  } else {
1367  av_log(av_log_obj, level, "%"PRId64, i);
1368  }
1369 }
1370 
1371 static void log_value(void *av_log_obj, int level, double d)
1372 {
1373  if (d == INT_MAX) {
1374  av_log(av_log_obj, level, "INT_MAX");
1375  } else if (d == INT_MIN) {
1376  av_log(av_log_obj, level, "INT_MIN");
1377  } else if (d == UINT32_MAX) {
1378  av_log(av_log_obj, level, "UINT32_MAX");
1379  } else if (d == (double)INT64_MAX) {
1380  av_log(av_log_obj, level, "I64_MAX");
1381  } else if (d == INT64_MIN) {
1382  av_log(av_log_obj, level, "I64_MIN");
1383  } else if (d == FLT_MAX) {
1384  av_log(av_log_obj, level, "FLT_MAX");
1385  } else if (d == FLT_MIN) {
1386  av_log(av_log_obj, level, "FLT_MIN");
1387  } else if (d == -FLT_MAX) {
1388  av_log(av_log_obj, level, "-FLT_MAX");
1389  } else if (d == -FLT_MIN) {
1390  av_log(av_log_obj, level, "-FLT_MIN");
1391  } else if (d == DBL_MAX) {
1392  av_log(av_log_obj, level, "DBL_MAX");
1393  } else if (d == DBL_MIN) {
1394  av_log(av_log_obj, level, "DBL_MIN");
1395  } else if (d == -DBL_MAX) {
1396  av_log(av_log_obj, level, "-DBL_MAX");
1397  } else if (d == -DBL_MIN) {
1398  av_log(av_log_obj, level, "-DBL_MIN");
1399  } else {
1400  av_log(av_log_obj, level, "%g", d);
1401  }
1402 }
1403 
1404 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1405 {
1406  const AVOption *opt = NULL;
1407 
1408  if (!unit)
1409  return NULL;
1410  while ((opt = av_opt_next(obj, opt)))
1411  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1412  opt->default_val.i64 == value)
1413  return opt->name;
1414  return NULL;
1415 }
1416 
1417 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1418 {
1419  const AVOption *opt = NULL;
1420  char flags[512];
1421 
1422  flags[0] = 0;
1423  if (!unit)
1424  return NULL;
1425  while ((opt = av_opt_next(obj, opt))) {
1426  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1427  opt->default_val.i64 & value) {
1428  if (flags[0])
1429  av_strlcatf(flags, sizeof(flags), "+");
1430  av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1431  }
1432  }
1433  if (flags[0])
1434  return av_strdup(flags);
1435  return NULL;
1436 }
1437 
1438 static void log_type(void *av_log_obj, const AVOption *o,
1439  enum AVOptionType parent_type)
1440 {
1441  const char *desc[] = {
1442  [AV_OPT_TYPE_FLAGS] = "<flags>",
1443  [AV_OPT_TYPE_INT] = "<int>",
1444  [AV_OPT_TYPE_INT64] = "<int64>",
1445  [AV_OPT_TYPE_UINT64] = "<uint64>",
1446  [AV_OPT_TYPE_DOUBLE] = "<double>",
1447  [AV_OPT_TYPE_FLOAT] = "<float>",
1448  [AV_OPT_TYPE_STRING] = "<string>",
1449  [AV_OPT_TYPE_RATIONAL] = "<rational>",
1450  [AV_OPT_TYPE_BINARY] = "<binary>",
1451  [AV_OPT_TYPE_DICT] = "<dictionary>",
1452  [AV_OPT_TYPE_IMAGE_SIZE] = "<image_size>",
1453  [AV_OPT_TYPE_VIDEO_RATE] = "<video_rate>",
1454  [AV_OPT_TYPE_PIXEL_FMT] = "<pix_fmt>",
1455  [AV_OPT_TYPE_SAMPLE_FMT] = "<sample_fmt>",
1456  [AV_OPT_TYPE_DURATION] = "<duration>",
1457  [AV_OPT_TYPE_COLOR] = "<color>",
1458  [AV_OPT_TYPE_CHLAYOUT] = "<channel_layout>",
1459  [AV_OPT_TYPE_BOOL] = "<boolean>",
1460  };
1461  const enum AVOptionType type = TYPE_BASE(o->type);
1462 
1463  if (o->type == AV_OPT_TYPE_CONST && TYPE_BASE(parent_type) == AV_OPT_TYPE_INT)
1464  av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
1465  else if (type < FF_ARRAY_ELEMS(desc) && desc[type]) {
1466  if (o->type & AV_OPT_TYPE_FLAG_ARRAY)
1467  av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", desc[type]);
1468  else
1469  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", desc[type]);
1470  }
1471  else
1472  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1473 }
1474 
1475 static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
1476 {
1477  if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY)
1478  return;
1479  if ((opt->type == AV_OPT_TYPE_COLOR ||
1480  opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1481  opt->type == AV_OPT_TYPE_STRING ||
1482  opt->type == AV_OPT_TYPE_DICT ||
1483  opt->type == AV_OPT_TYPE_CHLAYOUT ||
1484  opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1485  !opt->default_val.str)
1486  return;
1487 
1488  if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1489  const AVOptionArrayDef *arr = opt->default_val.arr;
1490  if (arr && arr->def)
1491  av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def);
1492  return;
1493  }
1494 
1495  av_log(av_log_obj, AV_LOG_INFO, " (default ");
1496  switch (opt->type) {
1497  case AV_OPT_TYPE_BOOL:
1498  av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64));
1499  break;
1500  case AV_OPT_TYPE_FLAGS: {
1501  char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1502  if (def_flags) {
1503  av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1504  av_freep(&def_flags);
1505  } else {
1506  av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1507  }
1508  break;
1509  }
1510  case AV_OPT_TYPE_DURATION: {
1511  char buf[25];
1512  format_duration(buf, sizeof(buf), opt->default_val.i64);
1513  av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1514  break;
1515  }
1516  case AV_OPT_TYPE_INT:
1517  case AV_OPT_TYPE_UINT64:
1518  case AV_OPT_TYPE_INT64: {
1519  const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1520  if (def_const)
1521  av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1522  else
1523  log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1524  break;
1525  }
1526  case AV_OPT_TYPE_DOUBLE:
1527  case AV_OPT_TYPE_FLOAT:
1528  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1529  break;
1530  case AV_OPT_TYPE_RATIONAL: {
1531  AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1532  av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1533  break;
1534  case AV_OPT_TYPE_PIXEL_FMT:
1535  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1536  break;
1538  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1539  break;
1540  case AV_OPT_TYPE_COLOR:
1542  case AV_OPT_TYPE_STRING:
1543  case AV_OPT_TYPE_DICT:
1545  case AV_OPT_TYPE_CHLAYOUT:
1546  av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1547  break;
1548  }
1549  av_log(av_log_obj, AV_LOG_INFO, ")");
1550 }
1551 
1552 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1553  int req_flags, int rej_flags, enum AVOptionType parent_type)
1554 {
1555  const AVOption *opt = NULL;
1556  AVOptionRanges *r;
1557  int i;
1558 
1559  while ((opt = av_opt_next(obj, opt))) {
1560  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1561  continue;
1562 
1563  /* Don't print CONST's on level one.
1564  * Don't print anything but CONST's on level two.
1565  * Only print items from the requested unit.
1566  */
1567  if (!unit && opt->type == AV_OPT_TYPE_CONST)
1568  continue;
1569  else if (unit && opt->type != AV_OPT_TYPE_CONST)
1570  continue;
1571  else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1572  continue;
1573  else if (unit && opt->type == AV_OPT_TYPE_CONST)
1574  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1575  else
1576  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1577  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1578  opt->name);
1579 
1580  log_type(av_log_obj, opt, parent_type);
1581 
1582  av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1583  (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1584  (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1585  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1586  (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1587  (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1588  (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1589  (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1590  (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1591  (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1592  (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1593  (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1594 
1595  if (opt->help)
1596  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1597 
1598  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1599  switch (opt->type) {
1600  case AV_OPT_TYPE_INT:
1601  case AV_OPT_TYPE_INT64:
1602  case AV_OPT_TYPE_UINT64:
1603  case AV_OPT_TYPE_DOUBLE:
1604  case AV_OPT_TYPE_FLOAT:
1605  case AV_OPT_TYPE_RATIONAL:
1606  for (i = 0; i < r->nb_ranges; i++) {
1607  av_log(av_log_obj, AV_LOG_INFO, " (from ");
1608  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1609  av_log(av_log_obj, AV_LOG_INFO, " to ");
1610  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1611  av_log(av_log_obj, AV_LOG_INFO, ")");
1612  }
1613  break;
1614  }
1616  }
1617 
1618  log_default(obj, av_log_obj, opt);
1619 
1620  av_log(av_log_obj, AV_LOG_INFO, "\n");
1621  if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1622  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1623  }
1624 }
1625 
1626 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1627 {
1628  if (!obj)
1629  return -1;
1630 
1631  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1632 
1633  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1634 
1635  return 0;
1636 }
1637 
1639 {
1640  av_opt_set_defaults2(s, 0, 0);
1641 }
1642 
1643 void av_opt_set_defaults2(void *s, int mask, int flags)
1644 {
1645  const AVOption *opt = NULL;
1646  while ((opt = av_opt_next(s, opt))) {
1647  void *dst = ((uint8_t*)s) + opt->offset;
1648 
1649  if ((opt->flags & mask) != flags)
1650  continue;
1651 
1652  if (opt->flags & AV_OPT_FLAG_READONLY)
1653  continue;
1654 
1655  if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1656  const AVOptionArrayDef *arr = opt->default_val.arr;
1657  const char sep = opt_array_sep(opt);
1658 
1659  av_assert0(sep && sep != '\\' &&
1660  (sep < 'a' || sep > 'z') &&
1661  (sep < 'A' || sep > 'Z') &&
1662  (sep < '0' || sep > '9'));
1663 
1664  if (arr && arr->def)
1665  opt_set_array(s, s, opt, arr->def, dst);
1666 
1667  continue;
1668  }
1669 
1670  switch (opt->type) {
1671  case AV_OPT_TYPE_CONST:
1672  /* Nothing to be done here */
1673  break;
1674  case AV_OPT_TYPE_BOOL:
1675  case AV_OPT_TYPE_FLAGS:
1676  case AV_OPT_TYPE_INT:
1677  case AV_OPT_TYPE_INT64:
1678  case AV_OPT_TYPE_UINT64:
1679  case AV_OPT_TYPE_DURATION:
1680  case AV_OPT_TYPE_PIXEL_FMT:
1682  write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1683  break;
1684  case AV_OPT_TYPE_DOUBLE:
1685  case AV_OPT_TYPE_FLOAT: {
1686  double val;
1687  val = opt->default_val.dbl;
1688  write_number(s, opt, dst, val, 1, 1);
1689  }
1690  break;
1691  case AV_OPT_TYPE_RATIONAL: {
1692  AVRational val;
1693  val = av_d2q(opt->default_val.dbl, INT_MAX);
1694  write_number(s, opt, dst, 1, val.den, val.num);
1695  }
1696  break;
1697  case AV_OPT_TYPE_COLOR:
1698  set_string_color(s, opt, opt->default_val.str, dst);
1699  break;
1700  case AV_OPT_TYPE_STRING:
1701  set_string(s, opt, opt->default_val.str, dst);
1702  break;
1704  set_string_image_size(s, opt, opt->default_val.str, dst);
1705  break;
1707  set_string_video_rate(s, opt, opt->default_val.str, dst);
1708  break;
1709  case AV_OPT_TYPE_BINARY:
1710  set_string_binary(s, opt, opt->default_val.str, dst);
1711  break;
1712  case AV_OPT_TYPE_CHLAYOUT:
1713  set_string_channel_layout(s, opt, opt->default_val.str, dst);
1714  break;
1715  case AV_OPT_TYPE_DICT:
1716  set_string_dict(s, opt, opt->default_val.str, dst);
1717  break;
1718  default:
1719  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1720  opt->type, opt->name);
1721  }
1722  }
1723 }
1724 
1725 /**
1726  * Store the value in the field in ctx that is named like key.
1727  * ctx must be an AVClass context, storing is done using AVOptions.
1728  *
1729  * @param buf the string to parse, buf will be updated to point at the
1730  * separator just after the parsed key/value pair
1731  * @param key_val_sep a 0-terminated list of characters used to
1732  * separate key from value
1733  * @param pairs_sep a 0-terminated list of characters used to separate
1734  * two pairs from each other
1735  * @return 0 if the key/value pair has been successfully parsed and
1736  * set, or a negative value corresponding to an AVERROR code in case
1737  * of error:
1738  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1739  * the error code issued by av_opt_set() if the key/value pair
1740  * cannot be set
1741  */
1742 static int parse_key_value_pair(void *ctx, const char **buf,
1743  const char *key_val_sep, const char *pairs_sep)
1744 {
1745  char *key = av_get_token(buf, key_val_sep);
1746  char *val;
1747  int ret;
1748 
1749  if (!key)
1750  return AVERROR(ENOMEM);
1751 
1752  if (*key && strspn(*buf, key_val_sep)) {
1753  (*buf)++;
1754  val = av_get_token(buf, pairs_sep);
1755  if (!val) {
1756  av_freep(&key);
1757  return AVERROR(ENOMEM);
1758  }
1759  } else {
1760  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1761  av_free(key);
1762  return AVERROR(EINVAL);
1763  }
1764 
1765  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1766 
1769  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1770 
1771  av_free(key);
1772  av_free(val);
1773  return ret;
1774 }
1775 
1776 int av_set_options_string(void *ctx, const char *opts,
1777  const char *key_val_sep, const char *pairs_sep)
1778 {
1779  int ret, count = 0;
1780 
1781  if (!opts)
1782  return 0;
1783 
1784  while (*opts) {
1785  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1786  return ret;
1787  count++;
1788 
1789  if (*opts)
1790  opts++;
1791  }
1792 
1793  return count;
1794 }
1795 
1796 #define WHITESPACES " \n\t\r"
1797 
1798 static int is_key_char(char c)
1799 {
1800  return (unsigned)((c | 32) - 'a') < 26 ||
1801  (unsigned)(c - '0') < 10 ||
1802  c == '-' || c == '_' || c == '/' || c == '.';
1803 }
1804 
1805 /**
1806  * Read a key from a string.
1807  *
1808  * The key consists of is_key_char characters and must be terminated by a
1809  * character from the delim string; spaces are ignored.
1810  *
1811  * @return 0 for success (even with ellipsis), <0 for failure
1812  */
1813 static int get_key(const char **ropts, const char *delim, char **rkey)
1814 {
1815  const char *opts = *ropts;
1816  const char *key_start, *key_end;
1817 
1818  key_start = opts += strspn(opts, WHITESPACES);
1819  while (is_key_char(*opts))
1820  opts++;
1821  key_end = opts;
1822  opts += strspn(opts, WHITESPACES);
1823  if (!*opts || !strchr(delim, *opts))
1824  return AVERROR(EINVAL);
1825  opts++;
1826  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1827  return AVERROR(ENOMEM);
1828  memcpy(*rkey, key_start, key_end - key_start);
1829  (*rkey)[key_end - key_start] = 0;
1830  *ropts = opts;
1831  return 0;
1832 }
1833 
1834 int av_opt_get_key_value(const char **ropts,
1835  const char *key_val_sep, const char *pairs_sep,
1836  unsigned flags,
1837  char **rkey, char **rval)
1838 {
1839  int ret;
1840  char *key = NULL, *val;
1841  const char *opts = *ropts;
1842 
1843  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1845  return AVERROR(EINVAL);
1846  if (!(val = av_get_token(&opts, pairs_sep))) {
1847  av_free(key);
1848  return AVERROR(ENOMEM);
1849  }
1850  *ropts = opts;
1851  *rkey = key;
1852  *rval = val;
1853  return 0;
1854 }
1855 
1856 int av_opt_set_from_string(void *ctx, const char *opts,
1857  const char *const *shorthand,
1858  const char *key_val_sep, const char *pairs_sep)
1859 {
1860  int ret, count = 0;
1861  const char *dummy_shorthand = NULL;
1862  char *av_uninit(parsed_key), *av_uninit(value);
1863  const char *key;
1864 
1865  if (!opts)
1866  return 0;
1867  if (!shorthand)
1868  shorthand = &dummy_shorthand;
1869 
1870  while (*opts) {
1871  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1872  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1873  &parsed_key, &value);
1874  if (ret < 0) {
1875  if (ret == AVERROR(EINVAL))
1876  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1877  else
1878  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1879  av_err2str(ret));
1880  return ret;
1881  }
1882  if (*opts)
1883  opts++;
1884  if (parsed_key) {
1885  key = parsed_key;
1886  while (*shorthand) /* discard all remaining shorthand */
1887  shorthand++;
1888  } else {
1889  key = *(shorthand++);
1890  }
1891 
1892  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1893  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1895  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1896  av_free(value);
1897  av_free(parsed_key);
1898  return ret;
1899  }
1900 
1901  av_free(value);
1902  av_free(parsed_key);
1903  count++;
1904  }
1905  return count;
1906 }
1907 
1908 void av_opt_free(void *obj)
1909 {
1910  const AVOption *o = NULL;
1911  while ((o = av_opt_next(obj, o))) {
1912  void *pitem = (uint8_t *)obj + o->offset;
1913 
1915  opt_free_array(o, pitem, opt_array_pcount(pitem));
1916  else
1917  opt_free_elem(o, pitem);
1918  }
1919 }
1920 
1921 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1922 {
1923  const AVDictionaryEntry *t = NULL;
1924  AVDictionary *tmp = NULL;
1925  int ret;
1926 
1927  if (!options)
1928  return 0;
1929 
1930  while ((t = av_dict_iterate(*options, t))) {
1931  ret = av_opt_set(obj, t->key, t->value, search_flags);
1934  if (ret < 0) {
1935  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1936  av_dict_free(&tmp);
1937  return ret;
1938  }
1939  }
1941  *options = tmp;
1942  return 0;
1943 }
1944 
1946 {
1947  return av_opt_set_dict2(obj, options, 0);
1948 }
1949 
1950 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1951  int opt_flags, int search_flags)
1952 {
1953  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1954 }
1955 
1956 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1957  int opt_flags, int search_flags, void **target_obj)
1958 {
1959  const AVClass *c;
1960  const AVOption *o = NULL;
1961 
1962  if(!obj)
1963  return NULL;
1964 
1965  c= *(AVClass**)obj;
1966 
1967  if (!c)
1968  return NULL;
1969 
1970  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1971  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1972  void *iter = NULL;
1973  const AVClass *child;
1974  while (child = av_opt_child_class_iterate(c, &iter))
1975  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1976  return o;
1977  } else {
1978  void *child = NULL;
1979  while (child = av_opt_child_next(obj, child))
1980  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1981  return o;
1982  }
1983  }
1984 
1985  while (o = av_opt_next(obj, o)) {
1986  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1987  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1988  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1989  if (target_obj) {
1990  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1991  *target_obj = obj;
1992  else
1993  *target_obj = NULL;
1994  }
1995  return o;
1996  }
1997  }
1998  return NULL;
1999 }
2000 
2001 void *av_opt_child_next(void *obj, void *prev)
2002 {
2003  const AVClass *c = *(AVClass **)obj;
2004  if (c->child_next)
2005  return c->child_next(obj, prev);
2006  return NULL;
2007 }
2008 
2009 const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
2010 {
2011  if (parent->child_class_iterate)
2012  return parent->child_class_iterate(iter);
2013  return NULL;
2014 }
2015 
2016 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
2017 {
2018  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
2019 
2020  // no direct access to array-type options
2021  if (!opt || (opt->type & AV_OPT_TYPE_FLAG_ARRAY))
2022  return NULL;
2023  return (uint8_t*)obj + opt->offset;
2024 }
2025 
2026 static int opt_copy_elem(void *logctx, enum AVOptionType type,
2027  void *dst, const void *src)
2028 {
2029  uint8_t **dst8 = (uint8_t **)dst;
2030  const uint8_t **src8 = (const uint8_t **)src;
2031 
2032  if (type == AV_OPT_TYPE_STRING) {
2033  if (*dst8 != *src8)
2034  av_freep(dst8);
2035  *dst8 = av_strdup(*src8);
2036  if (*src8 && !*dst8)
2037  return AVERROR(ENOMEM);
2038  } else if (type == AV_OPT_TYPE_BINARY) {
2039  int len = *(const int *)(src8 + 1);
2040  if (*dst8 != *src8)
2041  av_freep(dst8);
2042  *dst8 = av_memdup(*src8, len);
2043  if (len && !*dst8) {
2044  *(int *)(dst8 + 1) = 0;
2045  return AVERROR(ENOMEM);
2046  }
2047  *(int *)(dst8 + 1) = len;
2048  } else if (type == AV_OPT_TYPE_CONST) {
2049  // do nothing
2050  } else if (type == AV_OPT_TYPE_DICT) {
2051  AVDictionary **sdict = (AVDictionary **)src;
2052  AVDictionary **ddict = (AVDictionary **)dst;
2053  if (*sdict != *ddict)
2054  av_dict_free(ddict);
2055  *ddict = NULL;
2056  return av_dict_copy(ddict, *sdict, 0);
2057  } else if (type == AV_OPT_TYPE_CHLAYOUT) {
2058  if (dst != src)
2059  return av_channel_layout_copy(dst, src);
2060  } else if (opt_is_pod(type)) {
2061  size_t size = opt_elem_size[type];
2062  memcpy(dst, src, size);
2063  } else {
2064  av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type);
2065  return AVERROR(EINVAL);
2066  }
2067 
2068  return 0;
2069 }
2070 
2071 static int opt_copy_array(void *logctx, const AVOption *o,
2072  void **pdst, const void * const *psrc)
2073 {
2074  unsigned nb_elems = *opt_array_pcount(psrc);
2075  void *dst = NULL;
2076  int ret;
2077 
2078  if (*pdst == *psrc) {
2079  *pdst = NULL;
2080  *opt_array_pcount(pdst) = 0;
2081  }
2082 
2083  opt_free_array(o, pdst, opt_array_pcount(pdst));
2084 
2085  dst = av_calloc(nb_elems, opt_elem_size[TYPE_BASE(o->type)]);
2086  if (!dst)
2087  return AVERROR(ENOMEM);
2088 
2089  for (unsigned i = 0; i < nb_elems; i++) {
2090  ret = opt_copy_elem(logctx, TYPE_BASE(o->type),
2091  opt_array_pelem(o, dst, i),
2092  opt_array_pelem(o, *(void**)psrc, i));
2093  if (ret < 0) {
2094  opt_free_array(o, &dst, &nb_elems);
2095  return ret;
2096  }
2097  }
2098 
2099  *pdst = dst;
2100  *opt_array_pcount(pdst) = nb_elems;
2101 
2102  return 0;
2103 }
2104 
2105 int av_opt_copy(void *dst, const void *src)
2106 {
2107  const AVOption *o = NULL;
2108  const AVClass *c;
2109  int ret = 0;
2110 
2111  if (!src)
2112  return AVERROR(EINVAL);
2113 
2114  c = *(AVClass **)src;
2115  if (!c || c != *(AVClass **)dst)
2116  return AVERROR(EINVAL);
2117 
2118  while ((o = av_opt_next(src, o))) {
2119  void *field_dst = (uint8_t *)dst + o->offset;
2120  void *field_src = (uint8_t *)src + o->offset;
2121 
2122  int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
2123  opt_copy_array(dst, o, field_dst, field_src) :
2124  opt_copy_elem (dst, o->type, field_dst, field_src);
2125  if (err < 0)
2126  ret = err;
2127  }
2128  return ret;
2129 }
2130 
2131 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2132 {
2133  int ret;
2134  const AVClass *c = *(AVClass**)obj;
2135  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
2136 
2137  if (!callback)
2139 
2140  ret = callback(ranges_arg, obj, key, flags);
2141  if (ret >= 0) {
2143  ret = 1;
2144  (*ranges_arg)->nb_components = ret;
2145  }
2146  return ret;
2147 }
2148 
2149 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2150 {
2151  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
2152  AVOptionRange **range_array = av_mallocz(sizeof(void*));
2153  AVOptionRange *range = av_mallocz(sizeof(*range));
2154  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
2155  int ret;
2156 
2157  *ranges_arg = NULL;
2158 
2159  if (!ranges || !range || !range_array || !field) {
2160  ret = AVERROR(ENOMEM);
2161  goto fail;
2162  }
2163 
2164  ranges->range = range_array;
2165  ranges->range[0] = range;
2166  ranges->nb_ranges = 1;
2167  ranges->nb_components = 1;
2168  range->is_range = 1;
2169  range->value_min = field->min;
2170  range->value_max = field->max;
2171 
2172  switch (field->type) {
2173  case AV_OPT_TYPE_BOOL:
2174  case AV_OPT_TYPE_INT:
2175  case AV_OPT_TYPE_INT64:
2176  case AV_OPT_TYPE_UINT64:
2177  case AV_OPT_TYPE_PIXEL_FMT:
2179  case AV_OPT_TYPE_FLOAT:
2180  case AV_OPT_TYPE_DOUBLE:
2181  case AV_OPT_TYPE_DURATION:
2182  case AV_OPT_TYPE_COLOR:
2183  break;
2184  case AV_OPT_TYPE_STRING:
2185  range->component_min = 0;
2186  range->component_max = 0x10FFFF; // max unicode value
2187  range->value_min = -1;
2188  range->value_max = INT_MAX;
2189  break;
2190  case AV_OPT_TYPE_RATIONAL:
2191  range->component_min = INT_MIN;
2192  range->component_max = INT_MAX;
2193  break;
2195  range->component_min = 0;
2196  range->component_max = INT_MAX/128/8;
2197  range->value_min = 0;
2198  range->value_max = INT_MAX/8;
2199  break;
2201  range->component_min = 1;
2202  range->component_max = INT_MAX;
2203  range->value_min = 1;
2204  range->value_max = INT_MAX;
2205  break;
2206  default:
2207  ret = AVERROR(ENOSYS);
2208  goto fail;
2209  }
2210 
2211  *ranges_arg = ranges;
2212  return 1;
2213 fail:
2214  av_free(ranges);
2215  av_free(range);
2216  av_free(range_array);
2217  return ret;
2218 }
2219 
2221 {
2222  int i;
2223  AVOptionRanges *ranges = *rangesp;
2224 
2225  if (!ranges)
2226  return;
2227 
2228  for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
2229  AVOptionRange *range = ranges->range[i];
2230  if (range) {
2231  av_freep(&range->str);
2232  av_freep(&ranges->range[i]);
2233  }
2234  }
2235  av_freep(&ranges->range);
2236  av_freep(rangesp);
2237 }
2238 
2239 int av_opt_is_set_to_default(void *obj, const AVOption *o)
2240 {
2241  int64_t i64;
2242  double d;
2243  AVRational q;
2244  int ret, w, h;
2245  char *str;
2246  void *dst;
2247 
2248  if (!o || !obj)
2249  return AVERROR(EINVAL);
2250 
2251  dst = ((uint8_t*)obj) + o->offset;
2252 
2253  if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
2254  const char *def = o->default_val.arr ? o->default_val.arr->def : NULL;
2255  uint8_t *val;
2256 
2257  ret = opt_get_array(o, dst, &val);
2258  if (ret < 0)
2259  return ret;
2260 
2261  if (!!val != !!def)
2262  ret = 0;
2263  else if (val)
2264  ret = !strcmp(val, def);
2265 
2266  av_freep(&val);
2267 
2268  return ret;
2269  }
2270 
2271  switch (o->type) {
2272  case AV_OPT_TYPE_CONST:
2273  return 1;
2274  case AV_OPT_TYPE_BOOL:
2275  case AV_OPT_TYPE_FLAGS:
2276  case AV_OPT_TYPE_PIXEL_FMT:
2278  case AV_OPT_TYPE_INT:
2279  case AV_OPT_TYPE_DURATION:
2280  case AV_OPT_TYPE_INT64:
2281  case AV_OPT_TYPE_UINT64:
2282  read_number(o, dst, NULL, NULL, &i64);
2283  return o->default_val.i64 == i64;
2284  case AV_OPT_TYPE_CHLAYOUT: {
2285  AVChannelLayout ch_layout = { 0 };
2286  if (o->default_val.str) {
2287  if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
2288  return ret;
2289  }
2290  return !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout);
2291  }
2292  case AV_OPT_TYPE_STRING:
2293  str = *(char **)dst;
2294  if (str == o->default_val.str) //2 NULLs
2295  return 1;
2296  if (!str || !o->default_val.str) //1 NULL
2297  return 0;
2298  return !strcmp(str, o->default_val.str);
2299  case AV_OPT_TYPE_DOUBLE:
2300  d = *(double *)dst;
2301  return o->default_val.dbl == d;
2302  case AV_OPT_TYPE_FLOAT:
2303  d = *(float *)dst;
2304  return (float)o->default_val.dbl == d;
2305  case AV_OPT_TYPE_RATIONAL:
2306  q = av_d2q(o->default_val.dbl, INT_MAX);
2307  return !av_cmp_q(*(AVRational*)dst, q);
2308  case AV_OPT_TYPE_BINARY: {
2309  struct {
2310  uint8_t *data;
2311  int size;
2312  } tmp = {0};
2313  int opt_size = *(int *)((void **)dst + 1);
2314  void *opt_ptr = *(void **)dst;
2315  if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
2316  return 1;
2317  if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
2318  return 0;
2319  if (opt_size != strlen(o->default_val.str) / 2)
2320  return 0;
2321  ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
2322  if (!ret)
2323  ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2324  av_free(tmp.data);
2325  return ret;
2326  }
2327  case AV_OPT_TYPE_DICT: {
2328  AVDictionary *dict1 = NULL;
2329  AVDictionary *dict2 = *(AVDictionary **)dst;
2330  const AVDictionaryEntry *en1 = NULL;
2331  const AVDictionaryEntry *en2 = NULL;
2332  ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2333  if (ret < 0) {
2334  av_dict_free(&dict1);
2335  return ret;
2336  }
2337  do {
2338  en1 = av_dict_iterate(dict1, en1);
2339  en2 = av_dict_iterate(dict2, en2);
2340  } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2341  av_dict_free(&dict1);
2342  return (!en1 && !en2);
2343  }
2345  if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2346  w = h = 0;
2347  else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2348  return ret;
2349  return (w == *(int *)dst) && (h == *((int *)dst+1));
2351  q = (AVRational){0, 0};
2352  if (o->default_val.str) {
2353  if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2354  return ret;
2355  }
2356  return !av_cmp_q(*(AVRational*)dst, q);
2357  case AV_OPT_TYPE_COLOR: {
2358  uint8_t color[4] = {0, 0, 0, 0};
2359  if (o->default_val.str) {
2360  if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2361  return ret;
2362  }
2363  return !memcmp(color, dst, sizeof(color));
2364  }
2365  default:
2366  av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2367  break;
2368  }
2369  return AVERROR_PATCHWELCOME;
2370 }
2371 
2372 int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2373 {
2374  const AVOption *o;
2375  void *target;
2376  if (!obj)
2377  return AVERROR(EINVAL);
2378  o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2379  if (!o)
2380  return AVERROR_OPTION_NOT_FOUND;
2381  return av_opt_is_set_to_default(target, o);
2382 }
2383 
2384 int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2385  const char key_val_sep, const char pairs_sep)
2386 {
2387  const AVOption *o = NULL;
2388  uint8_t *buf;
2389  AVBPrint bprint;
2390  int ret, cnt = 0;
2391  const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2392 
2393  if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2394  pairs_sep == '\\' || key_val_sep == '\\') {
2395  av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2396  return AVERROR(EINVAL);
2397  }
2398 
2399  if (!obj || !buffer)
2400  return AVERROR(EINVAL);
2401 
2402  *buffer = NULL;
2404 
2405  while (o = av_opt_next(obj, o)) {
2406  if (o->type == AV_OPT_TYPE_CONST)
2407  continue;
2408  if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2409  continue;
2410  else if (((o->flags & opt_flags) != opt_flags))
2411  continue;
2413  continue;
2414  if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2415  av_bprint_finalize(&bprint, NULL);
2416  return ret;
2417  }
2418  if (buf) {
2419  if (cnt++)
2420  av_bprint_append_data(&bprint, &pairs_sep, 1);
2421  av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2422  av_bprint_append_data(&bprint, &key_val_sep, 1);
2423  av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2424  av_freep(&buf);
2425  }
2426  }
2427  ret = av_bprint_finalize(&bprint, buffer);
2428  if (ret < 0)
2429  return ret;
2430  return 0;
2431 }
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:463
OPT_EVAL_NUMBER
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition: opt.c:757
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:1324
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:834
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:1475
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:1354
level
uint8_t level
Definition: svq3.c:204
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:1638
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:126
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:1341
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:534
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:2009
out
FILE * out
Definition: movenc.c:54
color
Definition: vf_paletteuse.c:511
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:550
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:1404
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:794
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:1856
AVOption
AVOption.
Definition: opt.h:346
is_key_char
static int is_key_char(char c)
Definition: opt.c:1798
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:574
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:1956
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:2071
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:2384
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:302
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:2239
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:1834
get_bool_name
static const char * get_bool_name(int val)
Definition: opt.c:456
samplefmt.h
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1908
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:738
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:644
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:2026
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
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:913
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:903
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:1776
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:48
WHITESPACES
#define WHITESPACES
Definition: opt.c:1796
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:1298
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:1264
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:50
log_type
static void log_type(void *av_log_obj, const AVOption *o, enum AVOptionType parent_type)
Definition: opt.c:1438
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:856
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:804
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:584
log_value
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:1371
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:1218
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:874
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:1303
set_number
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:773
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:1552
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:1203
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:789
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:2105
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:1950
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
AVOption::default_val
union AVOption::@373 default_val
Native access only, except when documented otherwise.
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:804
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:932
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:186
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:494
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:1742
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:2646
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:1626
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:433
get_sample_fmt
static int get_sample_fmt(const char *name)
Definition: opt.c:545
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:800
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
DEFAULT_NUMVAL
#define DEFAULT_NUMVAL(opt)
Definition: opt.c:316
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:2016
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:1188
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:302
bprint.h
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
set_string_pixel_fmt
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:539
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:1921
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:1417
AVOption::str
const char * str
Definition: opt.h:371
common.h
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
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:254
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:262
get_key
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition: opt.c:1813
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
version.h
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
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:441
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:556
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2894
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:983
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:432
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_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
av_opt_get_chlayout
int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
Definition: opt.c:1308
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:2001
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:1643
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:439
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:2149
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:2131
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
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:73
AVOptionArrayDef::size_min
unsigned size_min
Minimum number of elements in the array.
Definition: opt.h:325
avutil.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:2220
set_string_number
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:324
opt_set_array
static int opt_set_array(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:659
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:948
AV_ESCAPE_MODE_BACKSLASH
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Definition: avstring.h:316
d
d
Definition: ffmpeg_filter.c:425
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:418
av_opt_get
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:1145
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:1945
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:1246
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:799
int
int
Definition: ffmpeg_filter.c:425
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:908
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:2372
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:1280
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:2882
opt_get_array
static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
Definition: opt.c:1085
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:1230