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