You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
9.4KB

  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. enum AVOptionType{
  31. FF_OPT_TYPE_FLAGS,
  32. FF_OPT_TYPE_INT,
  33. FF_OPT_TYPE_INT64,
  34. FF_OPT_TYPE_DOUBLE,
  35. FF_OPT_TYPE_FLOAT,
  36. FF_OPT_TYPE_STRING,
  37. FF_OPT_TYPE_RATIONAL,
  38. FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
  39. FF_OPT_TYPE_CONST=128,
  40. };
  41. /**
  42. * AVOption
  43. */
  44. typedef struct AVOption {
  45. const char *name;
  46. /**
  47. * short English help text
  48. * @todo What about other languages?
  49. */
  50. const char *help;
  51. /**
  52. * The offset relative to the context structure where the option
  53. * value is stored. It should be 0 for named constants.
  54. */
  55. int offset;
  56. enum AVOptionType type;
  57. /**
  58. * the default value for scalar options
  59. */
  60. union {
  61. double dbl;
  62. const char *str;
  63. /* TODO those are unused now */
  64. int64_t i64;
  65. AVRational q;
  66. } default_val;
  67. double min; ///< minimum valid value for the option
  68. double max; ///< maximum valid value for the option
  69. int flags;
  70. #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
  71. #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
  72. #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
  73. #define AV_OPT_FLAG_AUDIO_PARAM 8
  74. #define AV_OPT_FLAG_VIDEO_PARAM 16
  75. #define AV_OPT_FLAG_SUBTITLE_PARAM 32
  76. //FIXME think about enc-audio, ... style flags
  77. /**
  78. * The logical unit to which the option belongs. Non-constant
  79. * options and corresponding named constants share the same
  80. * unit. May be NULL.
  81. */
  82. const char *unit;
  83. } AVOption;
  84. #if FF_API_FIND_OPT
  85. /**
  86. * Look for an option in obj. Look only for the options which
  87. * have the flags set as specified in mask and flags (that is,
  88. * for which it is the case that opt->flags & mask == flags).
  89. *
  90. * @param[in] obj a pointer to a struct whose first element is a
  91. * pointer to an AVClass
  92. * @param[in] name the name of the option to look for
  93. * @param[in] unit the unit of the option to look for, or any if NULL
  94. * @return a pointer to the option found, or NULL if no option
  95. * has been found
  96. *
  97. * @deprecated use av_opt_find.
  98. */
  99. attribute_deprecated
  100. const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
  101. #endif
  102. /**
  103. * Set the field of obj with the given name to value.
  104. *
  105. * @param[in] obj A struct whose first element is a pointer to an
  106. * AVClass.
  107. * @param[in] name the name of the field to set
  108. * @param[in] val The value to set. If the field is not of a string
  109. * type, then the given string is parsed.
  110. * SI postfixes and some named scalars are supported.
  111. * If the field is of a numeric type, it has to be a numeric or named
  112. * scalar. Behavior with more than one scalar and +- infix operators
  113. * is undefined.
  114. * If the field is of a flags type, it has to be a sequence of numeric
  115. * scalars or named flags separated by '+' or '-'. Prefixing a flag
  116. * with '+' causes it to be set without affecting the other flags;
  117. * similarly, '-' unsets a flag.
  118. * @param[out] o_out if non-NULL put here a pointer to the AVOption
  119. * found
  120. * @param alloc when 1 then the old value will be av_freed() and the
  121. * new av_strduped()
  122. * when 0 then no av_free() nor av_strdup() will be used
  123. * @return 0 if the value has been set, or an AVERROR code in case of
  124. * error:
  125. * AVERROR_OPTION_NOT_FOUND if no matching option exists
  126. * AVERROR(ERANGE) if the value is out of range
  127. * AVERROR(EINVAL) if the value is not valid
  128. */
  129. int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
  130. const AVOption *av_set_double(void *obj, const char *name, double n);
  131. const AVOption *av_set_q(void *obj, const char *name, AVRational n);
  132. const AVOption *av_set_int(void *obj, const char *name, int64_t n);
  133. double av_get_double(void *obj, const char *name, const AVOption **o_out);
  134. AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
  135. int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
  136. const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
  137. const AVOption *av_next_option(void *obj, const AVOption *last);
  138. /**
  139. * Show the obj options.
  140. *
  141. * @param req_flags requested flags for the options to show. Show only the
  142. * options for which it is opt->flags & req_flags.
  143. * @param rej_flags rejected flags for the options to show. Show only the
  144. * options for which it is !(opt->flags & req_flags).
  145. * @param av_log_obj log context to use for showing the options
  146. */
  147. int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
  148. /**
  149. * Set the values of all AVOption fields to their default values.
  150. *
  151. * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
  152. */
  153. void av_opt_set_defaults(void *s);
  154. #if FF_API_OLD_AVOPTIONS
  155. attribute_deprecated
  156. void av_opt_set_defaults2(void *s, int mask, int flags);
  157. #endif
  158. /**
  159. * Parse the key/value pairs list in opts. For each key/value pair
  160. * found, stores the value in the field in ctx that is named like the
  161. * key. ctx must be an AVClass context, storing is done using
  162. * AVOptions.
  163. *
  164. * @param opts options string to parse, may be NULL
  165. * @param key_val_sep a 0-terminated list of characters used to
  166. * separate key from value
  167. * @param pairs_sep a 0-terminated list of characters used to separate
  168. * two pairs from each other
  169. * @return the number of successfully set key/value pairs, or a negative
  170. * value corresponding to an AVERROR code in case of error:
  171. * AVERROR(EINVAL) if opts cannot be parsed,
  172. * the error code issued by av_set_string3() if a key/value pair
  173. * cannot be set
  174. */
  175. int av_set_options_string(void *ctx, const char *opts,
  176. const char *key_val_sep, const char *pairs_sep);
  177. /**
  178. * Free all string and binary options in obj.
  179. */
  180. void av_opt_free(void *obj);
  181. /**
  182. * Check whether a particular flag is set in a flags field.
  183. *
  184. * @param field_name the name of the flag field option
  185. * @param flag_name the name of the flag to check
  186. * @return non-zero if the flag is set, zero if the flag isn't set,
  187. * isn't of the right type, or the flags field doesn't exist.
  188. */
  189. int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
  190. /*
  191. * Set all the options from a given dictionary on an object.
  192. *
  193. * @param obj a struct whose first element is a pointer to AVClass
  194. * @param options options to process. This dictionary will be freed and replaced
  195. * by a new one containing all options not found in obj.
  196. * Of course this new dictionary needs to be freed by caller
  197. * with av_dict_free().
  198. *
  199. * @return 0 on success, a negative AVERROR if some option was found in obj,
  200. * but could not be set.
  201. *
  202. * @see av_dict_copy()
  203. */
  204. int av_opt_set_dict(void *obj, struct AVDictionary **options);
  205. #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
  206. given object first. */
  207. /**
  208. * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
  209. * instead of a required pointer to a struct containing AVClass. This is
  210. * useful for searching for options without needing to allocate the corresponding
  211. * object.
  212. */
  213. #define AV_OPT_SEARCH_FAKE_OBJ 0x0002
  214. /**
  215. * Look for an option in an object. Consider only options which
  216. * have all the specified flags set.
  217. *
  218. * @param[in] obj A pointer to a struct whose first element is a
  219. * pointer to an AVClass.
  220. * Alternatively a double pointer to an AVClass, if
  221. * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
  222. * @param[in] name The name of the option to look for.
  223. * @param[in] unit When searching for named constants, name of the unit
  224. * it belongs to.
  225. * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
  226. * @param search_flags A combination of AV_OPT_SEARCH_*.
  227. *
  228. * @return A pointer to the option found, or NULL if no option
  229. * was found.
  230. *
  231. * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
  232. * directly with av_set_string3(). Use special calls which take an options
  233. * AVDictionary (e.g. avformat_open_input()) to set options found with this
  234. * flag.
  235. */
  236. const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
  237. int opt_flags, int search_flags);
  238. #endif /* AVUTIL_OPT_H */