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