FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  dst = ((uint8_t *)target_obj) + o->offset;
467  switch (o->type) {
468  case AV_OPT_TYPE_BOOL:
469  return set_string_bool(obj, o, val, dst);
470  case AV_OPT_TYPE_STRING:
471  return set_string(obj, o, val, dst);
472  case AV_OPT_TYPE_BINARY:
473  return set_string_binary(obj, o, val, dst);
474  case AV_OPT_TYPE_FLAGS:
475  case AV_OPT_TYPE_INT:
476  case AV_OPT_TYPE_INT64:
477  case AV_OPT_TYPE_UINT64:
478  case AV_OPT_TYPE_FLOAT:
479  case AV_OPT_TYPE_DOUBLE:
481  return set_string_number(obj, target_obj, o, val, dst);
483  return set_string_image_size(obj, o, val, dst);
484  case AV_OPT_TYPE_VIDEO_RATE: {
485  AVRational tmp;
486  ret = set_string_video_rate(obj, o, val, &tmp);
487  if (ret < 0)
488  return ret;
489  return write_number(obj, o, dst, 1, tmp.den, tmp.num);
490  }
492  return set_string_pixel_fmt(obj, o, val, dst);
494  return set_string_sample_fmt(obj, o, val, dst);
496  if (!val) {
497  *(int64_t *)dst = 0;
498  return 0;
499  } else {
500  if ((ret = av_parse_time(dst, val, 1)) < 0)
501  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
502  return ret;
503  }
504  break;
505  case AV_OPT_TYPE_COLOR:
506  return set_string_color(obj, o, val, dst);
508  if (!val || !strcmp(val, "none")) {
509  *(int64_t *)dst = 0;
510  } else {
511  int64_t cl = av_get_channel_layout(val);
512  if (!cl) {
513  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
514  ret = AVERROR(EINVAL);
515  }
516  *(int64_t *)dst = cl;
517  return ret;
518  }
519  break;
520  }
521 
522  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
523  return AVERROR(EINVAL);
524 }
525 
526 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
527 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
528  const char *val, vartype *name ## _out) \
529 { \
530  if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
531  return AVERROR(EINVAL); \
532  return set_string_number(obj, obj, o, val, name ## _out); \
533 }
534 
537 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
538 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
539 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
541 
542 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
543  int search_flags)
544 {
545  void *dst, *target_obj;
546  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
547 
548  if (!o || !target_obj)
550 
551  if (o->flags & AV_OPT_FLAG_READONLY)
552  return AVERROR(EINVAL);
553 
554  dst = ((uint8_t *)target_obj) + o->offset;
555  return write_number(obj, o, dst, num, den, intnum);
556 }
557 
558 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
559 {
560  return set_number(obj, name, 1, 1, val, search_flags);
561 }
562 
563 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
564 {
565  return set_number(obj, name, val, 1, 1, search_flags);
566 }
567 
568 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
569 {
570  return set_number(obj, name, val.num, val.den, 1, search_flags);
571 }
572 
573 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
574 {
575  void *target_obj;
576  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
577  uint8_t *ptr;
578  uint8_t **dst;
579  int *lendst;
580 
581  if (!o || !target_obj)
583 
585  return AVERROR(EINVAL);
586 
587  ptr = len ? av_malloc(len) : NULL;
588  if (len && !ptr)
589  return AVERROR(ENOMEM);
590 
591  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
592  lendst = (int *)(dst + 1);
593 
594  av_free(*dst);
595  *dst = ptr;
596  *lendst = len;
597  if (len)
598  memcpy(ptr, val, len);
599 
600  return 0;
601 }
602 
603 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
604 {
605  void *target_obj;
606  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
607 
608  if (!o || !target_obj)
610  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
611  av_log(obj, AV_LOG_ERROR,
612  "The value set by option '%s' is not an image size.\n", o->name);
613  return AVERROR(EINVAL);
614  }
615  if (w<0 || h<0) {
616  av_log(obj, AV_LOG_ERROR,
617  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
618  return AVERROR(EINVAL);
619  }
620  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
621  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
622  return 0;
623 }
624 
625 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
626 {
627  void *target_obj;
628  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
629 
630  if (!o || !target_obj)
632  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
633  av_log(obj, AV_LOG_ERROR,
634  "The value set by option '%s' is not a video rate.\n", o->name);
635  return AVERROR(EINVAL);
636  }
637  if (val.num <= 0 || val.den <= 0)
638  return AVERROR(EINVAL);
639  return set_number(obj, name, val.num, val.den, 1, search_flags);
640 }
641 
642 static int set_format(void *obj, const char *name, int fmt, int search_flags,
643  enum AVOptionType type, const char *desc, int nb_fmts)
644 {
645  void *target_obj;
646  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
647  search_flags, &target_obj);
648  int min, max;
649 
650  if (!o || !target_obj)
652  if (o->type != type) {
653  av_log(obj, AV_LOG_ERROR,
654  "The value set by option '%s' is not a %s format", name, desc);
655  return AVERROR(EINVAL);
656  }
657 
658  min = FFMAX(o->min, -1);
659  max = FFMIN(o->max, nb_fmts-1);
660 
661  if (fmt < min || fmt > max) {
662  av_log(obj, AV_LOG_ERROR,
663  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
664  fmt, name, desc, min, max);
665  return AVERROR(ERANGE);
666  }
667  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
668  return 0;
669 }
670 
671 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
672 {
673  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
674 }
675 
676 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
677 {
678  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
679 }
680 
681 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
682 {
683  void *target_obj;
684  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
685 
686  if (!o || !target_obj)
688  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
689  av_log(obj, AV_LOG_ERROR,
690  "The value set by option '%s' is not a channel layout.\n", o->name);
691  return AVERROR(EINVAL);
692  }
693  *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
694  return 0;
695 }
696 
697 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
698  int search_flags)
699 {
700  void *target_obj;
701  AVDictionary **dst;
702  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
703 
704  if (!o || !target_obj)
706  if (o->flags & AV_OPT_FLAG_READONLY)
707  return AVERROR(EINVAL);
708 
709  dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
710  av_dict_free(dst);
711  av_dict_copy(dst, val, 0);
712 
713  return 0;
714 }
715 
716 static void format_duration(char *buf, size_t size, int64_t d)
717 {
718  char *e;
719 
720  av_assert0(size >= 25);
721  if (d < 0 && d != INT64_MIN) {
722  *(buf++) = '-';
723  size--;
724  d = -d;
725  }
726  if (d == INT64_MAX)
727  snprintf(buf, size, "INT64_MAX");
728  else if (d == INT64_MIN)
729  snprintf(buf, size, "INT64_MIN");
730  else if (d > (int64_t)3600*1000000)
731  snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
732  (int)((d / 60000000) % 60),
733  (int)((d / 1000000) % 60),
734  (int)(d % 1000000));
735  else if (d > 60*1000000)
736  snprintf(buf, size, "%d:%02d.%06d",
737  (int)(d / 60000000),
738  (int)((d / 1000000) % 60),
739  (int)(d % 1000000));
740  else
741  snprintf(buf, size, "%d.%06d",
742  (int)(d / 1000000),
743  (int)(d % 1000000));
744  e = buf + strlen(buf);
745  while (e > buf && e[-1] == '0')
746  *(--e) = 0;
747  if (e > buf && e[-1] == '.')
748  *(--e) = 0;
749 }
750 
751 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
752 {
753  void *dst, *target_obj;
754  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
755  uint8_t *bin, buf[128];
756  int len, i, ret;
757  int64_t i64;
758 
759  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
761 
762  dst = (uint8_t *)target_obj + o->offset;
763 
764  buf[0] = 0;
765  switch (o->type) {
766  case AV_OPT_TYPE_BOOL:
767  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
768  break;
769  case AV_OPT_TYPE_FLAGS:
770  ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
771  break;
772  case AV_OPT_TYPE_INT:
773  ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
774  break;
775  case AV_OPT_TYPE_INT64:
776  ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
777  break;
778  case AV_OPT_TYPE_UINT64:
779  ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
780  break;
781  case AV_OPT_TYPE_FLOAT:
782  ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
783  break;
784  case AV_OPT_TYPE_DOUBLE:
785  ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
786  break;
789  ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
790  break;
791  case AV_OPT_TYPE_CONST:
792  ret = snprintf(buf, sizeof(buf), "%f", o->default_val.dbl);
793  break;
794  case AV_OPT_TYPE_STRING:
795  if (*(uint8_t **)dst) {
796  *out_val = av_strdup(*(uint8_t **)dst);
797  } else if (search_flags & AV_OPT_ALLOW_NULL) {
798  *out_val = NULL;
799  return 0;
800  } else {
801  *out_val = av_strdup("");
802  }
803  return *out_val ? 0 : AVERROR(ENOMEM);
804  case AV_OPT_TYPE_BINARY:
805  if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
806  *out_val = NULL;
807  return 0;
808  }
809  len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
810  if ((uint64_t)len * 2 + 1 > INT_MAX)
811  return AVERROR(EINVAL);
812  if (!(*out_val = av_malloc(len * 2 + 1)))
813  return AVERROR(ENOMEM);
814  if (!len) {
815  *out_val[0] = '\0';
816  return 0;
817  }
818  bin = *(uint8_t **)dst;
819  for (i = 0; i < len; i++)
820  snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
821  return 0;
823  ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
824  break;
826  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
827  break;
829  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
830  break;
832  i64 = *(int64_t *)dst;
833  format_duration(buf, sizeof(buf), i64);
834  ret = strlen(buf); // no overflow possible, checked by an assert
835  break;
836  case AV_OPT_TYPE_COLOR:
837  ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
838  (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
839  (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
840  break;
842  i64 = *(int64_t *)dst;
843  ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
844  break;
845  default:
846  return AVERROR(EINVAL);
847  }
848 
849  if (ret >= sizeof(buf))
850  return AVERROR(EINVAL);
851  *out_val = av_strdup(buf);
852  return *out_val ? 0 : AVERROR(ENOMEM);
853 }
854 
855 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
856  int search_flags)
857 {
858  void *dst, *target_obj;
859  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
860  if (!o || !target_obj)
861  goto error;
862 
863  dst = ((uint8_t *)target_obj) + o->offset;
864 
865  if (o_out) *o_out= o;
866 
867  return read_number(o, dst, num, den, intnum);
868 
869 error:
870  *den =
871  *intnum = 0;
872  return -1;
873 }
874 
875 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
876 {
877  int64_t intnum = 1;
878  double num = 1;
879  int ret, den = 1;
880 
881  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
882  return ret;
883  *out_val = num * intnum / den;
884  return 0;
885 }
886 
887 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
888 {
889  int64_t intnum = 1;
890  double num = 1;
891  int ret, den = 1;
892 
893  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
894  return ret;
895  *out_val = num * intnum / den;
896  return 0;
897 }
898 
899 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
900 {
901  int64_t intnum = 1;
902  double num = 1;
903  int ret, den = 1;
904 
905  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
906  return ret;
907 
908  if (num == 1.0 && (int)intnum == intnum)
909  *out_val = (AVRational){intnum, den};
910  else
911  *out_val = av_d2q(num*intnum/den, 1<<24);
912  return 0;
913 }
914 
915 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
916 {
917  void *dst, *target_obj;
918  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
919  if (!o || !target_obj)
921  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
922  av_log(obj, AV_LOG_ERROR,
923  "The value for option '%s' is not an image size.\n", name);
924  return AVERROR(EINVAL);
925  }
926 
927  dst = ((uint8_t*)target_obj) + o->offset;
928  if (w_out) *w_out = *(int *)dst;
929  if (h_out) *h_out = *((int *)dst+1);
930  return 0;
931 }
932 
933 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
934 {
935  int64_t intnum = 1;
936  double num = 1;
937  int ret, den = 1;
938 
939  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
940  return ret;
941 
942  if (num == 1.0 && (int)intnum == intnum)
943  *out_val = (AVRational) { intnum, den };
944  else
945  *out_val = av_d2q(num * intnum / den, 1 << 24);
946  return 0;
947 }
948 
949 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
950  enum AVOptionType type, const char *desc)
951 {
952  void *dst, *target_obj;
953  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
954  if (!o || !target_obj)
956  if (o->type != type) {
957  av_log(obj, AV_LOG_ERROR,
958  "The value for option '%s' is not a %s format.\n", desc, name);
959  return AVERROR(EINVAL);
960  }
961 
962  dst = ((uint8_t*)target_obj) + o->offset;
963  *out_fmt = *(int *)dst;
964  return 0;
965 }
966 
967 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
968 {
969  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
970 }
971 
972 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
973 {
974  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
975 }
976 
977 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
978 {
979  void *dst, *target_obj;
980  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
981  if (!o || !target_obj)
983  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
984  av_log(obj, AV_LOG_ERROR,
985  "The value for option '%s' is not a channel layout.\n", name);
986  return AVERROR(EINVAL);
987  }
988 
989  dst = ((uint8_t*)target_obj) + o->offset;
990  *cl = *(int64_t *)dst;
991  return 0;
992 }
993 
994 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
995 {
996  void *target_obj;
997  AVDictionary *src;
998  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
999 
1000  if (!o || !target_obj)
1001  return AVERROR_OPTION_NOT_FOUND;
1002  if (o->type != AV_OPT_TYPE_DICT)
1003  return AVERROR(EINVAL);
1004 
1005  src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1006  av_dict_copy(out_val, src, 0);
1007 
1008  return 0;
1009 }
1010 
1011 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1012 {
1013  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1014  const AVOption *flag = av_opt_find(obj, flag_name,
1015  field ? field->unit : NULL, 0, 0);
1016  int64_t res;
1017 
1018  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1019  av_opt_get_int(obj, field_name, 0, &res) < 0)
1020  return 0;
1021  return res & flag->default_val.i64;
1022 }
1023 
1024 static void log_value(void *av_log_obj, int level, double d)
1025 {
1026  if (d == INT_MAX) {
1027  av_log(av_log_obj, level, "INT_MAX");
1028  } else if (d == INT_MIN) {
1029  av_log(av_log_obj, level, "INT_MIN");
1030  } else if (d == UINT32_MAX) {
1031  av_log(av_log_obj, level, "UINT32_MAX");
1032  } else if (d == (double)INT64_MAX) {
1033  av_log(av_log_obj, level, "I64_MAX");
1034  } else if (d == INT64_MIN) {
1035  av_log(av_log_obj, level, "I64_MIN");
1036  } else if (d == FLT_MAX) {
1037  av_log(av_log_obj, level, "FLT_MAX");
1038  } else if (d == FLT_MIN) {
1039  av_log(av_log_obj, level, "FLT_MIN");
1040  } else if (d == -FLT_MAX) {
1041  av_log(av_log_obj, level, "-FLT_MAX");
1042  } else if (d == -FLT_MIN) {
1043  av_log(av_log_obj, level, "-FLT_MIN");
1044  } else if (d == DBL_MAX) {
1045  av_log(av_log_obj, level, "DBL_MAX");
1046  } else if (d == DBL_MIN) {
1047  av_log(av_log_obj, level, "DBL_MIN");
1048  } else if (d == -DBL_MAX) {
1049  av_log(av_log_obj, level, "-DBL_MAX");
1050  } else if (d == -DBL_MIN) {
1051  av_log(av_log_obj, level, "-DBL_MIN");
1052  } else {
1053  av_log(av_log_obj, level, "%g", d);
1054  }
1055 }
1056 
1057 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1058 {
1059  const AVOption *opt = NULL;
1060 
1061  if (!unit)
1062  return NULL;
1063  while ((opt = av_opt_next(obj, opt)))
1064  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1065  opt->default_val.i64 == value)
1066  return opt->name;
1067  return NULL;
1068 }
1069 
1070 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1071 {
1072  const AVOption *opt = NULL;
1073  char flags[512];
1074 
1075  flags[0] = 0;
1076  if (!unit)
1077  return NULL;
1078  while ((opt = av_opt_next(obj, opt))) {
1079  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1080  opt->default_val.i64 & value) {
1081  if (flags[0])
1082  av_strlcatf(flags, sizeof(flags), "+");
1083  av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1084  }
1085  }
1086  if (flags[0])
1087  return av_strdup(flags);
1088  return NULL;
1089 }
1090 
1091 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1092  int req_flags, int rej_flags)
1093 {
1094  const AVOption *opt = NULL;
1095  AVOptionRanges *r;
1096  int i;
1097 
1098  while ((opt = av_opt_next(obj, opt))) {
1099  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1100  continue;
1101 
1102  /* Don't print CONST's on level one.
1103  * Don't print anything but CONST's on level two.
1104  * Only print items from the requested unit.
1105  */
1106  if (!unit && opt->type == AV_OPT_TYPE_CONST)
1107  continue;
1108  else if (unit && opt->type != AV_OPT_TYPE_CONST)
1109  continue;
1110  else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1111  continue;
1112  else if (unit && opt->type == AV_OPT_TYPE_CONST)
1113  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1114  else
1115  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1116  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? "" : "-",
1117  opt->name);
1118 
1119  switch (opt->type) {
1120  case AV_OPT_TYPE_FLAGS:
1121  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
1122  break;
1123  case AV_OPT_TYPE_INT:
1124  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
1125  break;
1126  case AV_OPT_TYPE_INT64:
1127  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
1128  break;
1129  case AV_OPT_TYPE_UINT64:
1130  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<uint64>");
1131  break;
1132  case AV_OPT_TYPE_DOUBLE:
1133  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
1134  break;
1135  case AV_OPT_TYPE_FLOAT:
1136  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
1137  break;
1138  case AV_OPT_TYPE_STRING:
1139  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
1140  break;
1141  case AV_OPT_TYPE_RATIONAL:
1142  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
1143  break;
1144  case AV_OPT_TYPE_BINARY:
1145  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
1146  break;
1148  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
1149  break;
1151  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
1152  break;
1153  case AV_OPT_TYPE_PIXEL_FMT:
1154  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
1155  break;
1157  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
1158  break;
1159  case AV_OPT_TYPE_DURATION:
1160  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
1161  break;
1162  case AV_OPT_TYPE_COLOR:
1163  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
1164  break;
1166  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
1167  break;
1168  case AV_OPT_TYPE_BOOL:
1169  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
1170  break;
1171  case AV_OPT_TYPE_CONST:
1172  default:
1173  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1174  break;
1175  }
1176  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
1177  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
1178  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_FILTERING_PARAM)? 'F' : '.');
1179  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
1180  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
1181  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
1182  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.');
1183  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.');
1184  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.');
1185 
1186  if (opt->help)
1187  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1188 
1189  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1190  switch (opt->type) {
1191  case AV_OPT_TYPE_INT:
1192  case AV_OPT_TYPE_INT64:
1193  case AV_OPT_TYPE_UINT64:
1194  case AV_OPT_TYPE_DOUBLE:
1195  case AV_OPT_TYPE_FLOAT:
1196  case AV_OPT_TYPE_RATIONAL:
1197  for (i = 0; i < r->nb_ranges; i++) {
1198  av_log(av_log_obj, AV_LOG_INFO, " (from ");
1199  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1200  av_log(av_log_obj, AV_LOG_INFO, " to ");
1201  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1202  av_log(av_log_obj, AV_LOG_INFO, ")");
1203  }
1204  break;
1205  }
1206  av_opt_freep_ranges(&r);
1207  }
1208 
1209  if (opt->type != AV_OPT_TYPE_CONST &&
1210  opt->type != AV_OPT_TYPE_BINARY &&
1211  !((opt->type == AV_OPT_TYPE_COLOR ||
1212  opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1213  opt->type == AV_OPT_TYPE_STRING ||
1214  opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1215  !opt->default_val.str)) {
1216  av_log(av_log_obj, AV_LOG_INFO, " (default ");
1217  switch (opt->type) {
1218  case AV_OPT_TYPE_BOOL:
1219  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
1220  break;
1221  case AV_OPT_TYPE_FLAGS: {
1222  char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1223  if (def_flags) {
1224  av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1225  av_freep(&def_flags);
1226  } else {
1227  av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1228  }
1229  break;
1230  }
1231  case AV_OPT_TYPE_DURATION: {
1232  char buf[25];
1233  format_duration(buf, sizeof(buf), opt->default_val.i64);
1234  av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1235  break;
1236  }
1237  case AV_OPT_TYPE_INT:
1238  case AV_OPT_TYPE_UINT64:
1239  case AV_OPT_TYPE_INT64: {
1240  const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1241  if (def_const)
1242  av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1243  else
1244  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1245  break;
1246  }
1247  case AV_OPT_TYPE_DOUBLE:
1248  case AV_OPT_TYPE_FLOAT:
1249  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1250  break;
1251  case AV_OPT_TYPE_RATIONAL: {
1252  AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1253  av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1254  break;
1255  case AV_OPT_TYPE_PIXEL_FMT:
1256  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1257  break;
1259  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1260  break;
1261  case AV_OPT_TYPE_COLOR:
1263  case AV_OPT_TYPE_STRING:
1265  av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1266  break;
1268  av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
1269  break;
1270  }
1271  av_log(av_log_obj, AV_LOG_INFO, ")");
1272  }
1273 
1274  av_log(av_log_obj, AV_LOG_INFO, "\n");
1275  if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1276  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
1277  }
1278 }
1279 
1280 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1281 {
1282  if (!obj)
1283  return -1;
1284 
1285  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1286 
1287  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
1288 
1289  return 0;
1290 }
1291 
1293 {
1294  av_opt_set_defaults2(s, 0, 0);
1295 }
1296 
1297 void av_opt_set_defaults2(void *s, int mask, int flags)
1298 {
1299  const AVOption *opt = NULL;
1300  while ((opt = av_opt_next(s, opt))) {
1301  void *dst = ((uint8_t*)s) + opt->offset;
1302 
1303  if ((opt->flags & mask) != flags)
1304  continue;
1305 
1306  if (opt->flags & AV_OPT_FLAG_READONLY)
1307  continue;
1308 
1309  switch (opt->type) {
1310  case AV_OPT_TYPE_CONST:
1311  /* Nothing to be done here */
1312  break;
1313  case AV_OPT_TYPE_BOOL:
1314  case AV_OPT_TYPE_FLAGS:
1315  case AV_OPT_TYPE_INT:
1316  case AV_OPT_TYPE_INT64:
1317  case AV_OPT_TYPE_UINT64:
1318  case AV_OPT_TYPE_DURATION:
1320  case AV_OPT_TYPE_PIXEL_FMT:
1322  write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1323  break;
1324  case AV_OPT_TYPE_DOUBLE:
1325  case AV_OPT_TYPE_FLOAT: {
1326  double val;
1327  val = opt->default_val.dbl;
1328  write_number(s, opt, dst, val, 1, 1);
1329  }
1330  break;
1331  case AV_OPT_TYPE_RATIONAL: {
1332  AVRational val;
1333  val = av_d2q(opt->default_val.dbl, INT_MAX);
1334  write_number(s, opt, dst, 1, val.den, val.num);
1335  }
1336  break;
1337  case AV_OPT_TYPE_COLOR:
1338  set_string_color(s, opt, opt->default_val.str, dst);
1339  break;
1340  case AV_OPT_TYPE_STRING:
1341  set_string(s, opt, opt->default_val.str, dst);
1342  break;
1344  set_string_image_size(s, opt, opt->default_val.str, dst);
1345  break;
1347  set_string_video_rate(s, opt, opt->default_val.str, dst);
1348  break;
1349  case AV_OPT_TYPE_BINARY:
1350  set_string_binary(s, opt, opt->default_val.str, dst);
1351  break;
1352  case AV_OPT_TYPE_DICT:
1353  /* Cannot set defaults for these types */
1354  break;
1355  default:
1356  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1357  opt->type, opt->name);
1358  }
1359  }
1360 }
1361 
1362 /**
1363  * Store the value in the field in ctx that is named like key.
1364  * ctx must be an AVClass context, storing is done using AVOptions.
1365  *
1366  * @param buf the string to parse, buf will be updated to point at the
1367  * separator just after the parsed key/value pair
1368  * @param key_val_sep a 0-terminated list of characters used to
1369  * separate key from value
1370  * @param pairs_sep a 0-terminated list of characters used to separate
1371  * two pairs from each other
1372  * @return 0 if the key/value pair has been successfully parsed and
1373  * set, or a negative value corresponding to an AVERROR code in case
1374  * of error:
1375  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1376  * the error code issued by av_opt_set() if the key/value pair
1377  * cannot be set
1378  */
1379 static int parse_key_value_pair(void *ctx, const char **buf,
1380  const char *key_val_sep, const char *pairs_sep)
1381 {
1382  char *key = av_get_token(buf, key_val_sep);
1383  char *val;
1384  int ret;
1385 
1386  if (!key)
1387  return AVERROR(ENOMEM);
1388 
1389  if (*key && strspn(*buf, key_val_sep)) {
1390  (*buf)++;
1391  val = av_get_token(buf, pairs_sep);
1392  if (!val) {
1393  av_freep(&key);
1394  return AVERROR(ENOMEM);
1395  }
1396  } else {
1397  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1398  av_free(key);
1399  return AVERROR(EINVAL);
1400  }
1401 
1402  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1403 
1404  ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN);
1405  if (ret == AVERROR_OPTION_NOT_FOUND)
1406  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1407 
1408  av_free(key);
1409  av_free(val);
1410  return ret;
1411 }
1412 
1413 int av_set_options_string(void *ctx, const char *opts,
1414  const char *key_val_sep, const char *pairs_sep)
1415 {
1416  int ret, count = 0;
1417 
1418  if (!opts)
1419  return 0;
1420 
1421  while (*opts) {
1422  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1423  return ret;
1424  count++;
1425 
1426  if (*opts)
1427  opts++;
1428  }
1429 
1430  return count;
1431 }
1432 
1433 #define WHITESPACES " \n\t\r"
1434 
1435 static int is_key_char(char c)
1436 {
1437  return (unsigned)((c | 32) - 'a') < 26 ||
1438  (unsigned)(c - '0') < 10 ||
1439  c == '-' || c == '_' || c == '/' || c == '.';
1440 }
1441 
1442 /**
1443  * Read a key from a string.
1444  *
1445  * The key consists of is_key_char characters and must be terminated by a
1446  * character from the delim string; spaces are ignored.
1447  *
1448  * @return 0 for success (even with ellipsis), <0 for failure
1449  */
1450 static int get_key(const char **ropts, const char *delim, char **rkey)
1451 {
1452  const char *opts = *ropts;
1453  const char *key_start, *key_end;
1454 
1455  key_start = opts += strspn(opts, WHITESPACES);
1456  while (is_key_char(*opts))
1457  opts++;
1458  key_end = opts;
1459  opts += strspn(opts, WHITESPACES);
1460  if (!*opts || !strchr(delim, *opts))
1461  return AVERROR(EINVAL);
1462  opts++;
1463  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1464  return AVERROR(ENOMEM);
1465  memcpy(*rkey, key_start, key_end - key_start);
1466  (*rkey)[key_end - key_start] = 0;
1467  *ropts = opts;
1468  return 0;
1469 }
1470 
1471 int av_opt_get_key_value(const char **ropts,
1472  const char *key_val_sep, const char *pairs_sep,
1473  unsigned flags,
1474  char **rkey, char **rval)
1475 {
1476  int ret;
1477  char *key = NULL, *val;
1478  const char *opts = *ropts;
1479 
1480  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1481  !(flags & AV_OPT_FLAG_IMPLICIT_KEY))
1482  return AVERROR(EINVAL);
1483  if (!(val = av_get_token(&opts, pairs_sep))) {
1484  av_free(key);
1485  return AVERROR(ENOMEM);
1486  }
1487  *ropts = opts;
1488  *rkey = key;
1489  *rval = val;
1490  return 0;
1491 }
1492 
1493 int av_opt_set_from_string(void *ctx, const char *opts,
1494  const char *const *shorthand,
1495  const char *key_val_sep, const char *pairs_sep)
1496 {
1497  int ret, count = 0;
1498  const char *dummy_shorthand = NULL;
1499  char *av_uninit(parsed_key), *av_uninit(value);
1500  const char *key;
1501 
1502  if (!opts)
1503  return 0;
1504  if (!shorthand)
1505  shorthand = &dummy_shorthand;
1506 
1507  while (*opts) {
1508  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1509  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1510  &parsed_key, &value);
1511  if (ret < 0) {
1512  if (ret == AVERROR(EINVAL))
1513  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1514  else
1515  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1516  av_err2str(ret));
1517  return ret;
1518  }
1519  if (*opts)
1520  opts++;
1521  if (parsed_key) {
1522  key = parsed_key;
1523  while (*shorthand) /* discard all remaining shorthand */
1524  shorthand++;
1525  } else {
1526  key = *(shorthand++);
1527  }
1528 
1529  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1530  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1531  if (ret == AVERROR_OPTION_NOT_FOUND)
1532  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1533  av_free(value);
1534  av_free(parsed_key);
1535  return ret;
1536  }
1537 
1538  av_free(value);
1539  av_free(parsed_key);
1540  count++;
1541  }
1542  return count;
1543 }
1544 
1545 void av_opt_free(void *obj)
1546 {
1547  const AVOption *o = NULL;
1548  while ((o = av_opt_next(obj, o))) {
1549  switch (o->type) {
1550  case AV_OPT_TYPE_STRING:
1551  case AV_OPT_TYPE_BINARY:
1552  av_freep((uint8_t *)obj + o->offset);
1553  break;
1554 
1555  case AV_OPT_TYPE_DICT:
1556  av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
1557  break;
1558 
1559  default:
1560  break;
1561  }
1562  }
1563 }
1564 
1565 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1566 {
1567  AVDictionaryEntry *t = NULL;
1568  AVDictionary *tmp = NULL;
1569  int ret = 0;
1570 
1571  if (!options)
1572  return 0;
1573 
1574  while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
1575  ret = av_opt_set(obj, t->key, t->value, search_flags);
1576  if (ret == AVERROR_OPTION_NOT_FOUND)
1577  ret = av_dict_set(&tmp, t->key, t->value, 0);
1578  if (ret < 0) {
1579  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1580  av_dict_free(&tmp);
1581  return ret;
1582  }
1583  ret = 0;
1584  }
1585  av_dict_free(options);
1586  *options = tmp;
1587  return ret;
1588 }
1589 
1591 {
1592  return av_opt_set_dict2(obj, options, 0);
1593 }
1594 
1595 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1596  int opt_flags, int search_flags)
1597 {
1598  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1599 }
1600 
1601 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1602  int opt_flags, int search_flags, void **target_obj)
1603 {
1604  const AVClass *c;
1605  const AVOption *o = NULL;
1606 
1607  if(!obj)
1608  return NULL;
1609 
1610  c= *(AVClass**)obj;
1611 
1612  if (!c)
1613  return NULL;
1614 
1615  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1616  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1617  const AVClass *child = NULL;
1618  while (child = av_opt_child_class_next(c, child))
1619  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1620  return o;
1621  } else {
1622  void *child = NULL;
1623  while (child = av_opt_child_next(obj, child))
1624  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1625  return o;
1626  }
1627  }
1628 
1629  while (o = av_opt_next(obj, o)) {
1630  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1631  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1632  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1633  if (target_obj) {
1634  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1635  *target_obj = obj;
1636  else
1637  *target_obj = NULL;
1638  }
1639  return o;
1640  }
1641  }
1642  return NULL;
1643 }
1644 
1645 void *av_opt_child_next(void *obj, void *prev)
1646 {
1647  const AVClass *c = *(AVClass **)obj;
1648  if (c->child_next)
1649  return c->child_next(obj, prev);
1650  return NULL;
1651 }
1652 
1653 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
1654 {
1655  if (parent->child_class_next)
1656  return parent->child_class_next(prev);
1657  return NULL;
1658 }
1659 
1660 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
1661 {
1662  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
1663  if(!opt)
1664  return NULL;
1665  return (uint8_t*)obj + opt->offset;
1666 }
1667 
1668 static int opt_size(enum AVOptionType type)
1669 {
1670  switch(type) {
1671  case AV_OPT_TYPE_BOOL:
1672  case AV_OPT_TYPE_INT:
1673  case AV_OPT_TYPE_FLAGS:
1674  return sizeof(int);
1675  case AV_OPT_TYPE_DURATION:
1677  case AV_OPT_TYPE_INT64:
1678  case AV_OPT_TYPE_UINT64:
1679  return sizeof(int64_t);
1680  case AV_OPT_TYPE_DOUBLE:
1681  return sizeof(double);
1682  case AV_OPT_TYPE_FLOAT:
1683  return sizeof(float);
1684  case AV_OPT_TYPE_STRING:
1685  return sizeof(uint8_t*);
1687  case AV_OPT_TYPE_RATIONAL:
1688  return sizeof(AVRational);
1689  case AV_OPT_TYPE_BINARY:
1690  return sizeof(uint8_t*) + sizeof(int);
1692  return sizeof(int[2]);
1693  case AV_OPT_TYPE_PIXEL_FMT:
1694  return sizeof(enum AVPixelFormat);
1696  return sizeof(enum AVSampleFormat);
1697  case AV_OPT_TYPE_COLOR:
1698  return 4;
1699  }
1700  return AVERROR(EINVAL);
1701 }
1702 
1703 int av_opt_copy(void *dst, const void *src)
1704 {
1705  const AVOption *o = NULL;
1706  const AVClass *c;
1707  int ret = 0;
1708 
1709  if (!src)
1710  return AVERROR(EINVAL);
1711 
1712  c = *(AVClass **)src;
1713  if (!c || c != *(AVClass **)dst)
1714  return AVERROR(EINVAL);
1715 
1716  while ((o = av_opt_next(src, o))) {
1717  void *field_dst = (uint8_t *)dst + o->offset;
1718  void *field_src = (uint8_t *)src + o->offset;
1719  uint8_t **field_dst8 = (uint8_t **)field_dst;
1720  uint8_t **field_src8 = (uint8_t **)field_src;
1721 
1722  if (o->type == AV_OPT_TYPE_STRING) {
1723  if (*field_dst8 != *field_src8)
1724  av_freep(field_dst8);
1725  *field_dst8 = av_strdup(*field_src8);
1726  if (*field_src8 && !*field_dst8)
1727  ret = AVERROR(ENOMEM);
1728  } else if (o->type == AV_OPT_TYPE_BINARY) {
1729  int len = *(int *)(field_src8 + 1);
1730  if (*field_dst8 != *field_src8)
1731  av_freep(field_dst8);
1732  *field_dst8 = av_memdup(*field_src8, len);
1733  if (len && !*field_dst8) {
1734  ret = AVERROR(ENOMEM);
1735  len = 0;
1736  }
1737  *(int *)(field_dst8 + 1) = len;
1738  } else if (o->type == AV_OPT_TYPE_CONST) {
1739  // do nothing
1740  } else if (o->type == AV_OPT_TYPE_DICT) {
1741  AVDictionary **sdict = (AVDictionary **) field_src;
1742  AVDictionary **ddict = (AVDictionary **) field_dst;
1743  if (*sdict != *ddict)
1744  av_dict_free(ddict);
1745  *ddict = NULL;
1746  av_dict_copy(ddict, *sdict, 0);
1747  if (av_dict_count(*sdict) != av_dict_count(*ddict))
1748  ret = AVERROR(ENOMEM);
1749  } else {
1750  int size = opt_size(o->type);
1751  if (size < 0)
1752  ret = size;
1753  else
1754  memcpy(field_dst, field_src, size);
1755  }
1756  }
1757  return ret;
1758 }
1759 
1760 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1761 {
1762  int ret;
1763  const AVClass *c = *(AVClass**)obj;
1764  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;
1765 
1766  if (c->version > (52 << 16 | 11 << 8))
1767  callback = c->query_ranges;
1768 
1769  if (!callback)
1771 
1772  ret = callback(ranges_arg, obj, key, flags);
1773  if (ret >= 0) {
1774  if (!(flags & AV_OPT_MULTI_COMPONENT_RANGE))
1775  ret = 1;
1776  (*ranges_arg)->nb_components = ret;
1777  }
1778  return ret;
1779 }
1780 
1781 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1782 {
1783  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
1784  AVOptionRange **range_array = av_mallocz(sizeof(void*));
1785  AVOptionRange *range = av_mallocz(sizeof(*range));
1786  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
1787  int ret;
1788 
1789  *ranges_arg = NULL;
1790 
1791  if (!ranges || !range || !range_array || !field) {
1792  ret = AVERROR(ENOMEM);
1793  goto fail;
1794  }
1795 
1796  ranges->range = range_array;
1797  ranges->range[0] = range;
1798  ranges->nb_ranges = 1;
1799  ranges->nb_components = 1;
1800  range->is_range = 1;
1801  range->value_min = field->min;
1802  range->value_max = field->max;
1803 
1804  switch (field->type) {
1805  case AV_OPT_TYPE_BOOL:
1806  case AV_OPT_TYPE_INT:
1807  case AV_OPT_TYPE_INT64:
1808  case AV_OPT_TYPE_UINT64:
1809  case AV_OPT_TYPE_PIXEL_FMT:
1811  case AV_OPT_TYPE_FLOAT:
1812  case AV_OPT_TYPE_DOUBLE:
1813  case AV_OPT_TYPE_DURATION:
1814  case AV_OPT_TYPE_COLOR:
1816  break;
1817  case AV_OPT_TYPE_STRING:
1818  range->component_min = 0;
1819  range->component_max = 0x10FFFF; // max unicode value
1820  range->value_min = -1;
1821  range->value_max = INT_MAX;
1822  break;
1823  case AV_OPT_TYPE_RATIONAL:
1824  range->component_min = INT_MIN;
1825  range->component_max = INT_MAX;
1826  break;
1828  range->component_min = 0;
1829  range->component_max = INT_MAX/128/8;
1830  range->value_min = 0;
1831  range->value_max = INT_MAX/8;
1832  break;
1834  range->component_min = 1;
1835  range->component_max = INT_MAX;
1836  range->value_min = 1;
1837  range->value_max = INT_MAX;
1838  break;
1839  default:
1840  ret = AVERROR(ENOSYS);
1841  goto fail;
1842  }
1843 
1844  *ranges_arg = ranges;
1845  return 1;
1846 fail:
1847  av_free(ranges);
1848  av_free(range);
1849  av_free(range_array);
1850  return ret;
1851 }
1852 
1854 {
1855  int i;
1856  AVOptionRanges *ranges = *rangesp;
1857 
1858  if (!ranges)
1859  return;
1860 
1861  for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
1862  AVOptionRange *range = ranges->range[i];
1863  if (range) {
1864  av_freep(&range->str);
1865  av_freep(&ranges->range[i]);
1866  }
1867  }
1868  av_freep(&ranges->range);
1869  av_freep(rangesp);
1870 }
1871 
1872 int av_opt_is_set_to_default(void *obj, const AVOption *o)
1873 {
1874  int64_t i64;
1875  double d, d2;
1876  float f;
1877  AVRational q;
1878  int ret, w, h;
1879  char *str;
1880  void *dst;
1881 
1882  if (!o || !obj)
1883  return AVERROR(EINVAL);
1884 
1885  dst = ((uint8_t*)obj) + o->offset;
1886 
1887  switch (o->type) {
1888  case AV_OPT_TYPE_CONST:
1889  return 1;
1890  case AV_OPT_TYPE_BOOL:
1891  case AV_OPT_TYPE_FLAGS:
1892  case AV_OPT_TYPE_PIXEL_FMT:
1894  case AV_OPT_TYPE_INT:
1896  case AV_OPT_TYPE_DURATION:
1897  case AV_OPT_TYPE_INT64:
1898  case AV_OPT_TYPE_UINT64:
1899  read_number(o, dst, NULL, NULL, &i64);
1900  return o->default_val.i64 == i64;
1901  case AV_OPT_TYPE_STRING:
1902  str = *(char **)dst;
1903  if (str == o->default_val.str) //2 NULLs
1904  return 1;
1905  if (!str || !o->default_val.str) //1 NULL
1906  return 0;
1907  return !strcmp(str, o->default_val.str);
1908  case AV_OPT_TYPE_DOUBLE:
1909  read_number(o, dst, &d, NULL, NULL);
1910  return o->default_val.dbl == d;
1911  case AV_OPT_TYPE_FLOAT:
1912  read_number(o, dst, &d, NULL, NULL);
1913  f = o->default_val.dbl;
1914  d2 = f;
1915  return d2 == d;
1916  case AV_OPT_TYPE_RATIONAL:
1917  q = av_d2q(o->default_val.dbl, INT_MAX);
1918  return !av_cmp_q(*(AVRational*)dst, q);
1919  case AV_OPT_TYPE_BINARY: {
1920  struct {
1921  uint8_t *data;
1922  int size;
1923  } tmp = {0};
1924  int opt_size = *(int *)((void **)dst + 1);
1925  void *opt_ptr = *(void **)dst;
1926  if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
1927  return 1;
1928  if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
1929  return 0;
1930  if (opt_size != strlen(o->default_val.str) / 2)
1931  return 0;
1932  ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
1933  if (!ret)
1934  ret = !memcmp(opt_ptr, tmp.data, tmp.size);
1935  av_free(tmp.data);
1936  return ret;
1937  }
1938  case AV_OPT_TYPE_DICT:
1939  /* Binary and dict have not default support yet. Any pointer is not default. */
1940  return !!(*(void **)dst);
1942  if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
1943  w = h = 0;
1944  else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
1945  return ret;
1946  return (w == *(int *)dst) && (h == *((int *)dst+1));
1948  q = (AVRational){0, 0};
1949  if (o->default_val.str) {
1950  if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
1951  return ret;
1952  }
1953  return !av_cmp_q(*(AVRational*)dst, q);
1954  case AV_OPT_TYPE_COLOR: {
1955  uint8_t color[4] = {0, 0, 0, 0};
1956  if (o->default_val.str) {
1957  if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
1958  return ret;
1959  }
1960  return !memcmp(color, dst, sizeof(color));
1961  }
1962  default:
1963  av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
1964  break;
1965  }
1966  return AVERROR_PATCHWELCOME;
1967 }
1968 
1969 int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
1970 {
1971  const AVOption *o;
1972  void *target;
1973  if (!obj)
1974  return AVERROR(EINVAL);
1975  o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
1976  if (!o)
1977  return AVERROR_OPTION_NOT_FOUND;
1978  return av_opt_is_set_to_default(target, o);
1979 }
1980 
1981 int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
1982  const char key_val_sep, const char pairs_sep)
1983 {
1984  const AVOption *o = NULL;
1985  uint8_t *buf;
1986  AVBPrint bprint;
1987  int ret, cnt = 0;
1988  const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
1989 
1990  if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
1991  pairs_sep == '\\' || key_val_sep == '\\') {
1992  av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
1993  return AVERROR(EINVAL);
1994  }
1995 
1996  if (!obj || !buffer)
1997  return AVERROR(EINVAL);
1998 
1999  *buffer = NULL;
2001 
2002  while (o = av_opt_next(obj, o)) {
2003  if (o->type == AV_OPT_TYPE_CONST)
2004  continue;
2005  if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2006  continue;
2007  else if (((o->flags & opt_flags) != opt_flags))
2008  continue;
2009  if (flags & AV_OPT_SERIALIZE_SKIP_DEFAULTS && av_opt_is_set_to_default(obj, o) > 0)
2010  continue;
2011  if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2012  av_bprint_finalize(&bprint, NULL);
2013  return ret;
2014  }
2015  if (buf) {
2016  if (cnt++)
2017  av_bprint_append_data(&bprint, &pairs_sep, 1);
2018  av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2019  av_bprint_append_data(&bprint, &key_val_sep, 1);
2020  av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2021  av_freep(&buf);
2022  }
2023  }
2024  av_bprint_finalize(&bprint, buffer);
2025  return 0;
2026 }
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
Definition: opt.c:994
#define NULL
Definition: coverity.c:32
static const char * get_bool_name(int val)
Definition: opt.c:359
const char const char void * val
Definition: avisynth_c.h:771
union AVOption::@264 default_val
the default value for scalar options
A single allowed range of values, or a single allowed value.
Definition: opt.h:305
const char * s
Definition: avisynth_c.h:768
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:74
static char * get_opt_flags_string(void *obj, const char *unit, int64_t value)
Definition: opt.c:1070
Accept to parse a value without a key; the key will then be returned as NULL.
Definition: opt.h:528
#define flag(name)
Definition: cbs_h2645.c:346
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:179
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:568
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
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition: opt.h:284
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:280
const char * fmt
Definition: avisynth_c.h:769
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:316
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition: opt.c:1645
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
const char * desc
Definition: nvenc.c:65
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition: opt.c:1450
double value_max
Definition: opt.h:312
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:1653
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1292
static int opt_size(enum AVOptionType type)
Definition: opt.c:1668
int num
Numerator.
Definition: rational.h:59
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:278
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition: dict.c:35
const char * b
Definition: vf_curves.c:113
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:1413
static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:443
Convenience header that includes libavutil's core.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:217
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition: opt.c:573
Use backslash escaping.
Definition: avstring.h:315
const char * key
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
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:899
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:1981
static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags)
Definition: opt.c:1091
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
Definition: opt.c:697
#define src
Definition: vp8dsp.c:254
AVOptionType
Definition: opt.h:221
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:1969
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
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:1872
int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:933
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:1493
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, enum AVOptionType type, const char *desc)
Definition: opt.c:949
Public dictionary API.
const char * name
Definition: opt.h:247
#define WHITESPACES
Definition: opt.c:1433
uint8_t
AVOptionRange ** range
Array of option ranges.
Definition: opt.h:359
#define av_malloc(s)
class_name
Definition: libkvazaar.c:280
const char * help
short English help text
Definition: opt.h:253
AVOptions.
AVS_FilterInfo AVS_Value child
Definition: avisynth_c.h:731
static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
Definition: opt.c:58
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static const char * get_opt_const_name(void *obj, const char *unit, int64_t value)
Definition: opt.c:1057
const char * str
Definition: opt.h:268
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:563
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition: bprint.c:158
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
double component_max
Definition: opt.h:317
static int flags
Definition: log.c:55
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
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:855
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:625
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:276
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
static const double const_values[]
Definition: eval.c:28
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
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:437
static int hexchar2int(char c)
Definition: opt.c:170
int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
Definition: opt.c:967
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
int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
Definition: opt.c:671
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AV_BPRINT_SIZE_UNLIMITED
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:1660
static const uint16_t mask[17]
Definition: lzw.c:38
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
Definition: opt.h:291
double max
maximum valid value for the option
Definition: opt.h:273
#define AVERROR(e)
Definition: error.h:43
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
const char * r
Definition: vf_curves.c:111
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:558
simple assert() macros that are a bit more flexible than ISO C assert().
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:45
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:343
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
GLsizei count
Definition: opengl_enc.c:109
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:283
#define FFMAX(a, b)
Definition: common.h:94
#define fail()
Definition: checkasm.h:116
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
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:1595
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:214
AVDictionary * opts
Definition: movenc.c:50
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition: opt.c:972
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition: dshow.c:161
audio channel layout utility functions
const char * str
Definition: opt.h:306
#define NAN
Definition: mathematics.h:64
#define FFMIN(a, b)
Definition: common.h:96
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:555
uint8_t w
Definition: llviddspenc.c:38
const char * class
Definition: pixdesc_query.c:27
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
AVFormatContext * ctx
Definition: movenc.c:48
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:299
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:1379
double component_min
Value's component range.
Definition: opt.h:317
int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
Definition: opt.c:681
double min
minimum valid value for the option
Definition: opt.h:272
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:229
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:1297
#define AV_OPT_FLAG_BSF_PARAM
a generic parameter which can be set by the user for bit stream filtering
Definition: opt.h:290
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:180
int n
Definition: avisynth_c.h:684
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:1565
static void error(const char *err)
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
#define FF_ARRAY_ELEMS(a)
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:229
int flags
Definition: opt.h:275
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:1781
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int is_range
Range flag.
Definition: opt.h:322
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:875
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:1024
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
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:642
void av_opt_freep_ranges(AVOptionRanges **rangesp)
Free an AVOptionRanges struct and set it to NULL.
Definition: opt.c:1853
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
int offset
The offset relative to the context structure where the option value is stored.
Definition: opt.h:259
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1590
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:542
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:1280
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
static void format_duration(char *buf, size_t size, int64_t d)
Definition: opt.c:716
static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
Definition: opt.c:366
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition: opt.c:526
void * buf
Definition: avisynth_c.h:690
GLint GLenum type
Definition: opengl_enc.c:105
int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
Definition: opt.c:977
#define llrint(x)
Definition: libm.h:394
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
Describe the class of an AVClass context structure.
Definition: log.h:67
Rational number (pair of numerator and denominator).
Definition: rational.h:58
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
#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
double dbl
Definition: opt.h:267
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
offset must point to AVRational
Definition: opt.h:236
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
#define snprintf
Definition: snprintf.h:34
offset must point to two consecutive integers
Definition: opt.h:233
misc parsing utilities
uint8_t level
Definition: svq3.c:207
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
int version
LIBAVUTIL_VERSION with which this structure was created.
Definition: log.h:93
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:89
int
static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
Definition: opt.c:331
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
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1545
const OptionDef options[]
Definition: ffmpeg_opt.c:3292
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:1760
double value_min
Value range.
Definition: opt.h:312
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
#define DEFAULT_NUMVAL(opt)
Definition: opt.c:221
int(* query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags)
Callback to return the supported/allowed ranges.
Definition: log.h:142
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition: opt.c:887
static double c[64]
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
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1703
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:113
#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
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
Definition: opt.c:97
char * key
Definition: dict.h:86
int den
Denominator.
Definition: rational.h:60
int nb_ranges
Number of ranges per component.
Definition: opt.h:363
List of AVOptionRange structs.
Definition: opt.h:328
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:751
#define av_free(p)
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS
Serialize options that are not set to default values only.
Definition: opt.h:838
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:87
enum AVOptionType type
Definition: opt.h:260
int len
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:1471
int64_t i64
Definition: opt.h:266
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition: opt.h:289
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:1011
#define av_uninit(x)
Definition: attributes.h:148
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:333
#define av_freep(p)
static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:344
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:70
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
Serialize options that exactly match opt_flags only.
Definition: opt.h:839
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:1601
static const char *const const_names[]
Definition: eval.c:34
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2291
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:2279
#define INFINITY
Definition: mathematics.h:67
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition: opt.c:676
#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
float min
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
Definition: opt.c:603
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:449
static int is_key_char(char c)
Definition: opt.c:1435
GLuint buffer
Definition: opengl_enc.c:102
simple arithmetic expression evaluator
const char * name
Definition: opengl_enc.c:103
int nb_components
Number of componentes.
Definition: opt.h:367
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
Definition: opt.c:915
static uint8_t tmp[11]
Definition: aes_ctr.c:26