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