3 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of Libav.
7 * Libav 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.
12 * Libav 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * @author Michael Niedermayer <michaelni@gmx.at>
34 #include "mathematics.h"
37 const AVOption *av_opt_next(const void *obj, const AVOption *last)
39 AVClass *class = *(AVClass **)obj;
40 if (!last && class->option && class->option[0].name)
42 if (last && last[1].name)
47 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
50 case AV_OPT_TYPE_FLAGS:
51 *intnum = *(unsigned int *)dst;
54 *intnum = *(int *)dst;
56 case AV_OPT_TYPE_INT64:
57 *intnum = *(int64_t *)dst;
59 case AV_OPT_TYPE_FLOAT:
62 case AV_OPT_TYPE_DOUBLE:
63 *num = *(double *)dst;
65 case AV_OPT_TYPE_RATIONAL:
66 *intnum = ((AVRational *)dst)->num;
67 *den = ((AVRational *)dst)->den;
70 return AVERROR(EINVAL);
73 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
75 if (o->type != AV_OPT_TYPE_FLAGS &&
76 (o->max * den < num * intnum || o->min * den > num * intnum)) {
77 av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range\n",
78 num * intnum / den, o->name);
79 return AVERROR(ERANGE);
83 case AV_OPT_TYPE_FLAGS:
85 *(int *)dst = llrint(num / den) * intnum;
87 case AV_OPT_TYPE_INT64:
88 *(int64_t *)dst = llrint(num / den) * intnum;
90 case AV_OPT_TYPE_FLOAT:
91 *(float *)dst = num * intnum / den;
93 case AV_OPT_TYPE_DOUBLE:
94 *(double *)dst = num * intnum / den;
96 case AV_OPT_TYPE_RATIONAL:
98 *(AVRational *)dst = (AVRational) { num *intnum, den };
100 *(AVRational *)dst = av_d2q(num * intnum / den, 1 << 24);
103 return AVERROR(EINVAL);
108 static const double const_values[] = {
115 static const char *const const_names[] = {
122 static int hexchar2int(char c)
124 if (c >= '0' && c <= '9')
126 if (c >= 'a' && c <= 'f')
128 if (c >= 'A' && c <= 'F')
133 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
135 int *lendst = (int *)(dst + 1);
137 int len = strlen(val);
143 return AVERROR(EINVAL);
146 ptr = bin = av_malloc(len);
148 return AVERROR(ENOMEM);
150 int a = hexchar2int(*val++);
151 int b = hexchar2int(*val++);
152 if (a < 0 || b < 0) {
154 return AVERROR(EINVAL);
156 *ptr++ = (a << 4) | b;
164 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
167 *dst = av_strdup(val);
168 return *dst ? 0 : AVERROR(ENOMEM);
171 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
172 opt->type == AV_OPT_TYPE_CONST || \
173 opt->type == AV_OPT_TYPE_FLAGS || \
174 opt->type == AV_OPT_TYPE_INT) \
175 ? opt->default_val.i64 \
176 : opt->default_val.dbl)
178 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
180 int ret = 0, notfirst = 0;
189 if (*val == '+' || *val == '-') {
190 if (o->type == AV_OPT_TYPE_FLAGS)
196 for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
201 const AVOption *o_named = av_opt_find(target_obj, buf, o->unit, 0, 0);
202 if (o_named && o_named->type == AV_OPT_TYPE_CONST)
203 d = DEFAULT_NUMVAL(o_named);
204 else if (!strcmp(buf, "default"))
205 d = DEFAULT_NUMVAL(o);
206 else if (!strcmp(buf, "max"))
208 else if (!strcmp(buf, "min"))
210 else if (!strcmp(buf, "none"))
212 else if (!strcmp(buf, "all"))
215 int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
217 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
222 if (o->type == AV_OPT_TYPE_FLAGS) {
223 read_number(o, dst, NULL, NULL, &intnum);
225 d = intnum | (int64_t)d;
227 d = intnum & ~(int64_t)d;
229 read_number(o, dst, &num, &den, &intnum);
231 d = notfirst * num * intnum / den + d;
233 d = notfirst * num * intnum / den - d;
236 if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
247 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
249 void *dst, *target_obj;
250 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
251 if (!o || !target_obj)
252 return AVERROR_OPTION_NOT_FOUND;
253 if (!val || o->flags & AV_OPT_FLAG_READONLY)
254 return AVERROR(EINVAL);
256 dst = ((uint8_t *)target_obj) + o->offset;
258 case AV_OPT_TYPE_STRING:
259 return set_string(obj, o, val, dst);
260 case AV_OPT_TYPE_BINARY:
261 return set_string_binary(obj, o, val, dst);
262 case AV_OPT_TYPE_FLAGS:
263 case AV_OPT_TYPE_INT:
264 case AV_OPT_TYPE_INT64:
265 case AV_OPT_TYPE_FLOAT:
266 case AV_OPT_TYPE_DOUBLE:
267 case AV_OPT_TYPE_RATIONAL:
268 return set_string_number(obj, target_obj, o, val, dst);
271 av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
272 return AVERROR(EINVAL);
275 #define OPT_EVAL_NUMBER(name, opttype, vartype) \
276 int av_opt_eval_ ## name(void *obj, const AVOption *o, \
277 const char *val, vartype *name ## _out) \
279 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY) \
280 return AVERROR(EINVAL); \
281 return set_string_number(obj, obj, o, val, name ## _out); \
284 OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int)
285 OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int)
286 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
287 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
288 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
289 OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational)
291 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
294 void *dst, *target_obj;
295 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
297 if (!o || !target_obj)
298 return AVERROR_OPTION_NOT_FOUND;
300 if (o->flags & AV_OPT_FLAG_READONLY)
301 return AVERROR(EINVAL);
303 dst = ((uint8_t *)target_obj) + o->offset;
304 return write_number(obj, o, dst, num, den, intnum);
307 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
309 return set_number(obj, name, 1, 1, val, search_flags);
312 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
314 return set_number(obj, name, val, 1, 1, search_flags);
317 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
319 return set_number(obj, name, val.num, val.den, 1, search_flags);
322 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
325 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
330 if (!o || !target_obj)
331 return AVERROR_OPTION_NOT_FOUND;
333 if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
334 return AVERROR(EINVAL);
336 ptr = av_malloc(len);
338 return AVERROR(ENOMEM);
340 dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
341 lendst = (int *)(dst + 1);
346 memcpy(ptr, val, len);
351 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val,
356 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
358 if (!o || !target_obj)
359 return AVERROR_OPTION_NOT_FOUND;
360 if (o->flags & AV_OPT_FLAG_READONLY)
361 return AVERROR(EINVAL);
363 dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
365 av_dict_copy(dst, val, 0);
370 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
372 void *dst, *target_obj;
373 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
374 uint8_t *bin, buf[128];
377 if (!o || !target_obj)
378 return AVERROR_OPTION_NOT_FOUND;
380 dst = (uint8_t *)target_obj + o->offset;
384 case AV_OPT_TYPE_FLAGS:
385 ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
387 case AV_OPT_TYPE_INT:
388 ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
390 case AV_OPT_TYPE_INT64:
391 ret = snprintf(buf, sizeof(buf), "%" PRId64, *(int64_t *)dst);
393 case AV_OPT_TYPE_FLOAT:
394 ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
396 case AV_OPT_TYPE_DOUBLE:
397 ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
399 case AV_OPT_TYPE_RATIONAL:
400 ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num,
401 ((AVRational *)dst)->den);
403 case AV_OPT_TYPE_STRING:
404 if (*(uint8_t **)dst)
405 *out_val = av_strdup(*(uint8_t **)dst);
407 *out_val = av_strdup("");
408 return *out_val ? 0 : AVERROR(ENOMEM);
409 case AV_OPT_TYPE_BINARY:
410 len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
411 if ((uint64_t)len * 2 + 1 > INT_MAX)
412 return AVERROR(EINVAL);
413 if (!(*out_val = av_malloc(len * 2 + 1)))
414 return AVERROR(ENOMEM);
415 bin = *(uint8_t **)dst;
416 for (i = 0; i < len; i++)
417 snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
420 return AVERROR(EINVAL);
423 if (ret >= sizeof(buf))
424 return AVERROR(EINVAL);
425 *out_val = av_strdup(buf);
426 return *out_val ? 0 : AVERROR(ENOMEM);
429 static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
432 void *dst, *target_obj;
433 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
434 if (!o || !target_obj)
437 dst = ((uint8_t *)target_obj) + o->offset;
439 return read_number(o, dst, num, den, intnum);
447 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
453 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
455 *out_val = num * intnum / den;
459 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
465 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
467 *out_val = num * intnum / den;
471 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
477 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
480 if (num == 1.0 && (int)intnum == intnum)
481 *out_val = (AVRational) { intnum, den };
483 *out_val = av_d2q(num * intnum / den, 1 << 24);
487 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
491 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
493 if (!o || !target_obj)
494 return AVERROR_OPTION_NOT_FOUND;
495 if (o->type != AV_OPT_TYPE_DICT)
496 return AVERROR(EINVAL);
498 src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
499 av_dict_copy(out_val, src, 0);
504 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
506 const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
507 const AVOption *flag = av_opt_find(obj, flag_name,
508 field ? field->unit : NULL, 0, 0);
511 if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
512 av_opt_get_int(obj, field_name, 0, &res) < 0)
514 return res & flag->default_val.i64;
517 static void opt_list(void *obj, void *av_log_obj, const char *unit,
518 int req_flags, int rej_flags)
520 const AVOption *opt = NULL;
522 while ((opt = av_opt_next(obj, opt))) {
523 if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
526 /* Don't print CONST's on level one.
527 * Don't print anything but CONST's on level two.
528 * Only print items from the requested unit.
530 if (!unit && opt->type == AV_OPT_TYPE_CONST)
532 else if (unit && opt->type != AV_OPT_TYPE_CONST)
534 else if (unit && opt->type == AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
536 else if (unit && opt->type == AV_OPT_TYPE_CONST)
537 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
539 av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
542 case AV_OPT_TYPE_FLAGS:
543 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>");
545 case AV_OPT_TYPE_INT:
546 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
548 case AV_OPT_TYPE_INT64:
549 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
551 case AV_OPT_TYPE_DOUBLE:
552 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<double>");
554 case AV_OPT_TYPE_FLOAT:
555 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<float>");
557 case AV_OPT_TYPE_STRING:
558 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<string>");
560 case AV_OPT_TYPE_RATIONAL:
561 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>");
563 case AV_OPT_TYPE_BINARY:
564 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>");
566 case AV_OPT_TYPE_CONST:
568 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
571 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
572 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
573 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) ? 'V' : '.');
574 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) ? 'A' : '.');
575 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
576 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.');
577 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.');
580 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
581 av_log(av_log_obj, AV_LOG_INFO, "\n");
582 if (opt->unit && opt->type != AV_OPT_TYPE_CONST)
583 opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
587 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
592 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass **)obj)->class_name);
594 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
599 void av_opt_set_defaults(void *s)
601 const AVOption *opt = NULL;
602 while ((opt = av_opt_next(s, opt))) {
603 if (opt->flags & AV_OPT_FLAG_READONLY)
607 case AV_OPT_TYPE_CONST:
608 /* Nothing to be done here */
610 case AV_OPT_TYPE_FLAGS:
611 case AV_OPT_TYPE_INT:
612 case AV_OPT_TYPE_INT64:
613 av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
615 case AV_OPT_TYPE_DOUBLE:
616 case AV_OPT_TYPE_FLOAT:
619 val = opt->default_val.dbl;
620 av_opt_set_double(s, opt->name, val, 0);
623 case AV_OPT_TYPE_RATIONAL:
626 val = av_d2q(opt->default_val.dbl, INT_MAX);
627 av_opt_set_q(s, opt->name, val, 0);
630 case AV_OPT_TYPE_STRING:
631 av_opt_set(s, opt->name, opt->default_val.str, 0);
633 case AV_OPT_TYPE_BINARY:
634 case AV_OPT_TYPE_DICT:
635 /* Cannot set defaults for these types */
638 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n",
639 opt->type, opt->name);
645 * Store the value in the field in ctx that is named like key.
646 * ctx must be an AVClass context, storing is done using AVOptions.
648 * @param buf the string to parse, buf will be updated to point at the
649 * separator just after the parsed key/value pair
650 * @param key_val_sep a 0-terminated list of characters used to
651 * separate key from value
652 * @param pairs_sep a 0-terminated list of characters used to separate
653 * two pairs from each other
654 * @return 0 if the key/value pair has been successfully parsed and
655 * set, or a negative value corresponding to an AVERROR code in case
657 * AVERROR(EINVAL) if the key/value pair cannot be parsed,
658 * the error code issued by av_opt_set() if the key/value pair
661 static int parse_key_value_pair(void *ctx, const char **buf,
662 const char *key_val_sep, const char *pairs_sep)
664 char *key = av_get_token(buf, key_val_sep);
669 return AVERROR(ENOMEM);
671 if (*key && strspn(*buf, key_val_sep)) {
673 val = av_get_token(buf, pairs_sep);
676 return AVERROR(ENOMEM);
679 av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
681 return AVERROR(EINVAL);
684 av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key);
686 ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN);
687 if (ret == AVERROR_OPTION_NOT_FOUND)
688 av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
695 int av_set_options_string(void *ctx, const char *opts,
696 const char *key_val_sep, const char *pairs_sep)
704 if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
715 void av_opt_free(void *obj)
717 const AVOption *o = NULL;
718 while ((o = av_opt_next(obj, o))) {
720 case AV_OPT_TYPE_STRING:
721 case AV_OPT_TYPE_BINARY:
722 av_freep((uint8_t *)obj + o->offset);
725 case AV_OPT_TYPE_DICT:
726 av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
735 int av_opt_set_dict(void *obj, AVDictionary **options)
737 AVDictionaryEntry *t = NULL;
738 AVDictionary *tmp = NULL;
741 while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
742 ret = av_opt_set(obj, t->key, t->value, 0);
743 if (ret == AVERROR_OPTION_NOT_FOUND)
744 av_dict_set(&tmp, t->key, t->value, 0);
746 av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
751 av_dict_free(options);
756 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
757 int opt_flags, int search_flags)
759 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
762 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
763 int opt_flags, int search_flags, void **target_obj)
765 const AVClass *c = *(AVClass **)obj;
766 const AVOption *o = NULL;
771 if (search_flags & AV_OPT_SEARCH_CHILDREN) {
772 if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
773 const AVClass *child = NULL;
774 while (child = av_opt_child_class_next(c, child))
775 if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
779 while (child = av_opt_child_next(obj, child))
780 if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
785 while (o = av_opt_next(obj, o)) {
786 if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
787 ((!unit && o->type != AV_OPT_TYPE_CONST) ||
788 (unit && o->unit && !strcmp(o->unit, unit)))) {
790 if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
801 void *av_opt_child_next(void *obj, void *prev)
803 const AVClass *c = *(AVClass **)obj;
805 return c->child_next(obj, prev);
809 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
811 if (parent->child_class_next)
812 return parent->child_class_next(prev);
816 static int opt_size(enum AVOptionType type)
819 case AV_OPT_TYPE_INT:
820 case AV_OPT_TYPE_FLAGS:
822 case AV_OPT_TYPE_INT64:
823 return sizeof(int64_t);
824 case AV_OPT_TYPE_DOUBLE:
825 return sizeof(double);
826 case AV_OPT_TYPE_FLOAT:
827 return sizeof(float);
828 case AV_OPT_TYPE_STRING:
829 return sizeof(uint8_t *);
830 case AV_OPT_TYPE_RATIONAL:
831 return sizeof(AVRational);
832 case AV_OPT_TYPE_BINARY:
833 return sizeof(uint8_t *) + sizeof(int);
835 return AVERROR(EINVAL);
838 int av_opt_copy(void *dst, const void *src)
840 const AVOption *o = NULL;
845 return AVERROR(EINVAL);
847 c = *(AVClass **)src;
848 if (!c || c != *(AVClass **)dst)
849 return AVERROR(EINVAL);
851 while ((o = av_opt_next(src, o))) {
852 void *field_dst = (uint8_t *)dst + o->offset;
853 void *field_src = (uint8_t *)src + o->offset;
854 uint8_t **field_dst8 = (uint8_t **)field_dst;
855 uint8_t **field_src8 = (uint8_t **)field_src;
857 if (o->type == AV_OPT_TYPE_STRING) {
858 set_string(dst, o, *field_src8, field_dst8);
859 if (*field_src8 && !*field_dst8)
860 ret = AVERROR(ENOMEM);
861 } else if (o->type == AV_OPT_TYPE_BINARY) {
862 int len = *(int *)(field_src8 + 1);
863 if (*field_dst8 != *field_src8)
864 av_freep(field_dst8);
866 *field_dst8 = av_malloc(len);
868 ret = AVERROR(ENOMEM);
871 memcpy(*field_dst8, *field_src8, len);
875 *(int *)(field_dst8 + 1) = len;
876 } else if (o->type == AV_OPT_TYPE_CONST) {
879 int size = opt_size(o->type);
883 memcpy(field_dst, field_src, size);