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>
35 #include "mathematics.h"
37 const AVOption *av_opt_next(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, void *dst, double *num, int *den, int64_t *intnum)
50 case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0;
51 case AV_OPT_TYPE_INT: *intnum = *(int *)dst;return 0;
52 case AV_OPT_TYPE_INT64: *intnum = *(int64_t *)dst;return 0;
53 case AV_OPT_TYPE_FLOAT: *num = *(float *)dst;return 0;
54 case AV_OPT_TYPE_DOUBLE: *num = *(double *)dst;return 0;
55 case AV_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num;
56 *den = ((AVRational*)dst)->den;
59 return AVERROR(EINVAL);
62 static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum)
64 if (o->type != AV_OPT_TYPE_FLAGS &&
65 (o->max * den < num * intnum || o->min * den > num * intnum)) {
66 av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range\n",
67 num*intnum/den, o->name);
68 return AVERROR(ERANGE);
72 case AV_OPT_TYPE_FLAGS:
73 case AV_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
74 case AV_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break;
75 case AV_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
76 case AV_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
77 case AV_OPT_TYPE_RATIONAL:
78 if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
79 else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
82 return AVERROR(EINVAL);
87 static const double const_values[] = {
94 static const char * const const_names[] = {
101 static int hexchar2int(char c) {
102 if (c >= '0' && c <= '9') return c - '0';
103 if (c >= 'a' && c <= 'f') return c - 'a' + 10;
104 if (c >= 'A' && c <= 'F') return c - 'A' + 10;
108 static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst)
110 int *lendst = (int *)(dst + 1);
112 int len = strlen(val);
118 return AVERROR(EINVAL);
121 ptr = bin = av_malloc(len);
123 return AVERROR(ENOMEM);
125 int a = hexchar2int(*val++);
126 int b = hexchar2int(*val++);
127 if (a < 0 || b < 0) {
129 return AVERROR(EINVAL);
131 *ptr++ = (a << 4) | b;
139 static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst)
142 *dst = av_strdup(val);
143 return *dst ? 0 : AVERROR(ENOMEM);
146 #define DEFAULT_NUMVAL(opt) ((opt->type == AV_OPT_TYPE_INT64 || \
147 opt->type == AV_OPT_TYPE_CONST || \
148 opt->type == AV_OPT_TYPE_FLAGS || \
149 opt->type == AV_OPT_TYPE_INT) ? \
150 opt->default_val.i64 : opt->default_val.dbl)
152 static int set_string_number(void *obj, void *target_obj, const AVOption *o, const char *val, void *dst)
154 int ret = 0, notfirst = 0;
163 if (*val == '+' || *val == '-') {
164 if (o->type == AV_OPT_TYPE_FLAGS)
170 for (; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++)
175 const AVOption *o_named = av_opt_find(target_obj, buf, o->unit, 0, 0);
176 if (o_named && o_named->type == AV_OPT_TYPE_CONST)
177 d = DEFAULT_NUMVAL(o_named);
178 else if (!strcmp(buf, "default")) d = DEFAULT_NUMVAL(o);
179 else if (!strcmp(buf, "max" )) d = o->max;
180 else if (!strcmp(buf, "min" )) d = o->min;
181 else if (!strcmp(buf, "none" )) d = 0;
182 else if (!strcmp(buf, "all" )) d = ~0;
184 int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
186 av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
191 if (o->type == AV_OPT_TYPE_FLAGS) {
192 read_number(o, dst, NULL, NULL, &intnum);
193 if (cmd == '+') d = intnum | (int64_t)d;
194 else if (cmd == '-') d = intnum &~(int64_t)d;
196 read_number(o, dst, &num, &den, &intnum);
197 if (cmd == '+') d = notfirst*num*intnum/den + d;
198 else if (cmd == '-') d = notfirst*num*intnum/den - d;
201 if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0)
212 int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
214 void *dst, *target_obj;
215 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
216 if (!o || !target_obj)
217 return AVERROR_OPTION_NOT_FOUND;
218 if (!val || o->flags & AV_OPT_FLAG_READONLY)
219 return AVERROR(EINVAL);
221 dst = ((uint8_t*)target_obj) + o->offset;
223 case AV_OPT_TYPE_STRING: return set_string(obj, o, val, dst);
224 case AV_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst);
225 case AV_OPT_TYPE_FLAGS:
226 case AV_OPT_TYPE_INT:
227 case AV_OPT_TYPE_INT64:
228 case AV_OPT_TYPE_FLOAT:
229 case AV_OPT_TYPE_DOUBLE:
230 case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, target_obj, o, val, dst);
233 av_log(obj, AV_LOG_ERROR, "Invalid option type.\n");
234 return AVERROR(EINVAL);
237 #define OPT_EVAL_NUMBER(name, opttype, vartype)\
238 int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\
240 if (!o || o->type != opttype || o->flags & AV_OPT_FLAG_READONLY)\
241 return AVERROR(EINVAL);\
242 return set_string_number(obj, obj, o, val, name ## _out);\
245 OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int)
246 OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int)
247 OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t)
248 OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float)
249 OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double)
250 OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational)
252 static int set_number(void *obj, const char *name, double num, int den, int64_t intnum,
255 void *dst, *target_obj;
256 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
258 if (!o || !target_obj)
259 return AVERROR_OPTION_NOT_FOUND;
261 if (o->flags & AV_OPT_FLAG_READONLY)
262 return AVERROR(EINVAL);
264 dst = ((uint8_t*)target_obj) + o->offset;
265 return write_number(obj, o, dst, num, den, intnum);
268 int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
270 return set_number(obj, name, 1, 1, val, search_flags);
273 int av_opt_set_double(void *obj, const char *name, double val, int search_flags)
275 return set_number(obj, name, val, 1, 1, search_flags);
278 int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags)
280 return set_number(obj, name, val.num, val.den, 1, search_flags);
283 int av_opt_set_bin(void *obj, const char *name, const uint8_t *val, int len, int search_flags)
286 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
291 if (!o || !target_obj)
292 return AVERROR_OPTION_NOT_FOUND;
294 if (o->type != AV_OPT_TYPE_BINARY || o->flags & AV_OPT_FLAG_READONLY)
295 return AVERROR(EINVAL);
297 ptr = av_malloc(len);
299 return AVERROR(ENOMEM);
301 dst = (uint8_t **)(((uint8_t *)target_obj) + o->offset);
302 lendst = (int *)(dst + 1);
307 memcpy(ptr, val, len);
312 int av_opt_set_dict_val(void *obj, const char *name, const AVDictionary *val, int search_flags)
316 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
318 if (!o || !target_obj)
319 return AVERROR_OPTION_NOT_FOUND;
320 if (o->flags & AV_OPT_FLAG_READONLY)
321 return AVERROR(EINVAL);
323 dst = (AVDictionary **)(((uint8_t *)target_obj) + o->offset);
325 av_dict_copy(dst, val, 0);
330 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
332 void *dst, *target_obj;
333 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
334 uint8_t *bin, buf[128];
337 if (!o || !target_obj)
338 return AVERROR_OPTION_NOT_FOUND;
340 dst = (uint8_t*)target_obj + o->offset;
344 case AV_OPT_TYPE_FLAGS: ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);break;
345 case AV_OPT_TYPE_INT: ret = snprintf(buf, sizeof(buf), "%d" , *(int *)dst);break;
346 case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break;
347 case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break;
348 case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break;
349 case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
350 case AV_OPT_TYPE_STRING:
352 *out_val = av_strdup(*(uint8_t**)dst);
354 *out_val = av_strdup("");
355 return *out_val ? 0 : AVERROR(ENOMEM);
356 case AV_OPT_TYPE_BINARY:
357 len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
358 if ((uint64_t)len*2 + 1 > INT_MAX)
359 return AVERROR(EINVAL);
360 if (!(*out_val = av_malloc(len*2 + 1)))
361 return AVERROR(ENOMEM);
362 bin = *(uint8_t**)dst;
363 for (i = 0; i < len; i++)
364 snprintf(*out_val + i*2, 3, "%02X", bin[i]);
367 return AVERROR(EINVAL);
370 if (ret >= sizeof(buf))
371 return AVERROR(EINVAL);
372 *out_val = av_strdup(buf);
373 return *out_val ? 0 : AVERROR(ENOMEM);
376 static int get_number(void *obj, const char *name, double *num, int *den, int64_t *intnum,
379 void *dst, *target_obj;
380 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
381 if (!o || !target_obj)
384 dst = ((uint8_t*)target_obj) + o->offset;
386 return read_number(o, dst, num, den, intnum);
393 int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val)
399 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
401 *out_val = num*intnum/den;
405 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val)
411 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
413 *out_val = num*intnum/den;
417 int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val)
423 if ((ret = get_number(obj, name, &num, &den, &intnum, search_flags)) < 0)
426 if (num == 1.0 && (int)intnum == intnum)
427 *out_val = (AVRational){intnum, den};
429 *out_val = av_d2q(num*intnum/den, 1<<24);
433 int av_opt_get_dict_val(void *obj, const char *name, int search_flags, AVDictionary **out_val)
437 const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
439 if (!o || !target_obj)
440 return AVERROR_OPTION_NOT_FOUND;
441 if (o->type != AV_OPT_TYPE_DICT)
442 return AVERROR(EINVAL);
444 src = *(AVDictionary **)(((uint8_t *)target_obj) + o->offset);
445 av_dict_copy(out_val, src, 0);
450 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name)
452 const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0);
453 const AVOption *flag = av_opt_find(obj, flag_name,
454 field ? field->unit : NULL, 0, 0);
457 if (!field || !flag || flag->type != AV_OPT_TYPE_CONST ||
458 av_opt_get_int(obj, field_name, 0, &res) < 0)
460 return res & flag->default_val.i64;
463 static void opt_list(void *obj, void *av_log_obj, const char *unit,
464 int req_flags, int rej_flags)
466 const AVOption *opt=NULL;
468 while ((opt = av_opt_next(obj, opt))) {
469 if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
472 /* Don't print CONST's on level one.
473 * Don't print anything but CONST's on level two.
474 * Only print items from the requested unit.
476 if (!unit && opt->type==AV_OPT_TYPE_CONST)
478 else if (unit && opt->type!=AV_OPT_TYPE_CONST)
480 else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit))
482 else if (unit && opt->type == AV_OPT_TYPE_CONST)
483 av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
485 av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
488 case AV_OPT_TYPE_FLAGS:
489 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>");
491 case AV_OPT_TYPE_INT:
492 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
494 case AV_OPT_TYPE_INT64:
495 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
497 case AV_OPT_TYPE_DOUBLE:
498 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<double>");
500 case AV_OPT_TYPE_FLOAT:
501 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<float>");
503 case AV_OPT_TYPE_STRING:
504 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<string>");
506 case AV_OPT_TYPE_RATIONAL:
507 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>");
509 case AV_OPT_TYPE_BINARY:
510 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>");
512 case AV_OPT_TYPE_CONST:
514 av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
517 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
518 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
519 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
520 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
521 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
522 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_EXPORT) ? 'X' : '.');
523 av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_READONLY) ? 'R' : '.');
526 av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
527 av_log(av_log_obj, AV_LOG_INFO, "\n");
528 if (opt->unit && opt->type != AV_OPT_TYPE_CONST) {
529 opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
534 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
539 av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
541 opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
546 void av_opt_set_defaults(void *s)
548 const AVOption *opt = NULL;
549 while ((opt = av_opt_next(s, opt))) {
550 if (opt->flags & AV_OPT_FLAG_READONLY)
554 case AV_OPT_TYPE_CONST:
555 /* Nothing to be done here */
557 case AV_OPT_TYPE_FLAGS:
558 case AV_OPT_TYPE_INT:
559 case AV_OPT_TYPE_INT64:
560 av_opt_set_int(s, opt->name, opt->default_val.i64, 0);
562 case AV_OPT_TYPE_DOUBLE:
563 case AV_OPT_TYPE_FLOAT: {
565 val = opt->default_val.dbl;
566 av_opt_set_double(s, opt->name, val, 0);
569 case AV_OPT_TYPE_RATIONAL: {
571 val = av_d2q(opt->default_val.dbl, INT_MAX);
572 av_opt_set_q(s, opt->name, val, 0);
575 case AV_OPT_TYPE_STRING:
576 av_opt_set(s, opt->name, opt->default_val.str, 0);
578 case AV_OPT_TYPE_BINARY:
579 case AV_OPT_TYPE_DICT:
580 /* Cannot set defaults for these types */
583 av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
589 * Store the value in the field in ctx that is named like key.
590 * ctx must be an AVClass context, storing is done using AVOptions.
592 * @param buf the string to parse, buf will be updated to point at the
593 * separator just after the parsed key/value pair
594 * @param key_val_sep a 0-terminated list of characters used to
595 * separate key from value
596 * @param pairs_sep a 0-terminated list of characters used to separate
597 * two pairs from each other
598 * @return 0 if the key/value pair has been successfully parsed and
599 * set, or a negative value corresponding to an AVERROR code in case
601 * AVERROR(EINVAL) if the key/value pair cannot be parsed,
602 * the error code issued by av_opt_set() if the key/value pair
605 static int parse_key_value_pair(void *ctx, const char **buf,
606 const char *key_val_sep, const char *pairs_sep)
608 char *key = av_get_token(buf, key_val_sep);
613 return AVERROR(ENOMEM);
615 if (*key && strspn(*buf, key_val_sep)) {
617 val = av_get_token(buf, pairs_sep);
620 return AVERROR(ENOMEM);
623 av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
625 return AVERROR(EINVAL);
628 av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key);
630 ret = av_opt_set(ctx, key, val, AV_OPT_SEARCH_CHILDREN);
631 if (ret == AVERROR_OPTION_NOT_FOUND)
632 av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
639 int av_set_options_string(void *ctx, const char *opts,
640 const char *key_val_sep, const char *pairs_sep)
648 if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
659 void av_opt_free(void *obj)
661 const AVOption *o = NULL;
662 while ((o = av_opt_next(obj, o))) {
664 case AV_OPT_TYPE_STRING:
665 case AV_OPT_TYPE_BINARY:
666 av_freep((uint8_t *)obj + o->offset);
669 case AV_OPT_TYPE_DICT:
670 av_dict_free((AVDictionary **)(((uint8_t *)obj) + o->offset));
679 int av_opt_set_dict(void *obj, AVDictionary **options)
681 AVDictionaryEntry *t = NULL;
682 AVDictionary *tmp = NULL;
685 while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) {
686 ret = av_opt_set(obj, t->key, t->value, 0);
687 if (ret == AVERROR_OPTION_NOT_FOUND)
688 av_dict_set(&tmp, t->key, t->value, 0);
690 av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value);
695 av_dict_free(options);
700 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
701 int opt_flags, int search_flags)
703 return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL);
706 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
707 int opt_flags, int search_flags, void **target_obj)
709 const AVClass *c = *(AVClass**)obj;
710 const AVOption *o = NULL;
715 if (search_flags & AV_OPT_SEARCH_CHILDREN) {
716 if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) {
717 const AVClass *child = NULL;
718 while (child = av_opt_child_class_next(c, child))
719 if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL))
723 while (child = av_opt_child_next(obj, child))
724 if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj))
729 while (o = av_opt_next(obj, o)) {
730 if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags &&
731 ((!unit && o->type != AV_OPT_TYPE_CONST) ||
732 (unit && o->unit && !strcmp(o->unit, unit)))) {
734 if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ))
745 void *av_opt_child_next(void *obj, void *prev)
747 const AVClass *c = *(AVClass**)obj;
749 return c->child_next(obj, prev);
753 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev)
755 if (parent->child_class_next)
756 return parent->child_class_next(prev);
762 typedef struct TestContext
764 const AVClass *class;
772 #define OFFSET(x) offsetof(TestContext, x)
774 #define TEST_FLAG_COOL 01
775 #define TEST_FLAG_LAME 02
776 #define TEST_FLAG_MU 04
778 static const AVOption test_options[]= {
779 {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 100 },
780 {"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1 },
781 {"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10 },
782 {"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, {0}, CHAR_MIN, CHAR_MAX },
783 {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
784 {"cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" },
785 {"lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" },
786 {"mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, {.i64 = TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" },
790 static const char *test_get_name(void *ctx)
795 static const AVClass test_class = {
805 printf("\nTesting av_set_options_string()\n");
807 TestContext test_ctx;
808 const char *options[] = {
824 "flags=+mu-lame : num=42: toggle=0",
825 "num=42 : string=blahblah",
826 "rational=0 : rational=1/2 : rational=1/-1",
830 test_ctx.class = &test_class;
831 av_opt_set_defaults(&test_ctx);
832 test_ctx.string = av_strdup("default");
833 if (!test_ctx.string)
834 return AVERROR(ENOMEM);
836 av_log_set_level(AV_LOG_DEBUG);
838 for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
839 av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
840 if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
841 av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);