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 "avstring.h"
30 #include "common.h"
31 #include "opt.h"
32 #include "eval.h"
33 #include "dict.h"
34 #include "log.h"
35 #include "parseutils.h"
36 #include "pixdesc.h"
37 #include "mathematics.h"
38 #include "samplefmt.h"
39 
40 #include <float.h>
41 
42 #if FF_API_FIND_OPT
43 //FIXME order them and do a bin search
44 const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
45 {
46  const AVOption *o = NULL;
47 
48  while ((o = av_next_option(v, o))) {
49  if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags)
50  return o;
51  }
52  return NULL;
53 }
54 #endif
55 
56 #if FF_API_OLD_AVOPTIONS
57 const AVOption *av_next_option(void *obj, const AVOption *last)
58 {
59  return av_opt_next(obj, last);
60 }
61 #endif
62 
63 const AVOption *av_opt_next(void *obj, const AVOption *last)
64 {
65  AVClass *class = *(AVClass**)obj;
66  if (!last && class->option && class->option[0].name)
67  return class->option;
68  if (last && last[1].name)
69  return ++last;
70  return NULL;
71 }
72 
73 static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
74 {
75  switch (o->type) {
76  case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0;
79  case AV_OPT_TYPE_INT: *intnum = *(int *)dst;return 0;
81  case AV_OPT_TYPE_INT64: *intnum = *(int64_t *)dst;return 0;
82  case AV_OPT_TYPE_FLOAT: *num = *(float *)dst;return 0;
83  case AV_OPT_TYPE_DOUBLE: *num = *(double *)dst;return 0;
84  case AV_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num;
85  *den = ((AVRational*)dst)->den;
86  return 0;
87  case AV_OPT_TYPE_CONST: *num = o->default_val.dbl; return 0;
88  }
89  return AVERROR(EINVAL);
90 }
91 
92 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
93 {
94  if (o->max*den < num*intnum || o->min*den > num*intnum) {
95  av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
96  num*intnum/den, o->name, o->min, o->max);
97  return AVERROR(ERANGE);
98  }
99 
100  switch (o->type) {
101  case AV_OPT_TYPE_FLAGS:
104  case AV_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
106  case AV_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break;
107  case AV_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
108  case AV_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
110  if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
111  else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
112  break;
113  default:
114  return AVERROR(EINVAL);
115  }
116  return 0;
117 }
118 
119 static const double const_values[] = {
120  M_PI,
121  M_E,
122  FF_QP2LAMBDA,
123  0
124 };
125 
126 static const char * const const_names[] = {
127  "PI",
128  "E",
129  "QP2LAMBDA",
130  0
131 };
132 
133 static int hexchar2int(char c) {
134  if (c >= '0' && c <= '9') return c - '0';
135  if (c >= 'a' && c <= 'f') return c - 'a' + 10;
136  if (c >= 'A' && c <= 'F') return c - 'A' + 10;
137  return -1;
138 }
139 
140 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
141 {
142  int *lendst = (int *)(dst + 1);
143  uint8_t *bin, *ptr;
144  int len = strlen(val);
145 
146  av_freep(dst);
147  *lendst = 0;
148 
149  if (len & 1)
150  return AVERROR(EINVAL);
151  len /= 2;
152 
153  ptr = bin = av_malloc(len);
154  while (*val) {
155  int a = hexchar2int(*val++);
156  int b = hexchar2int(*val++);
157  if (a < 0 || b < 0) {
158  av_free(bin);
159  return AVERROR(EINVAL);
160  }
161  *ptr++ = (a << 4) | b;
162  }
163  *dst = bin;
164  *lendst = len;
165 
166  return 0;
167 }
168 
169 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
170 {
171  av_freep(dst);
172  *dst = av_strdup(val);
173  return 0;
174 }
175 
176 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
177  opt->type == AV_OPT_TYPE_CONST || \
178  opt->type == AV_OPT_TYPE_FLAGS || \
179  opt->type == AV_OPT_TYPE_INT) ? \
180  opt->default_val.i64 : opt->default_val.dbl)
181 
182 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
183 {
184  int ret = 0, notfirst = 0;
185  for (;;) {
186  int i, den = 1;
187  char buf[256];
188  int cmd = 0;
189  double d, num = 1;
190  int64_t intnum = 1;
191 
192  i = 0;
193  if (*val == '+' || *val == '-') {
194  if (o->type == AV_OPT_TYPE_FLAGS)
195  cmd = *(val++);
196  else if (!notfirst)
197  buf[i++] = *val;
198  }
199 
200  for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
201  buf[i] = val[i];
202  buf[i] = 0;
203 
204  {
205  const AVOption *o_named = av_opt_find(target_obj, buf, o->unit, 0, 0);
206  if (o_named && o_named->type == AV_OPT_TYPE_CONST)
207  d = DEFAULT_NUMVAL(o_named);
208  else if (!strcmp(buf, "default")) d = DEFAULT_NUMVAL(o);
209  else if (!strcmp(buf, "max" )) d = o->max;
210  else if (!strcmp(buf, "min" )) d = o->min;
211  else if (!strcmp(buf, "none" )) d = 0;
212  else if (!strcmp(buf, "all" )) d = ~0;
213  else {
214  int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
215  if (res < 0) {
216  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
217  return res;
218  }
219  }
220  }
221  if (o->type == AV_OPT_TYPE_FLAGS) {
222  read_number(o, dst, NULL, NULL, &intnum);
223  if (cmd == '+') d = intnum | (int64_t)d;
224  else if (cmd == '-') d = intnum &~(int64_t)d;
225  } else {
226  read_number(o, dst, &num, &den, &intnum);
227  if (cmd == '+') d = notfirst*num*intnum/den + d;
228  else if (cmd == '-') d = notfirst*num*intnum/den - d;
229  }
230 
231  if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
232  return ret;
233  val += i;
234  if (!*val)
235  return 0;
236  notfirst = 1;
237  }
238 
239  return 0;
240 }
241 
242 #if FF_API_OLD_AVOPTIONS
243 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
244 {
245  const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
246  if (o_out)
247  *o_out = o;
248  return av_opt_set(obj, name, val, 0);
249 }
250 #endif
251 
252 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
253 {
254  int ret;
255  void *dst, *target_obj;
256  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
257  if (!o || !target_obj)
259  if (!val && (o->type != AV_OPT_TYPE_STRING &&
262  o->type != AV_OPT_TYPE_DURATION))
263  return AVERROR(EINVAL);
264 
265  dst = ((uint8_t*)target_obj) + o->offset;
266  switch (o->type) {
267  case AV_OPT_TYPE_STRING: return set_string(obj, o, val, dst);
268  case AV_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst);
269  case AV_OPT_TYPE_FLAGS:
270  case AV_OPT_TYPE_INT:
271  case AV_OPT_TYPE_INT64:
272  case AV_OPT_TYPE_FLOAT:
273  case AV_OPT_TYPE_DOUBLE:
274  case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, target_obj, o, val, dst);
276  if (!val || !strcmp(val, "none")) {
277  *(int *)dst = *((int *)dst + 1) = 0;
278  return 0;
279  }
280  ret = av_parse_video_size(dst, ((int *)dst) + 1, val);
281  if (ret < 0)
282  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as image size\n", val);
283  return ret;
285  if (!val) {
286  ret = AVERROR(EINVAL);
287  } else {
288  ret = av_parse_video_rate(dst, val);
289  }
290  if (ret < 0)
291  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as video rate\n", val);
292  return ret;
294  if (!val || !strcmp(val, "none")) {
295  ret = AV_PIX_FMT_NONE;
296  } else {
297  ret = av_get_pix_fmt(val);
298  if (ret == AV_PIX_FMT_NONE) {
299  char *tail;
300  ret = strtol(val, &tail, 0);
301  if (*tail || (unsigned)ret >= AV_PIX_FMT_NB) {
302  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as pixel format\n", val);
303  return AVERROR(EINVAL);
304  }
305  }
306  }
307  *(enum AVPixelFormat *)dst = ret;
308  return 0;
310  if (!val || !strcmp(val, "none")) {
311  ret = AV_SAMPLE_FMT_NONE;
312  } else {
313  ret = av_get_sample_fmt(val);
314  if (ret == AV_SAMPLE_FMT_NONE) {
315  char *tail;
316  ret = strtol(val, &tail, 0);
317  if (*tail || (unsigned)ret >= AV_SAMPLE_FMT_NB) {
318  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as sample format\n", val);
319  return AVERROR(EINVAL);
320  }
321  }
322  }
323  *(enum AVSampleFormat *)dst = ret;
324  return 0;
326  if (!val) {
327  *(int64_t *)dst = 0;
328  return 0;
329  } else {
330  if ((ret = av_parse_time(dst, val, 1)) < 0)
331  av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\" as duration\n", val);
332  return ret;
333  }
334  }
335 
336  av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
337  return AVERROR(EINVAL);
338 }
339 
340 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
341  int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
342  {\
343  if (!o || o->type != opttype)\
344  return AVERROR(EINVAL);\
345  return set_string_number(obj, obj, o, val, name ## _out);\
346  }
347 
350 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
351 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
352 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
354 
355 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
356  int search_flags)
357 {
358  void *dst, *target_obj;
359  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
360 
361  if (!o || !target_obj)
363 
364  dst = ((uint8_t*)target_obj) + o->offset;
365  return write_number(obj, o, dst, num, den, intnum);
366 }
367 
368 #if FF_API_OLD_AVOPTIONS
369 const AVOption *av_set_double(void *obj, const char *name, double n)
370 {
371  const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
372  if (set_number(obj, name, n, 1, 1, 0) < 0)
373  return NULL;
374  return o;
375 }
376 
377 const AVOption *av_set_q(void *obj, const char *name, AVRational n)
378 {
379  const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
380  if (set_number(obj, name, n.num, n.den, 1, 0) < 0)
381  return NULL;
382  return o;
383 }
384 
385 const AVOption *av_set_int(void *obj, const char *name, int64_t n)
386 {
387  const AVOption *o = av_opt_find(obj, name, NULL, 0, 0);
388  if (set_number(obj, name, 1, 1, n, 0) < 0)
389  return NULL;
390  return o;
391 }
392 #endif
393 
394 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
395 {
396  return set_number(obj, name, 1, 1, val, search_flags);
397 }
398 
399 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
400 {
401  return set_number(obj, name, val, 1, 1, search_flags);
402 }
403 
404 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
405 {
406  return set_number(obj, name, val.num, val.den, 1, search_flags);
407 }
408 
409 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
410 {
411  void *target_obj;
412  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
413  uint8_t *ptr;
414  uint8_t **dst;
415  int *lendst;
416 
417  if (!o || !target_obj)
419 
420  if (o->type != AV_OPT_TYPE_BINARY)
421  return AVERROR(EINVAL);
422 
423  ptr = len ? av_malloc(len) : NULL;
424  if (len && !ptr)
425  return AVERROR(ENOMEM);
426 
427  dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
428  lendst = (int *)(dst + 1);
429 
430  av_free(*dst);
431  *dst = ptr;
432  *lendst = len;
433  if (len)
434  memcpy(ptr, val, len);
435 
436  return 0;
437 }
438 
439 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
440 {
441  void *target_obj;
442  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
443 
444  if (!o || !target_obj)
446  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
447  av_log(obj, AV_LOG_ERROR,
448  "The value set by option '%s' is not an image size.\n", o->name);
449  return AVERROR(EINVAL);
450  }
451  if (w<0 || h<0) {
452  av_log(obj, AV_LOG_ERROR,
453  "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
454  return AVERROR(EINVAL);
455  }
456  *(int *)(((uint8_t *)target_obj) + o->offset) = w;
457  *(int *)(((uint8_t *)target_obj+sizeof(int)) + o->offset) = h;
458  return 0;
459 }
460 
461 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
462 {
463  void *target_obj;
464  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
465 
466  if (!o || !target_obj)
468  if (o->type != AV_OPT_TYPE_VIDEO_RATE) {
469  av_log(obj, AV_LOG_ERROR,
470  "The value set by option '%s' is not a video rate.\n", o->name);
471  return AVERROR(EINVAL);
472  }
473  if (val.num <= 0 || val.den <= 0)
474  return AVERROR(EINVAL);
475  return set_number(obj, name, val.num, val.den, 1, search_flags);
476 }
477 
478 static int set_format(void *obj, const char *name, int fmt, int search_flags,
479  enum AVOptionType type, const char *desc, int nb_fmts)
480 {
481  void *target_obj;
482  const AVOption *o = av_opt_find2(obj, name, NULL, 0,
483  search_flags, &target_obj);
484  int min, max;
485  const AVClass *class = *(AVClass **)obj;
486 
487  if (!o || !target_obj)
489  if (o->type != type) {
490  av_log(obj, AV_LOG_ERROR,
491  "The value set by option '%s' is not a %s format", name, desc);
492  return AVERROR(EINVAL);
493  }
494 
495 #if LIBAVUTIL_VERSION_MAJOR < 53
496  if (class->version && class->version < AV_VERSION_INT(52, 11, 100)) {
497  min = -1;
498  max = nb_fmts-1;
499  } else
500 #endif
501  {
502  min = FFMIN(o->min, -1);
503  max = FFMAX(o->max, nb_fmts-1);
504  }
505  if (fmt < min || fmt > max) {
506  av_log(obj, AV_LOG_ERROR,
507  "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
508  fmt, name, desc, min, max);
509  return AVERROR(ERANGE);
510  }
511  *(int *)(((uint8_t *)target_obj) + o->offset) = fmt;
512  return 0;
513 }
514 
515 int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
516 {
517  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
518 }
519 
520 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
521 {
522  return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
523 }
524 
525 #if FF_API_OLD_AVOPTIONS
526 /**
527  *
528  * @param buf a buffer which is used for returning non string values as strings, can be NULL
529  * @param buf_len allocated length in bytes of buf
530  */
531 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
532 {
533  const AVOption *o = av_opt_find(obj, name, NULL, 0, AV_OPT_SEARCH_CHILDREN);
534  void *dst;
535  uint8_t *bin;
536  int len, i;
537  if (!o)
538  return NULL;
539  if (o->type != AV_OPT_TYPE_STRING && (!buf || !buf_len))
540  return NULL;
541 
542  dst= ((uint8_t*)obj) + o->offset;
543  if (o_out) *o_out= o;
544 
545  switch (o->type) {
546  case AV_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
547  case AV_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
548  case AV_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
549  case AV_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
550  case AV_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
551  case AV_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
552  case AV_OPT_TYPE_CONST: snprintf(buf, buf_len, "%f" , o->default_val.dbl);break;
553  case AV_OPT_TYPE_STRING: return *(void**)dst;
554  case AV_OPT_TYPE_BINARY:
555  len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
556  if (len >= (buf_len + 1)/2) return NULL;
557  bin = *(uint8_t**)dst;
558  for (i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]);
559  break;
560  default: return NULL;
561  }
562  return buf;
563 }
564 #endif
565 
566 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
567 {
568  void *dst, *target_obj;
569  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
570  uint8_t *bin, buf[128];
571  int len, i, ret;
572  int64_t i64;
573 
574  if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
576 
577  dst = (uint8_t*)target_obj + o->offset;
578 
579  buf[0] = 0;
580  switch (o->type) {
581  case AV_OPT_TYPE_FLAGS: ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);break;
582  case AV_OPT_TYPE_INT: ret = snprintf(buf, sizeof(buf), "%d" , *(int *)dst);break;
583  case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
584  case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break;
585  case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break;
587  case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
588  case AV_OPT_TYPE_CONST: ret = snprintf(buf, sizeof(buf), "%f" , o->default_val.dbl);break;
589  case AV_OPT_TYPE_STRING:
590  if (*(uint8_t**)dst)
591  *out_val = av_strdup(*(uint8_t**)dst);
592  else
593  *out_val = av_strdup("");
594  return 0;
595  case AV_OPT_TYPE_BINARY:
596  len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
597  if ((uint64_t)len*2 + 1 > INT_MAX)
598  return AVERROR(EINVAL);
599  if (!(*out_val = av_malloc(len*2 + 1)))
600  return AVERROR(ENOMEM);
601  bin = *(uint8_t**)dst;
602  for (i = 0; i < len; i++)
603  snprintf(*out_val + i*2, 3, "%02X", bin[i]);
604  return 0;
606  ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
607  break;
609  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
610  break;
612  ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
613  break;
615  i64 = *(int64_t *)dst;
616  ret = snprintf(buf, sizeof(buf), "%"PRIi64"d:%02d:%02d.%06d",
617  i64 / 3600000000, (int)((i64 / 60000000) % 60),
618  (int)((i64 / 1000000) % 60), (int)(i64 % 1000000));
619  break;
620  default:
621  return AVERROR(EINVAL);
622  }
623 
624  if (ret >= sizeof(buf))
625  return AVERROR(EINVAL);
626  *out_val = av_strdup(buf);
627  return 0;
628 }
629 
630 static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum,
631  int search_flags)
632 {
633  void *dst, *target_obj;
634  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
635  if (!o || !target_obj)
636  goto error;
637 
638  dst = ((uint8_t*)target_obj) + o->offset;
639 
640  if (o_out) *o_out= o;
641 
642  return read_number(o, dst, num, den, intnum);
643 
644 error:
645  *den=*intnum=0;
646  return -1;
647 }
648 
649 #if FF_API_OLD_AVOPTIONS
650 double av_get_double(void *obj, const char *name, const AVOption **o_out)
651 {
652  int64_t intnum=1;
653  double num=1;
654  int den=1;
655 
656  if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
657  return NAN;
658  return num*intnum/den;
659 }
660 
661 AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
662 {
663  int64_t intnum=1;
664  double num=1;
665  int den=1;
666 
667  if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
668  return (AVRational){0, 0};
669  if (num == 1.0 && (int)intnum == intnum)
670  return (AVRational){intnum, den};
671  else
672  return av_d2q(num*intnum/den, 1<<24);
673 }
674 
675 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
676 {
677  int64_t intnum=1;
678  double num=1;
679  int den=1;
680 
681  if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0)
682  return -1;
683  return num*intnum/den;
684 }
685 #endif
686 
687 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
688 {
689  int64_t intnum = 1;
690  double num = 1;
691  int ret, den = 1;
692 
693  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
694  return ret;
695  *out_val = num*intnum/den;
696  return 0;
697 }
698 
699 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
700 {
701  int64_t intnum = 1;
702  double num = 1;
703  int ret, den = 1;
704 
705  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
706  return ret;
707  *out_val = num*intnum/den;
708  return 0;
709 }
710 
711 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
712 {
713  int64_t intnum = 1;
714  double num = 1;
715  int ret, den = 1;
716 
717  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
718  return ret;
719 
720  if (num == 1.0 && (int)intnum == intnum)
721  *out_val = (AVRational){intnum, den};
722  else
723  *out_val = av_d2q(num*intnum/den, 1<<24);
724  return 0;
725 }
726 
727 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
728 {
729  void *dst, *target_obj;
730  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
731  if (!o || !target_obj)
733  if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
734  av_log(obj, AV_LOG_ERROR,
735  "The value for option '%s' is not an image size.\n", name);
736  return AVERROR(EINVAL);
737  }
738 
739  dst = ((uint8_t*)target_obj) + o->offset;
740  if (w_out) *w_out = *(int *)dst;
741  if (h_out) *h_out = *((int *)dst+1);
742  return 0;
743 }
744 
745 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
746 {
747  int64_t intnum = 1;
748  double num = 1;
749  int ret, den = 1;
750 
751  if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0)
752  return ret;
753 
754  if (num == 1.0 && (int)intnum == intnum)
755  *out_val = (AVRational){intnum, den};
756  else
757  *out_val = av_d2q(num*intnum/den, 1<<24);
758  return 0;
759 }
760 
761 static int get_format(void *obj, const char *name, int search_flags, int *out_fmt,
762  enum AVOptionType type, const char *desc)
763 {
764  void *dst, *target_obj;
765  const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
766  if (!o || !target_obj)
768  if (o->type != type) {
769  av_log(obj, AV_LOG_ERROR,
770  "The value for option '%s' is not a %s format.\n", desc, name);
771  return AVERROR(EINVAL);
772  }
773 
774  dst = ((uint8_t*)target_obj) + o->offset;
775  *out_fmt = *(int *)dst;
776  return 0;
777 }
778 
779 int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
780 {
781  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
782 }
783 
784 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
785 {
786  return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
787 }
788 
789 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
790 {
791  const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
792  const AVOption *flag = av_opt_find(obj, flag_name,
793  field ? field->unit : NULL, 0, 0);
794  int64_t res;
795 
796  if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
797  av_opt_get_int(obj, field_name, 0, &res) < 0)
798  return 0;
799  return res & flag->default_val.i64;
800 }
801 
802 static void log_value(void *av_log_obj, int level, double d)
803 {
804  if (d == INT_MAX) {
805  av_log(av_log_obj, level, "INT_MAX");
806  } else if (d == INT_MIN) {
807  av_log(av_log_obj, level, "INT_MIN");
808  } else if (d == (double)INT64_MAX) {
809  av_log(av_log_obj, level, "I64_MAX");
810  } else if (d == INT64_MIN) {
811  av_log(av_log_obj, level, "I64_MIN");
812  } else if (d == FLT_MAX) {
813  av_log(av_log_obj, level, "FLT_MAX");
814  } else if (d == FLT_MIN) {
815  av_log(av_log_obj, level, "FLT_MIN");
816  } else {
817  av_log(av_log_obj, level, "%g", d);
818  }
819 }
820 
821 static void opt_list(void *obj, void *av_log_obj, const char *unit,
822  int req_flags, int rej_flags)
823 {
824  const AVOption *opt=NULL;
825  AVOptionRanges *r;
826  int i;
827 
828  while ((opt = av_opt_next(obj, opt))) {
829  if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
830  continue;
831 
832  /* Don't print CONST's on level one.
833  * Don't print anything but CONST's on level two.
834  * Only print items from the requested unit.
835  */
836  if (!unit && opt->type==AV_OPT_TYPE_CONST)
837  continue;
838  else if (unit && opt->type!=AV_OPT_TYPE_CONST)
839  continue;
840  else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
841  continue;
842  else if (unit && opt->type == AV_OPT_TYPE_CONST)
843  av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
844  else
845  av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
846  (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? "" : "-",
847  opt->name);
848 
849  switch (opt->type) {
850  case AV_OPT_TYPE_FLAGS:
851  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<flags>");
852  break;
853  case AV_OPT_TYPE_INT:
854  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
855  break;
856  case AV_OPT_TYPE_INT64:
857  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
858  break;
859  case AV_OPT_TYPE_DOUBLE:
860  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<double>");
861  break;
862  case AV_OPT_TYPE_FLOAT:
863  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<float>");
864  break;
865  case AV_OPT_TYPE_STRING:
866  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<string>");
867  break;
869  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<rational>");
870  break;
871  case AV_OPT_TYPE_BINARY:
872  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<binary>");
873  break;
875  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<image_size>");
876  break;
878  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<video_rate>");
879  break;
881  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<pix_fmt>");
882  break;
884  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<sample_fmt>");
885  break;
887  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<duration>");
888  break;
889  case AV_OPT_TYPE_CONST:
890  default:
891  av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
892  break;
893  }
894  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
895  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
896  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_FILTERING_PARAM)? 'F' : '.');
897  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
898  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
899  av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
900 
901  if (opt->help)
902  av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
903 
904  if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
905  switch (opt->type) {
906  case AV_OPT_TYPE_INT:
907  case AV_OPT_TYPE_INT64:
908  case AV_OPT_TYPE_DOUBLE:
909  case AV_OPT_TYPE_FLOAT:
911  for (i = 0; i < r->nb_ranges; i++) {
912  av_log(av_log_obj, AV_LOG_INFO, " (from ");
913  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
914  av_log(av_log_obj, AV_LOG_INFO, " to ");
915  log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
916  av_log(av_log_obj, AV_LOG_INFO, ")");
917  }
918  break;
919  }
921  }
922 
923  av_log(av_log_obj, AV_LOG_INFO, "\n");
924  if (opt->unit && opt->type != AV_OPT_TYPE_CONST) {
925  opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
926  }
927  }
928 }
929 
930 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
931 {
932  if (!obj)
933  return -1;
934 
935  av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
936 
937  opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
938 
939  return 0;
940 }
941 
943 {
944 #if FF_API_OLD_AVOPTIONS
945  av_opt_set_defaults2(s, 0, 0);
946 }
947 
948 void av_opt_set_defaults2(void *s, int mask, int flags)
949 {
950 #endif
951  const AVClass *class = *(AVClass **)s;
952  const AVOption *opt = NULL;
953  while ((opt = av_opt_next(s, opt)) != NULL) {
954 #if FF_API_OLD_AVOPTIONS
955  if ((opt->flags & mask) != flags)
956  continue;
957 #endif
958  switch (opt->type) {
959  case AV_OPT_TYPE_CONST:
960  /* Nothing to be done here */
961  break;
962  case AV_OPT_TYPE_FLAGS:
963  case AV_OPT_TYPE_INT:
964  case AV_OPT_TYPE_INT64:
966  av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
967  break;
968  case AV_OPT_TYPE_DOUBLE:
969  case AV_OPT_TYPE_FLOAT: {
970  double val;
971  val = opt->default_val.dbl;
972  av_opt_set_double(s, opt->name, val, 0);
973  }
974  break;
975  case AV_OPT_TYPE_RATIONAL: {
976  AVRational val;
977  val = av_d2q(opt->default_val.dbl, INT_MAX);
978  av_opt_set_q(s, opt->name, val, 0);
979  }
980  break;
981  case AV_OPT_TYPE_STRING:
984  av_opt_set(s, opt->name, opt->default_val.str, 0);
985  break;
987 #if LIBAVUTIL_VERSION_MAJOR < 53
988  if (class->version && class->version < AV_VERSION_INT(52, 10, 100))
989  av_opt_set(s, opt->name, opt->default_val.str, 0);
990  else
991 #endif
992  av_opt_set_pixel_fmt(s, opt->name, opt->default_val.i64, 0);
993  break;
995 #if LIBAVUTIL_VERSION_MAJOR < 53
996  if (class->version && class->version < AV_VERSION_INT(52, 10, 100))
997  av_opt_set(s, opt->name, opt->default_val.str, 0);
998  else
999 #endif
1000  av_opt_set_sample_fmt(s, opt->name, opt->default_val.i64, 0);
1001  break;
1002  case AV_OPT_TYPE_BINARY:
1003  /* Cannot set default for binary */
1004  break;
1005  default:
1006  av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
1007  }
1008  }
1009 }
1010 
1011 /**
1012  * Store the value in the field in ctx that is named like key.
1013  * ctx must be an AVClass context, storing is done using AVOptions.
1014  *
1015  * @param buf the string to parse, buf will be updated to point at the
1016  * separator just after the parsed key/value pair
1017  * @param key_val_sep a 0-terminated list of characters used to
1018  * separate key from value
1019  * @param pairs_sep a 0-terminated list of characters used to separate
1020  * two pairs from each other
1021  * @return 0 if the key/value pair has been successfully parsed and
1022  * set, or a negative value corresponding to an AVERROR code in case
1023  * of error:
1024  * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1025  * the error code issued by av_opt_set() if the key/value pair
1026  * cannot be set
1027  */
1028 static int parse_key_value_pair(void *ctx, const char **buf,
1029  const char *key_val_sep, const char *pairs_sep)
1030 {
1031  char *key = av_get_token(buf, key_val_sep);
1032  char *val;
1033  int ret;
1034 
1035  if (!key)
1036  return AVERROR(ENOMEM);
1037 
1038  if (*key && strspn(*buf, key_val_sep)) {
1039  (*buf)++;
1040  val = av_get_token(buf, pairs_sep);
1041  if (!val) {
1042  av_freep(&key);
1043  return AVERROR(ENOMEM);
1044  }
1045  } else {
1046  av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1047  av_free(key);
1048  return AVERROR(EINVAL);
1049  }
1050 
1051  av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1052 
1053  ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN);
1054  if (ret == AVERROR_OPTION_NOT_FOUND)
1055  av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1056 
1057  av_free(key);
1058  av_free(val);
1059  return ret;
1060 }
1061 
1062 int av_set_options_string(void *ctx, const char *opts,
1063  const char *key_val_sep, const char *pairs_sep)
1064 {
1065  int ret, count = 0;
1066 
1067  if (!opts)
1068  return 0;
1069 
1070  while (*opts) {
1071  if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1072  return ret;
1073  count++;
1074 
1075  if (*opts)
1076  opts++;
1077  }
1078 
1079  return count;
1080 }
1081 
1082 #define WHITESPACES " \n\t"
1083 
1084 static int is_key_char(char c)
1085 {
1086  return (unsigned)((c | 32) - 'a') < 26 ||
1087  (unsigned)(c - '0') < 10 ||
1088  c == '-' || c == '_' || c == '/' || c == '.';
1089 }
1090 
1091 /**
1092  * Read a key from a string.
1093  *
1094  * The key consists of is_key_char characters and must be terminated by a
1095  * character from the delim string; spaces are ignored.
1096  *
1097  * @return 0 for success (even with ellipsis), <0 for failure
1098  */
1099 static int get_key(const char **ropts, const char *delim, char **rkey)
1100 {
1101  const char *opts = *ropts;
1102  const char *key_start, *key_end;
1103 
1104  key_start = opts += strspn(opts, WHITESPACES);
1105  while (is_key_char(*opts))
1106  opts++;
1107  key_end = opts;
1108  opts += strspn(opts, WHITESPACES);
1109  if (!*opts || !strchr(delim, *opts))
1110  return AVERROR(EINVAL);
1111  opts++;
1112  if (!(*rkey = av_malloc(key_end - key_start + 1)))
1113  return AVERROR(ENOMEM);
1114  memcpy(*rkey, key_start, key_end - key_start);
1115  (*rkey)[key_end - key_start] = 0;
1116  *ropts = opts;
1117  return 0;
1118 }
1119 
1120 int av_opt_get_key_value(const char **ropts,
1121  const char *key_val_sep, const char *pairs_sep,
1122  unsigned flags,
1123  char **rkey, char **rval)
1124 {
1125  int ret;
1126  char *key = NULL, *val;
1127  const char *opts = *ropts;
1128 
1129  if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1130  !(flags & AV_OPT_FLAG_IMPLICIT_KEY))
1131  return AVERROR(EINVAL);
1132  if (!(val = av_get_token(&opts, pairs_sep))) {
1133  av_free(key);
1134  return AVERROR(ENOMEM);
1135  }
1136  *ropts = opts;
1137  *rkey = key;
1138  *rval = val;
1139  return 0;
1140 }
1141 
1142 int av_opt_set_from_string(void *ctx, const char *opts,
1143  const char *const *shorthand,
1144  const char *key_val_sep, const char *pairs_sep)
1145 {
1146  int ret, count = 0;
1147  const char *dummy_shorthand = NULL;
1148  char *av_uninit(parsed_key), *av_uninit(value);
1149  const char *key;
1150 
1151  if (!opts)
1152  return 0;
1153  if (!shorthand)
1154  shorthand = &dummy_shorthand;
1155 
1156  while (*opts) {
1157  ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1158  *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1159  &parsed_key, &value);
1160  if (ret < 0) {
1161  if (ret == AVERROR(EINVAL))
1162  av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1163  else
1164  av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
1165  av_err2str(ret));
1166  return ret;
1167  }
1168  if (*opts)
1169  opts++;
1170  if (parsed_key) {
1171  key = parsed_key;
1172  while (*shorthand) /* discard all remaining shorthand */
1173  shorthand++;
1174  } else {
1175  key = *(shorthand++);
1176  }
1177 
1178  av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
1179  if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
1180  if (ret == AVERROR_OPTION_NOT_FOUND)
1181  av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
1182  av_free(value);
1183  av_free(parsed_key);
1184  return ret;
1185  }
1186 
1187  av_free(value);
1188  av_free(parsed_key);
1189  count++;
1190  }
1191  return count;
1192 }
1193 
1194 void av_opt_free(void *obj)
1195 {
1196  const AVOption *o = NULL;
1197  while ((o = av_opt_next(obj, o)))
1198  if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY)
1199  av_freep((uint8_t *)obj + o->offset);
1200 }
1201 
1203 {
1205  AVDictionary *tmp = NULL;
1206  int ret = 0;
1207 
1208  while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
1209  ret = av_opt_set(obj, t->key, t->value, 0);
1210  if (ret == AVERROR_OPTION_NOT_FOUND)
1211  av_dict_set(&tmp, t->key, t->value, 0);
1212  else if (ret < 0) {
1213  av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
1214  break;
1215  }
1216  ret = 0;
1217  }
1218  av_dict_free(options);
1219  *options = tmp;
1220  return ret;
1221 }
1222 
1223 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
1224  int opt_flags, int search_flags)
1225 {
1226  return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
1227 }
1228 
1229 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
1230  int opt_flags, int search_flags, void **target_obj)
1231 {
1232  const AVClass *c;
1233  const AVOption *o = NULL;
1234 
1235  if(!obj)
1236  return NULL;
1237 
1238  c= *(AVClass**)obj;
1239 
1240  if (search_flags & AV_OPT_SEARCH_CHILDREN) {
1241  if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
1242  const AVClass *child = NULL;
1243  while (child = av_opt_child_class_next(c, child))
1244  if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
1245  return o;
1246  } else {
1247  void *child = NULL;
1248  while (child = av_opt_child_next(obj, child))
1249  if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
1250  return o;
1251  }
1252  }
1253 
1254  while (o = av_opt_next(obj, o)) {
1255  if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
1256  ((!unit && o->type != AV_OPT_TYPE_CONST) ||
1257  (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
1258  if (target_obj) {
1259  if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
1260  *target_obj = obj;
1261  else
1262  *target_obj = NULL;
1263  }
1264  return o;
1265  }
1266  }
1267  return NULL;
1268 }
1269 
1270 void *av_opt_child_next(void *obj, void *prev)
1271 {
1272  const AVClass *c = *(AVClass**)obj;
1273  if (c->child_next)
1274  return c->child_next(obj, prev);
1275  return NULL;
1276 }
1277 
1278 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
1279 {
1280  if (parent->child_class_next)
1281  return parent->child_class_next(prev);
1282  return NULL;
1283 }
1284 
1285 void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
1286 {
1287  const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL);
1288  if(!opt)
1289  return NULL;
1290  return (uint8_t*)obj + opt->offset;
1291 }
1292 
1293 int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1294 {
1295  const AVClass *c = *(AVClass**)obj;
1296  int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = NULL;
1297 
1298  if (c->version > (52 << 16 | 11 << 8))
1299  callback = c->query_ranges;
1300 
1301  if (!callback)
1303 
1304  return callback(ranges_arg, obj, key, flags);
1305 }
1306 
1307 int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
1308 {
1309  AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
1310  AVOptionRange **range_array = av_mallocz(sizeof(void*));
1311  AVOptionRange *range = av_mallocz(sizeof(*range));
1312  const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
1313  int ret;
1314 
1315  *ranges_arg = NULL;
1316 
1317  if (!ranges || !range || !range_array || !field) {
1318  ret = AVERROR(ENOMEM);
1319  goto fail;
1320  }
1321 
1322  ranges->range = range_array;
1323  ranges->range[0] = range;
1324  ranges->nb_ranges = 1;
1325  range->is_range = 1;
1326  range->value_min = field->min;
1327  range->value_max = field->max;
1328 
1329  switch (field->type) {
1330  case AV_OPT_TYPE_INT:
1331  case AV_OPT_TYPE_INT64:
1332  case AV_OPT_TYPE_PIXEL_FMT:
1334  case AV_OPT_TYPE_FLOAT:
1335  case AV_OPT_TYPE_DOUBLE:
1336  case AV_OPT_TYPE_DURATION:
1337  break;
1338  case AV_OPT_TYPE_STRING:
1339  range->component_min = 0;
1340  range->component_max = 0x10FFFF; // max unicode value
1341  range->value_min = -1;
1342  range->value_max = INT_MAX;
1343  break;
1344  case AV_OPT_TYPE_RATIONAL:
1345  range->component_min = INT_MIN;
1346  range->component_max = INT_MAX;
1347  break;
1349  range->component_min = 0;
1350  range->component_max = INT_MAX/128/8;
1351  range->value_min = 0;
1352  range->value_max = INT_MAX/8;
1353  break;
1355  range->component_min = 1;
1356  range->component_max = INT_MAX;
1357  range->value_min = 1;
1358  range->value_max = INT_MAX;
1359  break;
1360  default:
1361  ret = AVERROR(ENOSYS);
1362  goto fail;
1363  }
1364 
1365  *ranges_arg = ranges;
1366  return 0;
1367 fail:
1368  av_free(ranges);
1369  av_free(range);
1370  av_free(range_array);
1371  return ret;
1372 }
1373 
1375 {
1376  int i;
1377  AVOptionRanges *ranges = *rangesp;
1378 
1379  for (i = 0; i < ranges->nb_ranges; i++) {
1380  AVOptionRange *range = ranges->range[i];
1381  av_freep(&range->str);
1382  av_freep(&ranges->range[i]);
1383  }
1384  av_freep(&ranges->range);
1385  av_freep(rangesp);
1386 }
1387 
1388 #ifdef TEST
1389 
1390 typedef struct TestContext
1391 {
1392  const AVClass *class;
1393  int num;
1394  int toggle;
1395  char *string;
1396  int flags;
1397  AVRational rational;
1398  AVRational video_rate;
1399  int w, h;
1400  enum AVPixelFormat pix_fmt;
1401  enum AVSampleFormat sample_fmt;
1402  int64_t duration;
1403 } TestContext;
1404 
1405 #define OFFSET(x) offsetof(TestContext, x)
1406 
1407 #define TEST_FLAG_COOL 01
1408 #define TEST_FLAG_LAME 02
1409 #define TEST_FLAG_MU 04
1410 
1411 static const AVOption test_options[]= {
1412 {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100 },
1413 {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1 },
1414 {"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10 },
1415 {"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, {.str = "default"}, CHAR_MIN, CHAR_MAX },
1416 {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
1417 {"cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" },
1418 {"lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" },
1419 {"mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" },
1420 {"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE,{0}, 0, 0 },
1421 {"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, {.i64 = AV_PIX_FMT_NONE}, -1, AV_PIX_FMT_NB-1},
1422 {"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, {.i64 = AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_NB-1},
1423 {"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0 },
1424 {"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX},
1425 {NULL},
1426 };
1427 
1428 static const char *test_get_name(void *ctx)
1429 {
1430  return "test";
1431 }
1432 
1433 static const AVClass test_class = {
1434  "TestContext",
1435  test_get_name,
1436  test_options
1437 };
1438 
1439 int main(void)
1440 {
1441  int i;
1442 
1443  printf("\nTesting av_set_options_string()\n");
1444  {
1445  TestContext test_ctx = { 0 };
1446  const char *options[] = {
1447  "",
1448  ":",
1449  "=",
1450  "foo=:",
1451  ":=foo",
1452  "=foo",
1453  "foo=",
1454  "foo",
1455  "foo=val",
1456  "foo==val",
1457  "toggle=:",
1458  "string=:",
1459  "toggle=1 : foo",
1460  "toggle=100",
1461  "toggle==1",
1462  "flags=+mu-lame : num=42: toggle=0",
1463  "num=42 : string=blahblah",
1464  "rational=0 : rational=1/2 : rational=1/-1",
1465  "rational=-1/0",
1466  "size=1024x768",
1467  "size=pal",
1468  "size=bogus",
1469  "pix_fmt=yuv420p",
1470  "pix_fmt=2",
1471  "pix_fmt=bogus",
1472  "sample_fmt=s16",
1473  "sample_fmt=2",
1474  "sample_fmt=bogus",
1475  "video_rate=pal",
1476  "video_rate=25",
1477  "video_rate=30000/1001",
1478  "video_rate=30/1.001",
1479  "video_rate=bogus",
1480  "duration=bogus",
1481  "duration=123.45",
1482  "duration=1\\:23\\:45.67",
1483  };
1484 
1485  test_ctx.class = &test_class;
1486  av_opt_set_defaults(&test_ctx);
1487 
1489 
1490  for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
1491  av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
1492  if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
1493  av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
1494  printf("\n");
1495  }
1496  av_freep(&test_ctx.string);
1497  }
1498 
1499  printf("\nTesting av_opt_set_from_string()\n");
1500  {
1501  TestContext test_ctx = { 0 };
1502  const char *options[] = {
1503  "",
1504  "5",
1505  "5:hello",
1506  "5:hello:size=pal",
1507  "5:size=pal:hello",
1508  ":",
1509  "=",
1510  " 5 : hello : size = pal ",
1511  "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
1512  };
1513  const char *shorthand[] = { "num", "string", NULL };
1514 
1515  test_ctx.class = &test_class;
1516  av_opt_set_defaults(&test_ctx);
1517  test_ctx.string = av_strdup("default");
1518 
1520 
1521  for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
1522  av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
1523  if (av_opt_set_from_string(&test_ctx, options[i], shorthand, "=", ":") < 0)
1524  av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
1525  printf("\n");
1526  }
1527  av_freep(&test_ctx.string);
1528  }
1529 
1530  return 0;
1531 }
1532 
1533 #endif
const char * name
Definition: avisynth_c.h:675
static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum)
Definition: opt.c:73
Number of sample formats. DO NOT USE if linking dynamically.
Definition: samplefmt.h:63
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
A single allowed range of values, or a single allowed value.
Definition: opt.h:301
float v
const char * s
Definition: avisynth_c.h:668
const AVOption * av_set_int(void *obj, const char *name, int64_t n)
Definition: opt.c:385
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
Definition: dshow.c:200
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition: parseutils.c:162
AVOption.
Definition: opt.h:251
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:404
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:131
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition: opt.h:286
const char * fmt
Definition: avisynth_c.h:669
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition: opt.c:1270
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:530
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition: opt.c:1099
if max(w)>1 w=0.9 *w/max(w)
double value_max
For string ranges this represents the min/max length, for dimensions this represents the min/max pixe...
Definition: opt.h:303
const AVClass * av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
Iterate over potential AVOptions-enabled children of parent.
Definition: opt.c:1278
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:942
class_name
Definition: dnxhdenc.c:47
int num
numerator
Definition: rational.h:44
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:284
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:1062
location of range
external API header
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition: opt.c:409
Accept to parse a value without a key; the key will then be returned as NULL.
Definition: opt.h:511
#define FF_ARRAY_ELEMS(a)
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:711
static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags)
Definition: opt.c:821
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
AVOptionType
Definition: opt.h:220
output residual component w
const char * av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
Definition: opt.c:531
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition: opt.c:745
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:1142
static int get_format(void *obj, const char *name, int search_flags, int *out_fmt, enum AVOptionType type, const char *desc)
Definition: opt.c:761
Public dictionary API.
const char * name
Definition: opt.h:252
#define WHITESPACES
Definition: opt.c:1082
uint8_t
AVOptionRange ** range
Definition: opt.h:312
const char * help
short English help text
Definition: opt.h:258
AVOptions.
const AVOption * av_next_option(void *obj, const AVOption *last)
Definition: opt.c:57
AVS_FilterInfo AVS_Value child
Definition: avisynth_c.h:635
#define b
Definition: input.c:42
const struct AVOption * option
a pointer to the first option specified in the class if any or NULL
Definition: log.h:68
const AVOption * av_set_double(void *obj, const char *name, double n)
Definition: opt.c:369
#define NAN
Definition: math.h:7
const char * str
Definition: opt.h:273
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition: opt.c:399
AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
Definition: opt.c:661
static const double const_values[]
Definition: opt.c:119
double component_max
For string this represents the unicode range for chars, 0-127 limits to ASCII.
Definition: opt.h:304
enum AVPixelFormat pix_fmt
Definition: v4l.c:63
Analy Windw Norm w_out
Definition: stpt.m:8
static int64_t duration
Definition: ffplay.c:294
const OptionDef options[]
Definition: ffserver.c:4697
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:630
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition: opt.c:461
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
Definition: opt.h:281
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:250
void *(* child_next)(void *obj, void *prev)
Return next AVOptions-enabled child or NULL.
Definition: log.h:96
static int hexchar2int(char c)
Definition: opt.c:133
int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
Definition: opt.c:779
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:701
int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
Definition: opt.c:515
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
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:1285
static const uint16_t mask[17]
Definition: lzw.c:37
#define AV_OPT_FLAG_FILTERING_PARAM
a generic parameter which can be set by the user for filtering
Definition: opt.h:287
int(* query_ranges)(struct AVOptionRanges **, void *obj, const char *key, int flags)
Callback to return the supported/allowed ranges.
Definition: log.h:125
double max
maximum valid value for the option
Definition: opt.h:278
const char * r
Definition: vf_curves.c:94
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
const AVOption * av_opt_next(void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:63
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition: opt.c:394
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
double av_get_double(void *obj, const char *name, const AVOption **o_out)
Definition: opt.c:650
void av_log_set_level(int level)
Definition: log.c:269
#define AV_VERSION_INT(a, b, c)
#define FFMAX(a, b)
Definition: common.h:56
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:148
static const char *const const_names[]
Definition: opt.c:126
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:1223
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:169
struct AVRational AVRational
rational number numerator/denominator
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition: opt.c:784
const AVOption * av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
Look for an option in obj.
Definition: opt.c:44
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
const char * str
Definition: opt.h:302
#define FFMIN(a, b)
Definition: common.h:58
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:538
ret
Definition: avfilter.c:821
#define M_E
Definition: ratecontrol.c:37
int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
Definition: opt.c:675
t
Definition: genspecsines3.m:6
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:110
const char * unit
The logical unit to which the option belongs.
Definition: opt.h:295
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:1028
double component_min
Definition: opt.h:304
union AVOption::@169 default_val
the default value for scalar options
double min
minimum valid value for the option
Definition: opt.h:277
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition: opt.c:182
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition: opt.c:140
const struct AVClass *(* child_class_next)(const struct AVClass *prev)
Return an AVClass corresponding to the next potential AVOptions-enabled child.
Definition: log.h:106
FIXME Range Coding of cr are level
Definition: snow.txt:367
const AVOption * av_set_q(void *obj, const char *name, AVRational n)
Definition: opt.c:377
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:47
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:228
int flags
Definition: opt.h:280
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:1307
int is_range
if set to 1 the struct encodes a range, if set to 0 a single value
Definition: opt.h:305
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition: opt.c:687
static void log_value(void *av_log_obj, int level, double d)
Definition: opt.c:802
NULL
Definition: eval.c:55
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:478
void av_opt_freep_ranges(AVOptionRanges **rangesp)
Free an AVOptionRanges struct and set it to NULL.
Definition: opt.c:1374
int offset
The offset relative to the context structure where the option value is stored.
Definition: opt.h:264
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition: opt.c:1202
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags)
Definition: opt.c:355
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:930
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:285
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition: opt.c:340
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
#define llrint(x)
Definition: libm.h:112
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:62
double value
Definition: eval.c:82
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Describe the class of an AVClass context structure.
Definition: log.h:50
synthesis window for stochastic i
rational number numerator/denominator
Definition: rational.h:43
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:282
double dbl
Definition: opt.h:272
offset must point to AVRational
Definition: opt.h:233
#define snprintf
Definition: snprintf.h:34
offset must point to two consecutive integers
Definition: opt.h:230
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
misc parsing utilities
#define type
static int flags
Definition: cpu.c:23
int version
LIBAVUTIL_VERSION with which this structure was created.
Definition: log.h:76
#define OFFSET(x)
Definition: ffmpeg_opt.c:2553
void av_opt_free(void *obj)
Free all string and binary options in obj.
Definition: opt.c:1194
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:1293
double value_min
Definition: opt.h:303
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
common internal and external API header
#define DEFAULT_NUMVAL(opt)
Definition: opt.c:176
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition: opt.c:699
static double c[64]
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
#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:547
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
Definition: opt.c:92
char * key
Definition: dict.h:81
int den
denominator
Definition: rational.h:45
int nb_ranges
Definition: opt.h:313
List of AVOptionRange structs.
Definition: opt.h:311
int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
Set the field of obj with the given name to value.
Definition: opt.c:243
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:566
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
char * value
Definition: dict.h:82
enum AVOptionType type
Definition: opt.h:265
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:1120
int64_t i64
Definition: opt.h:271
printf("static const uint8_t my_array[100] = {\n")
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:169
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:789
#define av_uninit(x)
Definition: attributes.h:137
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:237
#define AV_LOG_INFO
Definition: log.h:156
void INT64 INT64 count
Definition: avisynth_c.h:594
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:68
#define M_PI
Definition: mathematics.h:46
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:1229
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition: pixdesc.c:1712
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:1700
int main(int argc, char **argv)
Definition: main.c:22
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition: opt.c:520
float min
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
void av_opt_set_defaults2(void *s, int mask, int flags)
Definition: opt.c:948
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
Definition: opt.c:439
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:252
static int is_key_char(char c)
Definition: opt.c:1084
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:54
simple arithmetic expression evaluator
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
Definition: opt.c:727