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,
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 unsigned int operand;
509 /* Validate the operand of a '+' or '-' update and let
510 * write_number() convert it: casting a double outside the
511 * int64_t range (or inf/nan) to int64_t is undefined behaviour,
512 * and the cast would also drop a fractional part that
513 * write_number() is meant to reject, so "+1.5" used to be
514 * accepted while "1.5" is refused. */
515 if (cmd && (ret = write_number(obj, o, &operand, d, 1, 1, 0)) < 0)
516 return ret;
517 intnum = *(unsigned int*)dst;
518 if (cmd == '+')
519 d = intnum | operand;
520 else if (cmd == '-')
521 d = intnum &~operand;
522 }
523
524 if ((ret = write_number(obj, o, dst, d, 1, 1, 0)) < 0)
525 return ret;
526 val += i;
527 if (!i || !*val)
528 return 0;
529 }
530}
531
532static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
533{
534 void *logctx = dst ? obj : NULL;
535 int tmp[2];
536 int ret;
537
538 if (!val || !strcmp(val, "none")) {
539 if (dst) {
540 dst[0] =
541 dst[1] = 0;
542 }
543 return 0;
544 }
545 ret = av_parse_video_size(&tmp[0], &tmp[1], val);
546 if (ret < 0) {
547 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as image size\n", o->name, val);
548 return ret;
549 }
550 if (dst)
551 memcpy(dst, tmp, sizeof(tmp));
552 return ret;
553}
554
555static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
556{
557 void *logctx = dst ? obj : NULL;
560 if (ret < 0)
561 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as video rate\n", o->name, val);
562 if (dst)
563 *dst = tmp;
564 return ret;
565}
566
567static int set_string_color(void *obj, const AVOption *o, const char *val, uint8_t *dst)
568{
569 void *logctx = dst ? obj : NULL;
570 int ret;
571
572 if (!val) {
573 return 0;
574 } else {
575 uint8_t tmp[4];
576 ret = av_parse_color(tmp, val, -1, obj);
577 if (ret < 0) {
578 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as color\n", o->name, val);
579 return ret;
580 }
581 if (dst)
582 memcpy(dst, tmp, sizeof(tmp));
583 return ret;
584 }
585 return 0;
586}
587
588static const char *get_bool_name(int val)
589{
590 if (val < 0)
591 return "auto";
592 return val ? "true" : "false";
593}
594
595static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
596{
597 void *logctx = dst ? obj : NULL;
598 int n;
599
600 if (!val)
601 return 0;
602
603 if (!strcmp(val, "auto")) {
604 n = -1;
605 } else if (av_match_name(val, "true,y,yes,enable,enabled,on")) {
606 n = 1;
607 } else if (av_match_name(val, "false,n,no,disable,disabled,off")) {
608 n = 0;
609 } else {
610 char *end = NULL;
611 n = strtol(val, &end, 10);
612 if (val + strlen(val) != end)
613 goto fail;
614 }
615
616 if (n < o->min || n > o->max)
617 goto fail;
618
619 if (dst)
620 *dst = n;
621 return 0;
622
623fail:
624 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as boolean\n", o->name, val);
625 return AVERROR(EINVAL);
626}
627
628static int set_string_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst,
629 int fmt_nb, int ((*get_fmt)(const char *)), const char *desc,
630 enum AVOptionType type)
631{
632 void *logctx = dst ? obj : NULL;
633 int fmt, min, max;
634
635 if (!val || !strcmp(val, "none")) {
636 fmt = -1;
637 } else {
638 fmt = get_fmt(val);
639 if (fmt == -1) {
640 char *tail;
641 fmt = strtol(val, &tail, 0);
642 if (*tail || (unsigned)fmt >= fmt_nb) {
643 av_log(logctx, AV_LOG_ERROR,
644 "Unable to parse \"%s\" option value \"%s\" as %s\n", o->name, val, desc);
645 return AVERROR(EINVAL);
646 }
647 }
648 }
649
650 min = FFMAX(o->min, -1);
651 max = FFMIN(o->max, fmt_nb-1);
652
653 // hack for compatibility with old ffmpeg
654 if(min == 0 && max == 0) {
655 min = -1;
656 max = fmt_nb-1;
657 }
658
659 if (fmt < min || fmt > max) {
660 av_log(logctx, AV_LOG_ERROR,
661 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
662 fmt, o->name, desc, min, max);
663 return AVERROR(ERANGE);
664 }
665
666 if (dst)
667 switch (type) {
668 case AV_OPT_TYPE_PIXEL_FMT: *(enum AVPixelFormat *)dst = fmt; break;
669 case AV_OPT_TYPE_SAMPLE_FMT: *(enum AVSampleFormat*)dst = fmt; break;
670 default: av_unreachable("set_string_fmt() is only called for pixel and sample formats");
671 }
672 return 0;
673}
674
675static int get_pix_fmt(const char *name)
676{
677 return av_get_pix_fmt(name);
678}
679
680static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
681{
682 return set_string_fmt(obj, o, val, dst,
684 "pixel format", AV_OPT_TYPE_PIXEL_FMT);
685}
686
687static int get_sample_fmt(const char *name)
688{
689 return av_get_sample_fmt(name);
690}
691
692static int set_string_sample_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
693{
694 return set_string_fmt(obj, o, val, dst,
696 "sample format", AV_OPT_TYPE_SAMPLE_FMT);
697}
698
699static int set_string_dict(void *obj, const AVOption *o, const char *val, uint8_t **dst)
700{
702
703 if (val) {
704 int ret = av_dict_parse_string(&options, val, "=", ":", 0);
705 if (ret < 0) {
707 return ret;
708 }
709 }
710
711 if (!dst) {
713 return 0;
714 }
715
717 *dst = (uint8_t *)options;
718
719 return 0;
720}
721
722static int set_string_channel_layout(void *obj, const AVOption *o,
723 const char *val, void *dst)
724{
726 AVChannelLayout *channel_layout = dst;
727 int ret;
728 if (dst)
729 av_channel_layout_uninit(channel_layout);
730 else
731 channel_layout = &tmp;
732 if (!val)
733 return 0;
734 ret = av_channel_layout_from_string(channel_layout, val);
735 if (ret < 0)
736 return ret;
737 if (!dst)
738 av_channel_layout_uninit(channel_layout);
739 return 0;
740}
741
742static int opt_set_elem(void *obj, void *target_obj, const AVOption *o,
743 const char *val, void *dst)
744{
745 void *logctx = dst ? obj : NULL;
746 const enum AVOptionType type = TYPE_BASE(o->type);
747 int ret;
748
749 if (!val && (type != AV_OPT_TYPE_STRING &&
754 return AVERROR(EINVAL);
755
756 switch (type) {
757 case AV_OPT_TYPE_BOOL:
758 return set_string_bool(obj, o, val, dst);
760 return set_string(obj, o, val, dst);
762 return set_string_binary(obj, o, val, dst);
764 case AV_OPT_TYPE_INT:
765 case AV_OPT_TYPE_UINT:
771 return set_string_number(obj, target_obj, o, val, dst);
773 return set_string_image_size(obj, o, val, dst);
777 if (ret < 0)
778 return ret;
779 return write_number(obj, o, dst, 1, tmp.den, tmp.num, 0);
780 }
782 return set_string_pixel_fmt(obj, o, val, dst);
784 return set_string_sample_fmt(obj, o, val, dst);
786 {
787 int64_t usecs = 0;
788 if (val) {
789 if ((ret = av_parse_time(&usecs, val, 1)) < 0) {
790 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as duration\n", o->name, val);
791 return ret;
792 }
793 }
794 if (usecs < o->min || usecs > o->max) {
795 av_log(logctx, AV_LOG_ERROR, "Value %f for parameter '%s' out of range [%g - %g]\n",
796 usecs / 1000000.0, o->name, o->min / 1000000.0, o->max / 1000000.0);
797 return AVERROR(ERANGE);
798 }
799 if (dst)
800 *(int64_t *)dst = usecs;
801 return 0;
802 }
804 return set_string_color(obj, o, val, dst);
807 if (ret < 0) {
808 av_log(logctx, AV_LOG_ERROR, "Unable to parse \"%s\" option value \"%s\" as channel layout\n", o->name, val);
809 ret = AVERROR(EINVAL);
810 }
811 return ret;
812 case AV_OPT_TYPE_DICT:
813 return set_string_dict(obj, o, val, dst);
814 }
815
816 av_log(logctx, AV_LOG_ERROR, "Invalid option type.\n");
817 return AVERROR(EINVAL);
818}
819
820static int opt_set_array(void *obj, void *target_obj, const AVOption *o,
821 const char *val, void *dst)
822{
823 const AVOptionArrayDef *arr = o->default_val.arr;
824 const size_t elem_size = opt_type_desc[TYPE_BASE(o->type)].size;
825 const uint8_t sep = opt_array_sep(o);
826 uint8_t *str = NULL;
827
828 void *logctx = dst ? obj : NULL;
829 void *elems = NULL;
830 unsigned nb_elems = 0;
831 int ret;
832
833 if (val && *val) {
834 str = av_malloc(strlen(val) + 1);
835 if (!str)
836 return AVERROR(ENOMEM);
837 }
838
839 // split and unescape the string
840 while (val && *val) {
841 uint8_t *p = str;
842 void *tmp;
843
844 if (arr && arr->size_max && nb_elems >= arr->size_max) {
845 av_log(logctx, AV_LOG_ERROR,
846 "Cannot assign more than %u elements to array option %s\n",
847 arr->size_max, o->name);
848 ret = AVERROR(EINVAL);
849 goto fail;
850 }
851
852 for (; *val; val++, p++) {
853 if (*val == '\\' && val[1])
854 val++;
855 else if (*val == sep) {
856 val++;
857 break;
858 }
859 *p = *val;
860 }
861 *p = 0;
862
863 tmp = av_realloc_array(elems, nb_elems + 1, elem_size);
864 if (!tmp) {
865 ret = AVERROR(ENOMEM);
866 goto fail;
867 }
868 elems = tmp;
869
870 tmp = opt_array_pelem(o, elems, nb_elems);
871 memset(tmp, 0, elem_size);
872
873 ret = opt_set_elem(obj, target_obj, o, str, tmp);
874 if (ret < 0)
875 goto fail;
876 nb_elems++;
877 }
878 av_freep(&str);
879
880 if (dst)
882
883 if (arr && nb_elems < arr->size_min) {
884 av_log(logctx, AV_LOG_ERROR,
885 "Cannot assign fewer than %u elements to array option %s\n",
886 arr->size_min, o->name);
887 ret = AVERROR(EINVAL);
888 goto fail;
889 }
890
891 if (dst) {
892 *((void **)dst) = elems;
893 *opt_array_pcount(dst) = nb_elems;
894 } else
895 opt_free_array(o, &elems, &nb_elems);
896
897 return 0;
898fail:
899 av_freep(&str);
900 opt_free_array(o, &elems, &nb_elems);
901 return ret;
902}
903
904int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
905{
906 void *dst, *target_obj;
907 const AVOption *o;
908 int ret;
909
910 ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &dst);
911 if (ret < 0)
912 return ret;
913
914 return ((o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
915 opt_set_array : opt_set_elem)(obj, target_obj, o, val, dst);
916}
917
918#define OPT_EVAL_NUMBER(name, opttype, vartype) \
919int av_opt_eval_ ## name(void *obj, const AVOption *o, \
920 const char *val, vartype *name ## _out) \
921{ \
922 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
923 return AVERROR(EINVAL); \
924 return set_string_number(obj, obj, o, val, name ## _out); \
925}
926
929OPT_EVAL_NUMBER(uint, AV_OPT_TYPE_UINT, unsigned)
932OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
934
935static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
936 int search_flags, int require_type)
937{
938 void *dst;
939 const AVOption *o;
940 int ret;
941
942 ret = opt_set_init(obj, name, search_flags, require_type, NULL, &o, &dst);
943 if (ret < 0)
944 return ret;
945 if (dst)
946 ret = write_number(obj, o, dst, num, den, intnum, 0);
947
948 return ret;
949}
950
951int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
952{
953 return set_number(obj, name, 1, 1, val, search_flags, 0);
954}
955
956int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
957{
958 return set_number(obj, name, val, 1, 1, search_flags, 0);
959}
960
961int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
962{
963 return set_number(obj, name, val.num, val.den, 1, search_flags, 0);
964}
965
966int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
967{
968 uint8_t *ptr;
969 uint8_t **dst;
970 int *lendst;
971 int ret;
972
973 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_BINARY,
974 NULL, NULL, (void**)&dst);
975 if (ret < 0)
976 return ret;
977
978 if (dst) {
979 ptr = len ? av_malloc(len) : NULL;
980 if (len && !ptr)
981 return AVERROR(ENOMEM);
982
983 lendst = (int *)(dst + 1);
984
985 av_free(*dst);
986 *dst = ptr;
987 *lendst = len;
988 if (len)
989 memcpy(ptr, val, len);
990 }
991
992 return 0;
993}
994
995int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
996{
997 const AVOption *o;
998 void *logctx;
999 int *dst;
1000 int ret;
1001
1003 NULL, &o, (void**)&dst);
1004 if (ret < 0)
1005 return ret;
1006
1007 logctx = dst ? obj : NULL;
1008
1009 if (w<0 || h<0) {
1010 av_log(logctx, AV_LOG_ERROR,
1011 "Invalid negative size value %dx%d for size '%s'\n", w, h, o->name);
1012 return AVERROR(EINVAL);
1013 }
1014
1015 if (dst) {
1016 dst[0] = w;
1017 dst[1] = h;
1018 }
1019
1020 return 0;
1021}
1022
1023int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
1024{
1025 return set_number(obj, name, val.num, val.den, 1, search_flags, AV_OPT_TYPE_VIDEO_RATE);
1026}
1027
1028static int set_format(void *obj, const char *name, int fmt, int search_flags,
1029 enum AVOptionType type, const char *desc, int nb_fmts)
1030{
1031 const AVOption *o;
1032 void *logctx;
1033 int *dst;
1034 int min, max, ret;
1035
1036 ret = opt_set_init(obj, name, search_flags, type, NULL, &o, (void**)&dst);
1037 if (ret < 0)
1038 return ret;
1039
1040 logctx = dst ? obj : NULL;
1041
1042 min = FFMAX(o->min, -1);
1043 max = FFMIN(o->max, nb_fmts-1);
1044
1045 if (fmt < min || fmt > max) {
1046 av_log(logctx, AV_LOG_ERROR,
1047 "Value %d for parameter '%s' out of %s format range [%d - %d]\n",
1048 fmt, name, desc, min, max);
1049 return AVERROR(ERANGE);
1050 }
1051 if (dst)
1052 *dst = fmt;
1053 return 0;
1054}
1055
1056int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
1057{
1058 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_PIXEL_FMT, "pixel", AV_PIX_FMT_NB);
1059}
1060
1061int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
1062{
1063 return set_format(obj, name, fmt, search_flags, AV_OPT_TYPE_SAMPLE_FMT, "sample", AV_SAMPLE_FMT_NB);
1064}
1065
1066int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
1067 int search_flags)
1068{
1069 AVDictionary **dst;
1070 int ret;
1071
1072 ret = opt_set_init(obj, name, search_flags, AV_OPT_TYPE_DICT, NULL, NULL,
1073 (void**)&dst);
1074 if (ret < 0)
1075 return ret;
1076
1077 if (dst) {
1079
1080 ret = av_dict_copy(dst, val, 0);
1081 }
1082
1083 return ret;
1084}
1085
1086int av_opt_set_chlayout(void *obj, const char *name,
1087 const AVChannelLayout *channel_layout,
1088 int search_flags)
1089{
1091 int ret;
1092
1094 (void**)&dst);
1095 if (ret < 0)
1096 return ret;
1097
1098 if (dst)
1099 ret = av_channel_layout_copy(dst, channel_layout);
1100
1101 return ret;
1102}
1103
1104static void format_duration(char *buf, size_t size, int64_t d)
1105{
1106 char *e;
1107
1108 av_assert0(size >= 25);
1109 if (d < 0 && d != INT64_MIN) {
1110 *(buf++) = '-';
1111 size--;
1112 d = -d;
1113 }
1114 if (d == INT64_MAX)
1115 snprintf(buf, size, "INT64_MAX");
1116 else if (d == INT64_MIN)
1117 snprintf(buf, size, "INT64_MIN");
1118 else if (d > (int64_t)3600*1000000)
1119 snprintf(buf, size, "%"PRId64":%02d:%02d.%06d", d / 3600000000,
1120 (int)((d / 60000000) % 60),
1121 (int)((d / 1000000) % 60),
1122 (int)(d % 1000000));
1123 else if (d > 60*1000000)
1124 snprintf(buf, size, "%d:%02d.%06d",
1125 (int)(d / 60000000),
1126 (int)((d / 1000000) % 60),
1127 (int)(d % 1000000));
1128 else
1129 snprintf(buf, size, "%d.%06d",
1130 (int)(d / 1000000),
1131 (int)(d % 1000000));
1132 e = buf + strlen(buf);
1133 while (e > buf && e[-1] == '0')
1134 *(--e) = 0;
1135 if (e > buf && e[-1] == '.')
1136 *(--e) = 0;
1137}
1138
1139static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
1140 const void *dst, int search_flags)
1141{
1142 int ret;
1143
1144 switch (TYPE_BASE(o->type)) {
1145 case AV_OPT_TYPE_BOOL:
1146 ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
1147 break;
1148 case AV_OPT_TYPE_FLAGS:
1149 ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
1150 break;
1151 case AV_OPT_TYPE_INT:
1152 ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
1153 break;
1154 case AV_OPT_TYPE_UINT:
1155 ret = snprintf(*pbuf, buf_len, "%u", *(unsigned *)dst);
1156 break;
1157 case AV_OPT_TYPE_INT64:
1158 ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
1159 break;
1160 case AV_OPT_TYPE_UINT64:
1161 ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
1162 break;
1163 case AV_OPT_TYPE_FLOAT:
1164 ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
1165 break;
1166 case AV_OPT_TYPE_DOUBLE:
1167 ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
1168 break;
1171 ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
1172 break;
1173 case AV_OPT_TYPE_CONST:
1174 ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
1175 break;
1176 case AV_OPT_TYPE_STRING:
1177 if (*(uint8_t **)dst) {
1178 *pbuf = av_strdup(*(uint8_t **)dst);
1179 } else if (search_flags & AV_OPT_ALLOW_NULL) {
1180 *pbuf = NULL;
1181 return 0;
1182 } else {
1183 *pbuf = av_strdup("");
1184 }
1185 return *pbuf ? 0 : AVERROR(ENOMEM);
1186 case AV_OPT_TYPE_BINARY: {
1187 const uint8_t *bin;
1188 int len;
1189
1190 if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1191 *pbuf = NULL;
1192 return 0;
1193 }
1194 len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
1195 if ((uint64_t)len * 2 + 1 > INT_MAX)
1196 return AVERROR(EINVAL);
1197 if (!(*pbuf = av_malloc(len * 2 + 1)))
1198 return AVERROR(ENOMEM);
1199 if (!len) {
1200 *pbuf[0] = '\0';
1201 return 0;
1202 }
1203 bin = *(uint8_t **)dst;
1204 for (int i = 0; i < len; i++)
1205 snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
1206 return 0;
1207 }
1209 ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
1210 break;
1212 ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
1213 break;
1215 ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
1216 break;
1217 case AV_OPT_TYPE_DURATION: {
1218 int64_t i64 = *(int64_t *)dst;
1219 format_duration(*pbuf, buf_len, i64);
1220 ret = strlen(*pbuf); // no overflow possible, checked by an assert
1221 break;
1222 }
1223 case AV_OPT_TYPE_COLOR:
1224 ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
1225 (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
1226 (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
1227 break;
1229 ret = av_channel_layout_describe(dst, *pbuf, buf_len);
1230 break;
1231 case AV_OPT_TYPE_DICT:
1232 if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
1233 *pbuf = NULL;
1234 return 0;
1235 }
1236 return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
1237 default:
1238 return AVERROR(EINVAL);
1239 }
1240
1241 return ret;
1242}
1243
1244static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
1245{
1246 const unsigned count = *opt_array_pcount(dst);
1247 const uint8_t sep = opt_array_sep(o);
1248
1249 uint8_t *str = NULL;
1250 size_t str_len = 0;
1251 int ret;
1252
1253 *out_val = NULL;
1254
1255 for (unsigned i = 0; i < count; i++) {
1256 uint8_t buf[128], *out = buf;
1257 size_t out_len;
1258
1259 ret = opt_get_elem(o, &out, sizeof(buf),
1260 opt_array_pelem(o, *(void **)dst, i), 0);
1261 if (ret < 0)
1262 goto fail;
1263
1264 out_len = strlen(out);
1265 if (out_len > SIZE_MAX / 2 - !!i ||
1266 !!i + out_len * 2 > SIZE_MAX - str_len - 1) {
1267 ret = AVERROR(ERANGE);
1268 goto fail;
1269 }
1270
1271 // terminator escaping separator
1272 // ↓ ↓ ↓
1273 ret = av_reallocp(&str, str_len + 1 + out_len * 2 + !!i);
1274 if (ret < 0)
1275 goto fail;
1276
1277 // add separator if needed
1278 if (i)
1279 str[str_len++] = sep;
1280
1281 // escape the element
1282 for (unsigned j = 0; j < out_len; j++) {
1283 uint8_t val = out[j];
1284 if (val == sep || val == '\\')
1285 str[str_len++] = '\\';
1286 str[str_len++] = val;
1287 }
1288 str[str_len] = 0;
1289
1290fail:
1291 if (out != buf)
1292 av_freep(&out);
1293 if (ret < 0) {
1294 av_freep(&str);
1295 return ret;
1296 }
1297 }
1298
1299 *out_val = str;
1300
1301 return 0;
1302}
1303
1304int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
1305{
1306 void *dst, *target_obj;
1307 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1308 uint8_t *out, buf[128];
1309 int ret;
1310
1311 if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
1313
1315 av_log(obj, AV_LOG_WARNING, "The \"%s\" option is deprecated: %s\n", name, o->help);
1316
1317 dst = (uint8_t *)target_obj + o->offset;
1318
1319 if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
1320 ret = opt_get_array(o, dst, out_val);
1321 if (ret < 0)
1322 return ret;
1323 if (!*out_val && !(search_flags & AV_OPT_ALLOW_NULL)) {
1324 *out_val = av_strdup("");
1325 if (!*out_val)
1326 return AVERROR(ENOMEM);
1327 }
1328 return 0;
1329 }
1330
1331 buf[0] = 0;
1332 out = buf;
1333 ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
1334 if (ret < 0)
1335 return ret;
1336 if (out != buf) {
1337 *out_val = out;
1338 return 0;
1339 }
1340
1341 if (ret >= sizeof(buf))
1342 return AVERROR(EINVAL);
1343 *out_val = av_strdup(out);
1344 return *out_val ? 0 : AVERROR(ENOMEM);
1345}
1346
1347static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
1348 int search_flags)
1349{
1350 void *dst, *target_obj;
1351 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1352 if (!o || !target_obj)
1355 return AVERROR(EINVAL);
1356
1357 dst = ((uint8_t *)target_obj) + o->offset;
1358
1359 return read_number(o, dst, num, den, intnum);
1360}
1361
1362int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
1363{
1364 int64_t intnum = 1;
1365 double num = 1;
1366 int ret, den = 1;
1367
1368 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1369 return ret;
1370 if (num == den)
1371 *out_val = intnum;
1372 else
1373 *out_val = num * intnum / den;
1374 return 0;
1375}
1376
1377int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
1378{
1379 int64_t intnum = 1;
1380 double num = 1;
1381 int ret, den = 1;
1382
1383 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1384 return ret;
1385 *out_val = num * intnum / den;
1386 return 0;
1387}
1388
1389int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
1390{
1391 int64_t intnum = 1;
1392 double num = 1;
1393 int ret, den = 1;
1394
1395 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
1396 return ret;
1397
1398 if (num == 1.0 && (int)intnum == intnum)
1399 *out_val = (AVRational){intnum, den};
1400 else
1401 *out_val = double_to_rational(num*intnum/den);
1402 return 0;
1403}
1404
1405int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
1406{
1407 void *dst, *target_obj;
1408 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1409 if (!o || !target_obj)
1411 if (o->type != AV_OPT_TYPE_IMAGE_SIZE) {
1413 "The value for option '%s' is not a image size.\n", name);
1414 return AVERROR(EINVAL);
1415 }
1416
1417 dst = ((uint8_t*)target_obj) + o->offset;
1418 if (w_out) *w_out = *(int *)dst;
1419 if (h_out) *h_out = *((int *)dst+1);
1420 return 0;
1421}
1422
1423int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
1424{
1425 return av_opt_get_q(obj, name, search_flags, out_val);
1426}
1427
1428static int get_format(void *obj, const char *name, int search_flags, void *out_fmt,
1429 enum AVOptionType type, const char *desc)
1430{
1431 void *dst, *target_obj;
1432 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1433 if (!o || !target_obj)
1435 if (o->type != type) {
1437 "The value for option '%s' is not a %s format.\n", desc, name);
1438 return AVERROR(EINVAL);
1439 }
1440
1441 dst = ((uint8_t*)target_obj) + o->offset;
1443 *(enum AVPixelFormat *)out_fmt = *(enum AVPixelFormat *)dst;
1444 else
1445 *(enum AVSampleFormat*)out_fmt = *(enum AVSampleFormat*)dst;
1446
1447 return 0;
1448}
1449
1450int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
1451{
1452 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_PIXEL_FMT, "pixel");
1453}
1454
1455int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
1456{
1457 return get_format(obj, name, search_flags, out_fmt, AV_OPT_TYPE_SAMPLE_FMT, "sample");
1458}
1459
1460int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
1461{
1462 void *dst, *target_obj;
1463 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1464 if (!o || !target_obj)
1466 if (o->type != AV_OPT_TYPE_CHLAYOUT) {
1468 "The value for option '%s' is not a channel layout.\n", name);
1469 return AVERROR(EINVAL);
1470 }
1471
1472 dst = ((uint8_t*)target_obj) + o->offset;
1473 return av_channel_layout_copy(cl, dst);
1474}
1475
1476int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
1477{
1478 void *target_obj;
1480 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
1481
1482 if (!o || !target_obj)
1484 if (o->type != AV_OPT_TYPE_DICT)
1485 return AVERROR(EINVAL);
1486
1487 src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
1488
1489 return av_dict_copy(out_val, src, 0);
1490}
1491
1492int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
1493{
1494 const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
1495 const AVOption *flag = av_opt_find(obj, flag_name,
1496 field ? field->unit : NULL, 0, 0);
1497 int64_t res;
1498
1499 if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
1500 av_opt_get_int(obj, field_name, 0, &res) < 0)
1501 return 0;
1502 return res & flag->default_val.i64;
1503}
1504
1505static void log_int_value(void *av_log_obj, int level, int64_t i)
1506{
1507 if (i == INT_MAX) {
1508 av_log(av_log_obj, level, "INT_MAX");
1509 } else if (i == INT_MIN) {
1510 av_log(av_log_obj, level, "INT_MIN");
1511 } else if (i == UINT32_MAX) {
1512 av_log(av_log_obj, level, "UINT32_MAX");
1513 } else if (i == INT64_MAX) {
1514 av_log(av_log_obj, level, "I64_MAX");
1515 } else if (i == INT64_MIN) {
1516 av_log(av_log_obj, level, "I64_MIN");
1517 } else {
1518 av_log(av_log_obj, level, "%"PRId64, i);
1519 }
1520}
1521
1522static void log_value(void *av_log_obj, int level, double d)
1523{
1524 if (d == INT_MAX) {
1525 av_log(av_log_obj, level, "INT_MAX");
1526 } else if (d == INT_MIN) {
1527 av_log(av_log_obj, level, "INT_MIN");
1528 } else if (d == UINT32_MAX) {
1529 av_log(av_log_obj, level, "UINT32_MAX");
1530 } else if (d == (double)INT64_MAX) {
1531 av_log(av_log_obj, level, "I64_MAX");
1532 } else if (d == INT64_MIN) {
1533 av_log(av_log_obj, level, "I64_MIN");
1534 } else if (d == FLT_MAX) {
1535 av_log(av_log_obj, level, "FLT_MAX");
1536 } else if (d == FLT_MIN) {
1537 av_log(av_log_obj, level, "FLT_MIN");
1538 } else if (d == -FLT_MAX) {
1539 av_log(av_log_obj, level, "-FLT_MAX");
1540 } else if (d == -FLT_MIN) {
1541 av_log(av_log_obj, level, "-FLT_MIN");
1542 } else if (d == DBL_MAX) {
1543 av_log(av_log_obj, level, "DBL_MAX");
1544 } else if (d == DBL_MIN) {
1545 av_log(av_log_obj, level, "DBL_MIN");
1546 } else if (d == -DBL_MAX) {
1547 av_log(av_log_obj, level, "-DBL_MAX");
1548 } else if (d == -DBL_MIN) {
1549 av_log(av_log_obj, level, "-DBL_MIN");
1550 } else {
1551 av_log(av_log_obj, level, "%g", d);
1552 }
1553}
1554
1555static const char *get_opt_const_name(void *obj, const char *unit, int64_t value)
1556{
1557 const AVOption *opt = NULL;
1558
1559 if (!unit)
1560 return NULL;
1561 while ((opt = av_opt_next(obj, opt)))
1562 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1563 opt->default_val.i64 == value)
1564 return opt->name;
1565 return NULL;
1566}
1567
1568static char *get_opt_flags_string(void *obj, const char *unit, int64_t value)
1569{
1570 const AVOption *opt = NULL;
1571 char flags[512];
1572
1573 flags[0] = 0;
1574 if (!unit)
1575 return NULL;
1576 while ((opt = av_opt_next(obj, opt))) {
1577 if (opt->type == AV_OPT_TYPE_CONST && !strcmp(opt->unit, unit) &&
1578 opt->default_val.i64 & value) {
1579 if (flags[0])
1580 av_strlcatf(flags, sizeof(flags), "+");
1581 av_strlcatf(flags, sizeof(flags), "%s", opt->name);
1582 }
1583 }
1584 if (flags[0])
1585 return av_strdup(flags);
1586 return NULL;
1587}
1588
1589static void log_type(void *av_log_obj, const AVOption *o,
1590 enum AVOptionType parent_type)
1591{
1592 const enum AVOptionType type = TYPE_BASE(o->type);
1593
1594 if (o->type == AV_OPT_TYPE_CONST && (TYPE_BASE(parent_type) == AV_OPT_TYPE_INT || TYPE_BASE(parent_type) == AV_OPT_TYPE_INT64))
1595 av_log(av_log_obj, AV_LOG_INFO, "%-12"PRId64" ", o->default_val.i64);
1598 av_log(av_log_obj, AV_LOG_INFO, "[%-10s]", opt_type_desc[type].name);
1599 else
1600 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", opt_type_desc[type].name);
1601 }
1602 else
1603 av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "");
1604}
1605
1606static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
1607{
1608 if (opt->type == AV_OPT_TYPE_CONST || opt->type == AV_OPT_TYPE_BINARY)
1609 return;
1610 if ((opt->type == AV_OPT_TYPE_COLOR ||
1611 opt->type == AV_OPT_TYPE_IMAGE_SIZE ||
1612 opt->type == AV_OPT_TYPE_STRING ||
1613 opt->type == AV_OPT_TYPE_DICT ||
1614 opt->type == AV_OPT_TYPE_CHLAYOUT ||
1615 opt->type == AV_OPT_TYPE_VIDEO_RATE) &&
1616 !opt->default_val.str)
1617 return;
1618
1619 if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1620 const AVOptionArrayDef *arr = opt->default_val.arr;
1621 if (arr && arr->def)
1622 av_log(av_log_obj, AV_LOG_INFO, " (default %s)", arr->def);
1623 return;
1624 }
1625
1626 av_log(av_log_obj, AV_LOG_INFO, " (default ");
1627 switch (opt->type) {
1628 case AV_OPT_TYPE_BOOL:
1629 av_log(av_log_obj, AV_LOG_INFO, "%s", get_bool_name(opt->default_val.i64));
1630 break;
1631 case AV_OPT_TYPE_FLAGS: {
1632 char *def_flags = get_opt_flags_string(obj, opt->unit, opt->default_val.i64);
1633 if (def_flags) {
1634 av_log(av_log_obj, AV_LOG_INFO, "%s", def_flags);
1635 av_freep(&def_flags);
1636 } else {
1637 av_log(av_log_obj, AV_LOG_INFO, "%"PRIX64, opt->default_val.i64);
1638 }
1639 break;
1640 }
1641 case AV_OPT_TYPE_DURATION: {
1642 char buf[25];
1643 format_duration(buf, sizeof(buf), opt->default_val.i64);
1644 av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
1645 break;
1646 }
1647 case AV_OPT_TYPE_UINT:
1648 case AV_OPT_TYPE_INT:
1649 case AV_OPT_TYPE_UINT64:
1650 case AV_OPT_TYPE_INT64: {
1651 const char *def_const = get_opt_const_name(obj, opt->unit, opt->default_val.i64);
1652 if (def_const)
1653 av_log(av_log_obj, AV_LOG_INFO, "%s", def_const);
1654 else
1655 log_int_value(av_log_obj, AV_LOG_INFO, opt->default_val.i64);
1656 break;
1657 }
1658 case AV_OPT_TYPE_DOUBLE:
1659 case AV_OPT_TYPE_FLOAT:
1660 log_value(av_log_obj, AV_LOG_INFO, opt->default_val.dbl);
1661 break;
1662 case AV_OPT_TYPE_RATIONAL: {
1663 AVRational q = av_d2q(opt->default_val.dbl, INT_MAX);
1664 av_log(av_log_obj, AV_LOG_INFO, "%d/%d", q.num, q.den); }
1665 break;
1667 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(opt->default_val.i64), "none"));
1668 break;
1670 av_log(av_log_obj, AV_LOG_INFO, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(opt->default_val.i64), "none"));
1671 break;
1672 case AV_OPT_TYPE_COLOR:
1674 case AV_OPT_TYPE_STRING:
1675 case AV_OPT_TYPE_DICT:
1678 av_log(av_log_obj, AV_LOG_INFO, "\"%s\"", opt->default_val.str);
1679 break;
1680 }
1681 av_log(av_log_obj, AV_LOG_INFO, ")");
1682}
1683
1684static void opt_list(void *obj, void *av_log_obj, const char *unit,
1685 int req_flags, int rej_flags, enum AVOptionType parent_type)
1686{
1687 const AVOption *opt = NULL;
1689 int i;
1690
1691 while ((opt = av_opt_next(obj, opt))) {
1692 if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
1693 continue;
1694
1695 /* Don't print CONST's on level one.
1696 * Don't print anything but CONST's on level two.
1697 * Only print items from the requested unit.
1698 */
1699 if (!unit && opt->type == AV_OPT_TYPE_CONST)
1700 continue;
1701 else if (unit && opt->type != AV_OPT_TYPE_CONST)
1702 continue;
1703 else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
1704 continue;
1705 else if (unit && opt->type == AV_OPT_TYPE_CONST)
1706 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
1707 else
1708 av_log(av_log_obj, AV_LOG_INFO, " %s%-17s ",
1709 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? " " : "-",
1710 opt->name);
1711
1712 log_type(av_log_obj, opt, parent_type);
1713
1714 av_log(av_log_obj, AV_LOG_INFO, "%c%c%c%c%c%c%c%c%c%c%c",
1715 (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.',
1716 (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.',
1717 (opt->flags & AV_OPT_FLAG_FILTERING_PARAM) ? 'F' : '.',
1718 (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.',
1719 (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.',
1720 (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.',
1721 (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.',
1722 (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.',
1723 (opt->flags & AV_OPT_FLAG_BSF_PARAM) ? 'B' : '.',
1724 (opt->flags & AV_OPT_FLAG_RUNTIME_PARAM) ? 'T' : '.',
1725 (opt->flags & AV_OPT_FLAG_DEPRECATED) ? 'P' : '.');
1726
1727 if (opt->help)
1728 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
1729
1731 switch (opt->type) {
1732 case AV_OPT_TYPE_INT:
1733 case AV_OPT_TYPE_UINT:
1734 case AV_OPT_TYPE_INT64:
1735 case AV_OPT_TYPE_UINT64:
1736 case AV_OPT_TYPE_DOUBLE:
1737 case AV_OPT_TYPE_FLOAT:
1739 for (i = 0; i < r->nb_ranges; i++) {
1740 av_log(av_log_obj, AV_LOG_INFO, " (from ");
1741 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_min);
1742 av_log(av_log_obj, AV_LOG_INFO, " to ");
1743 log_value(av_log_obj, AV_LOG_INFO, r->range[i]->value_max);
1744 av_log(av_log_obj, AV_LOG_INFO, ")");
1745 }
1746 break;
1747 }
1749 }
1750
1751 log_default(obj, av_log_obj, opt);
1752
1753 av_log(av_log_obj, AV_LOG_INFO, "\n");
1754 if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
1755 opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags, opt->type);
1756 }
1757}
1758
1759int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
1760{
1761 if (!obj)
1762 return -1;
1763
1764 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
1765
1766 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags, -1);
1767
1768 return 0;
1769}
1770
1772{
1773 av_opt_set_defaults2(s, 0, 0);
1774}
1775
1776void av_opt_set_defaults2(void *s, int mask, int flags)
1777{
1778 const AVOption *opt = NULL;
1779 while ((opt = av_opt_next(s, opt))) {
1780 void *dst = ((uint8_t*)s) + opt->offset;
1781
1782 if ((opt->flags & mask) != flags)
1783 continue;
1784
1785 if (opt->flags & AV_OPT_FLAG_READONLY)
1786 continue;
1787
1788 if (opt->type & AV_OPT_TYPE_FLAG_ARRAY) {
1789 const AVOptionArrayDef *arr = opt->default_val.arr;
1790 const char sep = opt_array_sep(opt);
1791
1792 av_assert0(sep && sep != '\\' &&
1793 (sep < 'a' || sep > 'z') &&
1794 (sep < 'A' || sep > 'Z') &&
1795 (sep < '0' || sep > '9'));
1796
1797 if (arr && arr->def)
1798 opt_set_array(s, s, opt, arr->def, dst);
1799
1800 continue;
1801 }
1802
1803 switch (opt->type) {
1804 case AV_OPT_TYPE_CONST:
1805 /* Nothing to be done here */
1806 break;
1807 case AV_OPT_TYPE_BOOL:
1808 case AV_OPT_TYPE_FLAGS:
1809 case AV_OPT_TYPE_INT:
1810 case AV_OPT_TYPE_UINT:
1811 case AV_OPT_TYPE_INT64:
1812 case AV_OPT_TYPE_UINT64:
1816 write_number(s, opt, dst, 1, 1, opt->default_val.i64, 1);
1817 break;
1818 case AV_OPT_TYPE_DOUBLE:
1819 case AV_OPT_TYPE_FLOAT: {
1820 double val;
1821 val = opt->default_val.dbl;
1822 write_number(s, opt, dst, val, 1, 1, 1);
1823 }
1824 break;
1825 case AV_OPT_TYPE_RATIONAL: {
1827 val = av_d2q(opt->default_val.dbl, INT_MAX);
1828 write_number(s, opt, dst, 1, val.den, val.num, 1);
1829 }
1830 break;
1831 case AV_OPT_TYPE_COLOR:
1832 set_string_color(s, opt, opt->default_val.str, dst);
1833 break;
1834 case AV_OPT_TYPE_STRING:
1835 set_string(s, opt, opt->default_val.str, dst);
1836 break;
1839 break;
1842 break;
1843 case AV_OPT_TYPE_BINARY:
1844 set_string_binary(s, opt, opt->default_val.str, dst);
1845 break;
1848 break;
1849 case AV_OPT_TYPE_DICT:
1850 set_string_dict(s, opt, opt->default_val.str, dst);
1851 break;
1852 default:
1853 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
1854 opt->type, opt->name);
1855 }
1856 }
1857}
1858
1859/**
1860 * Store the value in the field in ctx that is named like key.
1861 * ctx must be an AVClass context, storing is done using AVOptions.
1862 *
1863 * @param buf the string to parse, buf will be updated to point at the
1864 * separator just after the parsed key/value pair
1865 * @param key_val_sep a 0-terminated list of characters used to
1866 * separate key from value
1867 * @param pairs_sep a 0-terminated list of characters used to separate
1868 * two pairs from each other
1869 * @return 0 if the key/value pair has been successfully parsed and
1870 * set, or a negative value corresponding to an AVERROR code in case
1871 * of error:
1872 * AVERROR(EINVAL) if the key/value pair cannot be parsed,
1873 * the error code issued by av_opt_set() if the key/value pair
1874 * cannot be set
1875 */
1876static int parse_key_value_pair(void *ctx, const char **buf,
1877 const char *key_val_sep, const char *pairs_sep)
1878{
1879 char *key = av_get_token(buf, key_val_sep);
1880 char *val;
1881 int ret;
1882
1883 if (!key)
1884 return AVERROR(ENOMEM);
1885
1886 if (*key && strspn(*buf, key_val_sep)) {
1887 (*buf)++;
1888 val = av_get_token(buf, pairs_sep);
1889 if (!val) {
1890 av_freep(&key);
1891 return AVERROR(ENOMEM);
1892 }
1893 } else {
1894 av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
1895 av_free(key);
1896 return AVERROR(EINVAL);
1897 }
1898
1899 av_log(ctx, AV_LOG_DEBUG, "Setting entry with key '%s' to value '%s'\n", key, val);
1900
1903 av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
1904
1905 av_free(key);
1906 av_free(val);
1907 return ret;
1908}
1909
1910int av_set_options_string(void *ctx, const char *opts,
1911 const char *key_val_sep, const char *pairs_sep)
1912{
1913 int ret, count = 0;
1914
1915 if (!opts)
1916 return 0;
1917
1918 while (*opts) {
1919 if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
1920 return ret;
1921 count++;
1922
1923 if (*opts)
1924 opts++;
1925 }
1926
1927 return count;
1928}
1929
1930#define WHITESPACES " \n\t\r"
1931
1932static int is_key_char(char c)
1933{
1934 return (unsigned)((c | 32) - 'a') < 26 ||
1935 (unsigned)(c - '0') < 10 ||
1936 c == '-' || c == '_' || c == '/' || c == '.';
1937}
1938
1939/**
1940 * Read a key from a string.
1941 *
1942 * The key consists of is_key_char characters and must be terminated by a
1943 * character from the delim string; spaces are ignored.
1944 *
1945 * @return 0 for success (even with ellipsis), <0 for failure
1946 */
1947static int get_key(const char **ropts, const char *delim, char **rkey)
1948{
1949 const char *opts = *ropts;
1950 const char *key_start, *key_end;
1951
1952 key_start = opts += strspn(opts, WHITESPACES);
1953 while (is_key_char(*opts))
1954 opts++;
1955 key_end = opts;
1956 opts += strspn(opts, WHITESPACES);
1957 if (!*opts || !strchr(delim, *opts))
1958 return AVERROR(EINVAL);
1959 opts++;
1960 if (!(*rkey = av_malloc(key_end - key_start + 1)))
1961 return AVERROR(ENOMEM);
1962 memcpy(*rkey, key_start, key_end - key_start);
1963 (*rkey)[key_end - key_start] = 0;
1964 *ropts = opts;
1965 return 0;
1966}
1967
1968int av_opt_get_key_value(const char **ropts,
1969 const char *key_val_sep, const char *pairs_sep,
1970 unsigned flags,
1971 char **rkey, char **rval)
1972{
1973 int ret;
1974 char *key = NULL, *val;
1975 const char *opts = *ropts;
1976
1977 if ((ret = get_key(&opts, key_val_sep, &key)) < 0 &&
1979 return AVERROR(EINVAL);
1980 if (!(val = av_get_token(&opts, pairs_sep))) {
1981 av_free(key);
1982 return AVERROR(ENOMEM);
1983 }
1984 *ropts = opts;
1985 *rkey = key;
1986 *rval = val;
1987 return 0;
1988}
1989
1990int av_opt_set_from_string(void *ctx, const char *opts,
1991 const char *const *shorthand,
1992 const char *key_val_sep, const char *pairs_sep)
1993{
1994 int ret, count = 0;
1995 const char *dummy_shorthand = NULL;
1996 const char *key;
1997
1998 if (!opts)
1999 return 0;
2000 if (!shorthand)
2001 shorthand = &dummy_shorthand;
2002
2003 while (*opts) {
2004 char *parsed_key, *value;
2005 ret = av_opt_get_key_value(&opts, key_val_sep, pairs_sep,
2006 *shorthand ? AV_OPT_FLAG_IMPLICIT_KEY : 0,
2007 &parsed_key, &value);
2008 if (ret < 0) {
2009 if (ret == AVERROR(EINVAL))
2010 av_log(ctx, AV_LOG_ERROR, "No option name near '%s'\n", opts);
2011 else
2012 av_log(ctx, AV_LOG_ERROR, "Unable to parse '%s': %s\n", opts,
2013 av_err2str(ret));
2014 return ret;
2015 }
2016 if (*opts)
2017 opts++;
2018 if (parsed_key) {
2019 key = parsed_key;
2020 while (*shorthand) /* discard all remaining shorthand */
2021 shorthand++;
2022 } else {
2023 key = *(shorthand++);
2024 }
2025
2026 av_log(ctx, AV_LOG_DEBUG, "Setting '%s' to value '%s'\n", key, value);
2027 if ((ret = av_opt_set(ctx, key, value, 0)) < 0) {
2029 av_log(ctx, AV_LOG_ERROR, "Option '%s' not found\n", key);
2030 av_free(value);
2031 av_free(parsed_key);
2032 return ret;
2033 }
2034
2035 av_free(value);
2036 av_free(parsed_key);
2037 count++;
2038 }
2039 return count;
2040}
2041
2042void av_opt_free(void *obj)
2043{
2044 const AVOption *o = NULL;
2045 while ((o = av_opt_next(obj, o))) {
2046 void *pitem = (uint8_t *)obj + o->offset;
2047
2049 opt_free_array(o, pitem, opt_array_pcount(pitem));
2050 else
2051 opt_free_elem(o->type, pitem);
2052 }
2053}
2054
2055int av_opt_set_dict2(void *obj, AVDictionary **options, int search_flags)
2056{
2057 const AVDictionaryEntry *t = NULL;
2059 int ret;
2060
2061 if (!options)
2062 return 0;
2063
2064 while ((t = av_dict_iterate(*options, t))) {
2065 ret = av_opt_set(obj, t->key, t->value, search_flags);
2068 if (ret < 0) {
2069 av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
2070 av_dict_free(&tmp);
2071 return ret;
2072 }
2073 }
2075 *options = tmp;
2076 return 0;
2077}
2078
2080{
2081 return av_opt_set_dict2(obj, options, 0);
2082}
2083
2084const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
2085 int opt_flags, int search_flags)
2086{
2087 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
2088}
2089
2090const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
2091 int opt_flags, int search_flags, void **target_obj)
2092{
2093 const AVClass *c;
2094 const AVOption *o = NULL;
2095
2096 if(!obj)
2097 return NULL;
2098
2099 c= *(AVClass**)obj;
2100
2101 if (!c)
2102 return NULL;
2103
2104 if (search_flags & AV_OPT_SEARCH_CHILDREN) {
2105 if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
2106 void *iter = NULL;
2107 const AVClass *child;
2108 while (child = av_opt_child_class_iterate(c, &iter))
2109 if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
2110 return o;
2111 } else {
2112 void *child = NULL;
2113 while (child = av_opt_child_next(obj, child))
2114 if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
2115 return o;
2116 }
2117 }
2118
2119 while (o = av_opt_next(obj, o)) {
2120 if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
2121 ((!unit && o->type != AV_OPT_TYPE_CONST) ||
2122 (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) {
2123 if (target_obj) {
2124 if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
2125 *target_obj = obj;
2126 else
2127 *target_obj = NULL;
2128 }
2129 return o;
2130 }
2131 }
2132 return NULL;
2133}
2134
2135void *av_opt_child_next(void *obj, void *prev)
2136{
2137 const AVClass *c = *(AVClass **)obj;
2138 if (c->child_next)
2139 return c->child_next(obj, prev);
2140 return NULL;
2141}
2142
2143const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter)
2144{
2145 if (parent->child_class_iterate)
2146 return parent->child_class_iterate(iter);
2147 return NULL;
2148}
2149
2150static int opt_copy_elem(void *logctx, enum AVOptionType type,
2151 void *dst, const void *src)
2152{
2153 if (type == AV_OPT_TYPE_STRING) {
2154 const char *src_str = *(const char *const *)src;
2155 char **dstp = (char **)dst;
2156 if (*dstp != src_str)
2157 av_freep(dstp);
2158 if (src_str) {
2159 *dstp = av_strdup(src_str);
2160 if (!*dstp)
2161 return AVERROR(ENOMEM);
2162 }
2163 } else if (type == AV_OPT_TYPE_BINARY) {
2164 const uint8_t *const *src8 = (const uint8_t *const *)src;
2165 uint8_t **dst8 = (uint8_t **)dst;
2166 int len = *(const int *)(src8 + 1);
2167 if (*dst8 != *src8)
2168 av_freep(dst8);
2169 *dst8 = av_memdup(*src8, len);
2170 if (len && !*dst8) {
2171 *(int *)(dst8 + 1) = 0;
2172 return AVERROR(ENOMEM);
2173 }
2174 *(int *)(dst8 + 1) = len;
2175 } else if (type == AV_OPT_TYPE_CONST) {
2176 // do nothing
2177 } else if (type == AV_OPT_TYPE_DICT) {
2178 const AVDictionary *sdict = *(const AVDictionary * const *)src;
2179 AVDictionary **ddictp = (AVDictionary **)dst;
2180 if (sdict != *ddictp)
2181 av_dict_free(ddictp);
2182 *ddictp = NULL;
2183 return av_dict_copy(ddictp, sdict, 0);
2184 } else if (type == AV_OPT_TYPE_CHLAYOUT) {
2185 const AVChannelLayout *slayout = (const AVChannelLayout *)src;
2186 AVChannelLayout *dlayout = (AVChannelLayout *)dst;
2187 if (dlayout != slayout) {
2188 if (dlayout->order == AV_CHANNEL_ORDER_CUSTOM &&
2189 slayout->order == AV_CHANNEL_ORDER_CUSTOM &&
2190 dlayout->u.map == slayout->u.map)
2191 dlayout->u.map = NULL;
2193 }
2194 } else if (opt_is_pod(type)) {
2195 size_t size = opt_type_desc[type].size;
2196 memcpy(dst, src, size);
2197 } else {
2198 av_log(logctx, AV_LOG_ERROR, "Unhandled option type: %d\n", type);
2199 return AVERROR(EINVAL);
2200 }
2201
2202 return 0;
2203}
2204
2205static int opt_copy_array(void *logctx, const AVOption *o,
2206 void **pdst, const void * const *psrc)
2207{
2208 unsigned nb_elems = *opt_array_pcount(psrc);
2209 void *dst = NULL;
2210 int ret;
2211
2212 if (*pdst == *psrc) {
2213 *pdst = NULL;
2214 *opt_array_pcount(pdst) = 0;
2215 }
2216
2217 opt_free_array(o, pdst, opt_array_pcount(pdst));
2218
2219 dst = av_calloc(nb_elems, opt_type_desc[TYPE_BASE(o->type)].size);
2220 if (!dst)
2221 return AVERROR(ENOMEM);
2222
2223 for (unsigned i = 0; i < nb_elems; i++) {
2224 ret = opt_copy_elem(logctx, TYPE_BASE(o->type),
2225 opt_array_pelem(o, dst, i),
2226 opt_array_pelem(o, *(void**)psrc, i));
2227 if (ret < 0) {
2228 opt_free_array(o, &dst, &nb_elems);
2229 return ret;
2230 }
2231 }
2232
2233 *pdst = dst;
2234 *opt_array_pcount(pdst) = nb_elems;
2235
2236 return 0;
2237}
2238
2239int av_opt_copy(void *dst, const void *src)
2240{
2241 const AVOption *o = NULL;
2242 const AVClass *c;
2243 int ret = 0;
2244
2245 if (!src)
2246 return AVERROR(EINVAL);
2247
2248 c = *(AVClass **)src;
2249 if (!c || c != *(AVClass **)dst)
2250 return AVERROR(EINVAL);
2251
2252 while ((o = av_opt_next(src, o))) {
2253 void *field_dst = (uint8_t *)dst + o->offset;
2254 void *field_src = (uint8_t *)src + o->offset;
2255
2256 int err = (o->type & AV_OPT_TYPE_FLAG_ARRAY) ?
2257 opt_copy_array(dst, o, field_dst, field_src) :
2258 opt_copy_elem (dst, o->type, field_dst, field_src);
2259 if (err < 0)
2260 ret = err;
2261 }
2262 return ret;
2263}
2264
2265int av_opt_get_array_size(void *obj, const char *name, int search_flags,
2266 unsigned int *out_val)
2267{
2268 void *target_obj, *parray;
2269 const AVOption *o;
2270
2271 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
2272 if (!o || !target_obj)
2274 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY))
2275 return AVERROR(EINVAL);
2276
2277 parray = (uint8_t *)target_obj + o->offset;
2278 *out_val = *opt_array_pcount(parray);
2279
2280 return 0;
2281}
2282
2283int av_opt_get_array(void *obj, const char *name, int search_flags,
2284 unsigned int start_elem, unsigned int nb_elems,
2285 enum AVOptionType out_type, void *out_val)
2286{
2287 const size_t elem_size_out = opt_type_desc[TYPE_BASE(out_type)].size;
2288
2289 const AVOption *o;
2290 void *target_obj;
2291
2292 const void *parray;
2293 unsigned array_size;
2294
2295 int ret;
2296
2297 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
2298 if (!o || !target_obj)
2300 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) ||
2301 (out_type & AV_OPT_TYPE_FLAG_ARRAY))
2302 return AVERROR(EINVAL);
2303
2304 parray = (uint8_t *)target_obj + o->offset;
2305 array_size = *opt_array_pcount(parray);
2306
2307 if (start_elem >= array_size ||
2308 array_size - start_elem < nb_elems)
2309 return AVERROR(EINVAL);
2310
2311 for (unsigned i = 0; i < nb_elems; i++) {
2312 const void *src = opt_array_pelem(o, *(void**)parray, start_elem + i);
2313 void *dst = (uint8_t*)out_val + i * elem_size_out;
2314
2315 if (out_type == TYPE_BASE(o->type)) {
2316 ret = opt_copy_elem(obj, out_type, dst, src);
2317 if (ret < 0)
2318 goto fail;
2319 } else if (out_type == AV_OPT_TYPE_STRING) {
2320 uint8_t buf[128], *out = buf;
2321
2322 ret = opt_get_elem(o, &out, sizeof(buf), src, search_flags);
2323 if (ret < 0)
2324 goto fail;
2325
2326 if (out == buf) {
2327 out = av_strdup(buf);
2328 if (!out) {
2329 ret = AVERROR(ENOMEM);
2330 goto fail;
2331 }
2332 }
2333
2334 *(uint8_t**)dst = out;
2335 } else if (out_type == AV_OPT_TYPE_INT64 ||
2336 out_type == AV_OPT_TYPE_DOUBLE ||
2337 out_type == AV_OPT_TYPE_RATIONAL) {
2338 double num = 1.0;
2339 int den = 1;
2340 int64_t intnum = 1;
2341
2342 ret = read_number(o, src, &num, &den, &intnum);
2343 if (ret < 0)
2344 goto fail;
2345
2346 switch (out_type) {
2347 case AV_OPT_TYPE_INT64:
2348 *(int64_t*)dst = (num == den) ? intnum : num * intnum / den;
2349 break;
2350 case AV_OPT_TYPE_DOUBLE:
2351 *(double*)dst = num * intnum / den;
2352 break;
2354 *(AVRational*)dst = (num == 1.0 && (int)intnum == intnum) ?
2355 (AVRational){ intnum, den } :
2356 double_to_rational(num * intnum / den);
2357 break;
2358 default: av_assert0(0);
2359 }
2360 } else
2361 return AVERROR(ENOSYS);
2362 }
2363
2364 return 0;
2365fail:
2366 for (unsigned i = 0; i < nb_elems; i++)
2367 opt_free_elem(out_type, (uint8_t*)out_val + i * elem_size_out);
2368 return ret;
2369}
2370
2371int av_opt_set_array(void *obj, const char *name, int search_flags,
2372 unsigned int start_elem, unsigned int nb_elems,
2373 enum AVOptionType val_type, const void *val)
2374{
2375 const size_t elem_size_val = opt_type_desc[TYPE_BASE(val_type)].size;
2376
2377 const AVOption *o;
2378 const AVOptionArrayDef *arr;
2379 void *target_obj;
2380
2381 void *parray;
2382 void *new_elems;
2383 unsigned *array_size, new_size;
2384 size_t elem_size;
2385
2386 int ret = 0;
2387
2388 ret = opt_set_init(obj, name, search_flags, 0, &target_obj, &o, &parray);
2389 if (ret < 0)
2390 return ret;
2391
2392 if (!(o->type & AV_OPT_TYPE_FLAG_ARRAY) ||
2393 (val_type & AV_OPT_TYPE_FLAG_ARRAY))
2394 return AVERROR(EINVAL);
2395
2396 arr = o->default_val.arr;
2397 array_size = opt_array_pcount(parray);
2398 elem_size = opt_type_desc[TYPE_BASE(o->type)].size;
2399
2400 if (start_elem > *array_size)
2401 return AVERROR(EINVAL);
2402
2403 // compute new array size
2404 if (!val) {
2405 if (*array_size - start_elem < nb_elems)
2406 return AVERROR(EINVAL);
2407
2408 new_size = *array_size - nb_elems;
2409 } else if (search_flags & AV_OPT_ARRAY_REPLACE) {
2410 if (start_elem >= UINT_MAX - nb_elems)
2411 return AVERROR(EINVAL);
2412
2413 new_size = FFMAX(*array_size, start_elem + nb_elems);
2414 } else {
2415 if (nb_elems >= UINT_MAX - *array_size)
2416 return AVERROR(EINVAL);
2417
2418 new_size = *array_size + nb_elems;
2419 }
2420
2421 if (arr &&
2422 ((arr->size_max && new_size > arr->size_max) ||
2423 (arr->size_min && new_size < arr->size_min)))
2424 return AVERROR(EINVAL);
2425
2426 // desired operation is shrinking the array
2427 if (!val) {
2428 void *array = *(void**)parray;
2429
2430 for (unsigned i = 0; i < nb_elems; i++) {
2432 opt_array_pelem(o, array, start_elem + i));
2433 }
2434
2435 if (new_size > 0) {
2436 memmove(opt_array_pelem(o, array, start_elem),
2437 opt_array_pelem(o, array, start_elem + nb_elems),
2438 elem_size * (*array_size - start_elem - nb_elems));
2439
2440 array = av_realloc_array(array, new_size, elem_size);
2441 if (!array)
2442 return AVERROR(ENOMEM);
2443
2444 *(void**)parray = array;
2445 } else
2446 av_freep(parray);
2447
2448 *array_size = new_size;
2449
2450 return 0;
2451 }
2452
2453 // otherwise, desired operation is insert/replace;
2454 // first, store new elements in a separate array to simplify
2455 // rollback on failure
2456 new_elems = av_calloc(nb_elems, elem_size);
2457 if (!new_elems)
2458 return AVERROR(ENOMEM);
2459
2460 // convert/validate each new element
2461 for (unsigned i = 0; i < nb_elems; i++) {
2462 void *dst = opt_array_pelem(o, new_elems, i);
2463 const void *src = (uint8_t*)val + i * elem_size_val;
2464
2465 double num = 1.0;
2466 int den = 1;
2467 int64_t intnum = 1;
2468
2469 if (val_type == TYPE_BASE(o->type)) {
2470 int err;
2471
2472 ret = opt_copy_elem(obj, val_type, dst, src);
2473 if (ret < 0)
2474 goto fail;
2475
2476 // validate the range for numeric options
2477 err = read_number(o, dst, &num, &den, &intnum);
2478 if (err >= 0 && TYPE_BASE(o->type) != AV_OPT_TYPE_FLAGS &&
2479 (!den || o->max * den < num * intnum || o->min * den > num * intnum)) {
2480 num = den ? num * intnum / den : (num && intnum ? INFINITY : NAN);
2481 av_log(obj, AV_LOG_ERROR, "Cannot set array element %u for "
2482 "parameter '%s': value %f out of range [%g - %g]\n",
2483 start_elem + i, o->name, num, o->min, o->max);
2484 ret = AVERROR(ERANGE);
2485 goto fail;
2486 }
2487 } else if (val_type == AV_OPT_TYPE_STRING) {
2488 ret = opt_set_elem(obj, target_obj, o, *(const char **)src, dst);
2489 if (ret < 0)
2490 goto fail;
2491 } else if (val_type == AV_OPT_TYPE_INT ||
2492 val_type == AV_OPT_TYPE_INT64 ||
2493 val_type == AV_OPT_TYPE_FLOAT ||
2494 val_type == AV_OPT_TYPE_DOUBLE ||
2495 val_type == AV_OPT_TYPE_RATIONAL) {
2496
2497 switch (val_type) {
2498 case AV_OPT_TYPE_INT: intnum = *(int*)src; break;
2499 case AV_OPT_TYPE_INT64: intnum = *(int64_t*)src; break;
2500 case AV_OPT_TYPE_FLOAT: num = *(float*)src; break;
2501 case AV_OPT_TYPE_DOUBLE: num = *(double*)src; break;
2502 case AV_OPT_TYPE_RATIONAL: intnum = ((AVRational*)src)->num;
2503 den = ((AVRational*)src)->den; break;
2504 default: av_assert0(0);
2505 }
2506
2507 ret = write_number(obj, o, dst, num, den, intnum, 0);
2508 if (ret < 0)
2509 goto fail;
2510 } else {
2511 ret = AVERROR(ENOSYS);
2512 goto fail;
2513 }
2514 }
2515
2516 // commit new elements to the array
2517 if (start_elem == 0 && nb_elems == new_size) {
2518 // replacing the existing array entirely
2519 opt_free_array(o, parray, array_size);
2520 *(void**)parray = new_elems;
2521 *array_size = nb_elems;
2522
2523 new_elems = NULL;
2524 nb_elems = 0;
2525 } else {
2526 void *array = av_realloc_array(*(void**)parray, new_size, elem_size);
2527 if (!array) {
2528 ret = AVERROR(ENOMEM);
2529 goto fail;
2530 }
2531
2532 if (search_flags & AV_OPT_ARRAY_REPLACE) {
2533 // free the elements being overwritten
2534 for (unsigned i = start_elem; i < FFMIN(start_elem + nb_elems, *array_size); i++)
2536 } else {
2537 // shift existing elements to the end
2538 memmove(opt_array_pelem(o, array, start_elem + nb_elems),
2539 opt_array_pelem(o, array, start_elem),
2540 elem_size * (*array_size - start_elem));
2541 }
2542
2543 memcpy((uint8_t*)array + elem_size * start_elem, new_elems, elem_size * nb_elems);
2544
2545 av_freep(&new_elems);
2546 nb_elems = 0;
2547
2548 *(void**)parray = array;
2549 *array_size = new_size;
2550 }
2551
2552fail:
2553 opt_free_array(o, &new_elems, &nb_elems);
2554
2555 return ret;
2556}
2557
2558int av_opt_query_ranges(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2559{
2560 int ret;
2561 const AVClass *c = *(AVClass**)obj;
2562 int (*callback)(AVOptionRanges **, void *obj, const char *key, int flags) = c->query_ranges;
2563
2564 if (!callback)
2566
2567 ret = callback(ranges_arg, obj, key, flags);
2568 if (ret >= 0) {
2570 ret = 1;
2571 (*ranges_arg)->nb_components = ret;
2572 }
2573 return ret;
2574}
2575
2576int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const char *key, int flags)
2577{
2578 AVOptionRanges *ranges = av_mallocz(sizeof(*ranges));
2579 AVOptionRange **range_array = av_mallocz(sizeof(void*));
2580 AVOptionRange *range = av_mallocz(sizeof(*range));
2581 const AVOption *field = av_opt_find(obj, key, NULL, 0, flags);
2582 int ret;
2583
2584 *ranges_arg = NULL;
2585
2586 if (!ranges || !range || !range_array || !field) {
2587 ret = AVERROR(ENOMEM);
2588 goto fail;
2589 }
2590
2591 ranges->range = range_array;
2592 ranges->range[0] = range;
2593 ranges->nb_ranges = 1;
2594 ranges->nb_components = 1;
2595 range->is_range = 1;
2596 range->value_min = field->min;
2597 range->value_max = field->max;
2598
2599 switch (field->type) {
2600 case AV_OPT_TYPE_BOOL:
2601 case AV_OPT_TYPE_INT:
2602 case AV_OPT_TYPE_UINT:
2603 case AV_OPT_TYPE_INT64:
2604 case AV_OPT_TYPE_UINT64:
2607 case AV_OPT_TYPE_FLOAT:
2608 case AV_OPT_TYPE_DOUBLE:
2610 case AV_OPT_TYPE_COLOR:
2611 break;
2612 case AV_OPT_TYPE_STRING:
2613 range->component_min = 0;
2614 range->component_max = 0x10FFFF; // max unicode value
2615 range->value_min = -1;
2616 range->value_max = INT_MAX;
2617 break;
2619 range->component_min = INT_MIN;
2620 range->component_max = INT_MAX;
2621 break;
2623 range->component_min = 0;
2624 range->component_max = INT_MAX/128/8;
2625 range->value_min = 0;
2626 range->value_max = INT_MAX/8;
2627 break;
2629 range->component_min = 1;
2630 range->component_max = INT_MAX;
2631 range->value_min = 1;
2632 range->value_max = INT_MAX;
2633 break;
2634 default:
2635 ret = AVERROR(ENOSYS);
2636 goto fail;
2637 }
2638
2639 *ranges_arg = ranges;
2640 return 1;
2641fail:
2642 av_free(ranges);
2643 av_free(range);
2644 av_free(range_array);
2645 return ret;
2646}
2647
2649{
2650 int i;
2651 AVOptionRanges *ranges = *rangesp;
2652
2653 if (!ranges)
2654 return;
2655
2656 for (i = 0; i < ranges->nb_ranges * ranges->nb_components; i++) {
2657 AVOptionRange *range = ranges->range[i];
2658 if (range) {
2659 av_freep(&range->str);
2660 av_freep(&ranges->range[i]);
2661 }
2662 }
2663 av_freep(&ranges->range);
2664 av_freep(rangesp);
2665}
2666
2668{
2669 int64_t i64;
2670 double d;
2671 AVRational q;
2672 int ret, w, h;
2673 char *str;
2674 void *dst;
2675
2676 if (!o || !obj)
2677 return AVERROR(EINVAL);
2678
2679 dst = ((uint8_t*)obj) + o->offset;
2680
2681 if (o->type & AV_OPT_TYPE_FLAG_ARRAY) {
2682 const char *def = o->default_val.arr ? o->default_val.arr->def : NULL;
2683 uint8_t *val;
2684
2685 ret = opt_get_array(o, dst, &val);
2686 if (ret < 0)
2687 return ret;
2688
2689 if (!!val != !!def)
2690 ret = 0;
2691 else if (val)
2692 ret = !strcmp(val, def);
2693 else
2694 ret = 1;
2695
2696 av_freep(&val);
2697
2698 return ret;
2699 }
2700
2701 switch (o->type) {
2702 case AV_OPT_TYPE_CONST:
2703 return 1;
2704 case AV_OPT_TYPE_BOOL:
2705 case AV_OPT_TYPE_FLAGS:
2708 case AV_OPT_TYPE_INT:
2709 case AV_OPT_TYPE_UINT:
2711 case AV_OPT_TYPE_INT64:
2712 case AV_OPT_TYPE_UINT64:
2713 read_number(o, dst, NULL, NULL, &i64);
2714 return o->default_val.i64 == i64;
2715 case AV_OPT_TYPE_CHLAYOUT: {
2716 AVChannelLayout ch_layout = { 0 };
2717 if (o->default_val.str) {
2718 if ((ret = av_channel_layout_from_string(&ch_layout, o->default_val.str)) < 0)
2719 return ret;
2720 }
2722 av_channel_layout_uninit(&ch_layout);
2723 return ret;
2724 }
2725 case AV_OPT_TYPE_STRING:
2726 str = *(char **)dst;
2727 if (str == o->default_val.str) //2 NULLs
2728 return 1;
2729 if (!str || !o->default_val.str) //1 NULL
2730 return 0;
2731 return !strcmp(str, o->default_val.str);
2732 case AV_OPT_TYPE_DOUBLE:
2733 d = *(double *)dst;
2734 return o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl);
2735 case AV_OPT_TYPE_FLOAT:
2736 d = *(float *)dst;
2737 return (float)o->default_val.dbl == d || isnan(d) && isnan(o->default_val.dbl);
2738 case AV_OPT_TYPE_RATIONAL: {
2739 AVRational v = *(AVRational *) dst;
2740 q = av_d2q(o->default_val.dbl, INT_MAX);
2741 return !av_cmp_q(v, q) || (!q.den && !v.den);
2742 }
2743 case AV_OPT_TYPE_BINARY: {
2744 struct {
2745 uint8_t *data;
2746 int size;
2747 } tmp = {0};
2748 int opt_size = *(int *)((void **)dst + 1);
2749 void *opt_ptr = *(void **)dst;
2750 if (!opt_size && (!o->default_val.str || !strlen(o->default_val.str)))
2751 return 1;
2752 if (!opt_size || !o->default_val.str || !strlen(o->default_val.str ))
2753 return 0;
2754 if (opt_size != strlen(o->default_val.str) / 2)
2755 return 0;
2757 if (!ret)
2758 ret = !memcmp(opt_ptr, tmp.data, tmp.size);
2759 av_free(tmp.data);
2760 return ret;
2761 }
2762 case AV_OPT_TYPE_DICT: {
2763 AVDictionary *dict1 = NULL;
2764 AVDictionary *dict2 = *(AVDictionary **)dst;
2765 const AVDictionaryEntry *en1 = NULL;
2766 const AVDictionaryEntry *en2 = NULL;
2767 ret = av_dict_parse_string(&dict1, o->default_val.str, "=", ":", 0);
2768 if (ret < 0) {
2769 av_dict_free(&dict1);
2770 return ret;
2771 }
2772 do {
2773 en1 = av_dict_iterate(dict1, en1);
2774 en2 = av_dict_iterate(dict2, en2);
2775 } while (en1 && en2 && !strcmp(en1->key, en2->key) && !strcmp(en1->value, en2->value));
2776 av_dict_free(&dict1);
2777 return (!en1 && !en2);
2778 }
2780 if (!o->default_val.str || !strcmp(o->default_val.str, "none"))
2781 w = h = 0;
2782 else if ((ret = av_parse_video_size(&w, &h, o->default_val.str)) < 0)
2783 return ret;
2784 return (w == *(int *)dst) && (h == *((int *)dst+1));
2786 q = (AVRational){0, 0};
2787 if (o->default_val.str) {
2788 if ((ret = av_parse_video_rate(&q, o->default_val.str)) < 0)
2789 return ret;
2790 }
2791 return !av_cmp_q(*(AVRational*)dst, q);
2792 case AV_OPT_TYPE_COLOR: {
2793 uint8_t color[4] = {0, 0, 0, 0};
2794 if (o->default_val.str) {
2795 if ((ret = av_parse_color(color, o->default_val.str, -1, NULL)) < 0)
2796 return ret;
2797 }
2798 return !memcmp(color, dst, sizeof(color));
2799 }
2800 default:
2801 av_log(obj, AV_LOG_WARNING, "Not supported option type: %d, option name: %s\n", o->type, o->name);
2802 break;
2803 }
2804 return AVERROR_PATCHWELCOME;
2805}
2806
2807int av_opt_is_set_to_default_by_name(void *obj, const char *name, int search_flags)
2808{
2809 const AVOption *o;
2810 void *target;
2811 if (!obj)
2812 return AVERROR(EINVAL);
2813 o = av_opt_find2(obj, name, NULL, 0, search_flags, &target);
2814 if (!o)
2816 return av_opt_is_set_to_default(target, o);
2817}
2818
2819static int opt_serialize(void *obj, int opt_flags, int flags, int *cnt,
2820 AVBPrint *bprint, const char key_val_sep, const char pairs_sep)
2821{
2822 const AVOption *o = NULL;
2823 void *child = NULL;
2824 uint8_t *buf;
2825 int ret;
2826 const char special_chars[] = {pairs_sep, key_val_sep, '\0'};
2827
2829 while (child = av_opt_child_next(obj, child)) {
2830 ret = opt_serialize(child, opt_flags, flags, cnt, bprint,
2831 key_val_sep, pairs_sep);
2832 if (ret < 0)
2833 return ret;
2834 }
2835
2836 while (o = av_opt_next(obj, o)) {
2837 if (o->type == AV_OPT_TYPE_CONST)
2838 continue;
2841 if (o->flags == opt_flags)
2842 continue;
2843 } else if ((o->flags & opt_flags) == opt_flags)
2844 continue;
2845 } else {
2846 if ((flags & AV_OPT_SERIALIZE_OPT_FLAGS_EXACT) && o->flags != opt_flags)
2847 continue;
2848 else if (((o->flags & opt_flags) != opt_flags))
2849 continue;
2850 }
2852 continue;
2853 if ((ret = av_opt_get(obj, o->name, 0, &buf)) < 0) {
2854 av_bprint_finalize(bprint, NULL);
2855 return ret;
2856 }
2857 if (buf) {
2858 if ((*cnt)++)
2859 av_bprint_append_data(bprint, &pairs_sep, 1);
2860 av_bprint_escape(bprint, o->name, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2861 av_bprint_append_data(bprint, &key_val_sep, 1);
2862 av_bprint_escape(bprint, buf, special_chars, AV_ESCAPE_MODE_BACKSLASH, 0);
2863 av_freep(&buf);
2864 }
2865 }
2866
2867 return 0;
2868}
2869
2870int av_opt_serialize(void *obj, int opt_flags, int flags, char **buffer,
2871 const char key_val_sep, const char pairs_sep)
2872{
2873 AVBPrint bprint;
2874 int ret, cnt = 0;
2875
2876 if (pairs_sep == '\0' || key_val_sep == '\0' || pairs_sep == key_val_sep ||
2877 pairs_sep == '\\' || key_val_sep == '\\') {
2878 av_log(obj, AV_LOG_ERROR, "Invalid separator(s) found.");
2879 return AVERROR(EINVAL);
2880 }
2881
2882 if (!obj || !buffer)
2883 return AVERROR(EINVAL);
2884
2885 *buffer = NULL;
2887
2888 ret = opt_serialize(obj, opt_flags, flags, &cnt, &bprint,
2889 key_val_sep, pairs_sep);
2890 if (ret < 0)
2891 return ret;
2892
2893 ret = av_bprint_finalize(&bprint, buffer);
2894 if (ret < 0)
2895 return ret;
2896 return 0;
2897}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
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
static void callback(void)
Definition atomic.c:34
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
int ret
Definition ffplay.c:391
#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:2576
#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:2648
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:2558
#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.
@ AV_CHANNEL_ORDER_CUSTOM
The channel order does not correspond to any other predefined order and is stored as an explicit map.
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:236
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:43
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:286
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
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:87
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:213
#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:318
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:289
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:408
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:344
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:2283
int av_opt_get_pixel_fmt(void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt)
Definition opt.c:1450
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:2265
int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
Definition opt.c:1377
int av_opt_get_chlayout(void *obj, const char *name, int search_flags, AVChannelLayout *cl)
Definition opt.c:1460
int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
Definition opt.c:1476
int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out)
Definition opt.c:1405
int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
Definition opt.c:1362
int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition opt.c:1389
int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt)
Definition opt.c:1455
int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
Definition opt.c:1304
int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val)
Definition opt.c:1423
const AVClass * av_opt_child_class_iterate(const AVClass *parent, void **iter)
Iterate over potential AVOptions-enabled children of parent.
Definition opt.c:2143
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:1968
#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:2090
#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:2084
#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:2042
void * av_opt_child_next(void *obj, void *prev)
Iterate over AVOptions-enabled children of obj.
Definition opt.c:2135
void av_opt_set_defaults(void *s)
Set the values of all AVOption fields to their default values.
Definition opt.c:1771
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:1776
int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
Show the obj options.
Definition opt.c:1759
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:1492
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:2667
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXACT
Match only options with the exact AVOption::flags flags in opt_flags, for exclusion or inclusion in s...
Definition opt.h:1097
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:2870
#define AV_OPT_SERIALIZE_OPT_FLAGS_EXCLUDE
Serialize options with AVOption::flags flags not in opt_flags.
Definition opt.h:1103
#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:2807
#define AV_OPT_SERIALIZE_SEARCH_CHILDREN
Serialize options in possible children of the given object.
Definition opt.h:1098
int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
Definition opt.c:956
int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags)
Definition opt.c:995
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
Definition opt.c:951
int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:961
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:2371
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
Definition opt.c:904
int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
Definition opt.c:966
int av_opt_set_chlayout(void *obj, const char *name, const AVChannelLayout *channel_layout, int search_flags)
Definition opt.c:1086
int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags)
Definition opt.c:1023
int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
Definition opt.c:1066
int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags)
Definition opt.c:1061
int av_opt_set_pixel_fmt(void *obj, const char *name, enum AVPixelFormat fmt, int search_flags)
Definition opt.c:1056
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
Definition opt.c:2239
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:2055
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:1990
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:1910
int av_opt_set_dict(void *obj, AVDictionary **options)
Set all the options from a given dictionary on an object.
Definition opt.c:2079
int a
#define r
Definition input.c:42
#define b
Definition input.c:43
enum MPFType type
Definition jpegmpfenc.c:55
class_name
Definition libkvazaar.c:310
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:370
Memory handling functions.
static const char * obj
Definition mscl.c:57
const char data[16]
Definition mxf.c:155
#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:567
#define OPT_EVAL_NUMBER(name, opttype, vartype)
Definition opt.c:918
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:1876
static int opt_set_elem(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:742
static void log_type(void *av_log_obj, const AVOption *o, enum AVOptionType parent_type)
Definition opt.c:1589
static int hexchar2int(char c)
Definition opt.c:356
static void format_duration(char *buf, size_t size, int64_t d)
Definition opt.c:1104
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:1028
static int opt_set_array(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:820
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:692
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:687
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:1505
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:1555
#define TYPE_BASE(type)
Definition opt.c:45
static int is_key_char(char c)
Definition opt.c:1932
#define DEFAULT_NUMVAL(opt)
Definition opt.c:419
static int get_pix_fmt(const char *name)
Definition opt.c:675
static int get_key(const char **ropts, const char *delim, char **rkey)
Read a key from a string.
Definition opt.c:1947
static int set_string_image_size(void *obj, const AVOption *o, const char *val, int *dst)
Definition opt.c:532
static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len, const void *dst, int search_flags)
Definition opt.c:1139
static int opt_copy_array(void *logctx, const AVOption *o, void **pdst, const void *const *psrc)
Definition opt.c:2205
static void log_value(void *av_log_obj, int level, double d)
Definition opt.c:1522
static char * get_opt_flags_string(void *obj, const char *unit, int64_t value)
Definition opt.c:1568
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:935
static void log_default(void *obj, void *av_log_obj, const AVOption *opt)
Definition opt.c:1606
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:588
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:1428
static int opt_get_array(const AVOption *o, void *dst, uint8_t **out_val)
Definition opt.c:1244
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:1684
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:2150
static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum, int search_flags)
Definition opt.c:1347
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:2819
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:699
static int set_string_channel_layout(void *obj, const AVOption *o, const char *val, void *dst)
Definition opt.c:722
static int set_string_video_rate(void *obj, const AVOption *o, const char *val, AVRational *dst)
Definition opt.c:555
static int set_string_pixel_fmt(void *obj, const AVOption *o, const char *val, uint8_t *dst)
Definition opt.c:680
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:628
static int set_string_bool(void *obj, const AVOption *o, const char *val, int *dst)
Definition opt.c:595
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:598
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:3404
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3416
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:511
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
An AVChannelLayout holds information about the channel layout of audio data.
enum AVChannelOrder order
Channel order used in this layout.
union AVChannelLayout::@162063043056170047076125117143030261346263330336 u
Details about which channels are present in this layout.
AVChannelCustom * map
This member must be used when the channel order is AV_CHANNEL_ORDER_CUSTOM.
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 llrint
Definition tablegen.h:47
#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
int num
Definition error.c:23
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:33
int size
int len
static double c[64]