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