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