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  *intnum = o->default_val.i64;
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 get_pix_fmt(const char *name)
448 {
449  return av_get_pix_fmt(name);
450 }
451 
452 static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
453 {
454  return set_string_fmt(obj, o, val, dst,
455  AV_PIX_FMT_NB, get_pix_fmt, "pixel format");
456 }
457 
458 static int get_sample_fmt(const char *name)
459 {
460  return av_get_sample_fmt(name);
461 }
462 
463 static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
464 {
465  return set_string_fmt(obj, o, val, dst,
466  AV_SAMPLE_FMT_NB, get_sample_fmt, "sample format");
467 }
468 
469 static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
470 {
472 
473  if (val) {
474  int ret = av_dict_parse_string(&options, val, "=", ":", 0);
475  if (ret < 0) {
477  return ret;
478  }
479  }
480 
481  av_dict_free((AVDictionary **)dst);
482  *dst = (uint8_t *)options;
483 
484  return 0;
485 }
486 
487 static int set_string_channel_layout(void *obj, const AVOption *o,
488  const char *val, void *dst)
489 {
490  AVChannelLayout *channel_layout = dst;
491  av_channel_layout_uninit(channel_layout);
492  if (!val)
493  return 0;
494  return av_channel_layout_from_string(channel_layout, val);
495 }
496 
497 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
498 {
499  int ret = 0;
500  void *dst, *target_obj;
501  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
502  if (!o || !target_obj)
505  if (!val && (o->type != AV_OPT_TYPE_STRING &&
511 #endif
512  o->type != AV_OPT_TYPE_BOOL))
513  return AVERROR(EINVAL);
515 
516  if (o->flags & AV_OPT_FLAG_READONLY)
517  return AVERROR(EINVAL);
518 
519  if (o->flags & AV_OPT_FLAG_DEPRECATED)
520  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
521 
522  dst = ((uint8_t *)target_obj) + o->offset;
523  switch (o->type) {
524  case AV_OPT_TYPE_BOOL:
525  return set_string_bool(obj, o, val, dst);
526  case AV_OPT_TYPE_STRING:
527  return set_string(obj, o, val, dst);
528  case AV_OPT_TYPE_BINARY:
529  return set_string_binary(obj, o, val, dst);
530  case AV_OPT_TYPE_FLAGS:
531  case AV_OPT_TYPE_INT:
532  case AV_OPT_TYPE_INT64:
533  case AV_OPT_TYPE_UINT64:
534  case AV_OPT_TYPE_FLOAT:
535  case AV_OPT_TYPE_DOUBLE:
537  return set_string_number(obj, target_obj, o, val, dst);
539  return set_string_image_size(obj, o, val, dst);
540  case AV_OPT_TYPE_VIDEO_RATE: {
541  AVRational tmp;
542  ret = set_string_video_rate(obj, o, val, &tmp);
543  if (ret < 0)
544  return ret;
545  return write_number(obj, o, dst, 1, tmp.den, tmp.num);
546  }
548  return set_string_pixel_fmt(obj, o, val, dst);
550  return set_string_sample_fmt(obj, o, val, dst);
552  {
553  int64_t usecs = 0;
554  if (val) {
555  if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
556  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
557  return ret;
558  }
559  }
560  if (usecs < o->min || usecs > o->max) {
561  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
562  usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
563  return AVERROR(ERANGE);
564  }
565  *(int64_t *)dst = usecs;
566  return 0;
567  }
568  case AV_OPT_TYPE_COLOR:
569  return set_string_color(obj, o, val, dst);
570 #if FF_API_OLD_CHANNEL_LAYOUT
573  if (!val || !strcmp(val, "none")) {
574  *(int64_t *)dst = 0;
575  } else {
576  int64_t cl = av_get_channel_layout(val);
577  if (!cl) {
578  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
579  ret = AVERROR(EINVAL);
580  }
581  *(int64_t *)dst = cl;
582  return ret;
583  }
584  break;
586 #endif
588  ret = set_string_channel_layout(obj, o, val, dst);
589  if (ret < 0) {
590  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as channel layout\n", val);
591  ret = AVERROR(EINVAL);
592  }
593  return ret;
594  case AV_OPT_TYPE_DICT:
595  return set_string_dict(obj, o, val, dst);
596  }
597 
598  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
599  return AVERROR(EINVAL);
600 }
601 
602 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
603 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
604  const char *val, vartype *name ## _out) \
605 { \
606  if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
607  return AVERROR(EINVAL); \
608  return set_string_number(obj, obj, o, val, name ## _out); \
609 }
610 
613 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
614 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
615 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
617 
618 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
619  int search_flags)
620 {
621  void *dst, *target_obj;
622  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
623 
624  if (!o || !target_obj)
626 
627  if (o->flags & AV_OPT_FLAG_READONLY)
628  return AVERROR(EINVAL);
629 
630  dst = ((uint8_t *)target_obj) + o->offset;
631  return write_number(obj, o, dst, num, den, intnum);
632 }
633 
634 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
635 {
636  return set_number(obj, name, 1, 1, val, search_flags);
637 }
638 
639 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
640 {
641  return set_number(obj, name, val, 1, 1, search_flags);
642 }
643 
644 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
645 {
646  return set_number(obj, name, val.num, val.den, 1, search_flags);
647 }
648 
649 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
650 {
651  void *target_obj;
652  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
653  uint8_t *ptr;
654  uint8_t **dst;
655  int *lendst;
656 
657  if (!o || !target_obj)
659 
661  return AVERROR(EINVAL);
662 
663  ptr = len ? av_malloc(len) : NULL;
664  if (len && !ptr)
665  return AVERROR(ENOMEM);
666 
667  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
668  lendst = (int *)(dst + 1);
669 
670  av_free(*dst);
671  *dst = ptr;
672  *lendst = len;
673  if (len)
674  memcpy(ptr, val, len);
675 
676  return 0;
677 }
678 
679 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
680 {
681  void *target_obj;
682  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
683 
684  if (!o || !target_obj)
686  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
687  av_log(obj, AV_LOG_ERROR,
688  "The value set by option '%s' is not an image size.\n", o->name);
689  return AVERROR(EINVAL);
690  }
691  if (w<0 || h<0) {
692  av_log(obj, AV_LOG_ERROR,
693  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
694  return AVERROR(EINVAL);
695  }
696  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
697  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
698  return 0;
699 }
700 
701 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
702 {
703  void *target_obj;
704  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
705 
706  if (!o || !target_obj)
708  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
709  av_log(obj, AV_LOG_ERROR,
710  "The value set by option '%s' is not a video rate.\n", o->name);
711  return AVERROR(EINVAL);
712  }
713  if (val.num <= 0 || val.den <= 0)
714  return AVERROR(EINVAL);
715  return set_number(obj, name, val.num, val.den, 1, search_flags);
716 }
717 
718 static int set_format(void *obj, const char *name, int fmt, int search_flags,
719  enum AVOptionType type, const char *desc, int nb_fmts)
720 {
721  void *target_obj;
722  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
723  search_flags, &target_obj);
724  int min, max;
725 
726  if (!o || !target_obj)
728  if (o->type != type) {
729  av_log(obj, AV_LOG_ERROR,
730  "The value set by option '%s' is not a %s format", name, desc);
731  return AVERROR(EINVAL);
732  }
733 
734  min = FFMAX(o->min, -1);
735  max = FFMIN(o->max, nb_fmts-1);
736 
737  if (fmt < min || fmt > max) {
738  av_log(obj, AV_LOG_ERROR,
739  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
740  fmt, name, desc, min, max);
741  return AVERROR(ERANGE);
742  }
743  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
744  return 0;
745 }
746 
747 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
748 {
749  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
750 }
751 
752 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
753 {
754  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
755 }
756 
757 #if FF_API_OLD_CHANNEL_LAYOUT
759 int av_opt_set_channel_layout(void *obj, const char *name, int64_t cl, int search_flags)
760 {
761  void *target_obj;
762  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
763 
764  if (!o || !target_obj)
766  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
767  av_log(obj, AV_LOG_ERROR,
768  "The value set by option '%s' is not a channel layout.\n", o->name);
769  return AVERROR(EINVAL);
770  }
771  *(int64_t *)(((uint8_t *)target_obj) + o->offset) = cl;
772  return 0;
773 }
775 #endif
776 
777 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
778  int search_flags)
779 {
780  void *target_obj;
781  AVDictionary **dst;
782  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
783 
784  if (!o || !target_obj)
786  if (o->flags & AV_OPT_FLAG_READONLY)
787  return AVERROR(EINVAL);
788 
789  dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
790  av_dict_free(dst);
791  av_dict_copy(dst, val, 0);
792 
793  return 0;
794 }
795 
796 int av_opt_set_chlayout(void *obj, const char *name,
797  const AVChannelLayout *channel_layout,
798  int search_flags)
799 {
800  void *target_obj;
801  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
802  AVChannelLayout *dst;
803 
804  if (!o || !target_obj)
806 
807  dst = (AVChannelLayout*)((uint8_t*)target_obj + o->offset);
808 
809  return av_channel_layout_copy(dst, channel_layout);
810 }
811 
812 static void format_duration(char *buf, size_t size, int64_t d)
813 {
814  char *e;
815 
816  av_assert0(size >= 25);
817  if (d < 0 && d != INT64_MIN) {
818  *(buf++) = '-';
819  size--;
820  d = -d;
821  }
822  if (d == INT64_MAX)
823  snprintf(buf, size, "INT64_MAX");
824  else if (d == INT64_MIN)
825  snprintf(buf, size, "INT64_MIN");
826  else if (d > (int64_t)3600*1000000)
827  snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
828  (int)((d / 60000000) % 60),
829  (int)((d / 1000000) % 60),
830  (int)(d % 1000000));
831  else if (d > 60*1000000)
832  snprintf(buf, size, "%d:%02d.%06d",
833  (int)(d / 60000000),
834  (int)((d / 1000000) % 60),
835  (int)(d % 1000000));
836  else
837  snprintf(buf, size, "%d.%06d",
838  (int)(d / 1000000),
839  (int)(d % 1000000));
840  e = buf + strlen(buf);
841  while (e > buf && e[-1] == '0')
842  *(--e) = 0;
843  if (e > buf && e[-1] == '.')
844  *(--e) = 0;
845 }
846 
847 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
848 {
849  void *dst, *target_obj;
850  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
851  uint8_t *bin, buf[128];
852  int len, i, ret;
853  int64_t i64;
854 
855  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
857 
858  if (o->flags & AV_OPT_FLAG_DEPRECATED)
859  av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
860 
861  dst = (uint8_t *)target_obj + o->offset;
862 
863  buf[0] = 0;
864  switch (o->type) {
865  case AV_OPT_TYPE_BOOL:
866  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(get_bool_name(*(int *)dst), "invalid"));
867  break;
868  case AV_OPT_TYPE_FLAGS:
869  ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
870  break;
871  case AV_OPT_TYPE_INT:
872  ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
873  break;
874  case AV_OPT_TYPE_INT64:
875  ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
876  break;
877  case AV_OPT_TYPE_UINT64:
878  ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
879  break;
880  case AV_OPT_TYPE_FLOAT:
881  ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
882  break;
883  case AV_OPT_TYPE_DOUBLE:
884  ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
885  break;
888  ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
889  break;
890  case AV_OPT_TYPE_CONST:
891  ret = snprintf(buf, sizeof(buf), "%"PRId64, o->default_val.i64);
892  break;
893  case AV_OPT_TYPE_STRING:
894  if (*(uint8_t **)dst) {
895  *out_val = av_strdup(*(uint8_t **)dst);
896  } else if (search_flags & AV_OPT_ALLOW_NULL) {
897  *out_val = NULL;
898  return 0;
899  } else {
900  *out_val = av_strdup("");
901  }
902  return *out_val ? 0 : AVERROR(ENOMEM);
903  case AV_OPT_TYPE_BINARY:
904  if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
905  *out_val = NULL;
906  return 0;
907  }
908  len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
909  if ((uint64_t)len * 2 + 1 > INT_MAX)
910  return AVERROR(EINVAL);
911  if (!(*out_val = av_malloc(len * 2 + 1)))
912  return AVERROR(ENOMEM);
913  if (!len) {
914  *out_val[0] = '\0';
915  return 0;
916  }
917  bin = *(uint8_t **)dst;
918  for (i = 0; i < len; i++)
919  snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
920  return 0;
922  ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
923  break;
925  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
926  break;
928  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
929  break;
931  i64 = *(int64_t *)dst;
932  format_duration(buf, sizeof(buf), i64);
933  ret = strlen(buf); // no overflow possible, checked by an assert
934  break;
935  case AV_OPT_TYPE_COLOR:
936  ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
937  (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
938  (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
939  break;
940 #if FF_API_OLD_CHANNEL_LAYOUT
943 
944  i64 = *(int64_t *)dst;
945  ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
946  break;
948 #endif
950  ret = av_channel_layout_describe(dst, buf, sizeof(buf));
951  break;
952  case AV_OPT_TYPE_DICT:
953  if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
954  *out_val = NULL;
955  return 0;
956  }
957  return av_dict_get_string(*(AVDictionary **)dst, (char **)out_val, '=', ':');
958  default:
959  return AVERROR(EINVAL);
960  }
961 
962  if (ret >= sizeof(buf))
963  return AVERROR(EINVAL);
964  *out_val = av_strdup(buf);
965  return *out_val ? 0 : AVERROR(ENOMEM);
966 }
967 
968 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
969  int search_flags)
970 {
971  void *dst, *target_obj;
972  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
973  if (!o || !target_obj)
974  goto error;
975 
976  dst = ((uint8_t *)target_obj) + o->offset;
977 
978  if (o_out) *o_out= o;
979 
980  return read_number(o, dst, num, den, intnum);
981 
982 error:
983  *den =
984  *intnum = 0;
985  return -1;
986 }
987 
988 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
989 {
990  int64_t intnum = 1;
991  double num = 1;
992  int ret, den = 1;
993 
994  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
995  return ret;
996  if (num == den)
997  *out_val = intnum;
998  else
999  *out_val = num * intnum / den;
1000  return 0;
1001 }
1002 
1003 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
1004 {
1005  int64_t intnum = 1;
1006  double num = 1;
1007  int ret, den = 1;
1008 
1009  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1010  return ret;
1011  *out_val = num * intnum / den;
1012  return 0;
1013 }
1014 
1015 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1016 {
1017  int64_t intnum = 1;
1018  double num = 1;
1019  int ret, den = 1;
1020 
1021  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1022  return ret;
1023 
1024  if (num == 1.0 && (int)intnum == intnum)
1025  *out_val = (AVRational){intnum, den};
1026  else
1027  *out_val = av_d2q(num*intnum/den, 1<<24);
1028  return 0;
1029 }
1030 
1031 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1032 {
1033  void *dst, *target_obj;
1034  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1035  if (!o || !target_obj)
1036  return AVERROR_OPTION_NOT_FOUND;
1037  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1038  av_log(obj, AV_LOG_ERROR,
1039  "The value for option '%s' is not an image size.\n", name);
1040  return AVERROR(EINVAL);
1041  }
1042 
1043  dst = ((uint8_t*)target_obj) + o->offset;
1044  if (w_out) *w_out = *(int *)dst;
1045  if (h_out) *h_out = *((int *)dst+1);
1046  return 0;
1047 }
1048 
1049 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1050 {
1051  int64_t intnum = 1;
1052  double num = 1;
1053  int ret, den = 1;
1054 
1055  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
1056  return ret;
1057 
1058  if (num == 1.0 && (int)intnum == intnum)
1059  *out_val = (AVRational) { intnum, den };
1060  else
1061  *out_val = av_d2q(num * intnum / den, 1 << 24);
1062  return 0;
1063 }
1064 
1065 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
1066  enum AVOptionType type, const char *desc)
1067 {
1068  void *dst, *target_obj;
1069  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1070  if (!o || !target_obj)
1071  return AVERROR_OPTION_NOT_FOUND;
1072  if (o->type != type) {
1073  av_log(obj, AV_LOG_ERROR,
1074  "The value for option '%s' is not a %s format.\n", desc, name);
1075  return AVERROR(EINVAL);
1076  }
1077 
1078  dst = ((uint8_t*)target_obj) + o->offset;
1079  *out_fmt = *(int *)dst;
1080  return 0;
1081 }
1082 
1083 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1084 {
1085  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1086 }
1087 
1088 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1089 {
1090  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1091 }
1092 
1093 #if FF_API_OLD_CHANNEL_LAYOUT
1095 int av_opt_get_channel_layout(void *obj, const char *name, int search_flags, int64_t *cl)
1096 {
1097  void *dst, *target_obj;
1098  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1099  if (!o || !target_obj)
1100  return AVERROR_OPTION_NOT_FOUND;
1101  if (o->type != AV_OPT_TYPE_CHANNEL_LAYOUT) {
1102  av_log(obj, AV_LOG_ERROR,
1103  "The value for option '%s' is not a channel layout.\n", name);
1104  return AVERROR(EINVAL);
1105  }
1106 
1107  dst = ((uint8_t*)target_obj) + o->offset;
1108  *cl = *(int64_t *)dst;
1109  return 0;
1110 }
1112 #endif
1113 
1114 int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1115 {
1116  void *dst, *target_obj;
1117  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1118  if (!o || !target_obj)
1119  return AVERROR_OPTION_NOT_FOUND;
1120  if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1121  av_log(obj, AV_LOG_ERROR,
1122  "The value for option '%s' is not a channel layout.\n", name);
1123  return AVERROR(EINVAL);
1124  }
1125 
1126  dst = ((uint8_t*)target_obj) + o->offset;
1127  return av_channel_layout_copy(cl, dst);
1128 }
1129 
1130 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1131 {
1132  void *target_obj;
1133  AVDictionary *src;
1134  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1135 
1136  if (!o || !target_obj)
1137  return AVERROR_OPTION_NOT_FOUND;
1138  if (o->type != AV_OPT_TYPE_DICT)
1139  return AVERROR(EINVAL);
1140 
1141  src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1142  av_dict_copy(out_val, src, 0);
1143 
1144  return 0;
1145 }
1146 
1147 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1148 {
1149  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1150  const AVOption *flag = av_opt_find(obj, flag_name,
1151  field ? field->unit : NULL, 0, 0);
1152  int64_t res;
1153 
1154  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1155  av_opt_get_int(obj, field_name, 0, &res) < 0)
1156  return 0;
1157  return res & flag->default_val.i64;
1158 }
1159 
1160 static void log_int_value(void *av_log_obj, int level, int64_t i)
1161 {
1162  if (i == INT_MAX) {
1163  av_log(av_log_obj, level, "INT_MAX");
1164  } else if (i == INT_MIN) {
1165  av_log(av_log_obj, level, "INT_MIN");
1166  } else if (i == UINT32_MAX) {
1167  av_log(av_log_obj, level, "UINT32_MAX");
1168  } else if (i == INT64_MAX) {
1169  av_log(av_log_obj, level, "I64_MAX");
1170  } else if (i == INT64_MIN) {
1171  av_log(av_log_obj, level, "I64_MIN");
1172  } else {
1173  av_log(av_log_obj, level, "%"PRId64, i);
1174  }
1175 }
1176 
1177 static void log_value(void *av_log_obj, int level, double d)
1178 {
1179  if (d == INT_MAX) {
1180  av_log(av_log_obj, level, "INT_MAX");
1181  } else if (d == INT_MIN) {
1182  av_log(av_log_obj, level, "INT_MIN");
1183  } else if (d == UINT32_MAX) {
1184  av_log(av_log_obj, level, "UINT32_MAX");
1185  } else if (d == (double)INT64_MAX) {
1186  av_log(av_log_obj, level, "I64_MAX");
1187  } else if (d == INT64_MIN) {
1188  av_log(av_log_obj, level, "I64_MIN");
1189  } else if (d == FLT_MAX) {
1190  av_log(av_log_obj, level, "FLT_MAX");
1191  } else if (d == FLT_MIN) {
1192  av_log(av_log_obj, level, "FLT_MIN");
1193  } else if (d == -FLT_MAX) {
1194  av_log(av_log_obj, level, "-FLT_MAX");
1195  } else if (d == -FLT_MIN) {
1196  av_log(av_log_obj, level, "-FLT_MIN");
1197  } else if (d == DBL_MAX) {
1198  av_log(av_log_obj, level, "DBL_MAX");
1199  } else if (d == DBL_MIN) {
1200  av_log(av_log_obj, level, "DBL_MIN");
1201  } else if (d == -DBL_MAX) {
1202  av_log(av_log_obj, level, "-DBL_MAX");
1203  } else if (d == -DBL_MIN) {
1204  av_log(av_log_obj, level, "-DBL_MIN");
1205  } else {
1206  av_log(av_log_obj, level, "%g", d);
1207  }
1208 }
1209 
1210 static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1211 {
1212  const AVOption *opt = NULL;
1213 
1214  if (!unit)
1215  return NULL;
1216  while ((opt = av_opt_next(obj, opt)))
1217  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1218  opt->default_val.i64 == value)
1219  return opt->name;
1220  return NULL;
1221 }
1222 
1223 static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1224 {
1225  const AVOption *opt = NULL;
1226  char flags[512];
1227 
1228  flags[0] = 0;
1229  if (!unit)
1230  return NULL;
1231  while ((opt = av_opt_next(obj, opt))) {
1232  if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1233  opt->default_val.i64 & value) {
1234  if (flags[0])
1235  av_strlcatf(flags, sizeof(flags), "+");
1236  av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1237  }
1238  }
1239  if (flags[0])
1240  return av_strdup(flags);
1241  return NULL;
1242 }
1243 
1244 static void opt_list(void *obj, void *av_log_obj, const char *unit,
1245  int req_flags, int rej_flags, enum AVOptionType parent_type)
1246 {
1247  const AVOption *opt = NULL;
1248  AVOptionRanges *r;
1249  int i;
1250 
1251  while ((opt = av_opt_next(obj, opt))) {
1252  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1253  continue;
1254 
1255  /* Don't print CONST's on level one.
1256  * Don't print anything but CONST's on level two.
1257  * Only print items from the requested unit.
1258  */
1259  if (!unit && opt->type == AV_OPT_TYPE_CONST)
1260  continue;
1261  else if (unit && opt->type != AV_OPT_TYPE_CONST)
1262  continue;
1263  else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1264  continue;
1265  else if (unit && opt->type == AV_OPT_TYPE_CONST)
1266  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1267  else
1268  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1269  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1270  opt->name);
1271 
1272  switch (opt->type) {
1273  case AV_OPT_TYPE_FLAGS:
1274  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
1275  break;
1276  case AV_OPT_TYPE_INT:
1277  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
1278  break;
1279  case AV_OPT_TYPE_INT64:
1280  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
1281  break;
1282  case AV_OPT_TYPE_UINT64:
1283  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<uint64>");
1284  break;
1285  case AV_OPT_TYPE_DOUBLE:
1286  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
1287  break;
1288  case AV_OPT_TYPE_FLOAT:
1289  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
1290  break;
1291  case AV_OPT_TYPE_STRING:
1292  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
1293  break;
1294  case AV_OPT_TYPE_RATIONAL:
1295  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
1296  break;
1297  case AV_OPT_TYPE_BINARY:
1298  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
1299  break;
1300  case AV_OPT_TYPE_DICT:
1301  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<dictionary>");
1302  break;
1304  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
1305  break;
1307  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
1308  break;
1309  case AV_OPT_TYPE_PIXEL_FMT:
1310  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
1311  break;
1313  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
1314  break;
1315  case AV_OPT_TYPE_DURATION:
1316  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
1317  break;
1318  case AV_OPT_TYPE_COLOR:
1319  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<color>");
1320  break;
1321  case AV_OPT_TYPE_CHLAYOUT:
1322 #if FF_API_OLD_CHANNEL_LAYOUT
1326 #endif
1327  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<channel_layout>");
1328  break;
1329  case AV_OPT_TYPE_BOOL:
1330  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<boolean>");
1331  break;
1332  case AV_OPT_TYPE_CONST:
1333  if (parent_type == AV_OPT_TYPE_INT)
1334  av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", opt->default_val.i64);
1335  else
1336  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1337  break;
1338  default:
1339  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1340  break;
1341  }
1342  av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1343  (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1344  (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1345  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1346  (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1347  (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1348  (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1349  (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1350  (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1351  (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1352  (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1353  (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1354 
1355  if (opt->help)
1356  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1357 
1358  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1359  switch (opt->type) {
1360  case AV_OPT_TYPE_INT:
1361  case AV_OPT_TYPE_INT64:
1362  case AV_OPT_TYPE_UINT64:
1363  case AV_OPT_TYPE_DOUBLE:
1364  case AV_OPT_TYPE_FLOAT:
1365  case AV_OPT_TYPE_RATIONAL:
1366  for (i = 0; i < r->nb_ranges; i++) {
1367  av_log(av_log_obj, AV_LOG_INFO, " (from ");
1368  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1369  av_log(av_log_obj, AV_LOG_INFO, " to ");
1370  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1371  av_log(av_log_obj, AV_LOG_INFO, ")");
1372  }
1373  break;
1374  }
1376  }
1377 
1378  if (opt->type != AV_OPT_TYPE_CONST &&
1379  opt->type != AV_OPT_TYPE_BINARY &&
1380  !((opt->type == AV_OPT_TYPE_COLOR ||
1381  opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1382  opt->type == AV_OPT_TYPE_STRING ||
1383  opt->type == AV_OPT_TYPE_DICT ||
1384  opt->type == AV_OPT_TYPE_CHLAYOUT ||
1385  opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1386  !opt->default_val.str)) {
1387  av_log(av_log_obj, AV_LOG_INFO, " (default ");
1388  switch (opt->type) {
1389  case AV_OPT_TYPE_BOOL:
1390  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(get_bool_name(opt->default_val.i64), "invalid"));
1391  break;
1392  case AV_OPT_TYPE_FLAGS: {
1393  char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1394  if (def_flags) {
1395  av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1396  av_freep(&def_flags);
1397  } else {
1398  av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1399  }
1400  break;
1401  }
1402  case AV_OPT_TYPE_DURATION: {
1403  char buf[25];
1404  format_duration(buf, sizeof(buf), opt->default_val.i64);
1405  av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1406  break;
1407  }
1408  case AV_OPT_TYPE_INT:
1409  case AV_OPT_TYPE_UINT64:
1410  case AV_OPT_TYPE_INT64: {
1411  const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1412  if (def_const)
1413  av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1414  else
1415  log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1416  break;
1417  }
1418  case AV_OPT_TYPE_DOUBLE:
1419  case AV_OPT_TYPE_FLOAT:
1420  log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1421  break;
1422  case AV_OPT_TYPE_RATIONAL: {
1423  AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1424  av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1425  break;
1426  case AV_OPT_TYPE_PIXEL_FMT:
1427  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1428  break;
1430  av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1431  break;
1432  case AV_OPT_TYPE_COLOR:
1434  case AV_OPT_TYPE_STRING:
1435  case AV_OPT_TYPE_DICT:
1437  case AV_OPT_TYPE_CHLAYOUT:
1438  av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1439  break;
1440 #if FF_API_OLD_CHANNEL_LAYOUT
1443  av_log(av_log_obj, AV_LOG_INFO, "0x%"PRIx64, opt->default_val.i64);
1444  break;
1446 #endif
1447  }
1448  av_log(av_log_obj, AV_LOG_INFO, ")");
1449  }
1450 
1451  av_log(av_log_obj, AV_LOG_INFO, "\n");
1452  if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1453  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1454  }
1455 }
1456 
1457 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1458 {
1459  if (!obj)
1460  return -1;
1461 
1462  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1463 
1464  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1465 
1466  return 0;
1467 }
1468 
1470 {
1471  av_opt_set_defaults2(s, 0, 0);
1472 }
1473 
1474 void av_opt_set_defaults2(void *s, int mask, int flags)
1475 {
1476  const AVOption *opt = NULL;
1477  while ((opt = av_opt_next(s, opt))) {
1478  void *dst = ((uint8_t*)s) + opt->offset;
1479 
1480  if ((opt->flags & mask) != flags)
1481  continue;
1482 
1483  if (opt->flags & AV_OPT_FLAG_READONLY)
1484  continue;
1485 
1486  switch (opt->type) {
1487  case AV_OPT_TYPE_CONST:
1488  /* Nothing to be done here */
1489  break;
1490  case AV_OPT_TYPE_BOOL:
1491  case AV_OPT_TYPE_FLAGS:
1492  case AV_OPT_TYPE_INT:
1493  case AV_OPT_TYPE_INT64:
1494  case AV_OPT_TYPE_UINT64:
1495  case AV_OPT_TYPE_DURATION:
1496 #if FF_API_OLD_CHANNEL_LAYOUT
1500 #endif
1501  case AV_OPT_TYPE_PIXEL_FMT:
1503  write_number(s, opt, dst, 1, 1, opt->default_val.i64);
1504  break;
1505  case AV_OPT_TYPE_DOUBLE:
1506  case AV_OPT_TYPE_FLOAT: {
1507  double val;
1508  val = opt->default_val.dbl;
1509  write_number(s, opt, dst, val, 1, 1);
1510  }
1511  break;
1512  case AV_OPT_TYPE_RATIONAL: {
1513  AVRational val;
1514  val = av_d2q(opt->default_val.dbl, INT_MAX);
1515  write_number(s, opt, dst, 1, val.den, val.num);
1516  }
1517  break;
1518  case AV_OPT_TYPE_COLOR:
1519  set_string_color(s, opt, opt->default_val.str, dst);
1520  break;
1521  case AV_OPT_TYPE_STRING:
1522  set_string(s, opt, opt->default_val.str, dst);
1523  break;
1525  set_string_image_size(s, opt, opt->default_val.str, dst);
1526  break;
1528  set_string_video_rate(s, opt, opt->default_val.str, dst);
1529  break;
1530  case AV_OPT_TYPE_BINARY:
1531  set_string_binary(s, opt, opt->default_val.str, dst);
1532  break;
1533  case AV_OPT_TYPE_CHLAYOUT:
1534  set_string_channel_layout(s, opt, opt->default_val.str, dst);
1535  break;
1536  case AV_OPT_TYPE_DICT:
1537  set_string_dict(s, opt, opt->default_val.str, dst);
1538  break;
1539  default:
1540  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1541  opt->type, opt->name);
1542  }
1543  }
1544 }
1545 
1546 /**
1547  * Store the value in the field in ctx that is named like key.
1548  * ctx must be an AVClass context, storing is done using AVOptions.
1549  *
1550  * @param buf the string to parse, buf will be updated to point at the
1551  * separator just after the parsed key/value pair
1552  * @param key_val_sep a 0-terminated list of characters used to
1553  * separate key from value
1554  * @param pairs_sep a 0-terminated list of characters used to separate
1555  * two pairs from each other
1556  * @return 0 if the key/value pair has been successfully parsed and
1557  * set, or a negative value corresponding to an AVERROR code in case
1558  * of error:
1559  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1560  * the error code issued by av_opt_set() if the key/value pair
1561  * cannot be set
1562  */
1563 static int parse_key_value_pair(void *ctx, const char **buf,
1564  const char *key_val_sep, const char *pairs_sep)
1565 {
1566  char *key = av_get_token(buf, key_val_sep);
1567  char *val;
1568  int ret;
1569 
1570  if (!key)
1571  return AVERROR(ENOMEM);
1572 
1573  if (*key && strspn(*buf, key_val_sep)) {
1574  (*buf)++;
1575  val = av_get_token(buf, pairs_sep);
1576  if (!val) {
1577  av_freep(&key);
1578  return AVERROR(ENOMEM);
1579  }
1580  } else {
1581  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1582  av_free(key);
1583  return AVERROR(EINVAL);
1584  }
1585 
1586  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1587 
1590  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1591 
1592  av_free(key);
1593  av_free(val);
1594  return ret;
1595 }
1596 
1597 int av_set_options_string(void *ctx, const char *opts,
1598  const char *key_val_sep, const char *pairs_sep)
1599 {
1600  int ret, count = 0;
1601 
1602  if (!opts)
1603  return 0;
1604 
1605  while (*opts) {
1606  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1607  return ret;
1608  count++;
1609 
1610  if (*opts)
1611  opts++;
1612  }
1613 
1614  return count;
1615 }
1616 
1617 #define WHITESPACES " \n\t\r"
1618 
1619 static int is_key_char(char c)
1620 {
1621  return (unsigned)((c | 32) - 'a') < 26 ||
1622  (unsigned)(c - '0') < 10 ||
1623  c == '-' || c == '_' || c == '/' || c == '.';
1624 }
1625 
1626 /**
1627  * Read a key from a string.
1628  *
1629  * The key consists of is_key_char characters and must be terminated by a
1630  * character from the delim string; spaces are ignored.
1631  *
1632  * @return 0 for success (even with ellipsis), <0 for failure
1633  */
1634 static int get_key(const char **ropts, const char *delim, char **rkey)
1635 {
1636  const char *opts = *ropts;
1637  const char *key_start, *key_end;
1638 
1639  key_start = opts += strspn(opts, WHITESPACES);
1640  while (is_key_char(*opts))
1641  opts++;
1642  key_end = opts;
1643  opts += strspn(opts, WHITESPACES);
1644  if (!*opts || !strchr(delim, *opts))
1645  return AVERROR(EINVAL);
1646  opts++;
1647  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1648  return AVERROR(ENOMEM);
1649  memcpy(*rkey, key_start, key_end - key_start);
1650  (*rkey)[key_end - key_start] = 0;
1651  *ropts = opts;
1652  return 0;
1653 }
1654 
1655 int av_opt_get_key_value(const char **ropts,
1656  const char *key_val_sep, const char *pairs_sep,
1657  unsigned flags,
1658  char **rkey, char **rval)
1659 {
1660  int ret;
1661  char *key = NULL, *val;
1662  const char *opts = *ropts;
1663 
1664  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1666  return AVERROR(EINVAL);
1667  if (!(val = av_get_token(&opts, pairs_sep))) {
1668  av_free(key);
1669  return AVERROR(ENOMEM);
1670  }
1671  *ropts = opts;
1672  *rkey = key;
1673  *rval = val;
1674  return 0;
1675 }
1676 
1677 int av_opt_set_from_string(void *ctx, const char *opts,
1678  const char *const *shorthand,
1679  const char *key_val_sep, const char *pairs_sep)
1680 {
1681  int ret, count = 0;
1682  const char *dummy_shorthand = NULL;
1683  char *av_uninit(parsed_key), *av_uninit(value);
1684  const char *key;
1685 
1686  if (!opts)
1687  return 0;
1688  if (!shorthand)
1689  shorthand = &dummy_shorthand;
1690 
1691  while (*opts) {
1692  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1693  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1694  &parsed_key, &value);
1695  if (ret < 0) {
1696  if (ret == AVERROR(EINVAL))
1697  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1698  else
1699  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1700  av_err2str(ret));
1701  return ret;
1702  }
1703  if (*opts)
1704  opts++;
1705  if (parsed_key) {
1706  key = parsed_key;
1707  while (*shorthand) /* discard all remaining shorthand */
1708  shorthand++;
1709  } else {
1710  key = *(shorthand++);
1711  }
1712 
1713  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1714  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1716  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1717  av_free(value);
1718  av_free(parsed_key);
1719  return ret;
1720  }
1721 
1722  av_free(value);
1723  av_free(parsed_key);
1724  count++;
1725  }
1726  return count;
1727 }
1728 
1729 void av_opt_free(void *obj)
1730 {
1731  const AVOption *o = NULL;
1732  while ((o = av_opt_next(obj, o))) {
1733  switch (o->type) {
1734  case AV_OPT_TYPE_STRING:
1735  case AV_OPT_TYPE_BINARY:
1736  av_freep((uint8_t *)obj + o->offset);
1737  break;
1738 
1739  case AV_OPT_TYPE_DICT:
1740  av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
1741  break;
1742 
1743  case AV_OPT_TYPE_CHLAYOUT:
1744  av_channel_layout_uninit((AVChannelLayout *)(((uint8_t *)obj) + o->offset));
1745  break;
1746 
1747  default:
1748  break;
1749  }
1750  }
1751 }
1752 
1753 int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
1754 {
1755  const AVDictionaryEntry *t = NULL;
1756  AVDictionary *tmp = NULL;
1757  int ret;
1758 
1759  if (!options)
1760  return 0;
1761 
1762  while ((t = av_dict_iterate(*options, t))) {
1763  ret = av_opt_set(obj, t->key, t->value, search_flags);
1766  if (ret < 0) {
1767  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1768  av_dict_free(&tmp);
1769  return ret;
1770  }
1771  }
1773  *options = tmp;
1774  return 0;
1775 }
1776 
1778 {
1779  return av_opt_set_dict2(obj, options, 0);
1780 }
1781 
1782 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1783  int opt_flags, int search_flags)
1784 {
1785  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1786 }
1787 
1788 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1789  int opt_flags, int search_flags, void **target_obj)
1790 {
1791  const AVClass *c;
1792  const AVOption *o = NULL;
1793 
1794  if(!obj)
1795  return NULL;
1796 
1797  c= *(AVClass**)obj;
1798 
1799  if (!c)
1800  return NULL;
1801 
1802  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1803  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1804  void *iter = NULL;
1805  const AVClass *child;
1806  while (child = av_opt_child_class_iterate(c, &iter))
1807  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1808  return o;
1809  } else {
1810  void *child = NULL;
1811  while (child = av_opt_child_next(obj, child))
1812  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1813  return o;
1814  }
1815  }
1816 
1817  while (o = av_opt_next(obj, o)) {
1818  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1819  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1820  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1821  if (target_obj) {
1822  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1823  *target_obj = obj;
1824  else
1825  *target_obj = NULL;
1826  }
1827  return o;
1828  }
1829  }
1830  return NULL;
1831 }
1832 
1833 void *av_opt_child_next(void *obj, void *prev)
1834 {
1835  const AVClass *c = *(AVClass **)obj;
1836  if (c->child_next)
1837  return c->child_next(obj, prev);
1838  return NULL;
1839 }
1840 
1841 const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
1842 {
1843  if (parent->child_class_iterate)
1844  return parent->child_class_iterate(iter);
1845  return NULL;
1846 }
1847 
1848 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
1849 {
1850  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
1851  if(!opt)
1852  return NULL;
1853  return (uint8_t*)obj + opt->offset;
1854 }
1855 
1856 static int opt_size(enum AVOptionType type)
1857 {
1858  switch(type) {
1859  case AV_OPT_TYPE_BOOL:
1860  case AV_OPT_TYPE_INT:
1861  case AV_OPT_TYPE_FLAGS:
1862  return sizeof(int);
1863  case AV_OPT_TYPE_DURATION:
1864 #if FF_API_OLD_CHANNEL_LAYOUT
1868 #endif
1869  case AV_OPT_TYPE_INT64:
1870  case AV_OPT_TYPE_UINT64:
1871  return sizeof(int64_t);
1872  case AV_OPT_TYPE_DOUBLE:
1873  return sizeof(double);
1874  case AV_OPT_TYPE_FLOAT:
1875  return sizeof(float);
1876  case AV_OPT_TYPE_STRING:
1877  return sizeof(uint8_t*);
1879  case AV_OPT_TYPE_RATIONAL:
1880  return sizeof(AVRational);
1881  case AV_OPT_TYPE_BINARY:
1882  return sizeof(uint8_t*) + sizeof(int);
1884  return sizeof(int[2]);
1885  case AV_OPT_TYPE_PIXEL_FMT:
1886  return sizeof(enum AVPixelFormat);
1888  return sizeof(enum AVSampleFormat);
1889  case AV_OPT_TYPE_COLOR:
1890  return 4;
1891  }
1892  return AVERROR(EINVAL);
1893 }
1894 
1895 int av_opt_copy(void *dst, const void *src)
1896 {
1897  const AVOption *o = NULL;
1898  const AVClass *c;
1899  int ret = 0;
1900 
1901  if (!src)
1902  return AVERROR(EINVAL);
1903 
1904  c = *(AVClass **)src;
1905  if (!c || c != *(AVClass **)dst)
1906  return AVERROR(EINVAL);
1907 
1908  while ((o = av_opt_next(src, o))) {
1909  void *field_dst = (uint8_t *)dst + o->offset;
1910  void *field_src = (uint8_t *)src + o->offset;
1911  uint8_t **field_dst8 = (uint8_t **)field_dst;
1912  uint8_t **field_src8 = (uint8_t **)field_src;
1913 
1914  if (o->type == AV_OPT_TYPE_STRING) {
1915  if (*field_dst8 != *field_src8)
1916  av_freep(field_dst8);
1917  *field_dst8 = av_strdup(*field_src8);
1918  if (*field_src8 && !*field_dst8)
1919  ret = AVERROR(ENOMEM);
1920  } else if (o->type == AV_OPT_TYPE_BINARY) {
1921  int len = *(int *)(field_src8 + 1);
1922  if (*field_dst8 != *field_src8)
1923  av_freep(field_dst8);
1924  *field_dst8 = av_memdup(*field_src8, len);
1925  if (len && !*field_dst8) {
1926  ret = AVERROR(ENOMEM);
1927  len = 0;
1928  }
1929  *(int *)(field_dst8 + 1) = len;
1930  } else if (o->type == AV_OPT_TYPE_CONST) {
1931  // do nothing
1932  } else if (o->type == AV_OPT_TYPE_DICT) {
1933  AVDictionary **sdict = (AVDictionary **) field_src;
1934  AVDictionary **ddict = (AVDictionary **) field_dst;
1935  int ret2;
1936  if (*sdict != *ddict)
1937  av_dict_free(ddict);
1938  *ddict = NULL;
1939  ret2 = av_dict_copy(ddict, *sdict, 0);
1940  if (ret2 < 0)
1941  ret = ret2;
1942  } else if (o->type == AV_OPT_TYPE_CHLAYOUT) {
1943  if (field_dst != field_src)
1944  ret = av_channel_layout_copy(field_dst, field_src);
1945  } else {
1946  int size = opt_size(o->type);
1947  if (size < 0)
1948  ret = size;
1949  else
1950  memcpy(field_dst, field_src, size);
1951  }
1952  }
1953  return ret;
1954 }
1955 
1956 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1957 {
1958  int ret;
1959  const AVClass *c = *(AVClass**)obj;
1960  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
1961 
1962  if (!callback)
1964 
1965  ret = callback(ranges_arg, obj, key, flags);
1966  if (ret >= 0) {
1968  ret = 1;
1969  (*ranges_arg)->nb_components = ret;
1970  }
1971  return ret;
1972 }
1973 
1974 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1975 {
1976  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
1977  AVOptionRange **range_array = av_mallocz(sizeof(void*));
1978  AVOptionRange *range = av_mallocz(sizeof(*range));
1979  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
1980  int ret;
1981 
1982  *ranges_arg = NULL;
1983 
1984  if (!ranges || !range || !range_array || !field) {
1985  ret = AVERROR(ENOMEM);
1986  goto fail;
1987  }
1988 
1989  ranges->range = range_array;
1990  ranges->range[0] = range;
1991  ranges->nb_ranges = 1;
1992  ranges->nb_components = 1;
1993  range->is_range = 1;
1994  range->value_min = field->min;
1995  range->value_max = field->max;
1996 
1997  switch (field->type) {
1998  case AV_OPT_TYPE_BOOL:
1999  case AV_OPT_TYPE_INT:
2000  case AV_OPT_TYPE_INT64:
2001  case AV_OPT_TYPE_UINT64:
2002  case AV_OPT_TYPE_PIXEL_FMT:
2004  case AV_OPT_TYPE_FLOAT:
2005  case AV_OPT_TYPE_DOUBLE:
2006  case AV_OPT_TYPE_DURATION:
2007  case AV_OPT_TYPE_COLOR:
2008 #if FF_API_OLD_CHANNEL_LAYOUT
2012 #endif
2013  break;
2014  case AV_OPT_TYPE_STRING:
2015  range->component_min = 0;
2016  range->component_max = 0x10FFFF; // max unicode value
2017  range->value_min = -1;
2018  range->value_max = INT_MAX;
2019  break;
2020  case AV_OPT_TYPE_RATIONAL:
2021  range->component_min = INT_MIN;
2022  range->component_max = INT_MAX;
2023  break;
2025  range->component_min = 0;
2026  range->component_max = INT_MAX/128/8;
2027  range->value_min = 0;
2028  range->value_max = INT_MAX/8;
2029  break;
2031  range->component_min = 1;
2032  range->component_max = INT_MAX;
2033  range->value_min = 1;
2034  range->value_max = INT_MAX;
2035  break;
2036  default:
2037  ret = AVERROR(ENOSYS);
2038  goto fail;
2039  }
2040 
2041  *ranges_arg = ranges;
2042  return 1;
2043 fail:
2044  av_free(ranges);
2045  av_free(range);
2046  av_free(range_array);
2047  return ret;
2048 }
2049 
2051 {
2052  int i;
2053  AVOptionRanges *ranges = *rangesp;
2054 
2055  if (!ranges)
2056  return;
2057 
2058  for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
2059  AVOptionRange *range = ranges->range[i];
2060  if (range) {
2061  av_freep(&range->str);
2062  av_freep(&ranges->range[i]);
2063  }
2064  }
2065  av_freep(&ranges->range);
2066  av_freep(rangesp);
2067 }
2068 
2069 int av_opt_is_set_to_default(void *obj, const AVOption *o)
2070 {
2071  int64_t i64;
2072  double d, d2;
2073  float f;
2074  AVRational q;
2075  int ret, w, h;
2076  char *str;
2077  void *dst;
2078 
2079  if (!o || !obj)
2080  return AVERROR(EINVAL);
2081 
2082  dst = ((uint8_t*)obj) + o->offset;
2083 
2084  switch (o->type) {
2085  case AV_OPT_TYPE_CONST:
2086  return 1;
2087  case AV_OPT_TYPE_BOOL:
2088  case AV_OPT_TYPE_FLAGS:
2089  case AV_OPT_TYPE_PIXEL_FMT:
2091  case AV_OPT_TYPE_INT:
2092 #if FF_API_OLD_CHANNEL_LAYOUT
2096 #endif
2097  case AV_OPT_TYPE_DURATION:
2098  case AV_OPT_TYPE_INT64:
2099  case AV_OPT_TYPE_UINT64:
2100  read_number(o, dst, NULL, NULL, &i64);
2101  return o->default_val.i64 == i64;
2102  case AV_OPT_TYPE_CHLAYOUT: {
2103  AVChannelLayout ch_layout = { 0 };
2104  if (o->default_val.str) {
2105  if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
2106  return ret;
2107  }
2108  return !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout);
2109  }
2110  case AV_OPT_TYPE_STRING:
2111  str = *(char **)dst;
2112  if (str == o->default_val.str) //2 NULLs
2113  return 1;
2114  if (!str || !o->default_val.str) //1 NULL
2115  return 0;
2116  return !strcmp(str, o->default_val.str);
2117  case AV_OPT_TYPE_DOUBLE:
2118  read_number(o, dst, &d, NULL, NULL);
2119  return o->default_val.dbl == d;
2120  case AV_OPT_TYPE_FLOAT:
2121  read_number(o, dst, &d, NULL, NULL);
2122  f = o->default_val.dbl;
2123  d2 = f;
2124  return d2 == d;
2125  case AV_OPT_TYPE_RATIONAL:
2126  q = av_d2q(o->default_val.dbl, INT_MAX);
2127  return !av_cmp_q(*(AVRational*)dst, q);
2128  case AV_OPT_TYPE_BINARY: {
2129  struct {
2130  uint8_t *data;
2131  int size;
2132  } tmp = {0};
2133  int opt_size = *(int *)((void **)dst + 1);
2134  void *opt_ptr = *(void **)dst;
2135  if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
2136  return 1;
2137  if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
2138  return 0;
2139  if (opt_size != strlen(o->default_val.str) / 2)
2140  return 0;
2141  ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
2142  if (!ret)
2143  ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2144  av_free(tmp.data);
2145  return ret;
2146  }
2147  case AV_OPT_TYPE_DICT: {
2148  AVDictionary *dict1 = NULL;
2149  AVDictionary *dict2 = *(AVDictionary **)dst;
2150  const AVDictionaryEntry *en1 = NULL;
2151  const AVDictionaryEntry *en2 = NULL;
2152  ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2153  if (ret < 0) {
2154  av_dict_free(&dict1);
2155  return ret;
2156  }
2157  do {
2158  en1 = av_dict_iterate(dict1, en1);
2159  en2 = av_dict_iterate(dict2, en2);
2160  } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2161  av_dict_free(&dict1);
2162  return (!en1 && !en2);
2163  }
2165  if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2166  w = h = 0;
2167  else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2168  return ret;
2169  return (w == *(int *)dst) && (h == *((int *)dst+1));
2171  q = (AVRational){0, 0};
2172  if (o->default_val.str) {
2173  if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2174  return ret;
2175  }
2176  return !av_cmp_q(*(AVRational*)dst, q);
2177  case AV_OPT_TYPE_COLOR: {
2178  uint8_t color[4] = {0, 0, 0, 0};
2179  if (o->default_val.str) {
2180  if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2181  return ret;
2182  }
2183  return !memcmp(color, dst, sizeof(color));
2184  }
2185  default:
2186  av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2187  break;
2188  }
2189  return AVERROR_PATCHWELCOME;
2190 }
2191 
2192 int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2193 {
2194  const AVOption *o;
2195  void *target;
2196  if (!obj)
2197  return AVERROR(EINVAL);
2198  o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2199  if (!o)
2200  return AVERROR_OPTION_NOT_FOUND;
2201  return av_opt_is_set_to_default(target, o);
2202 }
2203 
2204 int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2205  const char key_val_sep, const char pairs_sep)
2206 {
2207  const AVOption *o = NULL;
2208  uint8_t *buf;
2209  AVBPrint bprint;
2210  int ret, cnt = 0;
2211  const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2212 
2213  if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2214  pairs_sep == '\\' || key_val_sep == '\\') {
2215  av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2216  return AVERROR(EINVAL);
2217  }
2218 
2219  if (!obj || !buffer)
2220  return AVERROR(EINVAL);
2221 
2222  *buffer = NULL;
2224 
2225  while (o = av_opt_next(obj, o)) {
2226  if (o->type == AV_OPT_TYPE_CONST)
2227  continue;
2228  if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2229  continue;
2230  else if (((o->flags & opt_flags) != opt_flags))
2231  continue;
2233  continue;
2234  if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2235  av_bprint_finalize(&bprint, NULL);
2236  return ret;
2237  }
2238  if (buf) {
2239  if (cnt++)
2240  av_bprint_append_data(&bprint, &pairs_sep, 1);
2241  av_bprint_escape(&bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2242  av_bprint_append_data(&bprint, &key_val_sep, 1);
2243  av_bprint_escape(&bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2244  av_freep(&buf);
2245  }
2246  }
2247  ret = av_bprint_finalize(&bprint, buffer);
2248  if (ret < 0)
2249  return ret;
2250  return 0;
2251 }
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
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:602
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:1130
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
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:679
AVOption::default_val
union AVOption::@368 default_val
the default value for scalar options
AVOption::i64
int64_t i64
Definition: opt.h:271
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
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:1160
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:118
r
const char * r
Definition: vf_curves.c:126
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
get_pix_fmt
static int get_pix_fmt(const char *name)
Definition: opt.c:447
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:1469
color
Definition: vf_paletteuse.c:511
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
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:463
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:1848
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
get_opt_const_name
static const char * get_opt_const_name(void *obj, const char *unit, int64_t value)
Definition: opt.c:1210
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:2192
av_opt_set_double
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:639
AVOption
AVOption.
Definition: opt.h:251
is_key_char
static int is_key_char(char c)
Definition: opt.c:1619
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:487
data
const char data[16]
Definition: mxf.c:148
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_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:2069
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:34
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:103
const_values
static const double const_values[]
Definition: eval.c:28
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
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:446
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
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:1597
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:179
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
AVERROR_OPTION_NOT_FOUND
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:63
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
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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:497
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:759
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_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:1777
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:847
class
#define class
Definition: math.h:25
float
float
Definition: af_crystalizer.c:121
s
#define s(width, name)
Definition: cbs_vp9.c:198
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:90
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:227
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:777
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:747
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:40
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:1617
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:115
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:1083
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:1782
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:1049
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:701
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:649
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
AV_DICT_MULTIKEY
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition: dict.h:84
log_value
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:1177
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:268
av_opt_get_double
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition: opt.c:1003
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:718
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:1677
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
parseutils.h
av_opt_get_sample_fmt
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition: opt.c:1088
set_number
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:618
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1729
double
double
Definition: af_crystalizer.c:131
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:1244
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:249
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:988
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:634
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
options
const OptionDef options[]
eval.h
f
f
Definition: af_crystalizer.c:121
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:804
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:240
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:313
av_opt_set_chlayout
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition: opt.c:796
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:968
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:111
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:1563
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:1474
AVOption::name
const char * name
Definition: opt.h:252
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
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:1788
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:1753
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:225
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
get_sample_fmt
static int get_sample_fmt(const char *name)
Definition: opt.c:458
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:1003
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:466
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
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:434
bprint.h
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
set_string_pixel_fmt
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition: opt.c:452
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:1223
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:318
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:254
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:1634
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:1856
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:1655
dict.h
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:469
av_get_pix_fmt
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:2900
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:1841
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
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
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:143
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:662
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:345
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:202
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:1114
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:2204
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:669
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:1147
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
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:1974
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:1956
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
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:2050
av_opt_copy
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition: opt.c:1895
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:89
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:88
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:252
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:239
format_duration
static void format_duration(char *buf, size_t size, int64_t d)
Definition: opt.c:812
AV_ESCAPE_MODE_BACKSLASH
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Definition: avstring.h:316
d
d
Definition: ffmpeg_filter.c:424
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:224
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
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:847
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:91
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:1031
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:644
int
int
Definition: ffmpeg_filter.c:424
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:752
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:1457
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:163
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_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
av_opt_child_next
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition: opt.c:1833
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:1095
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:312
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:1065
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:2888
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:1015