FFmpeg
Loading...
Searching...
No Matches
opt.c
Go to the documentation of this file.
1/*
2 * AVOptions
3 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
23 * @file
24 * AVOptions
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28#include "avutil.h"
29#include "avassert.h"
30#include "avstring.h"
31#include "channel_layout.h"
32#include "dict.h"
33#include "eval.h"
34#include "log.h"
35#include "mem.h"
36#include "parseutils.h"
37#include "pixdesc.h"
38#include "mathematics.h"
39#include "opt.h"
40#include "samplefmt.h"
41#include "bprint.h"
42
43#include <float.h>
44
45#define TYPE_BASE(type) ((type) & ~AV_OPT_TYPE_FLAG_ARRAY)
46
47const AVOption *av_opt_next(const void *obj, const AVOption *last)
48{
49 const AVClass *class;
50 if (!obj)
51 return NULL;
52 class = *(const AVClass**)obj;
53 if (!last && class && class->option && class->option[0].name)
54 return class->option;
55 if (last && last[1].name)
56 return ++last;
57 return NULL;
58}
59
60static const struct {
61 size_t size;
62 const char *name;
63} opt_type_desc[] = {
64 [AV_OPT_TYPE_FLAGS] = { sizeof(unsigned), "<flags>" },
65 [AV_OPT_TYPE_INT] = { sizeof(int), "<int>" },
66 [AV_OPT_TYPE_INT64] = { sizeof(int64_t), "<int64>" },
67 [AV_OPT_TYPE_UINT] = { sizeof(unsigned), "<unsigned>" },
68 [AV_OPT_TYPE_UINT64] = { sizeof(uint64_t), "<uint64>" },
69 [AV_OPT_TYPE_DOUBLE] = { sizeof(double), "<double>" },
70 [AV_OPT_TYPE_FLOAT] = { sizeof(float), "<float>" },
71 [AV_OPT_TYPE_STRING] = { sizeof(char *), "<string>" },
72 [AV_OPT_TYPE_RATIONAL] = { sizeof(AVRational), "<rational>" },
73 [AV_OPT_TYPE_BINARY] = { sizeof(uint8_t *), "<binary>" },
74 [AV_OPT_TYPE_DICT] = { sizeof(AVDictionary *), "<dictionary>" },
75 [AV_OPT_TYPE_IMAGE_SIZE] = { sizeof(int[2]), "<image_size>" },
76 [AV_OPT_TYPE_VIDEO_RATE] = { sizeof(AVRational), "<video_rate>" },
77 [AV_OPT_TYPE_PIXEL_FMT] = { sizeof(enum AVPixelFormat), "<pix_fmt>" },
78 [AV_OPT_TYPE_SAMPLE_FMT] = { sizeof(enum AVSampleFormat), "<sample_fmt>" },
79 [AV_OPT_TYPE_DURATION] = { sizeof(int64_t), "<duration>" },
80 [AV_OPT_TYPE_COLOR] = { sizeof(uint8_t[4]), "<color>" },
81 [AV_OPT_TYPE_CHLAYOUT] = { sizeof(AVChannelLayout),"<channel_layout>" },
82 [AV_OPT_TYPE_BOOL] = { sizeof(int), "<boolean>" },
83};
84
85// option is plain old data
87{
88 switch (type) {
90 case AV_OPT_TYPE_INT:
102 case AV_OPT_TYPE_BOOL:
103 case AV_OPT_TYPE_UINT:
104 return 1;
105 }
106 return 0;
107}
108
109static uint8_t opt_array_sep(const AVOption *o)
110{
111 const AVOptionArrayDef *d = o->default_val.arr;
113 return (d && d->sep) ? d->sep : ',';
114}
115
116static void *opt_array_pelem(const AVOption *o, void *array, unsigned idx)
117{
119 return (uint8_t *)array + idx * opt_type_desc[TYPE_BASE(o->type)].size;
120}
121
122static unsigned *opt_array_pcount(const void *parray)
123{
124 return (unsigned *)((const void * const *)parray + 1);
125}
126
127static void opt_free_elem(enum AVOptionType type, void *ptr)
128{
129 switch (TYPE_BASE(type)) {
132 av_freep(ptr);
133 break;
134
135 case AV_OPT_TYPE_DICT:
136 av_dict_free((AVDictionary **)ptr);
137 break;
138
141 break;
142
143 default:
144 break;
145 }
146}
147
148static void opt_free_array(const AVOption *o, void *parray, unsigned *count)
149{
150 for (unsigned i = 0; i < *count; i++)
151 opt_free_elem(o->type, opt_array_pelem(o, *(void **)parray, i));
152
153 av_freep(parray);
154 *count = 0;
155}
156
157/**
158 * Perform common setup for option-setting functions.
159 *
160 * @param require_type when non-0, require the option to be of this type
161 * @param ptgt target object is written here
162 * @param po the option is written here
163 * @param pdst pointer to option value is written here
164 */
165static int opt_set_init(void *obj, const char *name, int search_flags,
166 int require_type,
167 void **ptgt, const AVOption **po, void **pdst)
168{
169 void *logctx;
170 const AVOption *o;
171 void *tgt;
172
173 o = av_opt_find2(obj, name, NULL, 0, search_flags, &tgt);
174 if (!o || (!tgt && !(search_flags & AV_OPT_SEARCH_FAKE_OBJ)))
176
178 return AVERROR(EINVAL);
179
180 logctx = tgt ? obj : NULL;
181
182 if (require_type && (o->type != require_type)) {
183 av_log(logctx, AV_LOG_ERROR,
184 "Tried to set option '%s' of type %s from value of type %s, "
185 "this is not supported\n", o->name, opt_type_desc[o->type].name,
186 opt_type_desc[require_type].name);
187 return AVERROR(EINVAL);
188 }
189
190 if (!(o->flags & AV_OPT_FLAG_RUNTIME_PARAM)) {
191 unsigned *state_flags = NULL;
192 const AVClass *class;
193
194 // try state flags first from the target (child), then from its parent
195 class = *(const AVClass**)tgt;
196 if (class->state_flags_offset)
197 state_flags = (unsigned*)((uint8_t*)tgt + class->state_flags_offset);
198
199 if (!state_flags && obj != tgt) {
200 class = *(const AVClass**)obj;
201 if (class->state_flags_offset)
202 state_flags = (unsigned*)((uint8_t*)obj + class->state_flags_offset);
203 }
204
205 if (state_flags && (*state_flags & AV_CLASS_STATE_INITIALIZED)) {
206 av_log(logctx, AV_LOG_ERROR, "Option '%s' is not a runtime option and "
207 "so cannot be set after the object has been initialized\n",
208 o->name);
209 return AVERROR(EINVAL);
210 }
211 }
212
214 av_log(logctx, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
215
216 if (po)
217 *po = o;
218 if (ptgt)
219 *ptgt = tgt;
220 if (pdst)
221 *pdst = tgt ? ((uint8_t *)tgt) + o->offset : NULL;
222
223 return 0;
224}
225
227{
228 AVRational r = av_d2q(d, 1 << 24);
229 if ((!r.num || !r.den) && d)
230 r = av_d2q(d, INT_MAX);
231 return r;
232}
233
234static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
235{
236 switch (TYPE_BASE(o->type)) {
238 *intnum = *(unsigned int*)dst;
239 return 0;
241 *intnum = *(enum AVPixelFormat *)dst;
242 return 0;
244 *intnum = *(enum AVSampleFormat *)dst;
245 return 0;
246 case AV_OPT_TYPE_BOOL:
247 case AV_OPT_TYPE_INT:
248 *intnum = *(int *)dst;
249 return 0;
250 case AV_OPT_TYPE_UINT:
251 *intnum = *(unsigned int *)dst;
252 return 0;
256 *intnum = *(int64_t *)dst;
257 return 0;
259 *num = *(float *)dst;
260 return 0;
262 *num = *(double *)dst;
263 return 0;
265 *intnum = ((AVRational *)dst)->num;
266 *den = ((AVRational *)dst)->den;
267 return 0;
269 *intnum = o->default_val.i64;
270 return 0;
271 }
272 return AVERROR(EINVAL);
273}
274
275static int write_number(void *obj, const AVOption *o, void *dst,
276 double num, int den, int64_t intnum,
277 int ignore_range)
278{
279 void *logctx = dst ? obj : NULL;
280 const enum AVOptionType type = TYPE_BASE(o->type);
281
282 if (!ignore_range && type != AV_OPT_TYPE_FLAGS &&
283 (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
284 num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
285 av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
286 num, o->name, o->min, o->max);
287 return AVERROR(ERANGE);
288 }
289 if (!ignore_range && type == AV_OPT_TYPE_FLAGS) {
290 double d = num*intnum/den;
291 if (d < -1.5 || d > 0xFFFFFFFF+0.5 || (llrint(d*256) & 255)) {
292 av_log(logctx, AV_LOG_ERROR,
293 "Value %f for parameter '%s' is not a valid set of 32bit integer flags\n",
294 num*intnum/den, o->name);
295 return AVERROR(ERANGE);
296 }
297 }
298
299 if (!dst)
300 return 0;
301
302 switch (type) {
304 *(enum AVPixelFormat *)dst = llrint(num / den) * intnum;
305 break;
307 *(enum AVSampleFormat *)dst = llrint(num / den) * intnum;
308 break;
309 case AV_OPT_TYPE_BOOL:
311 case AV_OPT_TYPE_INT:
312 case AV_OPT_TYPE_UINT:
313 *(int *)dst = llrint(num / den) * intnum;
314 break;
316 case AV_OPT_TYPE_INT64:{
317 double d = num / den;
318 if (intnum == 1 && d == (double)INT64_MAX) {
319 *(int64_t *)dst = INT64_MAX;
320 } else
321 *(int64_t *)dst = llrint(d) * intnum;
322 break;}
323 case AV_OPT_TYPE_UINT64:{
324 double d = num / den;
325 // We must special case uint64_t here as llrint() does not support values
326 // outside the int64_t range and there is no portable function which does
327 // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double
328 // while INT64_MAX is not
329 if (intnum == 1 && d == (double)UINT64_MAX) {
330 *(uint64_t *)dst = UINT64_MAX;
331 } else if (d > INT64_MAX + 1ULL) {
332 *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum;
333 } else {
334 *(uint64_t *)dst = llrint(d) * intnum;
335 }
336 break;}
338 *(float *)dst = num * intnum / den;
339 break;
341 *(double *)dst = num * intnum / den;
342 break;
345 if ((int) num == num)
346 *(AVRational *)dst = (AVRational) { num *intnum, den };
347 else
348 *(AVRational *)dst = double_to_rational(num * intnum / den);
349 break;
350 default:
351 return AVERROR(EINVAL);
352 }
353 return 0;
354}
355
356static int hexchar2int(char c) {
357 if (c >= '0' && c <= '9')
358 return c - '0';
359 if (c >= 'a' && c <= 'f')
360 return c - 'a' + 10;
361 if (c >= 'A' && c <= 'F')
362 return c - 'A' + 10;
363 return -1;
364}
365
366static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
367{
368 int *lendst;
369 uint8_t *bin, *ptr;
370 int len;
371
372 if (dst) {
373 lendst = (int *)(dst + 1);
374 av_freep(dst);
375 *lendst = 0;
376 }
377
378 if (!val || !(len = strlen(val)))
379 return 0;
380
381 if (len & 1)
382 return AVERROR(EINVAL);
383 len /= 2;
384
385 ptr = bin = av_malloc(len);
386 if (!ptr)
387 return AVERROR(ENOMEM);
388 while (*val) {
389 int a = hexchar2int(*val++);
390 int b = hexchar2int(*val++);
391 if (a < 0 || b < 0) {
392 av_free(bin);
393 return AVERROR(EINVAL);
394 }
395 *ptr++ = (a << 4) | b;
396 }
397
398 if (dst) {
399 *dst = bin;
400 *lendst = len;
401 } else {
402 av_free(bin);
403 }
404
405 return 0;
406}
407
408static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
409{
410 if (!dst)
411 return 0;
412 av_freep(dst);
413 if (!val)
414 return 0;
415 *dst = av_strdup(val);
416 return *dst ? 0 : AVERROR(ENOMEM);
417}
418
419#define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
420 opt->type == AV_OPT_TYPE_UINT64 || \
421 opt->type == AV_OPT_TYPE_CONST || \
422 opt->type == AV_OPT_TYPE_FLAGS || \
423 opt->type == AV_OPT_TYPE_UINT || \
424 opt->type == AV_OPT_TYPE_INT) \
425 ? opt->default_val.i64 \
426 : opt->default_val.dbl)
427
428static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
429{
430 void *logctx = dst ? obj : NULL;
431 const enum AVOptionType type = TYPE_BASE(o->type);
432 int ret = 0;
433
435 int num, den;
436 char c;
437 if (sscanf(val, "%d%*1[:/]%d%c", &num, &den, &c) == 2) {
438 if ((ret = write_number(obj, o, dst, 1, den, num, 0)) >= 0)
439 return ret;
440 ret = 0;
441 }
442 }
443
444 for (;;) {
445 int i = 0;
446 char buf[256];
447 int cmd = 0;
448 double d;
449 int64_t intnum = 1;
450
451 if (type == AV_OPT_TYPE_FLAGS) {
452 if (*val == '+' || *val == '-')
453 cmd = *(val++);
454 for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
455 buf[i] = val[i];
456 buf[i] = 0;
457 }
458
459 {
460 int res;
461 int ci = 0;
462 double const_values[64];
463 const char * const_names[64];
464 int search_flags = (o->flags & AV_OPT_FLAG_CHILD_CONSTS) ? AV_OPT_SEARCH_CHILDREN : 0;
465 const AVOption *o_named = av_opt_find(target_obj, i ? buf : val, o->unit, 0, search_flags);
466 if (o_named && o_named->type == AV_OPT_TYPE_CONST) {
467 d = DEFAULT_NUMVAL(o_named);
468 if (o_named->flags & AV_OPT_FLAG_DEPRECATED)
469 av_log(logctx, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n",
470 o_named->name, o_named->help);
471 } else {
472 if (o->unit) {
473 for (o_named = NULL; o_named = av_opt_next(target_obj, o_named); ) {
474 if (o_named->type == AV_OPT_TYPE_CONST &&
475 o_named->unit &&
476 !strcmp(o_named->unit, o->unit)) {
477 if (ci + 6 >= FF_ARRAY_ELEMS(const_values)) {
478 av_log(logctx, AV_LOG_ERROR, "const_values array too small for %s\n", o->unit);
480 }
481 const_names [ci ] = o_named->name;
482 const_values[ci++] = DEFAULT_NUMVAL(o_named);
483 }
484 }
485 }
486 const_names [ci ] = "default";
487 const_values[ci++] = DEFAULT_NUMVAL(o);
488 const_names [ci ] = "max";
489 const_values[ci++] = o->max;
490 const_names [ci ] = "min";
491 const_values[ci++] = o->min;
492 const_names [ci ] = "none";
493 const_values[ci++] = 0;
494 const_names [ci ] = "all";
495 const_values[ci++] = ~0;
496 const_names [ci] = NULL;
497 const_values[ci] = 0;
498
499 res = av_expr_parse_and_eval(&d, i ? buf : val, const_names,
500 const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
501 if (res < 0) {
502 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\"\n", o->name, val);
503 return res;
504 }
505 }
506 }
507 if (type == AV_OPT_TYPE_FLAGS && dst) {
508 intnum = *(unsigned int*)dst;
509 if (cmd == '+')
510 d = intnum | (int64_t)d;
511 else if (cmd == '-')
512 d = intnum &~(int64_t)d;
513 }
514
515 if ((ret = write_number(obj, o, dst, d, 1, 1, 0)) < 0)
516 return ret;
517 val += i;
518 if (!i || !*val)
519 return 0;
520 }
521}
522
523static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
524{
525 void *logctx = dst ? obj : NULL;
526 int tmp[2];
527 int ret;
528
529 if (!val || !strcmp(val, "none")) {
530 if (dst) {
531 dst[0] =
532 dst[1] = 0;
533 }
534 return 0;
535 }
536 ret = av_parse_video_size(&tmp[0], &tmp[1], val);
537 if (ret < 0)
538 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as image size\n", o->name, val);
539 if (dst)
540 memcpy(dst, tmp, sizeof(tmp));
541 return ret;
542}
543
544static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
545{
546 void *logctx = dst ? obj : NULL;
548 int ret = av_parse_video_rate(&tmp, val);
549 if (ret < 0)
550 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as video rate\n", o->name, val);
551 if (dst)
552 *dst = tmp;
553 return ret;
554}
555
556static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
557{
558 void *logctx = dst ? obj : NULL;
559 int ret;
560
561 if (!val) {
562 return 0;
563 } else {
564 uint8_t tmp[4];
565 ret = av_parse_color(tmp, val, -1, obj);
566 if (ret < 0)
567 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as color\n", o->name, val);
568 if (dst)
569 memcpy(dst, tmp, sizeof(tmp));
570 return ret;
571 }
572 return 0;
573}
574
575static const char *get_bool_name(int val)
576{
577 if (val < 0)
578 return "auto";
579 return val ? "true" : "false";
580}
581
582static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
583{
584 void *logctx = dst ? obj : NULL;
585 int n;
586
587 if (!val)
588 return 0;
589
590 if (!strcmp(val, "auto")) {
591 n = -1;
592 } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
593 n = 1;
594 } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
595 n = 0;
596 } else {
597 char *end = NULL;
598 n = strtol(val, &end, 10);
599 if (val + strlen(val) != end)
600 goto fail;
601 }
602
603 if (n < o->min || n > o->max)
604 goto fail;
605
606 if (dst)
607 *dst = n;
608 return 0;
609
610fail:
611 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as boolean\n", o->name, val);
612 return AVERROR(EINVAL);
613}
614
615static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
616 int fmt_nb, int ((*get_fmt)(const char *)), const char *desc,
617 enum AVOptionType type)
618{
619 void *logctx = dst ? obj : NULL;
620 int fmt, min, max;
621
622 if (!val || !strcmp(val, "none")) {
623 fmt = -1;
624 } else {
625 fmt = get_fmt(val);
626 if (fmt == -1) {
627 char *tail;
628 fmt = strtol(val, &tail, 0);
629 if (*tail || (unsigned)fmt >= fmt_nb) {
630 av_log(logctx, AV_LOG_ERROR,
631 "Unable to parse \"%s\" option value \"%s\" as %s\n", o->name, val, desc);
632 return AVERROR(EINVAL);
633 }
634 }
635 }
636
637 min = FFMAX(o->min, -1);
638 max = FFMIN(o->max, fmt_nb-1);
639
640 // hack for compatibility with old ffmpeg
641 if(min == 0 && max == 0) {
642 min = -1;
643 max = fmt_nb-1;
644 }
645
646 if (fmt < min || fmt > max) {
647 av_log(logctx, AV_LOG_ERROR,
648 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
649 fmt, o->name, desc, min, max);
650 return AVERROR(ERANGE);
651 }
652
653 if (dst)
654 switch (type) {
655 case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = fmt; break;
656 case AV_OPT_TYPE_SAMPLE_FMT: *(enum AVSampleFormat*)dst = fmt; break;
657 default: av_unreachable("set_string_fmt() is only called for pixel and sample formats");
658 }
659 return 0;
660}
661
662static int get_pix_fmt(const char *name)
663{
664 return av_get_pix_fmt(name);
665}
666
667static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
668{
669 return set_string_fmt(obj, o, val, dst,
671 "pixel format", AV_OPT_TYPE_PIXEL_FMT);
672}
673
674static int get_sample_fmt(const char *name)
675{
676 return av_get_sample_fmt(name);
677}
678
679static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
680{
681 return set_string_fmt(obj, o, val, dst,
683 "sample format", AV_OPT_TYPE_SAMPLE_FMT);
684}
685
686static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
687{
689
690 if (val) {
691 int ret = av_dict_parse_string(&options, val, "=", ":", 0);
692 if (ret < 0) {
694 return ret;
695 }
696 }
697
698 if (!dst) {
700 return 0;
701 }
702
704 *dst = (uint8_t *)options;
705
706 return 0;
707}
708
709static int set_string_channel_layout(void *obj, const AVOption *o,
710 const char *val, void *dst)
711{
713 AVChannelLayout *channel_layout = dst;
714 int ret;
715 if (dst)
716 av_channel_layout_uninit(channel_layout);
717 else
718 channel_layout = &tmp;
719 if (!val)
720 return 0;
721 ret = av_channel_layout_from_string(channel_layout, val);
722 if (ret < 0)
723 return ret;
724 if (!dst)
725 av_channel_layout_uninit(channel_layout);
726 return 0;
727}
728
729static int opt_set_elem(void *obj, void *target_obj, const AVOption *o,
730 const char *val, void *dst)
731{
732 void *logctx = dst ? obj : NULL;
733 const enum AVOptionType type = TYPE_BASE(o->type);
734 int ret;
735
736 if (!val && (type != AV_OPT_TYPE_STRING &&
741 return AVERROR(EINVAL);
742
743 switch (type) {
744 case AV_OPT_TYPE_BOOL:
745 return set_string_bool(obj, o, val, dst);
747 return set_string(obj, o, val, dst);
749 return set_string_binary(obj, o, val, dst);
751 case AV_OPT_TYPE_INT:
752 case AV_OPT_TYPE_UINT:
758 return set_string_number(obj, target_obj, o, val, dst);
760 return set_string_image_size(obj, o, val, dst);
763 ret = set_string_video_rate(obj, o, val, &tmp);
764 if (ret < 0)
765 return ret;
766 return write_number(obj, o, dst, 1, tmp.den, tmp.num, 0);
767 }
769 return set_string_pixel_fmt(obj, o, val, dst);
771 return set_string_sample_fmt(obj, o, val, dst);
773 {
774 int64_t usecs = 0;
775 if (val) {
776 if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
777 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as duration\n", o->name, val);
778 return ret;
779 }
780 }
781 if (usecs < o->min || usecs > o->max) {
782 av_log(logctx, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
783 usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
784 return AVERROR(ERANGE);
785 }
786 if (dst)
787 *(int64_t *)dst = usecs;
788 return 0;
789 }
791 return set_string_color(obj, o, val, dst);
793 ret = set_string_channel_layout(obj, o, val, dst);
794 if (ret < 0) {
795 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as channel layout\n", o->name, val);
796 ret = AVERROR(EINVAL);
797 }
798 return ret;
799 case AV_OPT_TYPE_DICT:
800 return set_string_dict(obj, o, val, dst);
801 }
802
803 av_log(logctx, AV_LOG_ERROR, "Invalid option type.\n");
804 return AVERROR(EINVAL);
805}
806
807static int opt_set_array(void *obj, void *target_obj, const AVOption *o,
808 const char *val, void *dst)
809{
810 const AVOptionArrayDef *arr = o->default_val.arr;
811 const size_t elem_size = opt_type_desc[TYPE_BASE(o->type)].size;
812 const uint8_t sep = opt_array_sep(o);
813 uint8_t *str = NULL;
814
815 void *logctx = dst ? obj : NULL;
816 void *elems = NULL;
817 unsigned nb_elems = 0;
818 int ret;
819
820 if (val && *val) {
821 str = av_malloc(strlen(val) + 1);
822 if (!str)
823 return AVERROR(ENOMEM);
824 }
825
826 // split and unescape the string
827 while (val && *val) {
828 uint8_t *p = str;
829 void *tmp;
830
831 if (arr && arr->size_max && nb_elems >= arr->size_max) {
832 av_log(logctx, AV_LOG_ERROR,
833 "Cannot assign more than %u elements to array option %s\n",
834 arr->size_max, o->name);
835 ret = AVERROR(EINVAL);
836 goto fail;
837 }
838
839 for (; *val; val++, p++) {
840 if (*val == '\\' && val[1])
841 val++;
842 else if (*val == sep) {
843 val++;
844 break;
845 }
846 *p = *val;
847 }
848 *p = 0;
849
850 tmp = av_realloc_array(elems, nb_elems + 1, elem_size);
851 if (!tmp) {
852 ret = AVERROR(ENOMEM);
853 goto fail;
854 }
855 elems = tmp;
856
857 tmp = opt_array_pelem(o, elems, nb_elems);
858 memset(tmp, 0, elem_size);
859
860 ret = opt_set_elem(obj, target_obj, o, str, tmp);
861 if (ret < 0)
862 goto fail;
863 nb_elems++;
864 }
865 av_freep(&str);
866
867 if (dst)
869
870 if (arr && nb_elems < arr->size_min) {
871 av_log(logctx, AV_LOG_ERROR,
872 "Cannot assign fewer than %u elements to array option %s\n",
873 arr->size_min, o->name);
874 ret = AVERROR(EINVAL);
875 goto fail;
876 }
877
878 if (dst) {
879 *((void **)dst) = elems;
880 *opt_array_pcount(dst) = nb_elems;
881 } else
882 opt_free_array(o, &elems, &nb_elems);
883
884 return 0;
885fail:
886 av_freep(&str);
887 opt_free_array(o, &elems, &nb_elems);
888 return ret;
889}
890
891int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
892{
893 void *dst, *target_obj;
894 const AVOption *o;
895 int ret;
896
897 ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &dst);
898 if (ret < 0)
899 return ret;
900
901 return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
902 opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst);
903}
904
905#define OPT_EVAL_NUMBER(name, opttype, vartype) \
906int av_opt_eval_ ## name(void *obj, const AVOption *o, \
907 const char *val, vartype *name ## _out) \
908{ \
909 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
910 return AVERROR(EINVAL); \
911 return set_string_number(obj, obj, o, val, name ## _out); \
912}
913
916OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned)
919OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
921
922static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
923 int search_flags, int require_type)
924{
925 void *dst;
926 const AVOption *o;
927 int ret;
928
929 ret = opt_set_init(obj, name, search_flags, require_type, NULL, &o, &dst);
930 if (ret < 0)
931 return ret;
932 if (dst)
933 ret = write_number(obj, o, dst, num, den, intnum, 0);
934
935 return ret;
936}
937
938int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
939{
940 return set_number(obj, name, 1, 1, val, search_flags, 0);
941}
942
943int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
944{
945 return set_number(obj, name, val, 1, 1, search_flags, 0);
946}
947
948int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
949{
950 return set_number(obj, name, val.num, val.den, 1, search_flags, 0);
951}
952
953int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
954{
955 uint8_t *ptr;
956 uint8_t **dst;
957 int *lendst;
958 int ret;
959
960 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_BINARY,
961 NULL, NULL, (void**)&dst);
962 if (ret < 0)
963 return ret;
964
965 if (dst) {
966 ptr = len ? av_malloc(len) : NULL;
967 if (len && !ptr)
968 return AVERROR(ENOMEM);
969
970 lendst = (int *)(dst + 1);
971
972 av_free(*dst);
973 *dst = ptr;
974 *lendst = len;
975 if (len)
976 memcpy(ptr, val, len);
977 }
978
979 return 0;
980}
981
982int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
983{
984 const AVOption *o;
985 void *logctx;
986 int *dst;
987 int ret;
988
989 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_IMAGE_SIZE,
990 NULL, &o, (void**)&dst);
991 if (ret < 0)
992 return ret;
993
994 logctx = dst ? obj : NULL;
995
996 if (w<0 || h<0) {
997 av_log(logctx, AV_LOG_ERROR,
998 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
999 return AVERROR(EINVAL);
1000 }
1001
1002 if (dst) {
1003 dst[0] = w;
1004 dst[1] = h;
1005 }
1006
1007 return 0;
1008}
1009
1010int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
1011{
1012 return set_number(obj, name, val.num, val.den, 1, search_flags, AV_OPT_TYPE_VIDEO_RATE);
1013}
1014
1015static int set_format(void *obj, const char *name, int fmt, int search_flags,
1016 enum AVOptionType type, const char *desc, int nb_fmts)
1017{
1018 const AVOption *o;
1019 void *logctx;
1020 int *dst;
1021 int min, max, ret;
1022
1023 ret = opt_set_init(obj, name, search_flags, type, NULL, &o, (void**)&dst);
1024 if (ret < 0)
1025 return ret;
1026
1027 logctx = dst ? obj : NULL;
1028
1029 min = FFMAX(o->min, -1);
1030 max = FFMIN(o->max, nb_fmts-1);
1031
1032 if (fmt < min || fmt > max) {
1033 av_log(logctx, AV_LOG_ERROR,
1034 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
1035 fmt, name, desc, min, max);
1036 return AVERROR(ERANGE);
1037 }
1038 if (dst)
1039 *dst = fmt;
1040 return 0;
1041}
1042
1043int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
1044{
1045 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
1046}
1047
1048int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
1049{
1050 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
1051}
1052
1053int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
1054 int search_flags)
1055{
1056 AVDictionary **dst;
1057 int ret;
1058
1059 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_DICT, NULL, NULL,
1060 (void**)&dst);
1061 if (ret < 0)
1062 return ret;
1063
1064 if (dst) {
1066
1067 ret = av_dict_copy(dst, val, 0);
1068 }
1069
1070 return ret;
1071}
1072
1073int av_opt_set_chlayout(void *obj, const char *name,
1074 const AVChannelLayout *channel_layout,
1075 int search_flags)
1076{
1078 int ret;
1079
1080 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_CHLAYOUT, NULL, NULL,
1081 (void**)&dst);
1082 if (ret < 0)
1083 return ret;
1084
1085 if (dst)
1086 ret = av_channel_layout_copy(dst, channel_layout);
1087
1088 return ret;
1089}
1090
1091static void format_duration(char *buf, size_t size, int64_t d)
1092{
1093 char *e;
1094
1095 av_assert0(size >= 25);
1096 if (d < 0 && d != INT64_MIN) {
1097 *(buf++) = '-';
1098 size--;
1099 d = -d;
1100 }
1101 if (d == INT64_MAX)
1102 snprintf(buf, size, "INT64_MAX");
1103 else if (d == INT64_MIN)
1104 snprintf(buf, size, "INT64_MIN");
1105 else if (d > (int64_t)3600*1000000)
1106 snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
1107 (int)((d / 60000000) % 60),
1108 (int)((d / 1000000) % 60),
1109 (int)(d % 1000000));
1110 else if (d > 60*1000000)
1111 snprintf(buf, size, "%d:%02d.%06d",
1112 (int)(d / 60000000),
1113 (int)((d / 1000000) % 60),
1114 (int)(d % 1000000));
1115 else
1116 snprintf(buf, size, "%d.%06d",
1117 (int)(d / 1000000),
1118 (int)(d % 1000000));
1119 e = buf + strlen(buf);
1120 while (e > buf && e[-1] == '0')
1121 *(--e) = 0;
1122 if (e > buf && e[-1] == '.')
1123 *(--e) = 0;
1124}
1125
1126static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
1127 const void *dst, int search_flags)
1128{
1129 int ret;
1130
1131 switch (TYPE_BASE(o->type)) {
1132 case AV_OPT_TYPE_BOOL:
1133 ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
1134 break;
1135 case AV_OPT_TYPE_FLAGS:
1136 ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
1137 break;
1138 case AV_OPT_TYPE_INT:
1139 ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
1140 break;
1141 case AV_OPT_TYPE_UINT:
1142 ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst);
1143 break;
1144 case AV_OPT_TYPE_INT64:
1145 ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
1146 break;
1147 case AV_OPT_TYPE_UINT64:
1148 ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
1149 break;
1150 case AV_OPT_TYPE_FLOAT:
1151 ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
1152 break;
1153 case AV_OPT_TYPE_DOUBLE:
1154 ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
1155 break;
1158 ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
1159 break;
1160 case AV_OPT_TYPE_CONST:
1161 ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
1162 break;
1163 case AV_OPT_TYPE_STRING:
1164 if (*(uint8_t **)dst) {
1165 *pbuf = av_strdup(*(uint8_t **)dst);
1166 } else if (search_flags & AV_OPT_ALLOW_NULL) {
1167 *pbuf = NULL;
1168 return 0;
1169 } else {
1170 *pbuf = av_strdup("");
1171 }
1172 return *pbuf ? 0 : AVERROR(ENOMEM);
1173 case AV_OPT_TYPE_BINARY: {
1174 const uint8_t *bin;
1175 int len;
1176
1177 if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1178 *pbuf = NULL;
1179 return 0;
1180 }
1181 len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
1182 if ((uint64_t)len * 2 + 1 > INT_MAX)
1183 return AVERROR(EINVAL);
1184 if (!(*pbuf = av_malloc(len * 2 + 1)))
1185 return AVERROR(ENOMEM);
1186 if (!len) {
1187 *pbuf[0] = '\0';
1188 return 0;
1189 }
1190 bin = *(uint8_t **)dst;
1191 for (int i = 0; i < len; i++)
1192 snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
1193 return 0;
1194 }
1196 ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
1197 break;
1199 ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
1200 break;
1202 ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
1203 break;
1204 case AV_OPT_TYPE_DURATION: {
1205 int64_t i64 = *(int64_t *)dst;
1206 format_duration(*pbuf, buf_len, i64);
1207 ret = strlen(*pbuf); // no overflow possible, checked by an assert
1208 break;
1209 }
1210 case AV_OPT_TYPE_COLOR:
1211 ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
1212 (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
1213 (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
1214 break;
1216 ret = av_channel_layout_describe(dst, *pbuf, buf_len);
1217 break;
1218 case AV_OPT_TYPE_DICT:
1219 if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1220 *pbuf = NULL;
1221 return 0;
1222 }
1223 return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
1224 default:
1225 return AVERROR(EINVAL);
1226 }
1227
1228 return ret;
1229}
1230
1231static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
1232{
1233 const unsigned count = *opt_array_pcount(dst);
1234 const uint8_t sep = opt_array_sep(o);
1235
1236 uint8_t *str = NULL;
1237 size_t str_len = 0;
1238 int ret;
1239
1240 *out_val = NULL;
1241
1242 for (unsigned i = 0; i < count; i++) {
1243 uint8_t buf[128], *out = buf;
1244 size_t out_len;
1245
1246 ret = opt_get_elem(o, &out, sizeof(buf),
1247 opt_array_pelem(o, *(void **)dst, i), 0);
1248 if (ret < 0)
1249 goto fail;
1250
1251 out_len = strlen(out);
1252 if (out_len > SIZE_MAX / 2 - !!i ||
1253 !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
1254 ret = AVERROR(ERANGE);
1255 goto fail;
1256 }
1257
1258 // terminator escaping separator
1259 // ↓ ↓ ↓
1260 ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
1261 if (ret < 0)
1262 goto fail;
1263
1264 // add separator if needed
1265 if (i)
1266 str[str_len++] = sep;
1267
1268 // escape the element
1269 for (unsigned j = 0; j < out_len; j++) {
1270 uint8_t val = out[j];
1271 if (val == sep || val == '\\')
1272 str[str_len++] = '\\';
1273 str[str_len++] = val;
1274 }
1275 str[str_len] = 0;
1276
1277fail:
1278 if (out != buf)
1279 av_freep(&out);
1280 if (ret < 0) {
1281 av_freep(&str);
1282 return ret;
1283 }
1284 }
1285
1286 *out_val = str;
1287
1288 return 0;
1289}
1290
1291int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
1292{
1293 void *dst, *target_obj;
1294 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1295 uint8_t *out, buf[128];
1296 int ret;
1297
1298 if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
1300
1302 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
1303
1304 dst = (uint8_t *)target_obj + o->offset;
1305
1306 if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
1307 ret = opt_get_array(o, dst, out_val);
1308 if (ret < 0)
1309 return ret;
1310 if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) {
1311 *out_val = av_strdup("");
1312 if (!*out_val)
1313 return AVERROR(ENOMEM);
1314 }
1315 return 0;
1316 }
1317
1318 buf[0] = 0;
1319 out = buf;
1320 ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
1321 if (ret < 0)
1322 return ret;
1323 if (out != buf) {
1324 *out_val = out;
1325 return 0;
1326 }
1327
1328 if (ret >= sizeof(buf))
1329 return AVERROR(EINVAL);
1330 *out_val = av_strdup(out);
1331 return *out_val ? 0 : AVERROR(ENOMEM);
1332}
1333
1334static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
1335 int search_flags)
1336{
1337 void *dst, *target_obj;
1338 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1339 if (!o || !target_obj)
1342 return AVERROR(EINVAL);
1343
1344 dst = ((uint8_t *)target_obj) + o->offset;
1345
1346 return read_number(o, dst, num, den, intnum);
1347}
1348
1349int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
1350{
1351 int64_t intnum = 1;
1352 double num = 1;
1353 int ret, den = 1;
1354
1355 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1356 return ret;
1357 if (num == den)
1358 *out_val = intnum;
1359 else
1360 *out_val = num * intnum / den;
1361 return 0;
1362}
1363
1364int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
1365{
1366 int64_t intnum = 1;
1367 double num = 1;
1368 int ret, den = 1;
1369
1370 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1371 return ret;
1372 *out_val = num * intnum / den;
1373 return 0;
1374}
1375
1376int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1377{
1378 int64_t intnum = 1;
1379 double num = 1;
1380 int ret, den = 1;
1381
1382 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1383 return ret;
1384
1385 if (num == 1.0 && (int)intnum == intnum)
1386 *out_val = (AVRational){intnum, den};
1387 else
1388 *out_val = double_to_rational(num*intnum/den);
1389 return 0;
1390}
1391
1392int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1393{
1394 void *dst, *target_obj;
1395 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1396 if (!o || !target_obj)
1398 if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1399 av_log(obj, AV_LOG_ERROR,
1400 "The value for option '%s' is not a image size.\n", name);
1401 return AVERROR(EINVAL);
1402 }
1403
1404 dst = ((uint8_t*)target_obj) + o->offset;
1405 if (w_out) *w_out = *(int *)dst;
1406 if (h_out) *h_out = *((int *)dst+1);
1407 return 0;
1408}
1409
1410int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1411{
1412 return av_opt_get_q(obj, name, search_flags, out_val);
1413}
1414
1415static int get_format(void *obj, const char *name, int search_flags, void *out_fmt,
1416 enum AVOptionType type, const char *desc)
1417{
1418 void *dst, *target_obj;
1419 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1420 if (!o || !target_obj)
1422 if (o->type != type) {
1423 av_log(obj, AV_LOG_ERROR,
1424 "The value for option '%s' is not a %s format.\n", desc, name);
1425 return AVERROR(EINVAL);
1426 }
1427
1428 dst = ((uint8_t*)target_obj) + o->offset;
1430 *(enum AVPixelFormat *)out_fmt = *(enum AVPixelFormat *)dst;
1431 else
1432 *(enum AVSampleFormat*)out_fmt = *(enum AVSampleFormat*)dst;
1433
1434 return 0;
1435}
1436
1437int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1438{
1439 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1440}
1441
1442int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1443{
1444 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1445}
1446
1447int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1448{
1449 void *dst, *target_obj;
1450 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1451 if (!o || !target_obj)
1453 if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1454 av_log(obj, AV_LOG_ERROR,
1455 "The value for option '%s' is not a channel layout.\n", name);
1456 return AVERROR(EINVAL);
1457 }
1458
1459 dst = ((uint8_t*)target_obj) + o->offset;
1460 return av_channel_layout_copy(cl, dst);
1461}
1462
1463int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1464{
1465 void *target_obj;
1467 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1468
1469 if (!o || !target_obj)
1471 if (o->type != AV_OPT_TYPE_DICT)
1472 return AVERROR(EINVAL);
1473
1474 src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1475
1476 return av_dict_copy(out_val, src, 0);
1477}
1478
1479int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1480{
1481 const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1482 const AVOption *flag = av_opt_find(obj, flag_name,
1483 field ? field->unit : NULL, 0, 0);
1484 int64_t res;
1485
1486 if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1487 av_opt_get_int(obj, field_name, 0, &res) < 0)
1488 return 0;
1489 return res & flag->default_val.i64;
1490}
1491
1492static void log_int_value(void *av_log_obj, int level, int64_t i)
1493{
1494 if (i == INT_MAX) {
1495 av_log(av_log_obj, level, "INT_MAX");
1496 } else if (i == INT_MIN) {
1497 av_log(av_log_obj, level, "INT_MIN");
1498 } else if (i == UINT32_MAX) {
1499 av_log(av_log_obj, level, "UINT32_MAX");
1500 } else if (i == INT64_MAX) {
1501 av_log(av_log_obj, level, "I64_MAX");
1502 } else if (i == INT64_MIN) {
1503 av_log(av_log_obj, level, "I64_MIN");
1504 } else {
1505 av_log(av_log_obj, level, "%"PRId64, i);
1506 }
1507}
1508
1509static void log_value(void *av_log_obj, int level, double d)
1510{
1511 if (d == INT_MAX) {
1512 av_log(av_log_obj, level, "INT_MAX");
1513 } else if (d == INT_MIN) {
1514 av_log(av_log_obj, level, "INT_MIN");
1515 } else if (d == UINT32_MAX) {
1516 av_log(av_log_obj, level, "UINT32_MAX");
1517 } else if (d == (double)INT64_MAX) {
1518 av_log(av_log_obj, level, "I64_MAX");
1519 } else if (d == INT64_MIN) {
1520 av_log(av_log_obj, level, "I64_MIN");
1521 } else if (d == FLT_MAX) {
1522 av_log(av_log_obj, level, "FLT_MAX");
1523 } else if (d == FLT_MIN) {
1524 av_log(av_log_obj, level, "FLT_MIN");
1525 } else if (d == -FLT_MAX) {
1526 av_log(av_log_obj, level, "-FLT_MAX");
1527 } else if (d == -FLT_MIN) {
1528 av_log(av_log_obj, level, "-FLT_MIN");
1529 } else if (d == DBL_MAX) {
1530 av_log(av_log_obj, level, "DBL_MAX");
1531 } else if (d == DBL_MIN) {
1532 av_log(av_log_obj, level, "DBL_MIN");
1533 } else if (d == -DBL_MAX) {
1534 av_log(av_log_obj, level, "-DBL_MAX");
1535 } else if (d == -DBL_MIN) {
1536 av_log(av_log_obj, level, "-DBL_MIN");
1537 } else {
1538 av_log(av_log_obj, level, "%g", d);
1539 }
1540}
1541
1542static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1543{
1544 const AVOption *opt = NULL;
1545
1546 if (!unit)
1547 return NULL;
1548 while ((opt = av_opt_next(obj, opt)))
1549 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1550 opt->default_val.i64 == value)
1551 return opt->name;
1552 return NULL;
1553}
1554
1555static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1556{
1557 const AVOption *opt = NULL;
1558 char flags[512];
1559
1560 flags[0] = 0;
1561 if (!unit)
1562 return NULL;
1563 while ((opt = av_opt_next(obj, opt))) {
1564 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1565 opt->default_val.i64 & value) {
1566 if (flags[0])
1567 av_strlcatf(flags, sizeof(flags), "+");
1568 av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1569 }
1570 }
1571 if (flags[0])
1572 return av_strdup(flags);
1573 return NULL;
1574}
1575
1576static void log_type(void *av_log_obj, const AVOption *o,
1577 enum AVOptionType parent_type)
1578{
1579 const enum AVOptionType type = TYPE_BASE(o->type);
1580
1581 if (o->type == AV_OPT_TYPE_CONST && (TYPE_BASE(parent_type) == AV_OPT_TYPE_INT || TYPE_BASE(parent_type) == AV_OPT_TYPE_INT64))
1582 av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
1585 av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", opt_type_desc[type].name);
1586 else
1587 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", opt_type_desc[type].name);
1588 }
1589 else
1590 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1591}
1592
1593static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
1594{
1595 if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY)
1596 return;
1597 if ((opt->type == AV_OPT_TYPE_COLOR ||
1598 opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1599 opt->type == AV_OPT_TYPE_STRING ||
1600 opt->type == AV_OPT_TYPE_DICT ||
1601 opt->type == AV_OPT_TYPE_CHLAYOUT ||
1602 opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1603 !opt->default_val.str)
1604 return;
1605
1606 if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1607 const AVOptionArrayDef *arr = opt->default_val.arr;
1608 if (arr && arr->def)
1609 av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def);
1610 return;
1611 }
1612
1613 av_log(av_log_obj, AV_LOG_INFO, " (default ");
1614 switch (opt->type) {
1615 case AV_OPT_TYPE_BOOL:
1616 av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64));
1617 break;
1618 case AV_OPT_TYPE_FLAGS: {
1619 char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1620 if (def_flags) {
1621 av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1622 av_freep(&def_flags);
1623 } else {
1624 av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1625 }
1626 break;
1627 }
1628 case AV_OPT_TYPE_DURATION: {
1629 char buf[25];
1630 format_duration(buf, sizeof(buf), opt->default_val.i64);
1631 av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1632 break;
1633 }
1634 case AV_OPT_TYPE_UINT:
1635 case AV_OPT_TYPE_INT:
1636 case AV_OPT_TYPE_UINT64:
1637 case AV_OPT_TYPE_INT64: {
1638 const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1639 if (def_const)
1640 av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1641 else
1642 log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1643 break;
1644 }
1645 case AV_OPT_TYPE_DOUBLE:
1646 case AV_OPT_TYPE_FLOAT:
1647 log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1648 break;
1649 case AV_OPT_TYPE_RATIONAL: {
1650 AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1651 av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1652 break;
1654 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1655 break;
1657 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1658 break;
1659 case AV_OPT_TYPE_COLOR:
1661 case AV_OPT_TYPE_STRING:
1662 case AV_OPT_TYPE_DICT:
1665 av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1666 break;
1667 }
1668 av_log(av_log_obj, AV_LOG_INFO, ")");
1669}
1670
1671static void opt_list(void *obj, void *av_log_obj, const char *unit,
1672 int req_flags, int rej_flags, enum AVOptionType parent_type)
1673{
1674 const AVOption *opt = NULL;
1676 int i;
1677
1678 while ((opt = av_opt_next(obj, opt))) {
1679 if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1680 continue;
1681
1682 /* Don't print CONST's on level one.
1683 * Don't print anything but CONST's on level two.
1684 * Only print items from the requested unit.
1685 */
1686 if (!unit && opt->type == AV_OPT_TYPE_CONST)
1687 continue;
1688 else if (unit && opt->type != AV_OPT_TYPE_CONST)
1689 continue;
1690 else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1691 continue;
1692 else if (unit && opt->type == AV_OPT_TYPE_CONST)
1693 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1694 else
1695 av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1696 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1697 opt->name);
1698
1699 log_type(av_log_obj, opt, parent_type);
1700
1701 av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1702 (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1703 (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1704 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1705 (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1706 (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1707 (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1708 (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1709 (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1710 (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1711 (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1712 (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1713
1714 if (opt->help)
1715 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1716
1717 if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
1718 switch (opt->type) {
1719 case AV_OPT_TYPE_INT:
1720 case AV_OPT_TYPE_UINT:
1721 case AV_OPT_TYPE_INT64:
1722 case AV_OPT_TYPE_UINT64:
1723 case AV_OPT_TYPE_DOUBLE:
1724 case AV_OPT_TYPE_FLOAT:
1726 for (i = 0; i < r->nb_ranges; i++) {
1727 av_log(av_log_obj, AV_LOG_INFO, " (from ");
1728 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1729 av_log(av_log_obj, AV_LOG_INFO, " to ");
1730 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1731 av_log(av_log_obj, AV_LOG_INFO, ")");
1732 }
1733 break;
1734 }
1736 }
1737
1738 log_default(obj, av_log_obj, opt);
1739
1740 av_log(av_log_obj, AV_LOG_INFO, "\n");
1741 if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1742 opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1743 }
1744}
1745
1746int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1747{
1748 if (!obj)
1749 return -1;
1750
1751 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1752
1753 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1754
1755 return 0;
1756}
1757
1759{
1760 av_opt_set_defaults2(s, 0, 0);
1761}
1762
1763void av_opt_set_defaults2(void *s, int mask, int flags)
1764{
1765 const AVOption *opt = NULL;
1766 while ((opt = av_opt_next(s, opt))) {
1767 void *dst = ((uint8_t*)s) + opt->offset;
1768
1769 if ((opt->flags & mask) != flags)
1770 continue;
1771
1772 if (opt->flags & AV_OPT_FLAG_READONLY)
1773 continue;
1774
1775 if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1776 const AVOptionArrayDef *arr = opt->default_val.arr;
1777 const char sep = opt_array_sep(opt);
1778
1779 av_assert0(sep && sep != '\\' &&
1780 (sep < 'a' || sep > 'z') &&
1781 (sep < 'A' || sep > 'Z') &&
1782 (sep < '0' || sep > '9'));
1783
1784 if (arr && arr->def)
1785 opt_set_array(s, s, opt, arr->def, dst);
1786
1787 continue;
1788 }
1789
1790 switch (opt->type) {
1791 case AV_OPT_TYPE_CONST:
1792 /* Nothing to be done here */
1793 break;
1794 case AV_OPT_TYPE_BOOL:
1795 case AV_OPT_TYPE_FLAGS:
1796 case AV_OPT_TYPE_INT:
1797 case AV_OPT_TYPE_UINT:
1798 case AV_OPT_TYPE_INT64:
1799 case AV_OPT_TYPE_UINT64:
1803 write_number(s, opt, dst, 1, 1, opt->default_val.i64, 1);
1804 break;
1805 case AV_OPT_TYPE_DOUBLE:
1806 case AV_OPT_TYPE_FLOAT: {
1807 double val;
1808 val = opt->default_val.dbl;
1809 write_number(s, opt, dst, val, 1, 1, 1);
1810 }
1811 break;
1812 case AV_OPT_TYPE_RATIONAL: {
1814 val = av_d2q(opt->default_val.dbl, INT_MAX);
1815 write_number(s, opt, dst, 1, val.den, val.num, 1);
1816 }
1817 break;
1818 case AV_OPT_TYPE_COLOR:
1819 set_string_color(s, opt, opt->default_val.str, dst);
1820 break;
1821 case AV_OPT_TYPE_STRING:
1822 set_string(s, opt, opt->default_val.str, dst);
1823 break;
1826 break;
1829 break;
1830 case AV_OPT_TYPE_BINARY:
1831 set_string_binary(s, opt, opt->default_val.str, dst);
1832 break;
1835 break;
1836 case AV_OPT_TYPE_DICT:
1837 set_string_dict(s, opt, opt->default_val.str, dst);
1838 break;
1839 default:
1840 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1841 opt->type, opt->name);
1842 }
1843 }
1844}
1845
1846/**
1847 * Store the value in the field in ctx that is named like key.
1848 * ctx must be an AVClass context, storing is done using AVOptions.
1849 *
1850 * @param buf the string to parse, buf will be updated to point at the
1851 * separator just after the parsed key/value pair
1852 * @param key_val_sep a 0-terminated list of characters used to
1853 * separate key from value
1854 * @param pairs_sep a 0-terminated list of characters used to separate
1855 * two pairs from each other
1856 * @return 0 if the key/value pair has been successfully parsed and
1857 * set, or a negative value corresponding to an AVERROR code in case
1858 * of error:
1859 * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1860 * the error code issued by av_opt_set() if the key/value pair
1861 * cannot be set
1862 */
1863static int parse_key_value_pair(void *ctx, const char **buf,
1864 const char *key_val_sep, const char *pairs_sep)
1865{
1866 char *key = av_get_token(buf, key_val_sep);
1867 char *val;
1868 int ret;
1869
1870 if (!key)
1871 return AVERROR(ENOMEM);
1872
1873 if (*key && strspn(*buf, key_val_sep)) {
1874 (*buf)++;
1875 val = av_get_token(buf, pairs_sep);
1876 if (!val) {
1877 av_freep(&key);
1878 return AVERROR(ENOMEM);
1879 }
1880 } else {
1881 av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1882 av_free(key);
1883 return AVERROR(EINVAL);
1884 }
1885
1886 av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1887
1889 if (ret == AVERROR_OPTION_NOT_FOUND)
1890 av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1891
1892 av_free(key);
1893 av_free(val);
1894 return ret;
1895}
1896
1897int av_set_options_string(void *ctx, const char *opts,
1898 const char *key_val_sep, const char *pairs_sep)
1899{
1900 int ret, count = 0;
1901
1902 if (!opts)
1903 return 0;
1904
1905 while (*opts) {
1906 if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1907 return ret;
1908 count++;
1909
1910 if (*opts)
1911 opts++;
1912 }
1913
1914 return count;
1915}
1916
1917#define WHITESPACES " \n\t\r"
1918
1919static int is_key_char(char c)
1920{
1921 return (unsigned)((c | 32) - 'a') < 26 ||
1922 (unsigned)(c - '0') < 10 ||
1923 c == '-' || c == '_' || c == '/' || c == '.';
1924}
1925
1926/**
1927 * Read a key from a string.
1928 *
1929 * The key consists of is_key_char characters and must be terminated by a
1930 * character from the delim string; spaces are ignored.
1931 *
1932 * @return 0 for success (even with ellipsis), <0 for failure
1933 */
1934static int get_key(const char **ropts, const char *delim, char **rkey)
1935{
1936 const char *opts = *ropts;
1937 const char *key_start, *key_end;
1938
1939 key_start = opts += strspn(opts, WHITESPACES);
1940 while (is_key_char(*opts))
1941 opts++;
1942 key_end = opts;
1943 opts += strspn(opts, WHITESPACES);
1944 if (!*opts || !strchr(delim, *opts))
1945 return AVERROR(EINVAL);
1946 opts++;
1947 if (!(*rkey = av_malloc(key_end - key_start + 1)))
1948 return AVERROR(ENOMEM);
1949 memcpy(*rkey, key_start, key_end - key_start);
1950 (*rkey)[key_end - key_start] = 0;
1951 *ropts = opts;
1952 return 0;
1953}
1954
1955int av_opt_get_key_value(const char **ropts,
1956 const char *key_val_sep, const char *pairs_sep,
1957 unsigned flags,
1958 char **rkey, char **rval)
1959{
1960 int ret;
1961 char *key = NULL, *val;
1962 const char *opts = *ropts;
1963
1964 if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1966 return AVERROR(EINVAL);
1967 if (!(val = av_get_token(&opts, pairs_sep))) {
1968 av_free(key);
1969 return AVERROR(ENOMEM);
1970 }
1971 *ropts = opts;
1972 *rkey = key;
1973 *rval = val;
1974 return 0;
1975}
1976
1977int av_opt_set_from_string(void *ctx, const char *opts,
1978 const char *const *shorthand,
1979 const char *key_val_sep, const char *pairs_sep)
1980{
1981 int ret, count = 0;
1982 const char *dummy_shorthand = NULL;
1983 const char *key;
1984
1985 if (!opts)
1986 return 0;
1987 if (!shorthand)
1988 shorthand = &dummy_shorthand;
1989
1990 while (*opts) {
1991 char *parsed_key, *value;
1992 ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
1993 *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
1994 &parsed_key, &value);
1995 if (ret < 0) {
1996 if (ret == AVERROR(EINVAL))
1997 av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
1998 else
1999 av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
2000 av_err2str(ret));
2001 return ret;
2002 }
2003 if (*opts)
2004 opts++;
2005 if (parsed_key) {
2006 key = parsed_key;
2007 while (*shorthand) /* discard all remaining shorthand */
2008 shorthand++;
2009 } else {
2010 key = *(shorthand++);
2011 }
2012
2013 av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
2014 if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
2015 if (ret == AVERROR_OPTION_NOT_FOUND)
2016 av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
2017 av_free(value);
2018 av_free(parsed_key);
2019 return ret;
2020 }
2021
2022 av_free(value);
2023 av_free(parsed_key);
2024 count++;
2025 }
2026 return count;
2027}
2028
2029void av_opt_free(void *obj)
2030{
2031 const AVOption *o = NULL;
2032 while ((o = av_opt_next(obj, o))) {
2033 void *pitem = (uint8_t *)obj + o->offset;
2034
2036 opt_free_array(o, pitem, opt_array_pcount(pitem));
2037 else
2038 opt_free_elem(o->type, pitem);
2039 }
2040}
2041
2042int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
2043{
2044 const AVDictionaryEntry *t = NULL;
2046 int ret;
2047
2048 if (!options)
2049 return 0;
2050
2051 while ((t = av_dict_iterate(*options, t))) {
2052 ret = av_opt_set(obj, t->key, t->value, search_flags);
2053 if (ret == AVERROR_OPTION_NOT_FOUND)
2054 ret = av_dict_set(&tmp, t->key, t->value, AV_DICT_MULTIKEY);
2055 if (ret < 0) {
2056 av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
2057 av_dict_free(&tmp);
2058 return ret;
2059 }
2060 }
2062 *options = tmp;
2063 return 0;
2064}
2065
2067{
2068 return av_opt_set_dict2(obj, options, 0);
2069}
2070
2071const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
2072 int opt_flags, int search_flags)
2073{
2074 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
2075}
2076
2077const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
2078 int opt_flags, int search_flags, void **target_obj)
2079{
2080 const AVClass *c;
2081 const AVOption *o = NULL;
2082
2083 if(!obj)
2084 return NULL;
2085
2086 c= *(AVClass**)obj;
2087
2088 if (!c)
2089 return NULL;
2090
2091 if (search_flags & AV_OPT_SEARCH_CHILDREN) {
2092 if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
2093 void *iter = NULL;
2094 const AVClass *child;
2095 while (child = av_opt_child_class_iterate(c, &iter))
2096 if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
2097 return o;
2098 } else {
2099 void *child = NULL;
2100 while (child = av_opt_child_next(obj, child))
2101 if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
2102 return o;
2103 }
2104 }
2105
2106 while (o = av_opt_next(obj, o)) {
2107 if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
2108 ((!unit && o->type != AV_OPT_TYPE_CONST) ||
2109 (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
2110 if (target_obj) {
2111 if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
2112 *target_obj = obj;
2113 else
2114 *target_obj = NULL;
2115 }
2116 return o;
2117 }
2118 }
2119 return NULL;
2120}
2121
2122void *av_opt_child_next(void *obj, void *prev)
2123{
2124 const AVClass *c = *(AVClass **)obj;
2125 if (c->child_next)
2126 return c->child_next(obj, prev);
2127 return NULL;
2128}
2129
2130const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
2131{
2132 if (parent->child_class_iterate)
2133 return parent->child_class_iterate(iter);
2134 return NULL;
2135}
2136
2137static int opt_copy_elem(void *logctx, enum AVOptionType type,
2138 void *dst, const void *src)
2139{
2140 if (type == AV_OPT_TYPE_STRING) {
2141 const char *src_str = *(const char *const *)src;
2142 char **dstp = (char **)dst;
2143 if (*dstp != src_str)
2144 av_freep(dstp);
2145 if (src_str) {
2146 *dstp = av_strdup(src_str);
2147 if (!*dstp)
2148 return AVERROR(ENOMEM);
2149 }
2150 } else if (type == AV_OPT_TYPE_BINARY) {
2151 const uint8_t *const *src8 = (const uint8_t *const *)src;
2152 uint8_t **dst8 = (uint8_t **)dst;
2153 int len = *(const int *)(src8 + 1);
2154 if (*dst8 != *src8)
2155 av_freep(dst8);
2156 *dst8 = av_memdup(*src8, len);
2157 if (len && !*dst8) {
2158 *(int *)(dst8 + 1) = 0;
2159 return AVERROR(ENOMEM);
2160 }
2161 *(int *)(dst8 + 1) = len;
2162 } else if (type == AV_OPT_TYPE_CONST) {
2163 // do nothing
2164 } else if (type == AV_OPT_TYPE_DICT) {
2165 const AVDictionary *sdict = *(const AVDictionary * const *)src;
2166 AVDictionary **ddictp = (AVDictionary **)dst;
2167 if (sdict != *ddictp)
2168 av_dict_free(ddictp);
2169 *ddictp = NULL;
2170 return av_dict_copy(ddictp, sdict, 0);
2171 } else if (type == AV_OPT_TYPE_CHLAYOUT) {
2172 if (dst != src)
2174 } else if (opt_is_pod(type)) {
2175 size_t size = opt_type_desc[type].size;
2176 memcpy(dst, src, size);
2177 } else {
2178 av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type);
2179 return AVERROR(EINVAL);
2180 }
2181
2182 return 0;
2183}
2184
2185static int opt_copy_array(void *logctx, const AVOption *o,
2186 void **pdst, const void * const *psrc)
2187{
2188 unsigned nb_elems = *opt_array_pcount(psrc);
2189 void *dst = NULL;
2190 int ret;
2191
2192 if (*pdst == *psrc) {
2193 *pdst = NULL;
2194 *opt_array_pcount(pdst) = 0;
2195 }
2196
2197 opt_free_array(o, pdst, opt_array_pcount(pdst));
2198
2199 dst = av_calloc(nb_elems, opt_type_desc[TYPE_BASE(o->type)].size);
2200 if (!dst)
2201 return AVERROR(ENOMEM);
2202
2203 for (unsigned i = 0; i < nb_elems; i++) {
2204 ret = opt_copy_elem(logctx, TYPE_BASE(o->type),
2205 opt_array_pelem(o, dst, i),
2206 opt_array_pelem(o, *(void**)psrc, i));
2207 if (ret < 0) {
2208 opt_free_array(o, &dst, &nb_elems);
2209 return ret;
2210 }
2211 }
2212
2213 *pdst = dst;
2214 *opt_array_pcount(pdst) = nb_elems;
2215
2216 return 0;
2217}
2218
2219int av_opt_copy(void *dst, const void *src)
2220{
2221 const AVOption *o = NULL;
2222 const AVClass *c;
2223 int ret = 0;
2224
2225 if (!src)
2226 return AVERROR(EINVAL);
2227
2228 c = *(AVClass **)src;
2229 if (!c || c != *(AVClass **)dst)
2230 return AVERROR(EINVAL);
2231
2232 while ((o = av_opt_next(src, o))) {
2233 void *field_dst = (uint8_t *)dst + o->offset;
2234 void *field_src = (uint8_t *)src + o->offset;
2235
2236 int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
2237 opt_copy_array(dst, o, field_dst, field_src) :
2238 opt_copy_elem (dst, o->type, field_dst, field_src);
2239 if (err < 0)
2240 ret = err;
2241 }
2242 return ret;
2243}
2244
2245int av_opt_get_array_size(void *obj, const char *name, int search_flags,
2246 unsigned int *out_val)
2247{
2248 void *target_obj, *parray;
2249 const AVOption *o;
2250
2251 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
2252 if (!o || !target_obj)
2254 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY))
2255 return AVERROR(EINVAL);
2256
2257 parray = (uint8_t *)target_obj + o->offset;
2258 *out_val = *opt_array_pcount(parray);
2259
2260 return 0;
2261}
2262
2263int av_opt_get_array(void *obj, const char *name, int search_flags,
2264 unsigned int start_elem, unsigned int nb_elems,
2265 enum AVOptionType out_type, void *out_val)
2266{
2267 const size_t elem_size_out = opt_type_desc[TYPE_BASE(out_type)].size;
2268
2269 const AVOption *o;
2270 void *target_obj;
2271
2272 const void *parray;
2273 unsigned array_size;
2274
2275 int ret;
2276
2277 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
2278 if (!o || !target_obj)
2280 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) ||
2281 (out_type & AV_OPT_TYPE_FLAG_ARRAY))
2282 return AVERROR(EINVAL);
2283
2284 parray = (uint8_t *)target_obj + o->offset;
2285 array_size = *opt_array_pcount(parray);
2286
2287 if (start_elem >= array_size ||
2288 array_size - start_elem < nb_elems)
2289 return AVERROR(EINVAL);
2290
2291 for (unsigned i = 0; i < nb_elems; i++) {
2292 const void *src = opt_array_pelem(o, *(void**)parray, start_elem + i);
2293 void *dst = (uint8_t*)out_val + i * elem_size_out;
2294
2295 if (out_type == TYPE_BASE(o->type)) {
2296 ret = opt_copy_elem(obj, out_type, dst, src);
2297 if (ret < 0)
2298 goto fail;
2299 } else if (out_type == AV_OPT_TYPE_STRING) {
2300 uint8_t buf[128], *out = buf;
2301
2302 ret = opt_get_elem(o, &out, sizeof(buf), src, search_flags);
2303 if (ret < 0)
2304 goto fail;
2305
2306 if (out == buf) {
2307 out = av_strdup(buf);
2308 if (!out) {
2309 ret = AVERROR(ENOMEM);
2310 goto fail;
2311 }
2312 }
2313
2314 *(uint8_t**)dst = out;
2315 } else if (out_type == AV_OPT_TYPE_INT64 ||
2316 out_type == AV_OPT_TYPE_DOUBLE ||
2317 out_type == AV_OPT_TYPE_RATIONAL) {
2318 double num = 1.0;
2319 int den = 1;
2320 int64_t intnum = 1;
2321
2322 ret = read_number(o, src, &num, &den, &intnum);
2323 if (ret < 0)
2324 goto fail;
2325
2326 switch (out_type) {
2327 case AV_OPT_TYPE_INT64:
2328 *(int64_t*)dst = (num == den) ? intnum : num * intnum / den;
2329 break;
2330 case AV_OPT_TYPE_DOUBLE:
2331 *(double*)dst = num * intnum / den;
2332 break;
2334 *(AVRational*)dst = (num == 1.0 && (int)intnum == intnum) ?
2335 (AVRational){ intnum, den } :
2336 double_to_rational(num * intnum / den);
2337 break;
2338 default: av_assert0(0);
2339 }
2340 } else
2341 return AVERROR(ENOSYS);
2342 }
2343
2344 return 0;
2345fail:
2346 for (unsigned i = 0; i < nb_elems; i++)
2347 opt_free_elem(out_type, (uint8_t*)out_val + i * elem_size_out);
2348 return ret;
2349}
2350
2351int av_opt_set_array(void *obj, const char *name, int search_flags,
2352 unsigned int start_elem, unsigned int nb_elems,
2353 enum AVOptionType val_type, const void *val)
2354{
2355 const size_t elem_size_val = opt_type_desc[TYPE_BASE(val_type)].size;
2356
2357 const AVOption *o;
2358 const AVOptionArrayDef *arr;
2359 void *target_obj;
2360
2361 void *parray;
2362 void *new_elems;
2363 unsigned *array_size, new_size;
2364 size_t elem_size;
2365
2366 int ret = 0;
2367
2368 ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &parray);
2369 if (ret < 0)
2370 return ret;
2371
2372 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) ||
2373 (val_type & AV_OPT_TYPE_FLAG_ARRAY))
2374 return AVERROR(EINVAL);
2375
2376 arr = o->default_val.arr;
2377 array_size = opt_array_pcount(parray);
2378 elem_size = opt_type_desc[TYPE_BASE(o->type)].size;
2379
2380 if (start_elem > *array_size)
2381 return AVERROR(EINVAL);
2382
2383 // compute new array size
2384 if (!val) {
2385 if (*array_size - start_elem < nb_elems)
2386 return AVERROR(EINVAL);
2387
2388 new_size = *array_size - nb_elems;
2389 } else if (search_flags & AV_OPT_ARRAY_REPLACE) {
2390 if (start_elem >= UINT_MAX - nb_elems)
2391 return AVERROR(EINVAL);
2392
2393 new_size = FFMAX(*array_size, start_elem + nb_elems);
2394 } else {
2395 if (nb_elems >= UINT_MAX - *array_size)
2396 return AVERROR(EINVAL);
2397
2398 new_size = *array_size + nb_elems;
2399 }
2400
2401 if (arr &&
2402 ((arr->size_max && new_size > arr->size_max) ||
2403 (arr->size_min && new_size < arr->size_min)))
2404 return AVERROR(EINVAL);
2405
2406 // desired operation is shrinking the array
2407 if (!val) {
2408 void *array = *(void**)parray;
2409
2410 for (unsigned i = 0; i < nb_elems; i++) {
2412 opt_array_pelem(o, array, start_elem + i));
2413 }
2414
2415 if (new_size > 0) {
2416 memmove(opt_array_pelem(o, array, start_elem),
2417 opt_array_pelem(o, array, start_elem + nb_elems),
2418 elem_size * (*array_size - start_elem - nb_elems));
2419
2420 array = av_realloc_array(array, new_size, elem_size);
2421 if (!array)
2422 return AVERROR(ENOMEM);
2423
2424 *(void**)parray = array;
2425 } else
2426 av_freep(parray);
2427
2428 *array_size = new_size;
2429
2430 return 0;
2431 }
2432
2433 // otherwise, desired operation is insert/replace;
2434 // first, store new elements in a separate array to simplify
2435 // rollback on failure
2436 new_elems = av_calloc(nb_elems, elem_size);
2437 if (!new_elems)
2438 return AVERROR(ENOMEM);
2439
2440 // convert/validate each new element
2441 for (unsigned i = 0; i < nb_elems; i++) {
2442 void *dst = opt_array_pelem(o, new_elems, i);
2443 const void *src = (uint8_t*)val + i * elem_size_val;
2444
2445 double num = 1.0;
2446 int den = 1;
2447 int64_t intnum = 1;
2448
2449 if (val_type == TYPE_BASE(o->type)) {
2450 int err;
2451
2452 ret = opt_copy_elem(obj, val_type, dst, src);
2453 if (ret < 0)
2454 goto fail;
2455
2456 // validate the range for numeric options
2457 err = read_number(o, dst, &num, &den, &intnum);
2458 if (err >= 0 && TYPE_BASE(o->type) != AV_OPT_TYPE_FLAGS &&
2459 (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
2460 num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
2461 av_log(obj, AV_LOG_ERROR, "Cannot set array element %u for "
2462 "parameter '%s': value %f out of range [%g - %g]\n",
2463 start_elem + i, o->name, num, o->min, o->max);
2464 ret = AVERROR(ERANGE);
2465 goto fail;
2466 }
2467 } else if (val_type == AV_OPT_TYPE_STRING) {
2468 ret = opt_set_elem(obj, target_obj, o, *(const char **)src, dst);
2469 if (ret < 0)
2470 goto fail;
2471 } else if (val_type == AV_OPT_TYPE_INT ||
2472 val_type == AV_OPT_TYPE_INT64 ||
2473 val_type == AV_OPT_TYPE_FLOAT ||
2474 val_type == AV_OPT_TYPE_DOUBLE ||
2475 val_type == AV_OPT_TYPE_RATIONAL) {
2476
2477 switch (val_type) {
2478 case AV_OPT_TYPE_INT: intnum = *(int*)src; break;
2479 case AV_OPT_TYPE_INT64: intnum = *(int64_t*)src; break;
2480 case AV_OPT_TYPE_FLOAT: num = *(float*)src; break;
2481 case AV_OPT_TYPE_DOUBLE: num = *(double*)src; break;
2482 case AV_OPT_TYPE_RATIONAL: intnum = ((AVRational*)src)->num;
2483 den = ((AVRational*)src)->den; break;
2484 default: av_assert0(0);
2485 }
2486
2487 ret = write_number(obj, o, dst, num, den, intnum, 0);
2488 if (ret < 0)
2489 goto fail;
2490 } else {
2491 ret = AVERROR(ENOSYS);
2492 goto fail;
2493 }
2494 }
2495
2496 // commit new elements to the array
2497 if (start_elem == 0 && nb_elems == new_size) {
2498 // replacing the existing array entirely
2499 opt_free_array(o, parray, array_size);
2500 *(void**)parray = new_elems;
2501 *array_size = nb_elems;
2502
2503 new_elems = NULL;
2504 nb_elems = 0;
2505 } else {
2506 void *array = av_realloc_array(*(void**)parray, new_size, elem_size);
2507 if (!array) {
2508 ret = AVERROR(ENOMEM);
2509 goto fail;
2510 }
2511
2512 if (search_flags & AV_OPT_ARRAY_REPLACE) {
2513 // free the elements being overwritten
2514 for (unsigned i = start_elem; i < FFMIN(start_elem + nb_elems, *array_size); i++)
2516 } else {
2517 // shift existing elements to the end
2518 memmove(opt_array_pelem(o, array, start_elem + nb_elems),
2519 opt_array_pelem(o, array, start_elem),
2520 elem_size * (*array_size - start_elem));
2521 }
2522
2523 memcpy((uint8_t*)array + elem_size * start_elem, new_elems, elem_size * nb_elems);
2524
2525 av_freep(&new_elems);
2526 nb_elems = 0;
2527
2528 *(void**)parray = array;
2529 *array_size = new_size;
2530 }
2531
2532fail:
2533 opt_free_array(o, &new_elems, &nb_elems);
2534
2535 return ret;
2536}
2537
2538int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2539{
2540 int ret;
2541 const AVClass *c = *(AVClass**)obj;
2542 int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
2543
2544 if (!callback)
2546
2547 ret = callback(ranges_arg, obj, key, flags);
2548 if (ret >= 0) {
2550 ret = 1;
2551 (*ranges_arg)->nb_components = ret;
2552 }
2553 return ret;
2554}
2555
2556int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2557{
2558 AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
2559 AVOptionRange **range_array = av_mallocz(sizeof(void*));
2560 AVOptionRange *range = av_mallocz(sizeof(*range));
2561 const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
2562 int ret;
2563
2564 *ranges_arg = NULL;
2565
2566 if (!ranges || !range || !range_array || !field) {
2567 ret = AVERROR(ENOMEM);
2568 goto fail;
2569 }
2570
2571 ranges->range = range_array;
2572 ranges->range[0] = range;
2573 ranges->nb_ranges = 1;
2574 ranges->nb_components = 1;
2575 range->is_range = 1;
2576 range->value_min = field->min;
2577 range->value_max = field->max;
2578
2579 switch (field->type) {
2580 case AV_OPT_TYPE_BOOL:
2581 case AV_OPT_TYPE_INT:
2582 case AV_OPT_TYPE_UINT:
2583 case AV_OPT_TYPE_INT64:
2584 case AV_OPT_TYPE_UINT64:
2587 case AV_OPT_TYPE_FLOAT:
2588 case AV_OPT_TYPE_DOUBLE:
2590 case AV_OPT_TYPE_COLOR:
2591 break;
2592 case AV_OPT_TYPE_STRING:
2593 range->component_min = 0;
2594 range->component_max = 0x10FFFF; // max unicode value
2595 range->value_min = -1;
2596 range->value_max = INT_MAX;
2597 break;
2599 range->component_min = INT_MIN;
2600 range->component_max = INT_MAX;
2601 break;
2603 range->component_min = 0;
2604 range->component_max = INT_MAX/128/8;
2605 range->value_min = 0;
2606 range->value_max = INT_MAX/8;
2607 break;
2609 range->component_min = 1;
2610 range->component_max = INT_MAX;
2611 range->value_min = 1;
2612 range->value_max = INT_MAX;
2613 break;
2614 default:
2615 ret = AVERROR(ENOSYS);
2616 goto fail;
2617 }
2618
2619 *ranges_arg = ranges;
2620 return 1;
2621fail:
2622 av_free(ranges);
2623 av_free(range);
2624 av_free(range_array);
2625 return ret;
2626}
2627
2629{
2630 int i;
2631 AVOptionRanges *ranges = *rangesp;
2632
2633 if (!ranges)
2634 return;
2635
2636 for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
2637 AVOptionRange *range = ranges->range[i];
2638 if (range) {
2639 av_freep(&range->str);
2640 av_freep(&ranges->range[i]);
2641 }
2642 }
2643 av_freep(&ranges->range);
2644 av_freep(rangesp);
2645}
2646
2647int av_opt_is_set_to_default(void *obj, const AVOption *o)
2648{
2649 int64_t i64;
2650 double d;
2651 AVRational q;
2652 int ret, w, h;
2653 char *str;
2654 void *dst;
2655
2656 if (!o || !obj)
2657 return AVERROR(EINVAL);
2658
2659 dst = ((uint8_t*)obj) + o->offset;
2660
2661 if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
2662 const char *def = o->default_val.arr ? o->default_val.arr->def : NULL;
2663 uint8_t *val;
2664
2665 ret = opt_get_array(o, dst, &val);
2666 if (ret < 0)
2667 return ret;
2668
2669 if (!!val != !!def)
2670 ret = 0;
2671 else if (val)
2672 ret = !strcmp(val, def);
2673 else
2674 ret = 1;
2675
2676 av_freep(&val);
2677
2678 return ret;
2679 }
2680
2681 switch (o->type) {
2682 case AV_OPT_TYPE_CONST:
2683 return 1;
2684 case AV_OPT_TYPE_BOOL:
2685 case AV_OPT_TYPE_FLAGS:
2688 case AV_OPT_TYPE_INT:
2689 case AV_OPT_TYPE_UINT:
2691 case AV_OPT_TYPE_INT64:
2692 case AV_OPT_TYPE_UINT64:
2693 read_number(o, dst, NULL, NULL, &i64);
2694 return o->default_val.i64 == i64;
2695 case AV_OPT_TYPE_CHLAYOUT: {
2696 AVChannelLayout ch_layout = { 0 };
2697 if (o->default_val.str) {
2698 if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
2699 return ret;
2700 }
2701 ret = !av_channel_layout_compare((AVChannelLayout *)dst, &ch_layout);
2702 av_channel_layout_uninit(&ch_layout);
2703 return ret;
2704 }
2705 case AV_OPT_TYPE_STRING:
2706 str = *(char **)dst;
2707 if (str == o->default_val.str) //2 NULLs
2708 return 1;
2709 if (!str || !o->default_val.str) //1 NULL
2710 return 0;
2711 return !strcmp(str, o->default_val.str);
2712 case AV_OPT_TYPE_DOUBLE:
2713 d = *(double *)dst;
2714 return o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl);
2715 case AV_OPT_TYPE_FLOAT:
2716 d = *(float *)dst;
2717 return (float)o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl);
2718 case AV_OPT_TYPE_RATIONAL: {
2719 AVRational v = *(AVRational *) dst;
2720 q = av_d2q(o->default_val.dbl, INT_MAX);
2721 return !av_cmp_q(v, q) || (!q.den && !v.den);
2722 }
2723 case AV_OPT_TYPE_BINARY: {
2724 struct {
2725 uint8_t *data;
2726 int size;
2727 } tmp = {0};
2728 int opt_size = *(int *)((void **)dst + 1);
2729 void *opt_ptr = *(void **)dst;
2730 if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
2731 return 1;
2732 if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
2733 return 0;
2734 if (opt_size != strlen(o->default_val.str) / 2)
2735 return 0;
2736 ret = set_string_binary(NULL, NULL, o->default_val.str, &tmp.data);
2737 if (!ret)
2738 ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2739 av_free(tmp.data);
2740 return ret;
2741 }
2742 case AV_OPT_TYPE_DICT: {
2743 AVDictionary *dict1 = NULL;
2744 AVDictionary *dict2 = *(AVDictionary **)dst;
2745 const AVDictionaryEntry *en1 = NULL;
2746 const AVDictionaryEntry *en2 = NULL;
2747 ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2748 if (ret < 0) {
2749 av_dict_free(&dict1);
2750 return ret;
2751 }
2752 do {
2753 en1 = av_dict_iterate(dict1, en1);
2754 en2 = av_dict_iterate(dict2, en2);
2755 } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2756 av_dict_free(&dict1);
2757 return (!en1 && !en2);
2758 }
2760 if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2761 w = h = 0;
2762 else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2763 return ret;
2764 return (w == *(int *)dst) && (h == *((int *)dst+1));
2766 q = (AVRational){0, 0};
2767 if (o->default_val.str) {
2768 if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2769 return ret;
2770 }
2771 return !av_cmp_q(*(AVRational*)dst, q);
2772 case AV_OPT_TYPE_COLOR: {
2773 uint8_t color[4] = {0, 0, 0, 0};
2774 if (o->default_val.str) {
2775 if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2776 return ret;
2777 }
2778 return !memcmp(color, dst, sizeof(color));
2779 }
2780 default:
2781 av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2782 break;
2783 }
2784 return AVERROR_PATCHWELCOME;
2785}
2786
2787int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2788{
2789 const AVOption *o;
2790 void *target;
2791 if (!obj)
2792 return AVERROR(EINVAL);
2793 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2794 if (!o)
2796 return av_opt_is_set_to_default(target, o);
2797}
2798
2799static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt,
2800 AVBPrint *bprint, const char key_val_sep, const char pairs_sep)
2801{
2802 const AVOption *o = NULL;
2803 void *child = NULL;
2804 uint8_t *buf;
2805 int ret;
2806 const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2807
2809 while (child = av_opt_child_next(obj, child)) {
2810 ret = opt_serialize(child, opt_flags, flags, cnt, bprint,
2811 key_val_sep, pairs_sep);
2812 if (ret < 0)
2813 return ret;
2814 }
2815
2816 while (o = av_opt_next(obj, o)) {
2817 if (o->type == AV_OPT_TYPE_CONST)
2818 continue;
2819 if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2820 continue;
2821 else if (((o->flags & opt_flags) != opt_flags))
2822 continue;
2824 continue;
2825 if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2826 av_bprint_finalize(bprint, NULL);
2827 return ret;
2828 }
2829 if (buf) {
2830 if ((*cnt)++)
2831 av_bprint_append_data(bprint, &pairs_sep, 1);
2832 av_bprint_escape(bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2833 av_bprint_append_data(bprint, &key_val_sep, 1);
2834 av_bprint_escape(bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2835 av_freep(&buf);
2836 }
2837 }
2838
2839 return 0;
2840}
2841
2842int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2843 const char key_val_sep, const char pairs_sep)
2844{
2845 AVBPrint bprint;
2846 int ret, cnt = 0;
2847
2848 if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2849 pairs_sep == '\\' || key_val_sep == '\\') {
2850 av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2851 return AVERROR(EINVAL);
2852 }
2853
2854 if (!obj || !buffer)
2855 return AVERROR(EINVAL);
2856
2857 *buffer = NULL;
2859
2860 ret = opt_serialize(obj, opt_flags, flags, &cnt, &bprint,
2861 key_val_sep, pairs_sep);
2862 if (ret < 0)
2863 return ret;
2864
2865 ret = av_bprint_finalize(&bprint, buffer);
2866 if (ret < 0)
2867 return ret;
2868 return 0;
2869}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static double val(void *priv, double ch)
Definition aeval.c:77
#define class
Definition math.h:25
static FILE * out
static AVFormatContext * ctx
static AVDictionary * opts
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition avstring.c:103
Convenience header that includes libavutil's core.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition bprint.c:68
AVBPrint public header.
#define AV_BPRINT_SIZE_UNLIMITED
#define flag(name)
Definition cbs_h264.c:60
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define min(a, b)
#define max(a, b)
Public dictionary API.
static void callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time, enum dshowDeviceType devtype)
Definition dshow.c:342
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:839
double value
Definition eval.c:102
simple arithmetic expression evaluator
const char * key
#define WHITESPACES
Definition graphparser.c:35
#define fail
Definition test.h:479
#define AV_OPT_FLAG_FILTERING_PARAM
A generic parameter which can be set by the user for filtering.
Definition opt.h:380
#define AV_OPT_FLAG_BSF_PARAM
A generic parameter which can be set by the user for bit stream filtering.
Definition opt.h:371
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:2556
#define AV_OPT_FLAG_CHILD_CONSTS
Set if option constants can also reside in child objects.
Definition opt.h:389
#define AV_OPT_FLAG_READONLY
The option may not be set through the AVOptions API, only read.
Definition opt.h:367
#define AV_OPT_FLAG_DEPRECATED
Set if option is deprecated, users should refer to AVOption.help text for more information.
Definition opt.h:385
void av_opt_freep_ranges(AVOptionRanges **rangesp)
Free an AVOptionRanges struct and set it to NULL.
Definition opt.c:2628
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:2538
#define AV_OPT_FLAG_AUDIO_PARAM
Definition opt.h:356
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition opt.h:351
AVOptionType
An option type determines:
Definition opt.h:250
#define AV_OPT_FLAG_SUBTITLE_PARAM
Definition opt.h:358
#define AV_OPT_FLAG_EXPORT
The option is intended for exporting values to the caller.
Definition opt.h:362
#define AV_OPT_FLAG_RUNTIME_PARAM
A generic parameter which can be set by the user at runtime.
Definition opt.h:376
@ AV_OPT_TYPE_IMAGE_SIZE
Underlying C type is two consecutive integers.
Definition opt.h:302
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
Definition opt.h:306
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
Definition opt.h:285
@ AV_OPT_TYPE_DURATION
Underlying C type is int64_t.
Definition opt.h:318
@ AV_OPT_TYPE_FLAG_ARRAY
May be combined with another regular option type to declare an array option.
Definition opt.h:345
@ AV_OPT_TYPE_SAMPLE_FMT
Underlying C type is enum AVSampleFormat.
Definition opt.h:310
@ AV_OPT_TYPE_RATIONAL
Underlying C type is AVRational.
Definition opt.h:279
@ AV_OPT_TYPE_FLAGS
Underlying C type is unsigned int.
Definition opt.h:254
@ AV_OPT_TYPE_VIDEO_RATE
Underlying C type is AVRational.
Definition opt.h:314
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition opt.h:262
@ AV_OPT_TYPE_UINT64
Underlying C type is uint64_t.
Definition opt.h:293
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_CHLAYOUT
Underlying C type is AVChannelLayout.
Definition opt.h:330
@ AV_OPT_TYPE_DOUBLE
Underlying C type is double.
Definition opt.h:266
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition opt.h:270
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition opt.h:289
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition opt.h:275
@ AV_OPT_TYPE_COLOR
Underlying C type is uint8_t[4].
Definition opt.h:322
@ AV_OPT_TYPE_UINT
Underlying C type is unsigned int.
Definition opt.h:334
int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str)
Initialize a channel layout from a given string description.
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
void av_bprint_escape(AVBPrint *dstbuf, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape the content in src and append it to dstbuf.
Definition bprint.c:262
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition bprint.c:234
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
Definition bprint.c:147
#define AV_DICT_MULTIKEY
Allow to store several equal keys in the dictionary.
Definition dict.h:84
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:233
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
int av_dict_get_string(const AVDictionary *m, char **buffer, const char key_val_sep, const char pairs_sep)
Get dictionary entries as a string.
Definition dict.c:260
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:247
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:86
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition dict.c:210
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition error.h:64
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition error.h:122
#define AVERROR(e)
Definition error.h:45
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition error.h:63
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_INFO
Standard information.
Definition log.h:221
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition rational.c:110
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition rational.h:89
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:217
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition mem.c:188
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:302
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition avutil.h:311
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:59
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:52
AVSampleFormat
Audio sample formats.
Definition samplefmt.h:55
@ AV_SAMPLE_FMT_NB
Number of sample formats. DO NOT USE if linking dynamically.
Definition samplefmt.h:79
int av_match_name(const char *name, const char *names)
Match instances of a name in a comma-separated list of names.
Definition avstring.c:341
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition avstring.c:143
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Definition avstring.h:316
int av_opt_get_array(void *obj, const char *name, int search_flags, unsigned int start_elem, unsigned int nb_elems, enum AVOptionType out_type, void *out_val)
For an array-type option, retrieve the values of one or more array elements.
Definition opt.c:2263
int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
Definition opt.c:1437
int av_opt_get_array_size(void *obj, const char *name, int search_flags, unsigned int *out_val)
For an array-type option, get the number of elements in the array.
Definition opt.c:2245
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition opt.c:1364
int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
Definition opt.c:1447
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
Definition opt.c:1463
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
Definition opt.c:1392
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition opt.c:1349
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition opt.c:1376
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition opt.c:1442
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition opt.c:1291
int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition opt.c:1410
const AVClass * av_opt_child_class_iterate(const AVClass *parent, void **iter)
Iterate over potential AVOptions-enabled children of parent.
Definition opt.c:2130
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:1955
#define AV_OPT_MULTI_COMPONENT_RANGE
Allows av_opt_query_ranges and av_opt_query_ranges_default to return more than one component for cert...
Definition opt.h:631
#define AV_OPT_SEARCH_CHILDREN
Search in possible children of the given object first.
Definition opt.h:604
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:2077
#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:618
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:2071
#define AV_OPT_ARRAY_REPLACE
May be used with av_opt_set_array() to signal that new elements should replace the existing ones in t...
Definition opt.h:624
#define AV_OPT_SEARCH_FAKE_OBJ
The obj passed to av_opt_find() or av_opt_set() is fake – only a double pointer to AVClass instead of...
Definition opt.h:612
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition opt.c:2029
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition opt.c:2122
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1758
void av_opt_set_defaults2(void *s, int mask, int flags)
Set the values of all AVOption fields to their default values.
Definition opt.c:1763
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition opt.c:1746
const AVOption * av_opt_next(const void *obj, const AVOption *last)
Iterate over all AVOptions belonging to obj.
Definition opt.c:47
@ AV_OPT_FLAG_IMPLICIT_KEY
Accept to parse a value without a key; the key will then be returned as NULL.
Definition opt.h:723
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:1479
int av_opt_is_set_to_default(void *obj, const AVOption *o)
Check if given option is set to its default value.
Definition opt.c:2647
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
Serialize options that exactly match opt_flags only.
Definition opt.h:1093
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:2842
#define AV_OPT_SERIALIZE_SKIP_DEFAULTS
Serialize options that are not set to default values only.
Definition opt.h:1092
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:2787
#define AV_OPT_SERIALIZE_SEARCH_CHILDREN
Serialize options in possible children of the given object.
Definition opt.h:1094
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition opt.c:943
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
Definition opt.c:982
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition opt.c:938
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:948
int av_opt_set_array(void *obj, const char *name, int search_flags, unsigned int start_elem, unsigned int nb_elems, enum AVOptionType val_type, const void *val)
Add, replace, or remove elements for an array option.
Definition opt.c:2351
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:891
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition opt.c:953
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition opt.c:1073
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:1010
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
Definition opt.c:1053
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition opt.c:1048
int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
Definition opt.c:1043
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition opt.c:2219
int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
Set all the options from a given dictionary on an object.
Definition opt.c:2042
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:1977
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:1897
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition opt.c:2066
int a
cl_device_type type
#define r
Definition input.c:42
#define b
Definition input.c:43
class_name
Definition libkvazaar.c:310
#define llrint(x)
Definition libm.h:396
#define isnan(x)
Definition libm.h:342
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
@ AV_CLASS_STATE_INITIALIZED
Object initialization has finished and it is now in the 'runtime' stage.
Definition log.h:56
static const uint16_t mask[17]
Definition lzw.c:38
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define NAN
#define INFINITY
enum AVColorRange range
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:264
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_strdup(s)
Definition ops_static.c:55
#define av_malloc(s)
Definition ops_static.c:52
static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition opt.c:556
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition opt.c:905
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:1863
static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:729
static void log_type(void *av_log_obj, const AVOption *o, enum AVOptionType parent_type)
Definition opt.c:1576
static int hexchar2int(char c)
Definition opt.c:356
static void format_duration(char *buf, size_t size, int64_t d)
Definition opt.c:1091
static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:428
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:1015
static int opt_set_array(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:807
static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition opt.c:366
static const struct @304073206145271053212042062205146224327011150156 opt_type_desc[]
static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition opt.c:679
static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
Definition opt.c:234
static int get_sample_fmt(const char *name)
Definition opt.c:674
static int opt_set_init(void *obj, const char *name, int search_flags, int require_type, void **ptgt, const AVOption **po, void **pdst)
Perform common setup for option-setting functions.
Definition opt.c:165
static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition opt.c:408
static void log_int_value(void *av_log_obj, int level, int64_t i)
Definition opt.c:1492
static void opt_free_array(const AVOption *o, void *parray, unsigned *count)
Definition opt.c:148
static const char * get_opt_const_name(void *obj, const char *unit, int64_t value)
Definition opt.c:1542
#define TYPE_BASE(type)
Definition opt.c:45
static int is_key_char(char c)
Definition opt.c:1919
#define DEFAULT_NUMVAL(opt)
Definition opt.c:419
static int get_pix_fmt(const char *name)
Definition opt.c:662
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition opt.c:1934
static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
Definition opt.c:523
static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, const void *dst, int search_flags)
Definition opt.c:1126
static int opt_copy_array(void *logctx, const AVOption *o, void **pdst, const void *const *psrc)
Definition opt.c:2185
static void log_value(void *av_log_obj, int level, double d)
Definition opt.c:1509
static char * get_opt_flags_string(void *obj, const char *unit, int64_t value)
Definition opt.c:1555
static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, int search_flags, int require_type)
Definition opt.c:922
static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
Definition opt.c:1593
static void opt_free_elem(enum AVOptionType type, void *ptr)
Definition opt.c:127
static const char * get_bool_name(int val)
Definition opt.c:575
static void * opt_array_pelem(const AVOption *o, void *array, unsigned idx)
Definition opt.c:116
static uint8_t opt_array_sep(const AVOption *o)
Definition opt.c:109
static int get_format(void *obj, const char *name, int search_flags, void *out_fmt, enum AVOptionType type, const char *desc)
Definition opt.c:1415
static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
Definition opt.c:1231
static AVRational double_to_rational(double d)
Definition opt.c:226
static void opt_list(void *obj, void *av_log_obj, const char *unit, int req_flags, int rej_flags, enum AVOptionType parent_type)
Definition opt.c:1671
static unsigned * opt_array_pcount(const void *parray)
Definition opt.c:122
static int opt_copy_elem(void *logctx, enum AVOptionType type, void *dst, const void *src)
Definition opt.c:2137
static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, int search_flags)
Definition opt.c:1334
static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt, AVBPrint *bprint, const char key_val_sep, const char pairs_sep)
Definition opt.c:2799
static int opt_is_pod(enum AVOptionType type)
Definition opt.c:86
static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
Definition opt.c:686
static int set_string_channel_layout(void *obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:709
static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
Definition opt.c:544
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition opt.c:667
static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst, int fmt_nb, int((*get_fmt)(const char *)), const char *desc, enum AVOptionType type)
Definition opt.c:615
static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
Definition opt.c:582
static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum, int ignore_range)
Definition opt.c:275
AVOptions.
int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, void *log_ctx)
Put the RGBA values that correspond to color_string in rgba_color.
Definition parseutils.c:359
int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str)
Parse str and put in width_ptr and height_ptr the detected values.
Definition parseutils.c:150
int av_parse_video_rate(AVRational *rate, const char *arg)
Parse str and store the detected values in *rate.
Definition parseutils.c:181
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:592
misc parsing utilities
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:3380
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition pixfmt.h:508
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
An AVChannelLayout holds information about the channel layout of audio data.
Describe the class of an AVClass context structure.
Definition log.h:76
const struct AVClass *(* child_class_iterate)(void **iter)
Iterate over the AVClasses corresponding to potential AVOptions-enabled children.
Definition log.h:167
char * key
Definition dict.h:91
char * value
Definition dict.h:92
May be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
Definition opt.h:394
const char * def
Native access only.
Definition opt.h:401
unsigned size_min
Minimum number of elements in the array.
Definition opt.h:407
unsigned size_max
Maximum number of elements in the array, 0 when unlimited.
Definition opt.h:411
char sep
Separator between array elements in string representations of this option, used by av_opt_set() and a...
Definition opt.h:422
A single allowed range of values, or a single allowed value.
Definition opt.h:484
List of AVOptionRange structs.
Definition opt.h:507
int nb_ranges
Number of ranges per component.
Definition opt.h:542
AVOptionRange ** range
Array of option ranges.
Definition opt.h:538
int nb_components
Number of components.
Definition opt.h:546
AVOption.
Definition opt.h:428
double max
maximum valid value for the option
Definition opt.h:466
int offset
Native access only.
Definition opt.h:443
const char * unit
The logical unit to which the option belongs.
Definition opt.h:478
const char * str
Definition opt.h:453
const char * help
short English help text
Definition opt.h:435
const char * name
Definition opt.h:429
int64_t i64
Definition opt.h:451
const AVOptionArrayDef * arr
Used for AV_OPT_TYPE_FLAG_ARRAY options.
Definition opt.h:463
double min
minimum valid value for the option
Definition opt.h:465
union AVOption::@264334322154243333237203365311152072005371076340 default_val
Native access only, except when documented otherwise.
int flags
A combination of AV_OPT_FLAG_*.
Definition opt.h:471
enum AVOptionType type
Definition opt.h:444
double dbl
Definition opt.h:452
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
uint8_t level
Definition svq3.c:208
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
static const double const_values[]
Definition eval.c:28
static const char *const const_names[]
Definition eval.c:34
static int array[MAX_W *MAX_W]
static char buffer[20]
Definition seek.c:32
int size
int len
static double c[64]