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
43 FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
44 FF_OPT_TYPE_CONST=128,
50 typedef struct AVOption {
54 * short English help text
55 * @todo What about other languages?
60 * The offset relative to the context structure where the option
61 * value is stored. It should be 0 for named constants.
64 enum AVOptionType type;
67 * the default value for scalar options
72 /* TODO those are unused now */
76 double min; ///< minimum valid value for the option
77 double max; ///< maximum valid value for the option
80 #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
81 #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
82 #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
83 #define AV_OPT_FLAG_AUDIO_PARAM 8
84 #define AV_OPT_FLAG_VIDEO_PARAM 16
85 #define AV_OPT_FLAG_SUBTITLE_PARAM 32
86 //FIXME think about enc-audio, ... style flags
89 * The logical unit to which the option belongs. Non-constant
90 * options and corresponding named constants share the same
98 * Look for an option in obj. Look only for the options which
99 * have the flags set as specified in mask and flags (that is,
100 * for which it is the case that opt->flags & mask == flags).
102 * @param[in] obj a pointer to a struct whose first element is a
103 * pointer to an AVClass
104 * @param[in] name the name of the option to look for
105 * @param[in] unit the unit of the option to look for, or any if NULL
106 * @return a pointer to the option found, or NULL if no option
109 * @deprecated use av_opt_find.
112 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
115 #if FF_API_OLD_AVOPTIONS
117 * Set the field of obj with the given name to value.
119 * @param[in] obj A struct whose first element is a pointer to an
121 * @param[in] name the name of the field to set
122 * @param[in] val The value to set. If the field is not of a string
123 * type, then the given string is parsed.
124 * SI postfixes and some named scalars are supported.
125 * If the field is of a numeric type, it has to be a numeric or named
126 * scalar. Behavior with more than one scalar and +- infix operators
128 * If the field is of a flags type, it has to be a sequence of numeric
129 * scalars or named flags separated by '+' or '-'. Prefixing a flag
130 * with '+' causes it to be set without affecting the other flags;
131 * similarly, '-' unsets a flag.
132 * @param[out] o_out if non-NULL put here a pointer to the AVOption
134 * @param alloc this parameter is currently ignored
135 * @return 0 if the value has been set, or an AVERROR code in case of
137 * AVERROR_OPTION_NOT_FOUND if no matching option exists
138 * AVERROR(ERANGE) if the value is out of range
139 * AVERROR(EINVAL) if the value is not valid
140 * @deprecated use av_opt_set()
143 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
145 attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
146 attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
147 attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
149 attribute_deprecated double av_get_double(void *obj, const char *name, const AVOption **o_out);
150 attribute_deprecated AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
151 attribute_deprecated int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
152 attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
153 attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
157 * Show the obj options.
159 * @param req_flags requested flags for the options to show. Show only the
160 * options for which it is opt->flags & req_flags.
161 * @param rej_flags rejected flags for the options to show. Show only the
162 * options for which it is !(opt->flags & req_flags).
163 * @param av_log_obj log context to use for showing the options
165 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
168 * Set the values of all AVOption fields to their default values.
170 * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
172 void av_opt_set_defaults(void *s);
174 #if FF_API_OLD_AVOPTIONS
176 void av_opt_set_defaults2(void *s, int mask, int flags);
180 * Parse the key/value pairs list in opts. For each key/value pair
181 * found, stores the value in the field in ctx that is named like the
182 * key. ctx must be an AVClass context, storing is done using
185 * @param key_val_sep a 0-terminated list of characters used to
186 * separate key from value
187 * @param pairs_sep a 0-terminated list of characters used to separate
188 * two pairs from each other
189 * @return the number of successfully set key/value pairs, or a negative
190 * value corresponding to an AVERROR code in case of error:
191 * AVERROR(EINVAL) if opts cannot be parsed,
192 * the error code issued by av_set_string3() if a key/value pair
195 int av_set_options_string(void *ctx, const char *opts,
196 const char *key_val_sep, const char *pairs_sep);
199 * Free all string and binary options in obj.
201 void av_opt_free(void *obj);
204 * Check whether a particular flag is set in a flags field.
206 * @param field_name the name of the flag field option
207 * @param flag_name the name of the flag to check
208 * @return non-zero if the flag is set, zero if the flag isn't set,
209 * isn't of the right type, or the flags field doesn't exist.
211 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
214 * Set all the options from a given dictionary on an object.
216 * @param obj a struct whose first element is a pointer to AVClass
217 * @param options options to process. This dictionary will be freed and replaced
218 * by a new one containing all options not found in obj.
219 * Of course this new dictionary needs to be freed by caller
220 * with av_dict_free().
222 * @return 0 on success, a negative AVERROR if some option was found in obj,
223 * but could not be set.
225 * @see av_dict_copy()
227 int av_opt_set_dict(void *obj, struct AVDictionary **options);
230 * @defgroup opt_eval_funcs Evaluating option strings
232 * This group of functions can be used to evaluate option strings
233 * and get numbers out of them. They do the same thing as av_opt_set(),
234 * except the result is written into the caller-supplied pointer.
236 * @param obj a struct whose first element is a pointer to AVClass.
237 * @param o an option for which the string is to be evaluated.
238 * @param val string to be evaluated.
239 * @param *_out value of the string will be written here.
241 * @return 0 on success, a negative number on failure.
243 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
244 int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
245 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
246 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
247 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
248 int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
253 #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
254 given object first. */
256 * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
257 * instead of a required pointer to a struct containing AVClass. This is
258 * useful for searching for options without needing to allocate the corresponding
261 #define AV_OPT_SEARCH_FAKE_OBJ 0x0002
264 * Look for an option in an object. Consider only options which
265 * have all the specified flags set.
267 * @param[in] obj A pointer to a struct whose first element is a
268 * pointer to an AVClass.
269 * Alternatively a double pointer to an AVClass, if
270 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
271 * @param[in] name The name of the option to look for.
272 * @param[in] unit When searching for named constants, name of the unit
274 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
275 * @param search_flags A combination of AV_OPT_SEARCH_*.
277 * @return A pointer to the option found, or NULL if no option
280 * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
281 * directly with av_set_string3(). Use special calls which take an options
282 * AVDictionary (e.g. avformat_open_input()) to set options found with this
285 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
286 int opt_flags, int search_flags);
289 * Look for an option in an object. Consider only options which
290 * have all the specified flags set.
292 * @param[in] obj A pointer to a struct whose first element is a
293 * pointer to an AVClass.
294 * Alternatively a double pointer to an AVClass, if
295 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
296 * @param[in] name The name of the option to look for.
297 * @param[in] unit When searching for named constants, name of the unit
299 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
300 * @param search_flags A combination of AV_OPT_SEARCH_*.
301 * @param[out] target_obj if non-NULL, an object to which the option belongs will be
302 * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
303 * in search_flags. This parameter is ignored if search_flags contain
304 * AV_OPT_SEARCH_FAKE_OBJ.
306 * @return A pointer to the option found, or NULL if no option
309 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
310 int opt_flags, int search_flags, void **target_obj);
313 * Iterate over all AVOptions belonging to obj.
315 * @param obj an AVOptions-enabled struct or a double pointer to an
316 * AVClass describing it.
317 * @param prev result of the previous call to av_opt_next() on this object
319 * @return next AVOption or NULL
321 const AVOption *av_opt_next(void *obj, const AVOption *prev);
324 * Iterate over AVOptions-enabled children of obj.
326 * @param prev result of a previous call to this function or NULL
327 * @return next AVOptions-enabled child or NULL
329 void *av_opt_child_next(void *obj, void *prev);
332 * Iterate over potential AVOptions-enabled children of parent.
334 * @param prev result of a previous call to this function or NULL
335 * @return AVClass corresponding to next potential child or NULL
337 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
340 * @defgroup opt_set_funcs Option setting functions
342 * Those functions set the field of obj with the given name to value.
344 * @param[in] obj A struct whose first element is a pointer to an AVClass.
345 * @param[in] name the name of the field to set
346 * @param[in] val The value to set. In case of av_opt_set() if the field is not
347 * of a string type, then the given string is parsed.
348 * SI postfixes and some named scalars are supported.
349 * If the field is of a numeric type, it has to be a numeric or named
350 * scalar. Behavior with more than one scalar and +- infix operators
352 * If the field is of a flags type, it has to be a sequence of numeric
353 * scalars or named flags separated by '+' or '-'. Prefixing a flag
354 * with '+' causes it to be set without affecting the other flags;
355 * similarly, '-' unsets a flag.
356 * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
357 * is passed here, then the option may be set on a child of obj.
359 * @return 0 if the value has been set, or an AVERROR code in case of
361 * AVERROR_OPTION_NOT_FOUND if no matching option exists
362 * AVERROR(ERANGE) if the value is out of range
363 * AVERROR(EINVAL) if the value is not valid
365 int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
366 int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
367 int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
368 int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
374 * @defgroup opt_get_funcs Option getting functions
376 * Those functions get a value of the option with the given name from an object.
378 * @param[in] obj a struct whose first element is a pointer to an AVClass.
379 * @param[in] name name of the option to get.
380 * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
381 * is passed here, then the option may be found in a child of obj.
382 * @param[out] out_val value of the option will be written here
383 * @return 0 on success, a negative error code otherwise
386 * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
388 int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
389 int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
390 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
391 int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
396 #endif /* AVUTIL_OPT_H */