opt.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. * @file
  23. * AVOptions
  24. * @author Michael Niedermayer <michaelni@gmx.at>
  25. */
  26. #include "avutil.h"
  27. #include "avstring.h"
  28. #include "opt.h"
  29. #include "eval.h"
  30. //FIXME order them and do a bin search
  31. const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags)
  32. {
  33. AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
  34. const AVOption *o= c->option;
  35. for (; o && o->name; o++) {
  36. if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags)
  37. return o;
  38. }
  39. return NULL;
  40. }
  41. const AVOption *av_next_option(void *obj, const AVOption *last)
  42. {
  43. if (last && last[1].name) return ++last;
  44. else if (last) return NULL;
  45. else return (*(AVClass**)obj)->option;
  46. }
  47. static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out)
  48. {
  49. const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
  50. void *dst;
  51. if (o_out)
  52. *o_out= o;
  53. if (!o || o->offset<=0)
  54. return AVERROR(ENOENT);
  55. if (o->max*den < num*intnum || o->min*den > num*intnum) {
  56. av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name);
  57. return AVERROR(ERANGE);
  58. }
  59. dst= ((uint8_t*)obj) + o->offset;
  60. switch (o->type) {
  61. case FF_OPT_TYPE_FLAGS:
  62. case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break;
  63. case FF_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break;
  64. case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break;
  65. case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break;
  66. case FF_OPT_TYPE_RATIONAL:
  67. if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den};
  68. else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24);
  69. break;
  70. default:
  71. return AVERROR(EINVAL);
  72. }
  73. return 0;
  74. }
  75. static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum)
  76. {
  77. const AVOption *o = NULL;
  78. if (av_set_number2(obj, name, num, den, intnum, &o) < 0)
  79. return NULL;
  80. else
  81. return o;
  82. }
  83. static const double const_values[] = {
  84. M_PI,
  85. M_E,
  86. FF_QP2LAMBDA,
  87. 0
  88. };
  89. static const char * const const_names[] = {
  90. "PI",
  91. "E",
  92. "QP2LAMBDA",
  93. 0
  94. };
  95. static int hexchar2int(char c) {
  96. if (c >= '0' && c <= '9') return c - '0';
  97. if (c >= 'a' && c <= 'f') return c - 'a' + 10;
  98. if (c >= 'A' && c <= 'F') return c - 'A' + 10;
  99. return -1;
  100. }
  101. int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)
  102. {
  103. int ret;
  104. const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
  105. if (o_out)
  106. *o_out = o;
  107. if (!o)
  108. return AVERROR(ENOENT);
  109. if (!val || o->offset<=0)
  110. return AVERROR(EINVAL);
  111. if (o->type == FF_OPT_TYPE_BINARY) {
  112. uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset);
  113. int *lendst = (int *)(dst + 1);
  114. uint8_t *bin, *ptr;
  115. int len = strlen(val);
  116. av_freep(dst);
  117. *lendst = 0;
  118. if (len & 1) return AVERROR(EINVAL);
  119. len /= 2;
  120. ptr = bin = av_malloc(len);
  121. while (*val) {
  122. int a = hexchar2int(*val++);
  123. int b = hexchar2int(*val++);
  124. if (a < 0 || b < 0) {
  125. av_free(bin);
  126. return AVERROR(EINVAL);
  127. }
  128. *ptr++ = (a << 4) | b;
  129. }
  130. *dst = bin;
  131. *lendst = len;
  132. return 0;
  133. }
  134. if (o->type != FF_OPT_TYPE_STRING) {
  135. int notfirst=0;
  136. for (;;) {
  137. int i;
  138. char buf[256];
  139. int cmd=0;
  140. double d;
  141. if (*val == '+' || *val == '-')
  142. cmd= *(val++);
  143. for (i=0; i<sizeof(buf)-1 && val[i] && val[i]!='+' && val[i]!='-'; i++)
  144. buf[i]= val[i];
  145. buf[i]=0;
  146. {
  147. const AVOption *o_named= av_find_opt(obj, buf, o->unit, 0, 0);
  148. if (o_named && o_named->type == FF_OPT_TYPE_CONST)
  149. d= o_named->default_val;
  150. else if (!strcmp(buf, "default")) d= o->default_val;
  151. else if (!strcmp(buf, "max" )) d= o->max;
  152. else if (!strcmp(buf, "min" )) d= o->min;
  153. else if (!strcmp(buf, "none" )) d= 0;
  154. else if (!strcmp(buf, "all" )) d= ~0;
  155. else {
  156. int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj);
  157. if (res < 0) {
  158. av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val);
  159. return res;
  160. }
  161. }
  162. }
  163. if (o->type == FF_OPT_TYPE_FLAGS) {
  164. if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d;
  165. else if (cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d;
  166. } else {
  167. if (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d;
  168. else if (cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d;
  169. }
  170. if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0)
  171. return ret;
  172. val+= i;
  173. if (!*val)
  174. return 0;
  175. notfirst=1;
  176. }
  177. return AVERROR(EINVAL);
  178. }
  179. if (alloc) {
  180. av_free(*(void**)(((uint8_t*)obj) + o->offset));
  181. val= av_strdup(val);
  182. }
  183. memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val));
  184. return 0;
  185. }
  186. const AVOption *av_set_double(void *obj, const char *name, double n)
  187. {
  188. return av_set_number(obj, name, n, 1, 1);
  189. }
  190. const AVOption *av_set_q(void *obj, const char *name, AVRational n)
  191. {
  192. return av_set_number(obj, name, n.num, n.den, 1);
  193. }
  194. const AVOption *av_set_int(void *obj, const char *name, int64_t n)
  195. {
  196. return av_set_number(obj, name, 1, 1, n);
  197. }
  198. /**
  199. *
  200. * @param buf a buffer which is used for returning non string values as strings, can be NULL
  201. * @param buf_len allocated length in bytes of buf
  202. */
  203. const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len)
  204. {
  205. const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
  206. void *dst;
  207. uint8_t *bin;
  208. int len, i;
  209. if (!o || o->offset<=0)
  210. return NULL;
  211. if (o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len))
  212. return NULL;
  213. dst= ((uint8_t*)obj) + o->offset;
  214. if (o_out) *o_out= o;
  215. switch (o->type) {
  216. case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break;
  217. case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break;
  218. case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break;
  219. case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break;
  220. case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break;
  221. case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break;
  222. case FF_OPT_TYPE_STRING: return *(void**)dst;
  223. case FF_OPT_TYPE_BINARY:
  224. len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *));
  225. if (len >= (buf_len + 1)/2) return NULL;
  226. bin = *(uint8_t**)dst;
  227. for (i = 0; i < len; i++) snprintf(buf + i*2, 3, "%02X", bin[i]);
  228. break;
  229. default: return NULL;
  230. }
  231. return buf;
  232. }
  233. static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum)
  234. {
  235. const AVOption *o= av_find_opt(obj, name, NULL, 0, 0);
  236. void *dst;
  237. if (!o || o->offset<=0)
  238. goto error;
  239. dst= ((uint8_t*)obj) + o->offset;
  240. if (o_out) *o_out= o;
  241. switch (o->type) {
  242. case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0;
  243. case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0;
  244. case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0;
  245. case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0;
  246. case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0;
  247. case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num;
  248. *den = ((AVRational*)dst)->den;
  249. return 0;
  250. }
  251. error:
  252. *den=*intnum=0;
  253. return -1;
  254. }
  255. double av_get_double(void *obj, const char *name, const AVOption **o_out)
  256. {
  257. int64_t intnum=1;
  258. double num=1;
  259. int den=1;
  260. av_get_number(obj, name, o_out, &num, &den, &intnum);
  261. return num*intnum/den;
  262. }
  263. AVRational av_get_q(void *obj, const char *name, const AVOption **o_out)
  264. {
  265. int64_t intnum=1;
  266. double num=1;
  267. int den=1;
  268. av_get_number(obj, name, o_out, &num, &den, &intnum);
  269. if (num == 1.0 && (int)intnum == intnum)
  270. return (AVRational){intnum, den};
  271. else
  272. return av_d2q(num*intnum/den, 1<<24);
  273. }
  274. int64_t av_get_int(void *obj, const char *name, const AVOption **o_out)
  275. {
  276. int64_t intnum=1;
  277. double num=1;
  278. int den=1;
  279. av_get_number(obj, name, o_out, &num, &den, &intnum);
  280. return num*intnum/den;
  281. }
  282. static void opt_list(void *obj, void *av_log_obj, const char *unit,
  283. int req_flags, int rej_flags)
  284. {
  285. const AVOption *opt=NULL;
  286. while ((opt= av_next_option(obj, opt))) {
  287. if (!(opt->flags & req_flags) || (opt->flags & rej_flags))
  288. continue;
  289. /* Don't print CONST's on level one.
  290. * Don't print anything but CONST's on level two.
  291. * Only print items from the requested unit.
  292. */
  293. if (!unit && opt->type==FF_OPT_TYPE_CONST)
  294. continue;
  295. else if (unit && opt->type!=FF_OPT_TYPE_CONST)
  296. continue;
  297. else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit))
  298. continue;
  299. else if (unit && opt->type == FF_OPT_TYPE_CONST)
  300. av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name);
  301. else
  302. av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name);
  303. switch (opt->type) {
  304. case FF_OPT_TYPE_FLAGS:
  305. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<flags>");
  306. break;
  307. case FF_OPT_TYPE_INT:
  308. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int>");
  309. break;
  310. case FF_OPT_TYPE_INT64:
  311. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<int64>");
  312. break;
  313. case FF_OPT_TYPE_DOUBLE:
  314. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<double>");
  315. break;
  316. case FF_OPT_TYPE_FLOAT:
  317. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<float>");
  318. break;
  319. case FF_OPT_TYPE_STRING:
  320. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<string>");
  321. break;
  322. case FF_OPT_TYPE_RATIONAL:
  323. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<rational>");
  324. break;
  325. case FF_OPT_TYPE_BINARY:
  326. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "<binary>");
  327. break;
  328. case FF_OPT_TYPE_CONST:
  329. default:
  330. av_log(av_log_obj, AV_LOG_INFO, "%-7s ", "");
  331. break;
  332. }
  333. av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_ENCODING_PARAM) ? 'E' : '.');
  334. av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_DECODING_PARAM) ? 'D' : '.');
  335. av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_VIDEO_PARAM ) ? 'V' : '.');
  336. av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_AUDIO_PARAM ) ? 'A' : '.');
  337. av_log(av_log_obj, AV_LOG_INFO, "%c", (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) ? 'S' : '.');
  338. if (opt->help)
  339. av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help);
  340. av_log(av_log_obj, AV_LOG_INFO, "\n");
  341. if (opt->unit && opt->type != FF_OPT_TYPE_CONST) {
  342. opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags);
  343. }
  344. }
  345. }
  346. int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags)
  347. {
  348. if (!obj)
  349. return -1;
  350. av_log(av_log_obj, AV_LOG_INFO, "%s AVOptions:\n", (*(AVClass**)obj)->class_name);
  351. opt_list(obj, av_log_obj, NULL, req_flags, rej_flags);
  352. return 0;
  353. }
  354. /** Set the values of the AVCodecContext or AVFormatContext structure.
  355. * They are set to the defaults specified in the according AVOption options
  356. * array default_val field.
  357. *
  358. * @param s AVCodecContext or AVFormatContext for which the defaults will be set
  359. */
  360. void av_opt_set_defaults2(void *s, int mask, int flags)
  361. {
  362. const AVOption *opt = NULL;
  363. while ((opt = av_next_option(s, opt)) != NULL) {
  364. if ((opt->flags & mask) != flags)
  365. continue;
  366. switch (opt->type) {
  367. case FF_OPT_TYPE_CONST:
  368. /* Nothing to be done here */
  369. break;
  370. case FF_OPT_TYPE_FLAGS:
  371. case FF_OPT_TYPE_INT: {
  372. int val;
  373. val = opt->default_val;
  374. av_set_int(s, opt->name, val);
  375. }
  376. break;
  377. case FF_OPT_TYPE_INT64:
  378. if ((double)(opt->default_val+0.6) == opt->default_val)
  379. av_log(s, AV_LOG_DEBUG, "loss of precision in default of %s\n", opt->name);
  380. av_set_int(s, opt->name, opt->default_val);
  381. break;
  382. case FF_OPT_TYPE_DOUBLE:
  383. case FF_OPT_TYPE_FLOAT: {
  384. double val;
  385. val = opt->default_val;
  386. av_set_double(s, opt->name, val);
  387. }
  388. break;
  389. case FF_OPT_TYPE_RATIONAL: {
  390. AVRational val;
  391. val = av_d2q(opt->default_val, INT_MAX);
  392. av_set_q(s, opt->name, val);
  393. }
  394. break;
  395. case FF_OPT_TYPE_STRING:
  396. case FF_OPT_TYPE_BINARY:
  397. /* Cannot set default for string as default_val is of type * double */
  398. break;
  399. default:
  400. av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name);
  401. }
  402. }
  403. }
  404. void av_opt_set_defaults(void *s)
  405. {
  406. av_opt_set_defaults2(s, 0, 0);
  407. }
  408. /**
  409. * Store the value in the field in ctx that is named like key.
  410. * ctx must be an AVClass context, storing is done using AVOptions.
  411. *
  412. * @param buf the string to parse, buf will be updated to point at the
  413. * separator just after the parsed key/value pair
  414. * @param key_val_sep a 0-terminated list of characters used to
  415. * separate key from value
  416. * @param pairs_sep a 0-terminated list of characters used to separate
  417. * two pairs from each other
  418. * @return 0 if the key/value pair has been successfully parsed and
  419. * set, or a negative value corresponding to an AVERROR code in case
  420. * of error:
  421. * AVERROR(EINVAL) if the key/value pair cannot be parsed,
  422. * the error code issued by av_set_string3() if the key/value pair
  423. * cannot be set
  424. */
  425. static int parse_key_value_pair(void *ctx, const char **buf,
  426. const char *key_val_sep, const char *pairs_sep)
  427. {
  428. char *key = av_get_token(buf, key_val_sep);
  429. char *val;
  430. int ret;
  431. if (*key && strspn(*buf, key_val_sep)) {
  432. (*buf)++;
  433. val = av_get_token(buf, pairs_sep);
  434. } else {
  435. av_log(ctx, AV_LOG_ERROR, "Missing key or no key/value separator found after key '%s'\n", key);
  436. av_free(key);
  437. return AVERROR(EINVAL);
  438. }
  439. av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key);
  440. ret = av_set_string3(ctx, key, val, 1, NULL);
  441. if (ret == AVERROR(ENOENT))
  442. av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key);
  443. av_free(key);
  444. av_free(val);
  445. return ret;
  446. }
  447. int av_set_options_string(void *ctx, const char *opts,
  448. const char *key_val_sep, const char *pairs_sep)
  449. {
  450. int ret, count = 0;
  451. while (*opts) {
  452. if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0)
  453. return ret;
  454. count++;
  455. if (*opts)
  456. opts++;
  457. }
  458. return count;
  459. }
  460. #ifdef TEST
  461. #undef printf
  462. typedef struct TestContext
  463. {
  464. const AVClass *class;
  465. int num;
  466. int toggle;
  467. char *string;
  468. int flags;
  469. AVRational rational;
  470. } TestContext;
  471. #define OFFSET(x) offsetof(TestContext, x)
  472. #define TEST_FLAG_COOL 01
  473. #define TEST_FLAG_LAME 02
  474. #define TEST_FLAG_MU 04
  475. static const AVOption test_options[]= {
  476. {"num", "set num", OFFSET(num), FF_OPT_TYPE_INT, 0, 0, 100 },
  477. {"toggle", "set toggle", OFFSET(toggle), FF_OPT_TYPE_INT, 0, 0, 1 },
  478. {"rational", "set rational", OFFSET(rational), FF_OPT_TYPE_RATIONAL, 0, 0, 10 },
  479. {"string", "set string", OFFSET(string), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX },
  480. {"flags", "set flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, 0, 0, INT_MAX, 0, "flags" },
  481. {"cool", "set cool flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_COOL, INT_MIN, INT_MAX, 0, "flags" },
  482. {"lame", "set lame flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_LAME, INT_MIN, INT_MAX, 0, "flags" },
  483. {"mu", "set mu flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_MU, INT_MIN, INT_MAX, 0, "flags" },
  484. {NULL},
  485. };
  486. static const char *test_get_name(void *ctx)
  487. {
  488. return "test";
  489. }
  490. static const AVClass test_class = {
  491. "TestContext",
  492. test_get_name,
  493. test_options
  494. };
  495. int main(void)
  496. {
  497. int i;
  498. printf("\nTesting av_set_options_string()\n");
  499. {
  500. TestContext test_ctx;
  501. const char *options[] = {
  502. "",
  503. ":",
  504. "=",
  505. "foo=:",
  506. ":=foo",
  507. "=foo",
  508. "foo=",
  509. "foo",
  510. "foo=val",
  511. "foo==val",
  512. "toggle=:",
  513. "string=:",
  514. "toggle=1 : foo",
  515. "toggle=100",
  516. "toggle==1",
  517. "flags=+mu-lame : num=42: toggle=0",
  518. "num=42 : string=blahblah",
  519. "rational=0 : rational=1/2 : rational=1/-1",
  520. "rational=-1/0",
  521. };
  522. test_ctx.class = &test_class;
  523. av_opt_set_defaults2(&test_ctx, 0, 0);
  524. test_ctx.string = av_strdup("default");
  525. av_log_set_level(AV_LOG_DEBUG);
  526. for (i=0; i < FF_ARRAY_ELEMS(options); i++) {
  527. av_log(&test_ctx, AV_LOG_DEBUG, "Setting options string '%s'\n", options[i]);
  528. if (av_set_options_string(&test_ctx, options[i], "=", ":") < 0)
  529. av_log(&test_ctx, AV_LOG_ERROR, "Error setting options string: '%s'\n", options[i]);
  530. printf("\n");
  531. }
  532. }
  533. return 0;
  534. }
  535. #endif