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