FFmpeg
opt.c
Go to the documentation of this file.
1 /*
2  * AVOptions
3  * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * AVOptions
25  * @author Michael Niedermayer <michaelni@gmx.at>
26  */
27 
28 #include "avutil.h"
29 #include "avassert.h"
30 #include "avstring.h"
31 #include "channel_layout.h"
32 #include "common.h"
33 #include "dict.h"
34 #include "eval.h"
35 #include "log.h"
36 #include "parseutils.h"
37 #include "pixdesc.h"
38 #include "mathematics.h"
39 #include "opt.h"
40 #include "samplefmt.h"
41 #include "bprint.h"
42 
43 #include <float.h>
44 
45 const AVOption *av_opt_next(const void *obj, const AVOption *last)
46 {
47  const AVClass *class;
48  if (!obj)
49  return NULL;
50  class = *(const AVClass**)obj;
51  if (!last && class && class->option && class->option[0].name)
52  return class->option;
53  if (last && last[1].name)
54  return ++last;
55  return NULL;
56 }
57 
58 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
59 {
60  switch (o->type) {
61  case AV_OPT_TYPE_FLAGS:
62  *intnum = *(unsigned int*)dst;
63  return 0;
65  *intnum = *(enum AVPixelFormat *)dst;
66  return 0;
68  *intnum = *(enum AVSampleFormat *)dst;
69  return 0;
70  case AV_OPT_TYPE_BOOL:
71  case AV_OPT_TYPE_INT:
72  *intnum = *(int *)dst;
73  return 0;
76  case AV_OPT_TYPE_INT64:
77  case AV_OPT_TYPE_UINT64:
78  *intnum = *(int64_t *)dst;
79  return 0;
80  case AV_OPT_TYPE_FLOAT:
81  *num = *(float *)dst;
82  return 0;
83  case AV_OPT_TYPE_DOUBLE:
84  *num = *(double *)dst;
85  return 0;
87  *intnum = ((AVRational *)dst)->num;
88  *den = ((AVRational *)dst)->den;
89  return 0;
90  case AV_OPT_TYPE_CONST:
91  *num = o->default_val.dbl;
92  return 0;
93  }
94  return AVERROR(EINVAL);
95 }
96 
97 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
98 {
99  if (o->type != AV_OPT_TYPE_FLAGS &&
100  (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
101  num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
102  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
103  num, o->name, o->min, o->max);
104  return AVERROR(ERANGE);
105  }
106  if (o->type == AV_OPT_TYPE_FLAGS) {
107  double d = num*intnum/den;
108  if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) {
109  av_log(obj, AV_LOG_ERROR,
110  "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
111  num*intnum/den, o->name);
112  return AVERROR(ERANGE);
113  }
114  }
115 
116  switch (o->type) {
118  *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
119  break;
121  *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
122  break;
123  case AV_OPT_TYPE_BOOL:
124  case AV_OPT_TYPE_FLAGS:
125  case AV_OPT_TYPE_INT:
126  *(int *)dst = llrint(num / den) * intnum;
127  break;
130  case AV_OPT_TYPE_INT64:{
131  double d = num / den;
132  if (intnum == 1 && d == (double)INT64_MAX) {
133  *(int64_t *)dst = INT64_MAX;
134  } else
135  *(int64_t *)dst = llrint(d) * intnum;
136  break;}
137  case AV_OPT_TYPE_UINT64:{
138  double d = num / den;
139  // We must special case uint64_t here as llrint() does not support values
140  // outside the int64_t range and there is no portable function which does
141  // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double
142  // while INT64_MAX is not
143  if (intnum == 1 && d == (double)UINT64_MAX) {
144  *(uint64_t *)dst = UINT64_MAX;
145  } else if (d > INT64_MAX + 1ULL) {
146  *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum;
147  } else {
148  *(uint64_t *)dst = llrint(d) * intnum;
149  }
150  break;}
151  case AV_OPT_TYPE_FLOAT:
152  *(float *)dst = num * intnum / den;
153  break;
154  case AV_OPT_TYPE_DOUBLE:
155  *(double *)dst = num * intnum / den;
156  break;
159  if ((int) num == num)
160  *(AVRational *)dst = (AVRational) { num *intnum, den };
161  else
162  *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
163  break;
164  default:
165  return AVERROR(EINVAL);
166  }
167  return 0;
168 }
169 
170 static int hexchar2int(char c) {
171  if (c >= '0' && c <= '9')
172  return c - '0';
173  if (c >= 'a' && c <= 'f')
174  return c - 'a' + 10;
175  if (c >= 'A' && c <= 'F')
176  return c - 'A' + 10;
177  return -1;
178 }
179 
180 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
181 {
182  int *lendst = (int *)(dst + 1);
183  uint8_t *bin, *ptr;
184  int len;
185 
186  av_freep(dst);
187  *lendst = 0;
188 
189  if (!val || !(len = strlen(val)))
190  return 0;
191 
192  if (len & 1)
193  return AVERROR(EINVAL);
194  len /= 2;
195 
196  ptr = bin = av_malloc(len);
197  if (!ptr)
198  return AVERROR(ENOMEM);
199  while (*val) {
200  int a = hexchar2int(*val++);
201  int b = hexchar2int(*val++);
202  if (a < 0 || b < 0) {
203  av_free(bin);
204  return AVERROR(EINVAL);
205  }
206  *ptr++ = (a << 4) | b;
207  }
208  *dst = bin;
209  *lendst = len;
210 
211  return 0;
212 }
213 
214 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
215 {
216  av_freep(dst);
217  *dst = av_strdup(val);
218  return *dst ? 0 : AVERROR(ENOMEM);
219 }
220 
221 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
222  opt->type == AV_OPT_TYPE_UINT64 || \
223  opt->type == AV_OPT_TYPE_CONST || \
224  opt->type == AV_OPT_TYPE_FLAGS || \
225  opt->type == AV_OPT_TYPE_INT) \
226  ? opt->default_val.i64 \
227  : opt->default_val.dbl)
228 
229 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
230 {
231  int ret = 0;
232 
234  int num, den;
235  char c;
236  if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
237  if ((ret = write_number(obj, o, dst, 1, den, num)) >= 0)
238  return ret;
239  ret = 0;
240  }
241  }
242 
243  for (;;) {
244  int i = 0;
245  char buf[256];
246  int cmd = 0;
247  double d;
248  int64_t intnum = 1;
249 
250  if (o->type == AV_OPT_TYPE_FLAGS) {
251  if (*val == '+' || *val == '-')
252  cmd = *(val++);
253  for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
254  buf[i] = val[i];
255  buf[i] = 0;
256  }
257 
258  {
259  int res;
260  int ci = 0;
261  double const_values[64];
262  const char * const_names[64];
263  int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0;
264  const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags);
265  if (o_named && o_named->type == AV_OPT_TYPE_CONST)
266  d = DEFAULT_NUMVAL(o_named);
267  else {
268  if (o->unit) {
269  for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
270  if (o_named->type == AV_OPT_TYPE_CONST &&
271  o_named->unit &&
272  !strcmp(o_named->unit, o->unit)) {
273  if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
274  av_log(obj, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
275  return AVERROR_PATCHWELCOME;
276  }
277  const_names [ci ] = o_named->name;
278  const_values[ci++] = DEFAULT_NUMVAL(o_named);
279  }
280  }
281  }
282  const_names [ci ] = "default";
283  const_values[ci++] = DEFAULT_NUMVAL(o);
284  const_names [ci ] = "max";
285  const_values[ci++] = o->max;
286  const_names [ci ] = "min";
287  const_values[ci++] = o->min;
288  const_names [ci ] = "none";
289  const_values[ci++] = 0;
290  const_names [ci ] = "all";
291  const_values[ci++] = ~0;
292  const_names [ci] = NULL;
293  const_values[ci] = 0;
294 
295  res = av_expr_parse_and_eval(&d, i ? buf : val, const_names,
296  const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
297  if (res < 0) {
298  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
299  return res;
300  }
301  }
302  }
303  if (o->type == AV_OPT_TYPE_FLAGS) {
304  read_number(o, dst, NULL, NULL, &intnum);
305  if (cmd == '+')
306  d = intnum | (int64_t)d;
307  else if (cmd == '-')
308  d = intnum &~(int64_t)d;
309  }
310 
311  if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
312  return ret;
313  val += i;
314  if (!i || !*val)
315  return 0;
316  }
317 }
318 
319 static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
320 {
321  int ret;
322 
323  if (!val || !strcmp(val, "none")) {
324  dst[0] =
325  dst[1] = 0;
326  return 0;
327  }
328  ret = av_parse_video_size(dst, dst + 1, val);
329  if (ret < 0)
330  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
331  return ret;
332 }
333 
334 static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
335 {
336  int ret = av_parse_video_rate(dst, val);
337  if (ret < 0)
338  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
339  return ret;
340 }
341 
342 static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
343 {
344  int ret;
345 
346  if (!val) {
347  return 0;
348  } else {
349  ret = av_parse_color(dst, val, -1, obj);
350  if (ret < 0)
351  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as color\n", val);
352  return ret;
353  }
354  return 0;
355 }
356 
357 static const char *get_bool_name(int val)
358 {
359  if (val < 0)
360  return "auto";
361  return val ? "true" : "false";
362 }
363 
364 static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
365 {
366  int n;
367 
368  if (!val)
369  return 0;
370 
371  if (!strcmp(val, "auto")) {
372  n = -1;
373  } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
374  n = 1;
375  } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
376  n = 0;
377  } else {
378  char *end = NULL;
379  n = strtol(val, &end, 10);
380  if (val + strlen(val) != end)
381  goto fail;
382  }
383 
384  if (n < o->min || n > o->max)
385  goto fail;
386 
387  *dst = n;
388  return 0;
389 
390 fail:
391  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as boolean\n", val);
392  return AVERROR(EINVAL);
393 }
394 
395 static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
396  int fmt_nb, int ((*get_fmt)(const char *)), const char *desc)
397 {
398  int fmt, min, max;
399 
400  if (!val || !strcmp(val, "none")) {
401  fmt = -1;
402  } else {
403  fmt = get_fmt(val);
404  if (fmt == -1) {
405  char *tail;
406  fmt = strtol(val, &tail, 0);
407  if (*tail || (unsigned)fmt >= fmt_nb) {
408  av_log(obj, AV_LOG_ERROR,
409  "Unable to parse option value \"%s\" as %s\n", val, desc);
410  return AVERROR(EINVAL);
411  }
412  }
413  }
414 
415  min = FFMAX(o->min, -1);
416  max = FFMIN(o->max, fmt_nb-1);
417 
418  // hack for compatibility with old ffmpeg
419  if(min == 0 && max == 0) {
420  min = -1;
421  max = fmt_nb-1;
422  }
423 
424  if (fmt < min || fmt > max) {
425  av_log(obj, AV_LOG_ERROR,
426  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
427  fmt, o->name, desc, min, max);
428  return AVERROR(ERANGE);
429  }
430 
431  *(int *)dst = fmt;
432  return 0;
433 }
434 
435 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
436 {
437  return set_string_fmt(obj, o, val, dst,
438  AV_PIX_FMT_NB, av_get_pix_fmt, "pixel format");
439 }
440 
441 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
442 {
443  return set_string_fmt(obj, o, val, dst,
444  AV_SAMPLE_FMT_NB, av_get_sample_fmt, "sample format");
445 }
446 
447 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
448 {
450 
451  if (val) {
452  int ret = av_dict_parse_string(&options, val, "=", ":", 0);
453  if (ret < 0) {
455  return ret;
456  }
457  }
458 
459  av_dict_free((AVDictionary **)dst);
460  *dst = (uint8_t *)options;
461 
462  return 0;
463 }
464 
465 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
466 {
467  int ret = 0;
468  void *dst, *target_obj;
469  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
470  if (!o || !target_obj)
472  if (!val && (o->type != AV_OPT_TYPE_STRING &&
477  return AVERROR(EINVAL);
478 
479  if (o->flags & AV_OPT_FLAG_READONLY)
480  return AVERROR(EINVAL);
481 
482  if (o->flags & AV_OPT_FLAG_DEPRECATED)
483  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
484 
485  dst = ((uint8_t *)target_obj) + o->offset;
486  switch (o->type) {
487  case AV_OPT_TYPE_BOOL:
488  return set_string_bool(obj, o, val, dst);
489  case AV_OPT_TYPE_STRING:
490  return set_string(obj, o, val, dst);
491  case AV_OPT_TYPE_BINARY:
492  return set_string_binary(obj, o, val, dst);
493  case AV_OPT_TYPE_FLAGS:
494  case AV_OPT_TYPE_INT:
495  case AV_OPT_TYPE_INT64:
496  case AV_OPT_TYPE_UINT64:
497  case AV_OPT_TYPE_FLOAT:
498  case AV_OPT_TYPE_DOUBLE:
500  return set_string_number(obj, target_obj, o, val, dst);
502  return set_string_image_size(obj, o, val, dst);
503  case AV_OPT_TYPE_VIDEO_RATE: {
504  AVRational tmp;
505  ret = set_string_video_rate(obj, o, val, &tmp);
506  if (ret < 0)
507  return ret;
508  return write_number(obj, o, dst, 1, tmp.den, tmp.num);
509  }
511  return set_string_pixel_fmt(obj, o, val, dst);
513  return set_string_sample_fmt(obj, o, val, dst);
515  {
516  int64_t usecs = 0;
517  if (val) {
518  if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
519  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
520  return ret;
521  }
522  }
523  if (usecs < o->min || usecs > o->max) {
524  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
525  usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
526  return AVERROR(ERANGE);
527  }
528  *(int64_t *)dst = usecs;
529  return 0;
530  }
531  case AV_OPT_TYPE_COLOR:
532  return set_string_color(obj, o, val, dst);
534  if (!val || !strcmp(val, "none")) {
535  *(int64_t *)dst = 0;
536  } else {
537  int64_t cl = av_get_channel_layout(val);
538  if (!cl) {
539  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
540  ret = AVERROR(EINVAL);
541  }
542  *(int64_t *)dst = cl;
543  return ret;
544  }
545  break;
546  case AV_OPT_TYPE_DICT:
547  return set_string_dict(obj, o, val, dst);
548  }
549 
550  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
551  return AVERROR(EINVAL);
552 }
553 
554 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
555 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
556  const char *val, vartype *name ## _out) \
557 { \
558  if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
559  return AVERROR(EINVAL); \
560  return set_string_number(obj, obj, o, val, name ## _out); \
561 }
562 
565 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
566 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
567 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
569 
570 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
571  int search_flags)
572 {
573  void *dst, *target_obj;
574  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
575 
576  if (!o || !target_obj)
578 
579  if (o->flags & AV_OPT_FLAG_READONLY)
580  return AVERROR(EINVAL);
581 
582  dst = ((uint8_t *)target_obj) + o->offset;
583  return write_number(obj, o, dst, num, den, intnum);
584 }
585 
586 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
587 {
588  return set_number(obj, name, 1, 1, val, search_flags);
589 }
590 
591 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
592 {
593  return set_number(obj, name, val, 1, 1, search_flags);
594 }
595 
596 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
597 {
598  return set_number(obj, name, val.num, val.den, 1, search_flags);
599 }
600 
601 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
602 {
603  void *target_obj;
604  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
605  uint8_t *ptr;
606  uint8_t **dst;
607  int *lendst;
608 
609  if (!o || !target_obj)
611 
613  return AVERROR(EINVAL);
614 
615  ptr = len ? av_malloc(len) : NULL;
616  if (len && !ptr)
617  return AVERROR(ENOMEM);
618 
619  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
620  lendst = (int *)(dst + 1);
621 
622  av_free(*dst);
623  *dst = ptr;
624  *lendst = len;
625  if (len)
626  memcpy(ptr, val, len);
627 
628  return 0;
629 }
630 
631 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
632 {
633  void *target_obj;
634  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
635 
636  if (!o || !target_obj)
638  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
639  av_log(obj, AV_LOG_ERROR,
640  "The value set by option '%s' is not an image size.\n", o->name);
641  return AVERROR(EINVAL);
642  }
643  if (w<0 || h<0) {
644  av_log(obj, AV_LOG_ERROR,
645  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
646  return AVERROR(EINVAL);
647  }
648  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
649  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
650  return 0;
651 }
652 
653 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
654 {
655  void *target_obj;
656  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
657 
658  if (!o || !target_obj)
660  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
661  av_log(obj, AV_LOG_ERROR,
662  "The value set by option '%s' is not a video rate.\n", o->name);
663  return AVERROR(EINVAL);
664  }
665  if (val.num <= 0 || val.den <= 0)
666  return AVERROR(EINVAL);
667  return set_number(obj, name, val.num, val.den, 1, search_flags);
668 }
669 
670 static int set_format(void *obj, const char *name, int fmt, int search_flags,
671  enum AVOptionType type, const char *desc, int nb_fmts)
672 {
673  void *target_obj;
674  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
675  search_flags, &target_obj);
676  int min, max;
677 
678  if (!o || !target_obj)
680  if (o->type != type) {
681  av_log(obj, AV_LOG_ERROR,
682  "The value set by option '%s' is not a %s format", name, desc);
683  return AVERROR(EINVAL);
684  }
685 
686  min = FFMAX(o->min, -1);
687  max = FFMIN(o->max, nb_fmts-1);
688 
689  if (fmt < min || fmt > max) {
690  av_log(obj, AV_LOG_ERROR,
691  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
692  fmt, name, desc, min, max);
693  return AVERROR(ERANGE);
694  }
695  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
696  return 0;
697 }
698 
699 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
700 {
701  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
702 }
703 
704 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
705 {
706  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
707 }
708 
709 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
710 {
711  void *target_obj;
712  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
713 
714  if (!o || !target_obj)
716  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
717  av_log(obj, AV_LOG_ERROR,
718  "The value set by option '%s' is not a channel layout.\n", o->name);
719  return AVERROR(EINVAL);
720  }
721  *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
722  return 0;
723 }
724 
725 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
726  int search_flags)
727 {
728  void *target_obj;
729  AVDictionary **dst;
730  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
731 
732  if (!o || !target_obj)
734  if (o->flags & AV_OPT_FLAG_READONLY)
735  return AVERROR(EINVAL);
736 
737  dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
738  av_dict_free(dst);
739  av_dict_copy(dst, val, 0);
740 
741  return 0;
742 }
743 
744 static void format_duration(char *buf, size_t size, int64_t d)
745 {
746  char *e;
747 
748  av_assert0(size >= 25);
749  if (d < 0 && d != INT64_MIN) {
750  *(buf++) = '-';
751  size--;
752  d = -d;
753  }
754  if (d == INT64_MAX)
755  snprintf(buf, size, "INT64_MAX");
756  else if (d == INT64_MIN)
757  snprintf(buf, size, "INT64_MIN");
758  else if (d > (int64_t)3600*1000000)
759  snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
760  (int)((d / 60000000) % 60),
761  (int)((d / 1000000) % 60),
762  (int)(d % 1000000));
763  else if (d > 60*1000000)
764  snprintf(buf, size, "%d:%02d.%06d",
765  (int)(d / 60000000),
766  (int)((d / 1000000) % 60),
767  (int)(d % 1000000));
768  else
769  snprintf(buf, size, "%d.%06d",
770  (int)(d / 1000000),
771  (int)(d % 1000000));
772  e = buf + strlen(buf);
773  while (e > buf && e[-1] == '0')
774  *(--e) = 0;
775  if (e > buf && e[-1] == '.')
776  *(--e) = 0;
777 }
778 
779 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
780 {
781  void *dst, *target_obj;
782  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
783  uint8_t *bin, buf[128];
784  int len, i, ret;
785  int64_t i64;
786 
787  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
789 
790  if (o->flags & AV_OPT_FLAG_DEPRECATED)
791  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
792 
793  dst = (uint8_t *)target_obj + o->offset;
794 
795  buf[0] = 0;
796  switch (o->type) {
797  case AV_OPT_TYPE_BOOL:
798  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
799  break;
800  case AV_OPT_TYPE_FLAGS:
801  ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
802  break;
803  case AV_OPT_TYPE_INT:
804  ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
805  break;
806  case AV_OPT_TYPE_INT64:
807  ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
808  break;
809  case AV_OPT_TYPE_UINT64:
810  ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
811  break;
812  case AV_OPT_TYPE_FLOAT:
813  ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
814  break;
815  case AV_OPT_TYPE_DOUBLE:
816  ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
817  break;
820  ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
821  break;
822  case AV_OPT_TYPE_CONST:
823  ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl);
824  break;
825  case AV_OPT_TYPE_STRING:
826  if (*(uint8_t **)dst) {
827  *out_val = av_strdup(*(uint8_t **)dst);
828  } else if (search_flags & AV_OPT_ALLOW_NULL) {
829  *out_val = NULL;
830  return 0;
831  } else {
832  *out_val = av_strdup("");
833  }
834  return *out_val ? 0 : AVERROR(ENOMEM);
835  case AV_OPT_TYPE_BINARY:
836  if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
837  *out_val = NULL;
838  return 0;
839  }
840  len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
841  if ((uint64_t)len * 2 + 1 > INT_MAX)
842  return AVERROR(EINVAL);
843  if (!(*out_val = av_malloc(len * 2 + 1)))
844  return AVERROR(ENOMEM);
845  if (!len) {
846  *out_val[0] = '\0';
847  return 0;
848  }
849  bin = *(uint8_t **)dst;
850  for (i = 0; i < len; i++)
851  snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
852  return 0;
854  ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
855  break;
857  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
858  break;
860  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
861  break;
863  i64 = *(int64_t *)dst;
864  format_duration(buf, sizeof(buf), i64);
865  ret = strlen(buf); // no overflow possible, checked by an assert
866  break;
867  case AV_OPT_TYPE_COLOR:
868  ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
869  (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
870  (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
871  break;
873  i64 = *(int64_t *)dst;
874  ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
875  break;
876  case AV_OPT_TYPE_DICT:
877  if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
878  *out_val = NULL;
879  return 0;
880  }
881  return av_dict_get_string(*(AVDictionary **)dst, (char **)out_val, '=', ':');
882  default:
883  return AVERROR(EINVAL);
884  }
885 
886  if (ret >= sizeof(buf))
887  return AVERROR(EINVAL);
888  *out_val = av_strdup(buf);
889  return *out_val ? 0 : AVERROR(ENOMEM);
890 }
891 
892 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
893  int search_flags)
894 {
895  void *dst, *target_obj;
896  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
897  if (!o || !target_obj)
898  goto error;
899 
900  dst = ((uint8_t *)target_obj) + o->offset;
901 
902  if (o_out) *o_out= o;
903 
904  return read_number(o, dst, num, den, intnum);
905 
906 error:
907  *den =
908  *intnum = 0;
909  return -1;
910 }
911 
912 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
913 {
914  int64_t intnum = 1;
915  double num = 1;
916  int ret, den = 1;
917 
918  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
919  return ret;
920  *out_val = num * intnum / den;
921  return 0;
922 }
923 
924 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
925 {
926  int64_t intnum = 1;
927  double num = 1;
928  int ret, den = 1;
929 
930  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
931  return ret;
932  *out_val = num * intnum / den;
933  return 0;
934 }
935 
936 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
937 {
938  int64_t intnum = 1;
939  double num = 1;
940  int ret, den = 1;
941 
942  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
943  return ret;
944 
945  if (num == 1.0 && (int)intnum == intnum)
946  *out_val = (AVRational){intnum, den};
947  else
948  *out_val = av_d2q(num*intnum/den, 1<<24);
949  return 0;
950 }
951 
952 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
953 {
954  void *dst, *target_obj;
955  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
956  if (!o || !target_obj)
958  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
959  av_log(obj, AV_LOG_ERROR,
960  "The value for option '%s' is not an image size.\n", name);
961  return AVERROR(EINVAL);
962  }
963 
964  dst = ((uint8_t*)target_obj) + o->offset;
965  if (w_out) *w_out = *(int *)dst;
966  if (h_out) *h_out = *((int *)dst+1);
967  return 0;
968 }
969 
970 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
971 {
972  int64_t intnum = 1;
973  double num = 1;
974  int ret, den = 1;
975 
976  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
977  return ret;
978 
979  if (num == 1.0 && (int)intnum == intnum)
980  *out_val = (AVRational) { intnum, den };
981  else
982  *out_val = av_d2q(num * intnum / den, 1 << 24);
983  return 0;
984 }
985 
986 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
987  enum AVOptionType type, const char *desc)
988 {
989  void *dst, *target_obj;
990  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
991  if (!o || !target_obj)
993  if (o->type != type) {
994  av_log(obj, AV_LOG_ERROR,
995  "The value for option '%s' is not a %s format.\n", desc, name);
996  return AVERROR(EINVAL);
997  }
998 
999  dst = ((uint8_t*)target_obj) + o->offset;
1000  *out_fmt = *(int *)dst;
1001  return 0;
1002 }
1003 
1004 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1005 {
1006  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1007 }
1008 
1009 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1010 {
1011  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1012 }
1013 
1014 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
1015 {
1016  void *dst, *target_obj;
1017  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1018  if (!o || !target_obj)
1019  return AVERROR_OPTION_NOT_FOUND;
1020  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
1021  av_log(obj, AV_LOG_ERROR,
1022  "The value for option '%s' is not a channel layout.\n", name);
1023  return AVERROR(EINVAL);
1024  }
1025 
1026  dst = ((uint8_t*)target_obj) + o->offset;
1027  *cl = *(int64_t *)dst;
1028  return 0;
1029 }
1030 
1031 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1032 {
1033  void *target_obj;
1034  AVDictionary *src;
1035  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1036 
1037  if (!o || !target_obj)
1038  return AVERROR_OPTION_NOT_FOUND;
1039  if (o->type != AV_OPT_TYPE_DICT)
1040  return AVERROR(EINVAL);
1041 
1042  src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1043  av_dict_copy(out_val, src, 0);
1044 
1045  return 0;
1046 }
1047 
1048 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1049 {
1050  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1051  const AVOption *flag = av_opt_find(obj, flag_name,
1052  field ? field->unit : NULL, 0, 0);
1053  int64_t res;
1054 
1055  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1056  av_opt_get_int(obj, field_name, 0, &res) < 0)
1057  return 0;
1058  return res & flag->default_val.i64;
1059 }
1060 
1061 static void log_int_value(void *av_log_obj, int level, int64_t i)
1062 {
1063  if (i == INT_MAX) {
1064  av_log(av_log_obj, level, "INT_MAX");
1065  } else if (i == INT_MIN) {
1066  av_log(av_log_obj, level, "INT_MIN");
1067  } else if (i == UINT32_MAX) {
1068  av_log(av_log_obj, level, "UINT32_MAX");
1069  } else if (i == INT64_MAX) {
1070  av_log(av_log_obj, level, "I64_MAX");
1071  } else if (i == INT64_MIN) {
1072  av_log(av_log_obj, level, "I64_MIN");
1073  } else {
1074  av_log(av_log_obj, level, "%"PRId64, i);
1075  }
1076 }
1077 
1078 static void log_value(void *av_log_obj, int level, double d)
1079 {
1080  if (d == INT_MAX) {
1081  av_log(av_log_obj, level, "INT_MAX");
1082  } else if (d == INT_MIN) {
1083  av_log(av_log_obj, level, "INT_MIN");
1084  } else if (d == UINT32_MAX) {
1085  av_log(av_log_obj, level, "UINT32_MAX");
1086  } else if (d == (double)INT64_MAX) {
1087  av_log(av_log_obj, level, "I64_MAX");
1088  } else if (d == INT64_MIN) {
1089  av_log(av_log_obj, level, "I64_MIN");
1090  } else if (d == FLT_MAX) {
1091  av_log(av_log_obj, level, "FLT_MAX");
1092  } else if (d == FLT_MIN) {
1093  av_log(av_log_obj, level, "FLT_MIN");
1094  } else if (d == -FLT_MAX) {
1095  av_log(av_log_obj, level, "-FLT_MAX");
1096  } else if (d == -FLT_MIN) {
1097  av_log(av_log_obj, level, "-FLT_MIN");
1098  } else if (d == DBL_MAX) {
1099  av_log(av_log_obj, level, "DBL_MAX");
1100  } else if (d == DBL_MIN) {
1101  av_log(av_log_obj, level, "DBL_MIN");
1102  } else if (d == -DBL_MAX) {
1103  av_log(av_log_obj, level, "-DBL_MAX");
1104  } else if (d == -DBL_MIN) {
1105  av_log(av_log_obj, level, "-DBL_MIN");
1106  } else {
1107  av_log(av_log_obj, level, "%g", d);
1108  }
1109 }
1110 
1111 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1112 {
1113  const AVOption *opt = NULL;
1114 
1115  if (!unit)
1116  return NULL;
1117  while ((opt = av_opt_next(obj, opt)))
1118  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1119  opt->default_val.i64 == value)
1120  return opt->name;
1121  return NULL;
1122 }
1123 
1124 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1125 {
1126  const AVOption *opt = NULL;
1127  char flags[512];
1128 
1129  flags[0] = 0;
1130  if (!unit)
1131  return NULL;
1132  while ((opt = av_opt_next(obj, opt))) {
1133  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1134  opt->default_val.i64 & value) {
1135  if (flags[0])
1136  av_strlcatf(flags, sizeof(flags), "+");
1137  av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1138  }
1139  }
1140  if (flags[0])
1141  return av_strdup(flags);
1142  return NULL;
1143 }
1144 
1145 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1146  int req_flags, int rej_flags, enum AVOptionType parent_type)
1147 {
1148  const AVOption *opt = NULL;
1149  AVOptionRanges *r;
1150  int i;
1151 
1152  while ((opt = av_opt_next(obj, opt))) {
1153  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1154  continue;
1155 
1156  /* Don't print CONST's on level one.
1157  * Don't print anything but CONST's on level two.
1158  * Only print items from the requested unit.
1159  */
1160  if (!unit && opt->type == AV_OPT_TYPE_CONST)
1161  continue;
1162  else if (unit && opt->type != AV_OPT_TYPE_CONST)
1163  continue;
1164  else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1165  continue;
1166  else if (unit && opt->type == AV_OPT_TYPE_CONST)
1167  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1168  else
1169  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1170  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? "" : "-",
1171  opt->name);
1172 
1173  switch (opt->type) {
1174  case AV_OPT_TYPE_FLAGS:
1175  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
1176  break;
1177  case AV_OPT_TYPE_INT:
1178  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
1179  break;
1180  case AV_OPT_TYPE_INT64:
1181  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
1182  break;
1183  case AV_OPT_TYPE_UINT64:
1184  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<uint64>");
1185  break;
1186  case AV_OPT_TYPE_DOUBLE:
1187  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
1188  break;
1189  case AV_OPT_TYPE_FLOAT:
1190  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
1191  break;
1192  case AV_OPT_TYPE_STRING:
1193  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
1194  break;
1195  case AV_OPT_TYPE_RATIONAL:
1196  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
1197  break;
1198  case AV_OPT_TYPE_BINARY:
1199  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
1200  break;
1201  case AV_OPT_TYPE_DICT:
1202  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<dictionary>");
1203  break;
1205  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
1206  break;
1208  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
1209  break;
1210  case AV_OPT_TYPE_PIXEL_FMT:
1211  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
1212  break;
1214  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
1215  break;
1216  case AV_OPT_TYPE_DURATION:
1217  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
1218  break;
1219  case AV_OPT_TYPE_COLOR:
1220  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
1221  break;
1223  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
1224  break;
1225  case AV_OPT_TYPE_BOOL:
1226  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
1227  break;
1228  case AV_OPT_TYPE_CONST:
1229  if (parent_type == AV_OPT_TYPE_INT)
1230  av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", opt->default_val.i64);
1231  else
1232  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1233  break;
1234  default:
1235  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1236  break;
1237  }
1238  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
1239  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
1240  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_FILTERING_PARAM)? 'F' : '.');
1241  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
1242  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
1243  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
1244  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.');
1245  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.');
1246  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.');
1247  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.');
1248 
1249  if (opt->help)
1250  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1251 
1252  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1253  switch (opt->type) {
1254  case AV_OPT_TYPE_INT:
1255  case AV_OPT_TYPE_INT64:
1256  case AV_OPT_TYPE_UINT64:
1257  case AV_OPT_TYPE_DOUBLE:
1258  case AV_OPT_TYPE_FLOAT:
1259  case AV_OPT_TYPE_RATIONAL:
1260  for (i = 0; i < r->nb_ranges; i++) {
1261  av_log(av_log_obj, AV_LOG_INFO, " (from ");
1262  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1263  av_log(av_log_obj, AV_LOG_INFO, " to ");
1264  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1265  av_log(av_log_obj, AV_LOG_INFO, ")");
1266  }
1267  break;
1268  }
1270  }
1271 
1272  if (opt->type != AV_OPT_TYPE_CONST &&
1273  opt->type != AV_OPT_TYPE_BINARY &&
1274  !((opt->type == AV_OPT_TYPE_COLOR ||
1275  opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1276  opt->type == AV_OPT_TYPE_STRING ||
1277  opt->type == AV_OPT_TYPE_DICT ||
1278  opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1279  !opt->default_val.str)) {
1280  av_log(av_log_obj, AV_LOG_INFO, " (default ");
1281  switch (opt->type) {
1282  case AV_OPT_TYPE_BOOL:
1283  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
1284  break;
1285  case AV_OPT_TYPE_FLAGS: {
1286  char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1287  if (def_flags) {
1288  av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1289  av_freep(&def_flags);
1290  } else {
1291  av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1292  }
1293  break;
1294  }
1295  case AV_OPT_TYPE_DURATION: {
1296  char buf[25];
1297  format_duration(buf, sizeof(buf), opt->default_val.i64);
1298  av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1299  break;
1300  }
1301  case AV_OPT_TYPE_INT:
1302  case AV_OPT_TYPE_UINT64:
1303  case AV_OPT_TYPE_INT64: {
1304  const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1305  if (def_const)
1306  av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1307  else
1308  log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1309  break;
1310  }
1311  case AV_OPT_TYPE_DOUBLE:
1312  case AV_OPT_TYPE_FLOAT:
1313  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1314  break;
1315  case AV_OPT_TYPE_RATIONAL: {
1316  AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1317  av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1318  break;
1319  case AV_OPT_TYPE_PIXEL_FMT:
1320  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1321  break;
1323  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1324  break;
1325  case AV_OPT_TYPE_COLOR:
1327  case AV_OPT_TYPE_STRING:
1328  case AV_OPT_TYPE_DICT:
1330  av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1331  break;
1333  av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
1334  break;
1335  }
1336  av_log(av_log_obj, AV_LOG_INFO, ")");
1337  }
1338 
1339  av_log(av_log_obj, AV_LOG_INFO, "\n");
1340  if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1341  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1342  }
1343 }
1344 
1345 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1346 {
1347  if (!obj)
1348  return -1;
1349 
1350  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1351 
1352  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1353 
1354  return 0;
1355 }
1356 
1358 {
1359  av_opt_set_defaults2(s, 0, 0);
1360 }
1361 
1362 void av_opt_set_defaults2(void *s, int mask, int flags)
1363 {
1364  const AVOption *opt = NULL;
1365  while ((opt = av_opt_next(s, opt))) {
1366  void *dst = ((uint8_t*)s) + opt->offset;
1367 
1368  if ((opt->flags & mask) != flags)
1369  continue;
1370 
1371  if (opt->flags & AV_OPT_FLAG_READONLY)
1372  continue;
1373 
1374  switch (opt->type) {
1375  case AV_OPT_TYPE_CONST:
1376  /* Nothing to be done here */
1377  break;
1378  case AV_OPT_TYPE_BOOL:
1379  case AV_OPT_TYPE_FLAGS:
1380  case AV_OPT_TYPE_INT:
1381  case AV_OPT_TYPE_INT64:
1382  case AV_OPT_TYPE_UINT64:
1383  case AV_OPT_TYPE_DURATION:
1385  case AV_OPT_TYPE_PIXEL_FMT:
1387  write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1388  break;
1389  case AV_OPT_TYPE_DOUBLE:
1390  case AV_OPT_TYPE_FLOAT: {
1391  double val;
1392  val = opt->default_val.dbl;
1393  write_number(s, opt, dst, val, 1, 1);
1394  }
1395  break;
1396  case AV_OPT_TYPE_RATIONAL: {
1397  AVRational val;
1398  val = av_d2q(opt->default_val.dbl, INT_MAX);
1399  write_number(s, opt, dst, 1, val.den, val.num);
1400  }
1401  break;
1402  case AV_OPT_TYPE_COLOR:
1403  set_string_color(s, opt, opt->default_val.str, dst);
1404  break;
1405  case AV_OPT_TYPE_STRING:
1406  set_string(s, opt, opt->default_val.str, dst);
1407  break;
1409  set_string_image_size(s, opt, opt->default_val.str, dst);
1410  break;
1412  set_string_video_rate(s, opt, opt->default_val.str, dst);
1413  break;
1414  case AV_OPT_TYPE_BINARY:
1415  set_string_binary(s, opt, opt->default_val.str, dst);
1416  break;
1417  case AV_OPT_TYPE_DICT:
1418  set_string_dict(s, opt, opt->default_val.str, dst);
1419  break;
1420  default:
1421  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1422  opt->type, opt->name);
1423  }
1424  }
1425 }
1426 
1427 /**
1428  * Store the value in the field in ctx that is named like key.
1429  * ctx must be an AVClass context, storing is done using AVOptions.
1430  *
1431  * @param buf the string to parse, buf will be updated to point at the
1432  * separator just after the parsed key/value pair
1433  * @param key_val_sep a 0-terminated list of characters used to
1434  * separate key from value
1435  * @param pairs_sep a 0-terminated list of characters used to separate
1436  * two pairs from each other
1437  * @return 0 if the key/value pair has been successfully parsed and
1438  * set, or a negative value corresponding to an AVERROR code in case
1439  * of error:
1440  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1441  * the error code issued by av_opt_set() if the key/value pair
1442  * cannot be set
1443  */
1444 static int parse_key_value_pair(void *ctx, const char **buf,
1445  const char *key_val_sep, const char *pairs_sep)
1446 {
1447  char *key = av_get_token(buf, key_val_sep);
1448  char *val;
1449  int ret;
1450 
1451  if (!key)
1452  return AVERROR(ENOMEM);
1453 
1454  if (*key && strspn(*buf, key_val_sep)) {
1455  (*buf)++;
1456  val = av_get_token(buf, pairs_sep);
1457  if (!val) {
1458  av_freep(&key);
1459  return AVERROR(ENOMEM);
1460  }
1461  } else {
1462  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1463  av_free(key);
1464  return AVERROR(EINVAL);
1465  }
1466 
1467  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1468 
1471  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1472 
1473  av_free(key);
1474  av_free(val);
1475  return ret;
1476 }
1477 
1478 int av_set_options_string(void *ctx, const char *opts,
1479  const char *key_val_sep, const char *pairs_sep)
1480 {
1481  int ret, count = 0;
1482 
1483  if (!opts)
1484  return 0;
1485 
1486  while (*opts) {
1487  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1488  return ret;
1489  count++;
1490 
1491  if (*opts)
1492  opts++;
1493  }
1494 
1495  return count;
1496 }
1497 
1498 #define WHITESPACES " \n\t\r"
1499 
1500 static int is_key_char(char c)
1501 {
1502  return (unsigned)((c | 32) - 'a') < 26 ||
1503  (unsigned)(c - '0') < 10 ||
1504  c == '-' || c == '_' || c == '/' || c == '.';
1505 }
1506 
1507 /**
1508  * Read a key from a string.
1509  *
1510  * The key consists of is_key_char characters and must be terminated by a
1511  * character from the delim string; spaces are ignored.
1512  *
1513  * @return 0 for success (even with ellipsis), <0 for failure
1514  */
1515 static int get_key(const char **ropts, const char *delim, char **rkey)
1516 {
1517  const char *opts = *ropts;
1518  const char *key_start, *key_end;
1519 
1520  key_start = opts += strspn(opts, WHITESPACES);
1521  while (is_key_char(*opts))
1522  opts++;
1523  key_end = opts;
1524  opts += strspn(opts, WHITESPACES);
1525  if (!*opts || !strchr(delim, *opts))
1526  return AVERROR(EINVAL);
1527  opts++;
1528  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1529  return AVERROR(ENOMEM);
1530  memcpy(*rkey, key_start, key_end - key_start);
1531  (*rkey)[key_end - key_start] = 0;
1532  *ropts = opts;
1533  return 0;
1534 }
1535 
1536 int av_opt_get_key_value(const char **ropts,
1537  const char *key_val_sep, const char *pairs_sep,
1538  unsigned flags,
1539  char **rkey, char **rval)
1540 {
1541  int ret;
1542  char *key = NULL, *val;
1543  const char *opts = *ropts;
1544 
1545  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1547  return AVERROR(EINVAL);
1548  if (!(val = av_get_token(&opts, pairs_sep))) {
1549  av_free(key);
1550  return AVERROR(ENOMEM);
1551  }
1552  *ropts = opts;
1553  *rkey = key;
1554  *rval = val;
1555  return 0;
1556 }
1557 
1558 int av_opt_set_from_string(void *ctx, const char *opts,
1559  const char *const *shorthand,
1560  const char *key_val_sep, const char *pairs_sep)
1561 {
1562  int ret, count = 0;
1563  const char *dummy_shorthand = NULL;
1564  char *av_uninit(parsed_key), *av_uninit(value);
1565  const char *key;
1566 
1567  if (!opts)
1568  return 0;
1569  if (!shorthand)
1570  shorthand = &dummy_shorthand;
1571 
1572  while (*opts) {
1573  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1574  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1575  &parsed_key, &value);
1576  if (ret < 0) {
1577  if (ret == AVERROR(EINVAL))
1578  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1579  else
1580  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1581  av_err2str(ret));
1582  return ret;
1583  }
1584  if (*opts)
1585  opts++;
1586  if (parsed_key) {
1587  key = parsed_key;
1588  while (*shorthand) /* discard all remaining shorthand */
1589  shorthand++;
1590  } else {
1591  key = *(shorthand++);
1592  }
1593 
1594  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1595  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1597  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1598  av_free(value);
1599  av_free(parsed_key);
1600  return ret;
1601  }
1602 
1603  av_free(value);
1604  av_free(parsed_key);
1605  count++;
1606  }
1607  return count;
1608 }
1609 
1610 void av_opt_free(void *obj)
1611 {
1612  const AVOption *o = NULL;
1613  while ((o = av_opt_next(obj, o))) {
1614  switch (o->type) {
1615  case AV_OPT_TYPE_STRING:
1616  case AV_OPT_TYPE_BINARY:
1617  av_freep((uint8_t *)obj + o->offset);
1618  break;
1619 
1620  case AV_OPT_TYPE_DICT:
1621  av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
1622  break;
1623 
1624  default:
1625  break;
1626  }
1627  }
1628 }
1629 
1630 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1631 {
1632  AVDictionaryEntry *t = NULL;
1633  AVDictionary *tmp = NULL;
1634  int ret = 0;
1635 
1636  if (!options)
1637  return 0;
1638 
1639  while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
1640  ret = av_opt_set(obj, t->key, t->value, search_flags);
1642  ret = av_dict_set(&tmp, t->key, t->value, 0);
1643  if (ret < 0) {
1644  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1645  av_dict_free(&tmp);
1646  return ret;
1647  }
1648  ret = 0;
1649  }
1651  *options = tmp;
1652  return ret;
1653 }
1654 
1656 {
1657  return av_opt_set_dict2(obj, options, 0);
1658 }
1659 
1660 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1661  int opt_flags, int search_flags)
1662 {
1663  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1664 }
1665 
1666 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1667  int opt_flags, int search_flags, void **target_obj)
1668 {
1669  const AVClass *c;
1670  const AVOption *o = NULL;
1671 
1672  if(!obj)
1673  return NULL;
1674 
1675  c= *(AVClass**)obj;
1676 
1677  if (!c)
1678  return NULL;
1679 
1680  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1681  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1682  const AVClass *child = NULL;
1683  while (child = av_opt_child_class_next(c, child))
1684  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1685  return o;
1686  } else {
1687  void *child = NULL;
1688  while (child = av_opt_child_next(obj, child))
1689  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1690  return o;
1691  }
1692  }
1693 
1694  while (o = av_opt_next(obj, o)) {
1695  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1696  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1697  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1698  if (target_obj) {
1699  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1700  *target_obj = obj;
1701  else
1702  *target_obj = NULL;
1703  }
1704  return o;
1705  }
1706  }
1707  return NULL;
1708 }
1709 
1710 void *av_opt_child_next(void *obj, void *prev)
1711 {
1712  const AVClass *c = *(AVClass **)obj;
1713  if (c->child_next)
1714  return c->child_next(obj, prev);
1715  return NULL;
1716 }
1717 
1718 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
1719 {
1720  if (parent->child_class_next)
1721  return parent->child_class_next(prev);
1722  return NULL;
1723 }
1724 
1725 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
1726 {
1727  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
1728  if(!opt)
1729  return NULL;
1730  return (uint8_t*)obj + opt->offset;
1731 }
1732 
1733 static int opt_size(enum AVOptionType type)
1734 {
1735  switch(type) {
1736  case AV_OPT_TYPE_BOOL:
1737  case AV_OPT_TYPE_INT:
1738  case AV_OPT_TYPE_FLAGS:
1739  return sizeof(int);
1740  case AV_OPT_TYPE_DURATION:
1742  case AV_OPT_TYPE_INT64:
1743  case AV_OPT_TYPE_UINT64:
1744  return sizeof(int64_t);
1745  case AV_OPT_TYPE_DOUBLE:
1746  return sizeof(double);
1747  case AV_OPT_TYPE_FLOAT:
1748  return sizeof(float);
1749  case AV_OPT_TYPE_STRING:
1750  return sizeof(uint8_t*);
1752  case AV_OPT_TYPE_RATIONAL:
1753  return sizeof(AVRational);
1754  case AV_OPT_TYPE_BINARY:
1755  return sizeof(uint8_t*) + sizeof(int);
1757  return sizeof(int[2]);
1758  case AV_OPT_TYPE_PIXEL_FMT:
1759  return sizeof(enum AVPixelFormat);
1761  return sizeof(enum AVSampleFormat);
1762  case AV_OPT_TYPE_COLOR:
1763  return 4;
1764  }
1765  return AVERROR(EINVAL);
1766 }
1767 
1768 int av_opt_copy(void *dst, const void *src)
1769 {
1770  const AVOption *o = NULL;
1771  const AVClass *c;
1772  int ret = 0;
1773 
1774  if (!src)
1775  return AVERROR(EINVAL);
1776 
1777  c = *(AVClass **)src;
1778  if (!c || c != *(AVClass **)dst)
1779  return AVERROR(EINVAL);
1780 
1781  while ((o = av_opt_next(src, o))) {
1782  void *field_dst = (uint8_t *)dst + o->offset;
1783  void *field_src = (uint8_t *)src + o->offset;
1784  uint8_t **field_dst8 = (uint8_t **)field_dst;
1785  uint8_t **field_src8 = (uint8_t **)field_src;
1786 
1787  if (o->type == AV_OPT_TYPE_STRING) {
1788  if (*field_dst8 != *field_src8)
1789  av_freep(field_dst8);
1790  *field_dst8 = av_strdup(*field_src8);
1791  if (*field_src8 && !*field_dst8)
1792  ret = AVERROR(ENOMEM);
1793  } else if (o->type == AV_OPT_TYPE_BINARY) {
1794  int len = *(int *)(field_src8 + 1);
1795  if (*field_dst8 != *field_src8)
1796  av_freep(field_dst8);
1797  *field_dst8 = av_memdup(*field_src8, len);
1798  if (len && !*field_dst8) {
1799  ret = AVERROR(ENOMEM);
1800  len = 0;
1801  }
1802  *(int *)(field_dst8 + 1) = len;
1803  } else if (o->type == AV_OPT_TYPE_CONST) {
1804  // do nothing
1805  } else if (o->type == AV_OPT_TYPE_DICT) {
1806  AVDictionary **sdict = (AVDictionary **) field_src;
1807  AVDictionary **ddict = (AVDictionary **) field_dst;
1808  if (*sdict != *ddict)
1809  av_dict_free(ddict);
1810  *ddict = NULL;
1811  av_dict_copy(ddict, *sdict, 0);
1812  if (av_dict_count(*sdict) != av_dict_count(*ddict))
1813  ret = AVERROR(ENOMEM);
1814  } else {
1815  int size = opt_size(o->type);
1816  if (size < 0)
1817  ret = size;
1818  else
1819  memcpy(field_dst, field_src, size);
1820  }
1821  }
1822  return ret;
1823 }
1824 
1825 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1826 {
1827  int ret;
1828  const AVClass *c = *(AVClass**)obj;
1829  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;
1830 
1831  if (c->version > (52 << 16 | 11 << 8))
1832  callback = c->query_ranges;
1833 
1834  if (!callback)
1836 
1837  ret = callback(ranges_arg, obj, key, flags);
1838  if (ret >= 0) {
1840  ret = 1;
1841  (*ranges_arg)->nb_components = ret;
1842  }
1843  return ret;
1844 }
1845 
1846 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1847 {
1848  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
1849  AVOptionRange **range_array = av_mallocz(sizeof(void*));
1850  AVOptionRange *range = av_mallocz(sizeof(*range));
1851  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
1852  int ret;
1853 
1854  *ranges_arg = NULL;
1855 
1856  if (!ranges || !range || !range_array || !field) {
1857  ret = AVERROR(ENOMEM);
1858  goto fail;
1859  }
1860 
1861  ranges->range = range_array;
1862  ranges->range[0] = range;
1863  ranges->nb_ranges = 1;
1864  ranges->nb_components = 1;
1865  range->is_range = 1;
1866  range->value_min = field->min;
1867  range->value_max = field->max;
1868 
1869  switch (field->type) {
1870  case AV_OPT_TYPE_BOOL:
1871  case AV_OPT_TYPE_INT:
1872  case AV_OPT_TYPE_INT64:
1873  case AV_OPT_TYPE_UINT64:
1874  case AV_OPT_TYPE_PIXEL_FMT:
1876  case AV_OPT_TYPE_FLOAT:
1877  case AV_OPT_TYPE_DOUBLE:
1878  case AV_OPT_TYPE_DURATION:
1879  case AV_OPT_TYPE_COLOR:
1881  break;
1882  case AV_OPT_TYPE_STRING:
1883  range->component_min = 0;
1884  range->component_max = 0x10FFFF; // max unicode value
1885  range->value_min = -1;
1886  range->value_max = INT_MAX;
1887  break;
1888  case AV_OPT_TYPE_RATIONAL:
1889  range->component_min = INT_MIN;
1890  range->component_max = INT_MAX;
1891  break;
1893  range->component_min = 0;
1894  range->component_max = INT_MAX/128/8;
1895  range->value_min = 0;
1896  range->value_max = INT_MAX/8;
1897  break;
1899  range->component_min = 1;
1900  range->component_max = INT_MAX;
1901  range->value_min = 1;
1902  range->value_max = INT_MAX;
1903  break;
1904  default:
1905  ret = AVERROR(ENOSYS);
1906  goto fail;
1907  }
1908 
1909  *ranges_arg = ranges;
1910  return 1;
1911 fail:
1912  av_free(ranges);
1913  av_free(range);
1914  av_free(range_array);
1915  return ret;
1916 }
1917 
1919 {
1920  int i;
1921  AVOptionRanges *ranges = *rangesp;
1922 
1923  if (!ranges)
1924  return;
1925 
1926  for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
1927  AVOptionRange *range = ranges->range[i];
1928  if (range) {
1929  av_freep(&range->str);
1930  av_freep(&ranges->range[i]);
1931  }
1932  }
1933  av_freep(&ranges->range);
1934  av_freep(rangesp);
1935 }
1936 
1937 int av_opt_is_set_to_default(void *obj, const AVOption *o)
1938 {
1939  int64_t i64;
1940  double d, d2;
1941  float f;
1942  AVRational q;
1943  int ret, w, h;
1944  char *str;
1945  void *dst;
1946 
1947  if (!o || !obj)
1948  return AVERROR(EINVAL);
1949 
1950  dst = ((uint8_t*)obj) + o->offset;
1951 
1952  switch (o->type) {
1953  case AV_OPT_TYPE_CONST:
1954  return 1;
1955  case AV_OPT_TYPE_BOOL:
1956  case AV_OPT_TYPE_FLAGS:
1957  case AV_OPT_TYPE_PIXEL_FMT:
1959  case AV_OPT_TYPE_INT:
1961  case AV_OPT_TYPE_DURATION:
1962  case AV_OPT_TYPE_INT64:
1963  case AV_OPT_TYPE_UINT64:
1964  read_number(o, dst, NULL, NULL, &i64);
1965  return o->default_val.i64 == i64;
1966  case AV_OPT_TYPE_STRING:
1967  str = *(char **)dst;
1968  if (str == o->default_val.str) //2 NULLs
1969  return 1;
1970  if (!str || !o->default_val.str) //1 NULL
1971  return 0;
1972  return !strcmp(str, o->default_val.str);
1973  case AV_OPT_TYPE_DOUBLE:
1974  read_number(o, dst, &d, NULL, NULL);
1975  return o->default_val.dbl == d;
1976  case AV_OPT_TYPE_FLOAT:
1977  read_number(o, dst, &d, NULL, NULL);
1978  f = o->default_val.dbl;
1979  d2 = f;
1980  return d2 == d;
1981  case AV_OPT_TYPE_RATIONAL:
1982  q = av_d2q(o->default_val.dbl, INT_MAX);
1983  return !av_cmp_q(*(AVRational*)dst, q);
1984  case AV_OPT_TYPE_BINARY: {
1985  struct {
1986  uint8_t *data;
1987  int size;
1988  } tmp = {0};
1989  int opt_size = *(int *)((void **)dst + 1);
1990  void *opt_ptr = *(void **)dst;
1991  if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
1992  return 1;
1993  if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
1994  return 0;
1995  if (opt_size != strlen(o->default_val.str) / 2)
1996  return 0;
1997  ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
1998  if (!ret)
1999  ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2000  av_free(tmp.data);
2001  return ret;
2002  }
2003  case AV_OPT_TYPE_DICT: {
2004  AVDictionary *dict1 = NULL;
2005  AVDictionary *dict2 = *(AVDictionary **)dst;
2006  AVDictionaryEntry *en1 = NULL;
2007  AVDictionaryEntry *en2 = NULL;
2008  ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2009  if (ret < 0) {
2010  av_dict_free(&dict1);
2011  return ret;
2012  }
2013  do {
2014  en1 = av_dict_get(dict1, "", en1, AV_DICT_IGNORE_SUFFIX);
2015  en2 = av_dict_get(dict2, "", en2, AV_DICT_IGNORE_SUFFIX);
2016  } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2017  av_dict_free(&dict1);
2018  return (!en1 && !en2);
2019  }
2021  if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2022  w = h = 0;
2023  else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2024  return ret;
2025  return (w == *(int *)dst) && (h == *((int *)dst+1));
2027  q = (AVRational){0, 0};
2028  if (o->default_val.str) {
2029  if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2030  return ret;
2031  }
2032  return !av_cmp_q(*(AVRational*)dst, q);
2033  case AV_OPT_TYPE_COLOR: {
2034  uint8_t color[4] = {0, 0, 0, 0};
2035  if (o->default_val.str) {
2036  if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2037  return ret;
2038  }
2039  return !memcmp(color, dst, sizeof(color));
2040  }
2041  default:
2042  av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2043  break;
2044  }
2045  return AVERROR_PATCHWELCOME;
2046 }
2047 
2048 int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2049 {
2050  const AVOption *o;
2051  void *target;
2052  if (!obj)
2053  return AVERROR(EINVAL);
2054  o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2055  if (!o)
2056  return AVERROR_OPTION_NOT_FOUND;
2057  return av_opt_is_set_to_default(target, o);
2058 }
2059 
2060 int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2061  const char key_val_sep, const char pairs_sep)
2062 {
2063  const AVOption *o = NULL;
2064  uint8_t *buf;
2065  AVBPrint bprint;
2066  int ret, cnt = 0;
2067  const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2068 
2069  if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2070  pairs_sep == '\\' || key_val_sep == '\\') {
2071  av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2072  return AVERROR(EINVAL);
2073  }
2074 
2075  if (!obj || !buffer)
2076  return AVERROR(EINVAL);
2077 
2078  *buffer = NULL;
2080 
2081  while (o = av_opt_next(obj, o)) {
2082  if (o->type == AV_OPT_TYPE_CONST)
2083  continue;
2084  if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2085  continue;
2086  else if (((o->flags & opt_flags) != opt_flags))
2087  continue;
2089  continue;
2090  if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2091  av_bprint_finalize(&bprint, NULL);
2092  return ret;
2093  }
2094  if (buf) {
2095  if (cnt++)
2096  av_bprint_append_data(&bprint, &pairs_sep, 1);
2097  av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2098  av_bprint_append_data(&bprint, &key_val_sep, 1);
2099  av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2100  av_freep(&buf);
2101  }
2102  }
2103  av_bprint_finalize(&bprint, buffer);
2104  return 0;
2105 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:29
AVOptionRange::is_range
int is_range
Range flag.
Definition: opt.h:325
set_string_bool
static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:364
OPT_EVAL_NUMBER
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition: opt.c:554
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:1031
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
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:631
AVOption::i64
int64_t i64
Definition: opt.h:266
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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:1061
level
uint8_t level
Definition: svq3.c:210
AVOptionRanges::nb_components
int nb_components
Number of componentes.
Definition: opt.h:370
INFINITY
#define INFINITY
Definition: mathematics.h:67
r
const char * r
Definition: vf_curves.c:114
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_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
AV_OPT_FLAG_READONLY
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:289
AV_OPT_TYPE_SAMPLE_FMT
@ AV_OPT_TYPE_SAMPLE_FMT
Definition: opt.h:235
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:1357
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
AVOptionRange::value_max
double value_max
Definition: opt.h:315
color
Definition: vf_paletteuse.c:582
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
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:149
AVOptionType
AVOptionType
Definition: opt.h:221
set_string_sample_fmt
static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:441
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:1725
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:354
av_dict_count
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:35
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:236
AVOptionRange::value_min
double value_min
Value range.
Definition: opt.h:315
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
get_opt_const_name
static const char * get_opt_const_name(void *obj, const char *unit, int64_t value)
Definition: opt.c:1111
AVOptionRanges::nb_ranges
int nb_ranges
Number of ranges per component.
Definition: opt.h:366
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
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:2048
av_opt_set_double
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:591
AVOption
AVOption.
Definition: opt.h:246
is_key_char
static int is_key_char(char c)
Definition: opt.c:1500
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:91
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:237
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:291
AV_DICT_IGNORE_SUFFIX
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
Definition: dict.h:70
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:1937
AVOption::help
const char * help
short English help text
Definition: opt.h:253
float.h
AVOption::flags
int flags
Definition: opt.h:275
max
#define max(a, b)
Definition: cuda_runtime.h:33
av_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:139
mathematics.h
AVDictionary
Definition: dict.c:30
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:158
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:228
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:292
av_strlcatf
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
const_values
static const double const_values[]
Definition: eval.c:28
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
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:361
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:285
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:1478
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:229
AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
Serialize options that exactly match opt_flags only.
Definition: opt.h:845
fail
#define fail()
Definition: checkasm.h:123
AVOption::offset
int offset
The offset relative to the context structure where the option value is stored.
Definition: opt.h:259
get_bool_name
static const char * get_bool_name(int val)
Definition: opt.c:357
samplefmt.h
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
val
static double val(void *priv, double ch)
Definition: aeval.c:76
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:465
AVRational::num
int num
Numerator.
Definition: rational.h:59
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_opt_get_channel_layout
int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
Definition: opt.c:1014
mask
static const uint16_t mask[17]
Definition: lzw.c:38
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
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:1655
class
#define class
Definition: math.h:25
s
#define s(width, name)
Definition: cbs_vp9.c:257
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:276
AVDictionaryEntry::key
char * key
Definition: dict.h:82
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:225
AVOptionRange::str
const char * str
Definition: opt.h:309
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:725
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:699
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:224
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
ctx
AVFormatContext * ctx
Definition: movenc.c:48
WHITESPACES
#define WHITESPACES
Definition: opt.c:1498
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_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:290
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:49
key
const char * key
Definition: hwcontext_opencl.c:168
NAN
#define NAN
Definition: mathematics.h:64
f
#define f(width, name)
Definition: cbs_vp9.c:255
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:278
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:1004
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:1660
callback
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition: dshow.c:161
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:970
if
if(ret)
Definition: filter_design.txt:179
opts
AVDictionary * opts
Definition: movenc.c:50
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
av_opt_set_video_rate
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:653
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:601
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
log_value
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:1078
av_opt_get_double
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition: opt.c:924
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:670
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:238
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:1558
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive integers
Definition: opt.h:233
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:230
src
#define src
Definition: vp8dsp.c:254
AVOptionRange::component_min
double component_min
Value's component range.
Definition: opt.h:320
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:1009
set_number
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:570
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1610
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:587
AVOptionRanges::range
AVOptionRange ** range
Array of option ranges.
Definition: opt.h:362
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:1145
AVOption::min
double min
minimum valid value for the option
Definition: opt.h:272
av_opt_get_int
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:912
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:586
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:566
options
const OptionDef options[]
eval.h
av_opt_set_channel_layout
int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
Definition: opt.c:709
desc
const char * desc
Definition: nvenc.c:79
AVOptionRange
A single allowed range of values, or a single allowed value.
Definition: opt.h:308
AV_SAMPLE_FMT_NB
@ AV_SAMPLE_FMT_NB
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:74
AV_OPT_SERIALIZE_SKIP_DEFAULTS
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS
Serialize options that are not set to default values only.
Definition: opt.h:844
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:776
AVClass::child_class_next
const struct AVClass *(* child_class_next)(const struct AVClass *prev)
Return an AVClass corresponding to the next potential AVOptions-enabled child.
Definition: log.h:123
get_number
static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum, int search_flags)
Definition: opt.c:892
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:119
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
size
int size
Definition: twinvq_data.h:11134
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:395
read_number
static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
Definition: opt.c:58
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:1444
AVOption::default_val
union AVOption::@305 default_val
the default value for scalar options
hexchar2int
static int hexchar2int(char c)
Definition: opt.c:170
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:572
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:1362
AVOption::name
const char * name
Definition: opt.h:247
AV_OPT_TYPE_CHANNEL_LAYOUT
@ AV_OPT_TYPE_CHANNEL_LAYOUT
Definition: opt.h:239
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:558
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
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_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:1666
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:1630
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:203
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:148
set_string_video_rate
static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
Definition: opt.c:334
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
DEFAULT_NUMVAL
#define DEFAULT_NUMVAL(opt)
Definition: opt.c:221
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
flag
#define flag(name)
Definition: cbs_av1.c:557
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:179
bprint.h
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
set_string_pixel_fmt
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:435
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:56
get_opt_flags_string
static char * get_opt_flags_string(void *obj, const char *unit, int64_t value)
Definition: opt.c:1124
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:579
AVOption::str
const char * str
Definition: opt.h:268
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_OPT_FLAG_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:277
class_name
class_name
Definition: libkvazaar.c:289
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
set_string
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:214
uint8_t
uint8_t
Definition: audio_convert.c:194
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:237
len
int len
Definition: vorbis_enc_data.h:452
AVOptionRanges
List of AVOptionRange structs.
Definition: opt.h:331
av_opt_next
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:45
get_key
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition: opt.c:1515
av_cmp_q
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
av_uninit
#define av_uninit(x)
Definition: attributes.h:154
ret
ret
Definition: filter_design.txt:187
AVOption::dbl
double dbl
Definition: opt.h:267
set_string_color
static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:342
opt_size
static int opt_size(enum AVOptionType type)
Definition: opt.c:1733
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:1536
dict.h
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:265
AVOption::type
enum AVOptionType type
Definition: opt.h:260
const_names
static const char *const const_names[]
Definition: eval.c:34
av_opt_child_class_next
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:1718
set_string_dict
static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:447
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2477
set_string_binary
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:180
channel_layout.h
AV_OPT_FLAG_EXPORT
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:284
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
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:350
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:180
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Definition: opt.h:234
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:2060
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:1048
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:1846
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:1825
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
avutil.h
AV_OPT_FLAG_SUBTITLE_PARAM
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:280
AVOption::unit
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:302
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:1918
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1768
set_string_number
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:229
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVDictionaryEntry
Definition: dict.h:81
AVOptionRange::component_max
double component_max
Definition: opt.h:320
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:70
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:230
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:217
format_duration
static void format_duration(char *buf, size_t size, int64_t d)
Definition: opt.c:744
AV_ESCAPE_MODE_BACKSLASH
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Definition: avstring.h:320
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:222
convert_header.str
string str
Definition: convert_header.py:20
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
set_string_image_size
static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:319
av_opt_get
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:779
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
AVDictionaryEntry::value
char * value
Definition: dict.h:83
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:952
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
av_opt_set_q
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:596
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:531
int
int
Definition: ffmpeg_filter.c:192
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:704
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:1345
AV_OPT_FLAG_CHILD_CONSTS
#define AV_OPT_FLAG_CHILD_CONSTS
set if option constants can also reside in child objects
Definition: opt.h:294
AVOption::max
double max
maximum valid value for the option
Definition: opt.h:273
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
snprintf
#define snprintf
Definition: snprintf.h:34
av_opt_child_next
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition: opt.c:1710
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:308
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:986
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:2465
min
float min
Definition: vorbis_enc_data.h:456
write_number
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
Definition: opt.c:97
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:293
AV_OPT_TYPE_UINT64
@ AV_OPT_TYPE_UINT64
Definition: opt.h:231
av_opt_get_q
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:936