FFmpeg
opt.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <limits.h>
20 #include <stdio.h>
21 
22 #include "libavutil/common.h"
24 #include "libavutil/error.h"
25 #include "libavutil/log.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/rational.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 
31 typedef struct TestContext {
32  const AVClass *class;
34  int num;
35  int unum;
36  int toggle;
37  char *string;
38  int flags;
41  int w, h;
45  uint8_t color[4];
47  void *binary;
49  void *binary1;
51  void *binary2;
54  float flt;
55  double dbl;
56  char *escape;
57  int bool1;
58  int bool2;
59  int bool3;
62 
63  int **array_int;
64  unsigned nb_array_int;
65 
66  char **array_str;
67  unsigned nb_array_str;
68 
70  unsigned nb_array_dict;
71 } TestContext;
72 
73 #define OFFSET(x) offsetof(TestContext, x)
74 
75 #define TEST_FLAG_COOL 01
76 #define TEST_FLAG_LAME 02
77 #define TEST_FLAG_MU 04
78 
79 static const AVOptionArrayDef array_str = {
80  .sep = '|',
81  .def = "str0|str\\|1|str\\\\2",
82 };
83 
84 static const AVOptionArrayDef array_dict = {
85  // there are three levels of escaping - C string, array option, dict - so 8 backslashes are needed to get a literal one inside a dict key/val
86  .def = "k00=v\\\\\\\\00:k01=v\\,01,k10=v\\\\=1\\\\:0",
87 };
88 
89 static const AVOption test_options[]= {
90  {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 100, 1 },
91  {"unum", "set unum", OFFSET(unum), AV_OPT_TYPE_UINT, { .i64 = 1U << 31 }, 0, 1U << 31, 1 },
92  {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 1 },
93  {"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, { .dbl = 1 }, 0, 10, 1 },
94  {"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, { .str = "default" }, CHAR_MIN, CHAR_MAX, 1 },
95  {"escape", "set escape str", OFFSET(escape), AV_OPT_TYPE_STRING, { .str = "\\=," }, CHAR_MIN, CHAR_MAX, 1 },
96  {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 1 }, 0, INT_MAX, 1, .unit = "flags" },
97  {"cool", "set cool flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_COOL }, INT_MIN, INT_MAX, 1, .unit = "flags" },
98  {"lame", "set lame flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_LAME }, INT_MIN, INT_MAX, 1, .unit = "flags" },
99  {"mu", "set mu flag", 0, AV_OPT_TYPE_CONST, { .i64 = TEST_FLAG_MU }, INT_MIN, INT_MAX, 1, .unit = "flags" },
100  {"size", "set size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, { .str="200x300" }, 0, 0, 1 },
101  {"pix_fmt", "set pixfmt", OFFSET(pix_fmt), AV_OPT_TYPE_PIXEL_FMT, { .i64 = AV_PIX_FMT_0BGR }, -1, INT_MAX, 1 },
102  {"sample_fmt", "set samplefmt", OFFSET(sample_fmt), AV_OPT_TYPE_SAMPLE_FMT, { .i64 = AV_SAMPLE_FMT_S16 }, -1, INT_MAX, 1 },
103  {"video_rate", "set videorate", OFFSET(video_rate), AV_OPT_TYPE_VIDEO_RATE, { .str = "25" }, 0, INT_MAX, 1 },
104  {"duration", "set duration", OFFSET(duration), AV_OPT_TYPE_DURATION, { .i64 = 1000 }, 0, INT64_MAX, 1 },
105  {"color", "set color", OFFSET(color), AV_OPT_TYPE_COLOR, { .str = "pink" }, 0, 0, 1 },
106  {"cl", "set channel layout", OFFSET(channel_layout), AV_OPT_TYPE_CHLAYOUT, { .str = "hexagonal" }, 0, 0, 1 },
107  {"bin", "set binary value", OFFSET(binary), AV_OPT_TYPE_BINARY, { .str="62696e00" }, 0, 0, 1 },
108  {"bin1", "set binary value", OFFSET(binary1), AV_OPT_TYPE_BINARY, { .str=NULL }, 0, 0, 1 },
109  {"bin2", "set binary value", OFFSET(binary2), AV_OPT_TYPE_BINARY, { .str="" }, 0, 0, 1 },
110  {"num64", "set num 64bit", OFFSET(num64), AV_OPT_TYPE_INT64, { .i64 = 1LL << 32 }, -1, 1LL << 32, 1 },
111  {"flt", "set float", OFFSET(flt), AV_OPT_TYPE_FLOAT, { .dbl = 1.0 / 3 }, 0, 100, 1 },
112  {"dbl", "set double", OFFSET(dbl), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 / 3 }, 0, 100, 1 },
113  {"bool1", "set boolean value", OFFSET(bool1), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, 1 },
114  {"bool2", "set boolean value", OFFSET(bool2), AV_OPT_TYPE_BOOL, { .i64 = 1 }, -1, 1, 1 },
115  {"bool3", "set boolean value", OFFSET(bool3), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 1 },
116  {"dict1", "set dictionary value", OFFSET(dict1), AV_OPT_TYPE_DICT, { .str = NULL}, 0, 0, 1 },
117  {"dict2", "set dictionary value", OFFSET(dict2), AV_OPT_TYPE_DICT, { .str = "happy=':-)'"}, 0, 0, 1 },
118  {"array_int", "array of ints", OFFSET(array_int), AV_OPT_TYPE_INT | AV_OPT_TYPE_FLAG_ARRAY, .max = INT_MAX, .flags = AV_OPT_FLAG_RUNTIME_PARAM },
119  {"array_str", "array of strings", OFFSET(array_str), AV_OPT_TYPE_STRING | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &array_str }, .flags = AV_OPT_FLAG_RUNTIME_PARAM },
120  {"array_dict", "array of dicts", OFFSET(array_dict), AV_OPT_TYPE_DICT | AV_OPT_TYPE_FLAG_ARRAY, { .arr = &array_dict }, .flags = AV_OPT_FLAG_RUNTIME_PARAM },
121  { NULL },
122 };
123 
124 static const char *test_get_name(void *ctx)
125 {
126  return "test";
127 }
128 
129 typedef struct ChildContext {
130  const AVClass *class;
133 } ChildContext;
134 
135 #undef OFFSET
136 #define OFFSET(x) offsetof(ChildContext, x)
137 
138 static const AVOption child_options[]= {
139  {"child_num64", "set num 64bit", OFFSET(child_num64), AV_OPT_TYPE_INT64, { .i64 = 0 }, 0, 100, 1 },
140  {"child_num", "set child_num", OFFSET(child_num), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 100, 1 },
141  { NULL },
142 };
143 
144 static const char *child_get_name(void *ctx)
145 {
146  return "child";
147 }
148 
149 static const AVClass child_class = {
150  .class_name = "ChildContext",
151  .item_name = child_get_name,
152  .option = child_options,
153  .version = LIBAVUTIL_VERSION_INT,
154 };
155 
156 static void *test_child_next(void *obj, void *prev)
157 {
158  TestContext *test_ctx = obj;
159  if (!prev)
160  return test_ctx->child;
161  return NULL;
162 }
163 
164 static const AVClass test_class = {
165  .class_name = "TestContext",
166  .item_name = test_get_name,
167  .option = test_options,
168  .child_next = test_child_next,
169  .version = LIBAVUTIL_VERSION_INT,
170 };
171 
172 static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
173 {
174  vfprintf(stdout, fmt, vl);
175 }
176 
177 int main(void)
178 {
179  int i;
180 
183 
184  printf("Testing default values\n");
185  {
186  TestContext test_ctx = { 0 };
187  test_ctx.class = &test_class;
188  av_opt_set_defaults(&test_ctx);
189 
190  printf("num=%d\n", test_ctx.num);
191  printf("unum=%u\n", test_ctx.unum);
192  printf("toggle=%d\n", test_ctx.toggle);
193  printf("string=%s\n", test_ctx.string);
194  printf("escape=%s\n", test_ctx.escape);
195  printf("flags=%d\n", test_ctx.flags);
196  printf("rational=%d/%d\n", test_ctx.rational.num, test_ctx.rational.den);
197  printf("video_rate=%d/%d\n", test_ctx.video_rate.num, test_ctx.video_rate.den);
198  printf("width=%d height=%d\n", test_ctx.w, test_ctx.h);
199  printf("pix_fmt=%s\n", av_get_pix_fmt_name(test_ctx.pix_fmt));
200  printf("sample_fmt=%s\n", av_get_sample_fmt_name(test_ctx.sample_fmt));
201  printf("duration=%"PRId64"\n", test_ctx.duration);
202  printf("color=%d %d %d %d\n", test_ctx.color[0], test_ctx.color[1], test_ctx.color[2], test_ctx.color[3]);
203  printf("channel_layout=%"PRId64"=%"PRId64"\n", test_ctx.channel_layout.u.mask, (int64_t)AV_CH_LAYOUT_HEXAGONAL);
204  if (test_ctx.binary)
205  printf("binary=%x %x %x %x\n", ((uint8_t*)test_ctx.binary)[0], ((uint8_t*)test_ctx.binary)[1], ((uint8_t*)test_ctx.binary)[2], ((uint8_t*)test_ctx.binary)[3]);
206  printf("binary_size=%d\n", test_ctx.binary_size);
207  printf("num64=%"PRId64"\n", test_ctx.num64);
208  printf("flt=%.6f\n", test_ctx.flt);
209  printf("dbl=%.6f\n", test_ctx.dbl);
210 
211  for (unsigned i = 0; i < test_ctx.nb_array_str; i++)
212  printf("array_str[%u]=%s\n", i, test_ctx.array_str[i]);
213 
214  for (unsigned i = 0; i < test_ctx.nb_array_dict; i++) {
215  AVDictionary *d = test_ctx.array_dict[i];
216  const AVDictionaryEntry *e = NULL;
217 
218  while ((e = av_dict_iterate(d, e)))
219  printf("array_dict[%u]: %s\t%s\n", i, e->key, e->value);
220  }
221 
222  av_opt_show2(&test_ctx, NULL, -1, 0);
223 
224  av_opt_free(&test_ctx);
225  }
226 
227  printf("\nTesting av_opt_is_set_to_default()\n");
228  {
229  int ret;
230  TestContext test_ctx = { 0 };
231  const AVOption *o = NULL;
232  test_ctx.class = &test_class;
233 
235 
236  while (o = av_opt_next(&test_ctx, o)) {
237  ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
238  printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
239  }
240  av_opt_set_defaults(&test_ctx);
241  while (o = av_opt_next(&test_ctx, o)) {
242  ret = av_opt_is_set_to_default_by_name(&test_ctx, o->name, 0);
243  printf("name:%10s default:%d error:%s\n", o->name, !!ret, ret < 0 ? av_err2str(ret) : "");
244  }
245  av_opt_free(&test_ctx);
246  }
247 
248  printf("\nTesting av_opt_get/av_opt_set()\n");
249  {
250  TestContext test_ctx = { 0 };
251  TestContext test2_ctx = { 0 };
252  const AVOption *o = NULL;
253  char *val = NULL;
254  int ret;
255 
256  test_ctx.class = &test_class;
257  test2_ctx.class = &test_class;
258 
260 
261  av_opt_set_defaults(&test_ctx);
262 
263  while (o = av_opt_next(&test_ctx, o)) {
264  char *value1 = NULL;
265  char *value2 = NULL;
266  int ret1 = AVERROR_BUG;
267  int ret2 = AVERROR_BUG;
268  int ret3 = AVERROR_BUG;
269 
270  if (o->type == AV_OPT_TYPE_CONST)
271  continue;
272 
273  ret1 = av_opt_get(&test_ctx, o->name, 0, (uint8_t **)&value1);
274  if (ret1 >= 0) {
275  ret2 = av_opt_set(&test2_ctx, o->name, value1, 0);
276  if (ret2 >= 0)
277  ret3 = av_opt_get(&test2_ctx, o->name, 0, (uint8_t **)&value2);
278  }
279 
280  printf("name: %-11s get: %-16s set: %-16s get: %-16s %s\n", o->name,
281  ret1 >= 0 ? value1 : av_err2str(ret1),
282  ret2 >= 0 ? "OK" : av_err2str(ret2),
283  ret3 >= 0 ? value2 : av_err2str(ret3),
284  ret1 >= 0 && ret2 >= 0 && ret3 >= 0 && !strcmp(value1, value2) ? "OK" : "Mismatch");
285  av_free(value1);
286  av_free(value2);
287  }
288 
289  // av_opt_set(NULL) with an array option resets it
290  ret = av_opt_set(&test_ctx, "array_dict", NULL, 0);
291  printf("av_opt_set(\"array_dict\", NULL) -> %d\n", ret);
292  printf("array_dict=%sNULL; nb_array_dict=%u\n",
293  test_ctx.array_dict ? "non-" : "", test_ctx.nb_array_dict);
294 
295  // av_opt_get() on an empty array should return a NULL string
296  ret = av_opt_get(&test_ctx, "array_dict", AV_OPT_ALLOW_NULL, (uint8_t**)&val);
297  printf("av_opt_get(\"array_dict\") -> %s\n", val ? val : "NULL");
298 
299  av_opt_free(&test_ctx);
300  av_opt_free(&test2_ctx);
301  }
302 
303  printf("\nTest av_opt_serialize()\n");
304  {
305  TestContext test_ctx = { 0 };
306  char *buf;
307  int ret;
308  test_ctx.class = &test_class;
309 
311 
312  av_opt_set_defaults(&test_ctx);
313  if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
314  printf("%s\n", buf);
315  av_opt_free(&test_ctx);
316  memset(&test_ctx, 0, sizeof(test_ctx));
317  test_ctx.class = &test_class;
318  ret = av_set_options_string(&test_ctx, buf, "=", ",");
319  av_free(buf);
320  if (ret < 0)
321  printf("Error ret '%d'\n", ret);
322  if (av_opt_serialize(&test_ctx, 0, 0, &buf, '=', ',') >= 0) {
323  ChildContext child_ctx = { 0 };
324  printf("%s\n", buf);
325  av_free(buf);
326  child_ctx.class = &child_class;
327  test_ctx.child = &child_ctx;
328  if (av_opt_serialize(&test_ctx, 0,
330  &buf, '=', ',') >= 0) {
331  printf("%s\n", buf);
332  av_free(buf);
333  }
334  av_opt_free(&child_ctx);
335  test_ctx.child = NULL;
336  }
337  }
338  av_opt_free(&test_ctx);
339  }
340 
341  printf("\nTesting av_set_options_string()\n");
342  {
343  TestContext test_ctx = { 0 };
344  static const char * const options[] = {
345  "",
346  ":",
347  "=",
348  "foo=:",
349  ":=foo",
350  "=foo",
351  "foo=",
352  "foo",
353  "foo=val",
354  "foo==val",
355  "toggle=:",
356  "string=:",
357  "toggle=1 : foo",
358  "toggle=100",
359  "toggle==1",
360  "flags=+mu-lame : num=42: toggle=0",
361  "num=42 : string=blahblah",
362  "rational=0 : rational=1/2 : rational=1/-1",
363  "rational=-1/0",
364  "size=1024x768",
365  "size=pal",
366  "size=bogus",
367  "pix_fmt=yuv420p",
368  "pix_fmt=2",
369  "pix_fmt=bogus",
370  "sample_fmt=s16",
371  "sample_fmt=2",
372  "sample_fmt=bogus",
373  "video_rate=pal",
374  "video_rate=25",
375  "video_rate=30000/1001",
376  "video_rate=30/1.001",
377  "video_rate=bogus",
378  "duration=bogus",
379  "duration=123.45",
380  "duration=1\\:23\\:45.67",
381  "color=blue",
382  "color=0x223300",
383  "color=0x42FF07AA",
384  "cl=FL+FR",
385  "cl=foo",
386  "bin=boguss",
387  "bin=111",
388  "bin=ffff",
389  "num=bogus",
390  "num=44",
391  "num=44.4",
392  "num=-1",
393  "num=-2",
394  "num=101",
395  "unum=bogus",
396  "unum=44",
397  "unum=44.4",
398  "unum=-1",
399  "unum=2147483648",
400  "unum=2147483649",
401  "num64=bogus",
402  "num64=44",
403  "num64=44.4",
404  "num64=-1",
405  "num64=-2",
406  "num64=4294967296",
407  "num64=4294967297",
408  "flt=bogus",
409  "flt=2",
410  "flt=2.2",
411  "flt=-1",
412  "flt=101",
413  "dbl=bogus",
414  "dbl=2",
415  "dbl=2.2",
416  "dbl=-1",
417  "dbl=101",
418  "bool1=true",
419  "bool2=auto",
420  "dict1='happy=\\:-):sad=\\:-('",
421  "array_int=0,32,2147483647",
422  "array_int=2147483648", // out of range, should fail
423  };
424 
425  test_ctx.class = &test_class;
426  av_opt_set_defaults(&test_ctx);
427 
429 
430  for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
431  int silence_log = !strcmp(options[i], "rational=-1/0"); // inf formating differs between platforms
432  av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
433  if (silence_log)
435  if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
436  printf("Error '%s'\n", options[i]);
437  else
438  printf("OK '%s'\n", options[i]);
440  }
441  av_opt_free(&test_ctx);
442  }
443 
444  printf("\nTesting av_opt_set_from_string()\n");
445  {
446  TestContext test_ctx = { 0 };
447  static const char * const options[] = {
448  "",
449  "5",
450  "5:hello",
451  "5:hello:size=pal",
452  "5:size=pal:hello",
453  ":",
454  "=",
455  " 5 : hello : size = pal ",
456  "a_very_long_option_name_that_will_need_to_be_ellipsized_around_here=42"
457  };
458  static const char * const shorthand[] = { "num", "string", NULL };
459 
460  test_ctx.class = &test_class;
461  av_opt_set_defaults(&test_ctx);
462 
464 
465  for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
466  av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
467  if (av_opt_set_from_string(&test_ctx, options[i], shorthand, "=", ":") < 0)
468  printf("Error '%s'\n", options[i]);
469  else
470  printf("OK '%s'\n", options[i]);
471  }
472  av_opt_free(&test_ctx);
473  }
474 
475  printf("\nTesting av_opt_find2()\n");
476  {
477  TestContext test_ctx = { 0 };
478  ChildContext child_ctx = { 0 };
479  void *target;
480  const AVOption *opt;
481 
482  test_ctx.class = &test_class;
483  child_ctx.class = &child_class;
484  test_ctx.child = &child_ctx;
485 
487 
488  // Should succeed. num exists and has opt_flags 1
489  opt = av_opt_find2(&test_ctx, "num", NULL, 1, 0, &target);
490  if (opt && target == &test_ctx)
491  printf("OK '%s'\n", opt->name);
492  else
493  printf("Error 'num'\n");
494 
495  // Should fail. num64 exists but has opt_flags 1, not 2
496  opt = av_opt_find(&test_ctx, "num64", NULL, 2, 0);
497  if (opt)
498  printf("OK '%s'\n", opt->name);
499  else
500  printf("Error 'num64'\n");
501 
502  // Should fail. child_num exists but in a child object we're not searching
503  opt = av_opt_find(&test_ctx, "child_num", NULL, 0, 0);
504  if (opt)
505  printf("OK '%s'\n", opt->name);
506  else
507  printf("Error 'child_num'\n");
508 
509  // Should succeed. child_num exists in a child object we're searching
510  opt = av_opt_find2(&test_ctx, "child_num", NULL, 0, AV_OPT_SEARCH_CHILDREN, &target);
511  if (opt && target == &child_ctx)
512  printf("OK '%s'\n", opt->name);
513  else
514  printf("Error 'child_num'\n");
515 
516  // Should fail. foo doesn't exist
517  opt = av_opt_find(&test_ctx, "foo", NULL, 0, 0);
518  if (opt)
519  printf("OK '%s'\n", opt->name);
520  else
521  printf("Error 'foo'\n");
522  }
523 
524  return 0;
525 }
AV_OPT_SEARCH_CHILDREN
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition: opt.h:533
AVChannelLayout::u
union AVChannelLayout::@402 u
Details about which channels are present in this layout.
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
level
uint8_t level
Definition: svq3.c:205
av_opt_set_defaults
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition: opt.c:1654
opt.h
TestContext::video_rate
AVRational video_rate
Definition: opt.c:40
AV_OPT_TYPE_SAMPLE_FMT
@ AV_OPT_TYPE_SAMPLE_FMT
Definition: opt.h:257
color
Definition: vf_paletteuse.c:512
AVOptionArrayDef::sep
char sep
Separator between array elements in string representations of this option, used by av_opt_set() and a...
Definition: opt.h:351
AV_LOG_QUIET
#define AV_LOG_QUIET
Print no output.
Definition: log.h:162
AVOptionArrayDef
May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
Definition: opt.h:323
TestContext::color
uint8_t color[4]
Definition: opt.c:45
AV_OPT_TYPE_VIDEO_RATE
@ AV_OPT_TYPE_VIDEO_RATE
offset must point to AVRational
Definition: opt.h:258
rational.h
int64_t
long long int64_t
Definition: coverity.c:34
ChildContext::class
const AVClass * class
Definition: opt.c:130
pixdesc.h
TestContext::binary_size
int binary_size
Definition: opt.c:48
w
uint8_t w
Definition: llviddspenc.c:38
AV_CH_LAYOUT_HEXAGONAL
#define AV_CH_LAYOUT_HEXAGONAL
Definition: channel_layout.h:228
av_opt_set_from_string
int av_opt_set_from_string(void *ctx, const char *opts, const char *const *shorthand, const char *key_val_sep, const char *pairs_sep)
Parse the key-value pairs list in opts.
Definition: opt.c:1873
AVOption
AVOption.
Definition: opt.h:357
test_get_name
static const char * test_get_name(void *ctx)
Definition: opt.c:124
main
int main(void)
Definition: opt.c:177
AV_OPT_TYPE_DURATION
@ AV_OPT_TYPE_DURATION
Definition: opt.h:259
av_opt_find2
const AVOption * av_opt_find2(void *obj, const char *name, const char *unit, int opt_flags, int search_flags, void **target_obj)
Look for an option in an object.
Definition: opt.c:1973
TEST_FLAG_LAME
#define TEST_FLAG_LAME
Definition: opt.c:76
TestContext::string
char * string
Definition: opt.c:37
AVDictionary
Definition: dict.c:34
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:343
AV_OPT_TYPE_RATIONAL
@ AV_OPT_TYPE_RATIONAL
Definition: opt.h:250
TestContext::toggle
int toggle
Definition: opt.c:36
av_opt_serialize
int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer, const char key_val_sep, const char pairs_sep)
Serialize object's options.
Definition: opt.c:2451
array_str
static const AVOptionArrayDef array_str
Definition: opt.c:79
TestContext::num64
int64_t num64
Definition: opt.c:53
AV_OPT_SERIALIZE_SEARCH_CHILDREN
#define AV_OPT_SERIALIZE_SEARCH_CHILDREN
Serialize options in possible children of the given object.
Definition: opt.h:952
TestContext::binary_size2
int binary_size2
Definition: opt.c:52
AV_OPT_TYPE_BINARY
@ AV_OPT_TYPE_BINARY
offset must point to a pointer immediately followed by an int for the length
Definition: opt.h:251
TestContext::duration
int64_t duration
Definition: opt.c:44
av_opt_free
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1925
TestContext::flags
int flags
Definition: opt.c:38
val
static double val(void *priv, double ch)
Definition: aeval.c:78
av_opt_set
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition: opt.c:747
AV_OPT_SERIALIZE_SKIP_DEFAULTS
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS
Serialize options that are not set to default values only.
Definition: opt.h:950
AVRational::num
int num
Numerator.
Definition: rational.h:59
TestContext::dbl
double dbl
Definition: opt.c:55
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
TestContext::binary
void * binary
Definition: opt.c:47
TestContext::class
const AVClass * class
Definition: opt.c:32
duration
int64_t duration
Definition: movenc.c:65
AVOptionArrayDef::def
const char * def
Native access only.
Definition: opt.h:330
TestContext::h
int h
Definition: opt.c:41
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demux_decode.c:41
AVDictionaryEntry::key
char * key
Definition: dict.h:90
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:247
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Definition: opt.h:246
av_set_options_string
int av_set_options_string(void *ctx, const char *opts, const char *key_val_sep, const char *pairs_sep)
Parse the key/value pairs list in opts.
Definition: opt.c:1793
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
ctx
AVFormatContext * ctx
Definition: movenc.c:49
limits.h
child_options
static const AVOption child_options[]
Definition: opt.c:138
ChildContext::child_num
int child_num
Definition: opt.c:132
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
TestContext::bool1
int bool1
Definition: opt.c:57
child_get_name
static const char * child_get_name(void *ctx)
Definition: opt.c:144
TestContext::bool2
int bool2
Definition: opt.c:58
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
TestContext
Definition: opt.c:31
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
TEST_FLAG_COOL
#define TEST_FLAG_COOL
Definition: opt.c:75
TestContext::num
int num
Definition: opt.c:34
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_OPT_TYPE_COLOR
@ AV_OPT_TYPE_COLOR
Definition: opt.h:260
child_class
static const AVClass child_class
Definition: opt.c:149
AV_OPT_TYPE_IMAGE_SIZE
@ AV_OPT_TYPE_IMAGE_SIZE
offset must point to two consecutive ints
Definition: opt.h:255
AV_OPT_TYPE_DICT
@ AV_OPT_TYPE_DICT
Definition: opt.h:252
TestContext::pix_fmt
enum AVPixelFormat pix_fmt
Definition: opt.c:42
TestContext::flt
float flt
Definition: opt.c:54
AV_OPT_TYPE_UINT
@ AV_OPT_TYPE_UINT
Definition: opt.h:263
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Definition: opt.h:262
TestContext::w
int w
Definition: opt.c:41
TestContext::binary2
void * binary2
Definition: opt.c:51
TestContext::rational
AVRational rational
Definition: opt.c:39
error.h
options
const OptionDef options[]
av_opt_find
const AVOption * av_opt_find(void *obj, const char *name, const char *unit, int opt_flags, int search_flags)
Look for an option in an object.
Definition: opt.c:1967
av_log_set_callback
void av_log_set_callback(void(*callback)(void *, int, const char *, va_list))
Set the logging callback.
Definition: log.c:462
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:311
AV_OPT_TYPE_FLAG_ARRAY
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition: opt.h:274
av_err2str
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:122
OFFSET
#define OFFSET(x)
Definition: opt.c:136
TestContext::dict2
AVDictionary * dict2
Definition: opt.c:61
TEST_FLAG_MU
#define TEST_FLAG_MU
Definition: opt.c:77
printf
printf("static const uint8_t my_array[100] = {\n")
AVOption::name
const char * name
Definition: opt.h:358
ChildContext
Definition: teeproto.c:31
av_opt_show2
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition: opt.c:1642
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:248
TestContext::escape
char * escape
Definition: opt.c:56
array_dict
static const AVOptionArrayDef array_dict
Definition: opt.c:84
ChildContext::child_num64
int64_t child_num64
Definition: opt.c:131
av_opt_next
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition: opt.c:48
av_log_set_level
void av_log_set_level(int level)
Set the log level.
Definition: log.c:447
TestContext::nb_array_int
unsigned nb_array_int
Definition: opt.c:64
TestContext::channel_layout
AVChannelLayout channel_layout
Definition: opt.c:46
log.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
TestContext::binary_size1
int binary_size1
Definition: opt.c:50
common.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
TestContext::unum
int unum
Definition: opt.c:35
TestContext::nb_array_str
unsigned nb_array_str
Definition: opt.c:67
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_0BGR
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
Definition: pixfmt.h:264
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
AVOption::type
enum AVOptionType type
Definition: opt.h:373
U
#define U(x)
Definition: vpx_arith.h:37
channel_layout.h
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_FLAG_RUNTIME_PARAM
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition: opt.h:305
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:245
log_callback_help
static void log_callback_help(void *ptr, int level, const char *fmt, va_list vl)
Definition: opt.c:172
TestContext::child
struct ChildContext * child
Definition: opt.c:33
AV_OPT_TYPE_PIXEL_FMT
@ AV_OPT_TYPE_PIXEL_FMT
Definition: opt.h:256
TestContext::array_dict
AVDictionary ** array_dict
Definition: opt.c:69
test_child_next
static void * test_child_next(void *obj, void *prev)
Definition: opt.c:156
mem.h
AV_OPT_ALLOW_NULL
#define AV_OPT_ALLOW_NULL
In av_opt_get, return NULL if the option has a pointer type and is set to NULL, rather than returning...
Definition: opt.h:547
test_class
static const AVClass test_class
Definition: opt.c:164
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AVDictionaryEntry
Definition: dict.h:89
TestContext::array_int
int ** array_int
Definition: opt.c:63
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:261
TestContext::binary1
void * binary1
Definition: opt.c:49
TestContext::nb_array_dict
unsigned nb_array_dict
Definition: opt.c:70
TestContext::dict1
AVDictionary * dict1
Definition: opt.c:60
TestContext::bool3
int bool3
Definition: opt.c:59
d
d
Definition: ffmpeg_filter.c:424
AV_OPT_TYPE_FLAGS
@ AV_OPT_TYPE_FLAGS
Definition: opt.h:244
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
av_opt_get
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition: opt.c:1159
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVDictionaryEntry::value
char * value
Definition: dict.h:91
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:249
TestContext::array_str
char ** array_str
Definition: opt.c:66
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:254
test_options
static const AVOption test_options[]
Definition: opt.c:89
TestContext::sample_fmt
enum AVSampleFormat sample_fmt
Definition: opt.c:43
av_dict_iterate
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition: dict.c:44
av_opt_is_set_to_default_by_name
int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
Check if given option is set to its default value.
Definition: opt.c:2396
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2885