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