opt.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. void av_opt_set_defaults(void *s);
  149. void av_opt_set_defaults2(void *s, int mask, int flags);
  150. /**
  151. * Parse the key/value pairs list in opts. For each key/value pair
  152. * found, stores the value in the field in ctx that is named like the
  153. * key. ctx must be an AVClass context, storing is done using
  154. * AVOptions.
  155. *
  156. * @param opts options string to parse, may be NULL
  157. * @param key_val_sep a 0-terminated list of characters used to
  158. * separate key from value
  159. * @param pairs_sep a 0-terminated list of characters used to separate
  160. * two pairs from each other
  161. * @return the number of successfully set key/value pairs, or a negative
  162. * value corresponding to an AVERROR code in case of error:
  163. * AVERROR(EINVAL) if opts cannot be parsed,
  164. * the error code issued by av_set_string3() if a key/value pair
  165. * cannot be set
  166. */
  167. int av_set_options_string(void *ctx, const char *opts,
  168. const char *key_val_sep, const char *pairs_sep);
  169. /**
  170. * Free all string and binary options in obj.
  171. */
  172. void av_opt_free(void *obj);
  173. /**
  174. * Check whether a particular flag is set in a flags field.
  175. *
  176. * @param field_name the name of the flag field option
  177. * @param flag_name the name of the flag to check
  178. * @return non-zero if the flag is set, zero if the flag isn't set,
  179. * isn't of the right type, or the flags field doesn't exist.
  180. */
  181. int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
  182. /*
  183. * Set all the options from a given dictionary on an object.
  184. *
  185. * @param obj a struct whose first element is a pointer to AVClass
  186. * @param options options to process. This dictionary will be freed and replaced
  187. * by a new one containing all options not found in obj.
  188. * Of course this new dictionary needs to be freed by caller
  189. * with av_dict_free().
  190. *
  191. * @return 0 on success, a negative AVERROR if some option was found in obj,
  192. * but could not be set.
  193. *
  194. * @see av_dict_copy()
  195. */
  196. int av_opt_set_dict(void *obj, struct AVDictionary **options);
  197. #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
  198. given object first. */
  199. /**
  200. * Look for an option in an object. Consider only options which
  201. * have all the specified flags set.
  202. *
  203. * @param[in] obj A pointer to a struct whose first element is a
  204. * pointer to an AVClass.
  205. * @param[in] name The name of the option to look for.
  206. * @param[in] unit When searching for named constants, name of the unit
  207. * it belongs to.
  208. * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
  209. * @param search_flags A combination of AV_OPT_SEARCH_*.
  210. *
  211. * @return A pointer to the option found, or NULL if no option
  212. * was found.
  213. *
  214. * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
  215. * directly with av_set_string3(). Use special calls which take an options
  216. * AVDictionary (e.g. avformat_open_input()) to set options found with this
  217. * flag.
  218. */
  219. const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
  220. int opt_flags, int search_flags);
  221. #endif /* AVUTIL_OPT_H */