opt.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. #ifndef AVUTIL_OPT_H
  22. #define AVUTIL_OPT_H
  23. /**
  24. * @file
  25. * AVOptions
  26. */
  27. #include "rational.h"
  28. #include "avutil.h"
  29. #include "dict.h"
  30. #include "log.h"
  31. /**
  32. * @defgroup avoptions AVOptions
  33. * @ingroup lavu_data
  34. * @{
  35. * AVOptions provide a generic system to declare options on arbitrary structs
  36. * ("objects"). An option can have a help text, a type and a range of possible
  37. * values. Options may then be enumerated, read and written to.
  38. *
  39. * @section avoptions_implement Implementing AVOptions
  40. * This section describes how to add AVOptions capabilities to a struct.
  41. *
  42. * All AVOptions-related information is stored in an AVClass. Therefore
  43. * the first member of the struct should be a pointer to an AVClass describing it.
  44. * The option field of the AVClass must be set to a NULL-terminated static array
  45. * of AVOptions. Each AVOption must have a non-empty name, a type, a default
  46. * value and for number-type AVOptions also a range of allowed values. It must
  47. * also declare an offset in bytes from the start of the struct, where the field
  48. * associated with this AVOption is located. Other fields in the AVOption struct
  49. * should also be set when applicable, but are not required.
  50. *
  51. * The following example illustrates an AVOptions-enabled struct:
  52. * @code
  53. * typedef struct test_struct {
  54. * AVClass *class;
  55. * int int_opt;
  56. * char *str_opt;
  57. * uint8_t *bin_opt;
  58. * int bin_len;
  59. * } test_struct;
  60. *
  61. * static const AVOption options[] = {
  62. * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
  63. * AV_OPT_TYPE_INT, { -1 }, INT_MIN, INT_MAX },
  64. * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
  65. * AV_OPT_TYPE_STRING },
  66. * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
  67. * AV_OPT_TYPE_BINARY },
  68. * { NULL },
  69. * };
  70. *
  71. * static const AVClass test_class = {
  72. * .class_name = "test class",
  73. * .item_name = av_default_item_name,
  74. * .option = options,
  75. * .version = LIBAVUTIL_VERSION_INT,
  76. * };
  77. * @endcode
  78. *
  79. * Next, when allocating your struct, you must ensure that the AVClass pointer
  80. * is set to the correct value. Then, av_opt_set_defaults() can be called to
  81. * initialize defaults. After that the struct is ready to be used with the
  82. * AVOptions API.
  83. *
  84. * When cleaning up, you may use the av_opt_free() function to automatically
  85. * free all the allocated string and binary options.
  86. *
  87. * Continuing with the above example:
  88. *
  89. * @code
  90. * test_struct *alloc_test_struct(void)
  91. * {
  92. * test_struct *ret = av_malloc(sizeof(*ret));
  93. * ret->class = &test_class;
  94. * av_opt_set_defaults(ret);
  95. * return ret;
  96. * }
  97. * void free_test_struct(test_struct **foo)
  98. * {
  99. * av_opt_free(*foo);
  100. * av_freep(foo);
  101. * }
  102. * @endcode
  103. *
  104. * @subsection avoptions_implement_nesting Nesting
  105. * It may happen that an AVOptions-enabled struct contains another
  106. * AVOptions-enabled struct as a member (e.g. AVCodecContext in
  107. * libavcodec exports generic options, while its priv_data field exports
  108. * codec-specific options). In such a case, it is possible to set up the
  109. * parent struct to export a child's options. To do that, simply
  110. * implement AVClass.child_next() and AVClass.child_class_next() in the
  111. * parent struct's AVClass.
  112. * Assuming that the test_struct from above now also contains a
  113. * child_struct field:
  114. *
  115. * @code
  116. * typedef struct child_struct {
  117. * AVClass *class;
  118. * int flags_opt;
  119. * } child_struct;
  120. * static const AVOption child_opts[] = {
  121. * { "test_flags", "This is a test option of flags type.",
  122. * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX },
  123. * { NULL },
  124. * };
  125. * static const AVClass child_class = {
  126. * .class_name = "child class",
  127. * .item_name = av_default_item_name,
  128. * .option = child_opts,
  129. * .version = LIBAVUTIL_VERSION_INT,
  130. * };
  131. *
  132. * void *child_next(void *obj, void *prev)
  133. * {
  134. * test_struct *t = obj;
  135. * if (!prev && t->child_struct)
  136. * return t->child_struct;
  137. * return NULL
  138. * }
  139. * const AVClass child_class_next(const AVClass *prev)
  140. * {
  141. * return prev ? NULL : &child_class;
  142. * }
  143. * @endcode
  144. * Putting child_next() and child_class_next() as defined above into
  145. * test_class will now make child_struct's options accessible through
  146. * test_struct (again, proper setup as described above needs to be done on
  147. * child_struct right after it is created).
  148. *
  149. * From the above example it might not be clear why both child_next()
  150. * and child_class_next() are needed. The distinction is that child_next()
  151. * iterates over actually existing objects, while child_class_next()
  152. * iterates over all possible child classes. E.g. if an AVCodecContext
  153. * was initialized to use a codec which has private options, then its
  154. * child_next() will return AVCodecContext.priv_data and finish
  155. * iterating. OTOH child_class_next() on AVCodecContext.av_class will
  156. * iterate over all available codecs with private options.
  157. *
  158. * @subsection avoptions_implement_named_constants Named constants
  159. * It is possible to create named constants for options. Simply set the unit
  160. * field of the option the constants should apply to to a string and
  161. * create the constants themselves as options of type AV_OPT_TYPE_CONST
  162. * with their unit field set to the same string.
  163. * Their default_val field should contain the value of the named
  164. * constant.
  165. * For example, to add some named constants for the test_flags option
  166. * above, put the following into the child_opts array:
  167. * @code
  168. * { "test_flags", "This is a test option of flags type.",
  169. * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, "test_unit" },
  170. * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { 16 }, 0, 0, "test_unit" },
  171. * @endcode
  172. *
  173. * @section avoptions_use Using AVOptions
  174. * This section deals with accessing options in an AVOptions-enabled struct.
  175. * Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or
  176. * AVFormatContext in libavformat.
  177. *
  178. * @subsection avoptions_use_examine Examining AVOptions
  179. * The basic functions for examining options are av_opt_next(), which iterates
  180. * over all options defined for one object, and av_opt_find(), which searches
  181. * for an option with the given name.
  182. *
  183. * The situation is more complicated with nesting. An AVOptions-enabled struct
  184. * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag
  185. * to av_opt_find() will make the function search children recursively.
  186. *
  187. * For enumerating there are basically two cases. The first is when you want to
  188. * get all options that may potentially exist on the struct and its children
  189. * (e.g. when constructing documentation). In that case you should call
  190. * av_opt_child_class_next() recursively on the parent struct's AVClass. The
  191. * second case is when you have an already initialized struct with all its
  192. * children and you want to get all options that can be actually written or read
  193. * from it. In that case you should call av_opt_child_next() recursively (and
  194. * av_opt_next() on each result).
  195. *
  196. * @subsection avoptions_use_get_set Reading and writing AVOptions
  197. * When setting options, you often have a string read directly from the
  198. * user. In such a case, simply passing it to av_opt_set() is enough. For
  199. * non-string type options, av_opt_set() will parse the string according to the
  200. * option type.
  201. *
  202. * Similarly av_opt_get() will read any option type and convert it to a string
  203. * which will be returned. Do not forget that the string is allocated, so you
  204. * have to free it with av_free().
  205. *
  206. * In some cases it may be more convenient to put all options into an
  207. * AVDictionary and call av_opt_set_dict() on it. A specific case of this
  208. * are the format/codec open functions in lavf/lavc which take a dictionary
  209. * filled with option as a parameter. This allows to set some options
  210. * that cannot be set otherwise, since e.g. the input file format is not known
  211. * before the file is actually opened.
  212. */
  213. enum AVOptionType{
  214. AV_OPT_TYPE_FLAGS,
  215. AV_OPT_TYPE_INT,
  216. AV_OPT_TYPE_INT64,
  217. AV_OPT_TYPE_DOUBLE,
  218. AV_OPT_TYPE_FLOAT,
  219. AV_OPT_TYPE_STRING,
  220. AV_OPT_TYPE_RATIONAL,
  221. AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
  222. AV_OPT_TYPE_CONST = 128,
  223. AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers
  224. #if FF_API_OLD_AVOPTIONS
  225. FF_OPT_TYPE_FLAGS = 0,
  226. FF_OPT_TYPE_INT,
  227. FF_OPT_TYPE_INT64,
  228. FF_OPT_TYPE_DOUBLE,
  229. FF_OPT_TYPE_FLOAT,
  230. FF_OPT_TYPE_STRING,
  231. FF_OPT_TYPE_RATIONAL,
  232. FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
  233. FF_OPT_TYPE_CONST=128,
  234. #endif
  235. };
  236. /**
  237. * AVOption
  238. */
  239. typedef struct AVOption {
  240. const char *name;
  241. /**
  242. * short English help text
  243. * @todo What about other languages?
  244. */
  245. const char *help;
  246. /**
  247. * The offset relative to the context structure where the option
  248. * value is stored. It should be 0 for named constants.
  249. */
  250. int offset;
  251. enum AVOptionType type;
  252. /**
  253. * the default value for scalar options
  254. */
  255. union {
  256. double dbl;
  257. const char *str;
  258. /* TODO those are unused now */
  259. int64_t i64;
  260. AVRational q;
  261. } default_val;
  262. double min; ///< minimum valid value for the option
  263. double max; ///< maximum valid value for the option
  264. int flags;
  265. #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
  266. #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
  267. #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
  268. #define AV_OPT_FLAG_AUDIO_PARAM 8
  269. #define AV_OPT_FLAG_VIDEO_PARAM 16
  270. #define AV_OPT_FLAG_SUBTITLE_PARAM 32
  271. //FIXME think about enc-audio, ... style flags
  272. /**
  273. * The logical unit to which the option belongs. Non-constant
  274. * options and corresponding named constants share the same
  275. * unit. May be NULL.
  276. */
  277. const char *unit;
  278. } AVOption;
  279. #if FF_API_FIND_OPT
  280. /**
  281. * Look for an option in obj. Look only for the options which
  282. * have the flags set as specified in mask and flags (that is,
  283. * for which it is the case that opt->flags & mask == flags).
  284. *
  285. * @param[in] obj a pointer to a struct whose first element is a
  286. * pointer to an AVClass
  287. * @param[in] name the name of the option to look for
  288. * @param[in] unit the unit of the option to look for, or any if NULL
  289. * @return a pointer to the option found, or NULL if no option
  290. * has been found
  291. *
  292. * @deprecated use av_opt_find.
  293. */
  294. attribute_deprecated
  295. const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
  296. #endif
  297. #if FF_API_OLD_AVOPTIONS
  298. /**
  299. * Set the field of obj with the given name to value.
  300. *
  301. * @param[in] obj A struct whose first element is a pointer to an
  302. * AVClass.
  303. * @param[in] name the name of the field to set
  304. * @param[in] val The value to set. If the field is not of a string
  305. * type, then the given string is parsed.
  306. * SI postfixes and some named scalars are supported.
  307. * If the field is of a numeric type, it has to be a numeric or named
  308. * scalar. Behavior with more than one scalar and +- infix operators
  309. * is undefined.
  310. * If the field is of a flags type, it has to be a sequence of numeric
  311. * scalars or named flags separated by '+' or '-'. Prefixing a flag
  312. * with '+' causes it to be set without affecting the other flags;
  313. * similarly, '-' unsets a flag.
  314. * @param[out] o_out if non-NULL put here a pointer to the AVOption
  315. * found
  316. * @param alloc this parameter is currently ignored
  317. * @return 0 if the value has been set, or an AVERROR code in case of
  318. * error:
  319. * AVERROR_OPTION_NOT_FOUND if no matching option exists
  320. * AVERROR(ERANGE) if the value is out of range
  321. * AVERROR(EINVAL) if the value is not valid
  322. * @deprecated use av_opt_set()
  323. */
  324. attribute_deprecated
  325. int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
  326. attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
  327. attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
  328. attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
  329. double av_get_double(void *obj, const char *name, const AVOption **o_out);
  330. AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
  331. int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
  332. attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
  333. attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
  334. #endif
  335. /**
  336. * Show the obj options.
  337. *
  338. * @param req_flags requested flags for the options to show. Show only the
  339. * options for which it is opt->flags & req_flags.
  340. * @param rej_flags rejected flags for the options to show. Show only the
  341. * options for which it is !(opt->flags & req_flags).
  342. * @param av_log_obj log context to use for showing the options
  343. */
  344. int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
  345. /**
  346. * Set the values of all AVOption fields to their default values.
  347. *
  348. * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
  349. */
  350. void av_opt_set_defaults(void *s);
  351. #if FF_API_OLD_AVOPTIONS
  352. attribute_deprecated
  353. void av_opt_set_defaults2(void *s, int mask, int flags);
  354. #endif
  355. /**
  356. * Parse the key/value pairs list in opts. For each key/value pair
  357. * found, stores the value in the field in ctx that is named like the
  358. * key. ctx must be an AVClass context, storing is done using
  359. * AVOptions.
  360. *
  361. * @param opts options string to parse, may be NULL
  362. * @param key_val_sep a 0-terminated list of characters used to
  363. * separate key from value
  364. * @param pairs_sep a 0-terminated list of characters used to separate
  365. * two pairs from each other
  366. * @return the number of successfully set key/value pairs, or a negative
  367. * value corresponding to an AVERROR code in case of error:
  368. * AVERROR(EINVAL) if opts cannot be parsed,
  369. * the error code issued by av_set_string3() if a key/value pair
  370. * cannot be set
  371. */
  372. int av_set_options_string(void *ctx, const char *opts,
  373. const char *key_val_sep, const char *pairs_sep);
  374. /**
  375. * Free all string and binary options in obj.
  376. */
  377. void av_opt_free(void *obj);
  378. /**
  379. * Check whether a particular flag is set in a flags field.
  380. *
  381. * @param field_name the name of the flag field option
  382. * @param flag_name the name of the flag to check
  383. * @return non-zero if the flag is set, zero if the flag isn't set,
  384. * isn't of the right type, or the flags field doesn't exist.
  385. */
  386. int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
  387. /*
  388. * Set all the options from a given dictionary on an object.
  389. *
  390. * @param obj a struct whose first element is a pointer to AVClass
  391. * @param options options to process. This dictionary will be freed and replaced
  392. * by a new one containing all options not found in obj.
  393. * Of course this new dictionary needs to be freed by caller
  394. * with av_dict_free().
  395. *
  396. * @return 0 on success, a negative AVERROR if some option was found in obj,
  397. * but could not be set.
  398. *
  399. * @see av_dict_copy()
  400. */
  401. int av_opt_set_dict(void *obj, struct AVDictionary **options);
  402. /**
  403. * @defgroup opt_eval_funcs Evaluating option strings
  404. * @{
  405. * This group of functions can be used to evaluate option strings
  406. * and get numbers out of them. They do the same thing as av_opt_set(),
  407. * except the result is written into the caller-supplied pointer.
  408. *
  409. * @param obj a struct whose first element is a pointer to AVClass.
  410. * @param o an option for which the string is to be evaluated.
  411. * @param val string to be evaluated.
  412. * @param *_out value of the string will be written here.
  413. *
  414. * @return 0 on success, a negative number on failure.
  415. */
  416. int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
  417. int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
  418. int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
  419. int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
  420. int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
  421. int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
  422. /**
  423. * @}
  424. */
  425. #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
  426. given object first. */
  427. /**
  428. * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
  429. * instead of a required pointer to a struct containing AVClass. This is
  430. * useful for searching for options without needing to allocate the corresponding
  431. * object.
  432. */
  433. #define AV_OPT_SEARCH_FAKE_OBJ 0x0002
  434. /**
  435. * Look for an option in an object. Consider only options which
  436. * have all the specified flags set.
  437. *
  438. * @param[in] obj A pointer to a struct whose first element is a
  439. * pointer to an AVClass.
  440. * Alternatively a double pointer to an AVClass, if
  441. * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
  442. * @param[in] name The name of the option to look for.
  443. * @param[in] unit When searching for named constants, name of the unit
  444. * it belongs to.
  445. * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
  446. * @param search_flags A combination of AV_OPT_SEARCH_*.
  447. *
  448. * @return A pointer to the option found, or NULL if no option
  449. * was found.
  450. *
  451. * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
  452. * directly with av_set_string3(). Use special calls which take an options
  453. * AVDictionary (e.g. avformat_open_input()) to set options found with this
  454. * flag.
  455. */
  456. const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
  457. int opt_flags, int search_flags);
  458. /**
  459. * Look for an option in an object. Consider only options which
  460. * have all the specified flags set.
  461. *
  462. * @param[in] obj A pointer to a struct whose first element is a
  463. * pointer to an AVClass.
  464. * Alternatively a double pointer to an AVClass, if
  465. * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
  466. * @param[in] name The name of the option to look for.
  467. * @param[in] unit When searching for named constants, name of the unit
  468. * it belongs to.
  469. * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
  470. * @param search_flags A combination of AV_OPT_SEARCH_*.
  471. * @param[out] target_obj if non-NULL, an object to which the option belongs will be
  472. * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
  473. * in search_flags. This parameter is ignored if search_flags contain
  474. * AV_OPT_SEARCH_FAKE_OBJ.
  475. *
  476. * @return A pointer to the option found, or NULL if no option
  477. * was found.
  478. */
  479. const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
  480. int opt_flags, int search_flags, void **target_obj);
  481. /**
  482. * Iterate over all AVOptions belonging to obj.
  483. *
  484. * @param obj an AVOptions-enabled struct or a double pointer to an
  485. * AVClass describing it.
  486. * @param prev result of the previous call to av_opt_next() on this object
  487. * or NULL
  488. * @return next AVOption or NULL
  489. */
  490. const AVOption *av_opt_next(void *obj, const AVOption *prev);
  491. /**
  492. * Iterate over AVOptions-enabled children of obj.
  493. *
  494. * @param prev result of a previous call to this function or NULL
  495. * @return next AVOptions-enabled child or NULL
  496. */
  497. void *av_opt_child_next(void *obj, void *prev);
  498. /**
  499. * Iterate over potential AVOptions-enabled children of parent.
  500. *
  501. * @param prev result of a previous call to this function or NULL
  502. * @return AVClass corresponding to next potential child or NULL
  503. */
  504. const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
  505. /**
  506. * @defgroup opt_set_funcs Option setting functions
  507. * @{
  508. * Those functions set the field of obj with the given name to value.
  509. *
  510. * @param[in] obj A struct whose first element is a pointer to an AVClass.
  511. * @param[in] name the name of the field to set
  512. * @param[in] val The value to set. In case of av_opt_set() if the field is not
  513. * of a string type, then the given string is parsed.
  514. * SI postfixes and some named scalars are supported.
  515. * If the field is of a numeric type, it has to be a numeric or named
  516. * scalar. Behavior with more than one scalar and +- infix operators
  517. * is undefined.
  518. * If the field is of a flags type, it has to be a sequence of numeric
  519. * scalars or named flags separated by '+' or '-'. Prefixing a flag
  520. * with '+' causes it to be set without affecting the other flags;
  521. * similarly, '-' unsets a flag.
  522. * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
  523. * is passed here, then the option may be set on a child of obj.
  524. *
  525. * @return 0 if the value has been set, or an AVERROR code in case of
  526. * error:
  527. * AVERROR_OPTION_NOT_FOUND if no matching option exists
  528. * AVERROR(ERANGE) if the value is out of range
  529. * AVERROR(EINVAL) if the value is not valid
  530. */
  531. int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
  532. int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
  533. int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
  534. int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
  535. /**
  536. * @}
  537. */
  538. /**
  539. * @defgroup opt_get_funcs Option getting functions
  540. * @{
  541. * Those functions get a value of the option with the given name from an object.
  542. *
  543. * @param[in] obj a struct whose first element is a pointer to an AVClass.
  544. * @param[in] name name of the option to get.
  545. * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
  546. * is passed here, then the option may be found in a child of obj.
  547. * @param[out] out_val value of the option will be written here
  548. * @return 0 on success, a negative error code otherwise
  549. */
  550. /**
  551. * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
  552. */
  553. int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
  554. int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
  555. int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
  556. int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
  557. /**
  558. * @}
  559. */
  560. /**
  561. * Gets a pointer to the requested field in a struct.
  562. * This function allows accessing a struct even when its fields are moved or
  563. * renamed since the application making the access has been compiled,
  564. *
  565. * @returns a pointer to the field, it can be cast to the correct type and read
  566. * or written to.
  567. */
  568. void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
  569. /**
  570. * @}
  571. */
  572. #endif /* AVUTIL_OPT_H */