3 * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
5 * This file is part of FFmpeg.
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.
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.
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
43 AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
44 AV_OPT_TYPE_CONST = 128,
45 #if FF_API_OLD_AVOPTIONS
46 FF_OPT_TYPE_FLAGS = 0,
53 FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
54 FF_OPT_TYPE_CONST=128,
61 typedef struct AVOption {
65 * short English help text
66 * @todo What about other languages?
71 * The offset relative to the context structure where the option
72 * value is stored. It should be 0 for named constants.
75 enum AVOptionType type;
78 * the default value for scalar options
83 /* TODO those are unused now */
87 double min; ///< minimum valid value for the option
88 double max; ///< maximum valid value for the option
91 #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
92 #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
93 #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
94 #define AV_OPT_FLAG_AUDIO_PARAM 8
95 #define AV_OPT_FLAG_VIDEO_PARAM 16
96 #define AV_OPT_FLAG_SUBTITLE_PARAM 32
97 //FIXME think about enc-audio, ... style flags
100 * The logical unit to which the option belongs. Non-constant
101 * options and corresponding named constants share the same
109 * Look for an option in obj. Look only for the options which
110 * have the flags set as specified in mask and flags (that is,
111 * for which it is the case that opt->flags & mask == flags).
113 * @param[in] obj a pointer to a struct whose first element is a
114 * pointer to an AVClass
115 * @param[in] name the name of the option to look for
116 * @param[in] unit the unit of the option to look for, or any if NULL
117 * @return a pointer to the option found, or NULL if no option
120 * @deprecated use av_opt_find.
123 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
126 #if FF_API_OLD_AVOPTIONS
128 * Set the field of obj with the given name to value.
130 * @param[in] obj A struct whose first element is a pointer to an
132 * @param[in] name the name of the field to set
133 * @param[in] val The value to set. If the field is not of a string
134 * type, then the given string is parsed.
135 * SI postfixes and some named scalars are supported.
136 * If the field is of a numeric type, it has to be a numeric or named
137 * scalar. Behavior with more than one scalar and +- infix operators
139 * If the field is of a flags type, it has to be a sequence of numeric
140 * scalars or named flags separated by '+' or '-'. Prefixing a flag
141 * with '+' causes it to be set without affecting the other flags;
142 * similarly, '-' unsets a flag.
143 * @param[out] o_out if non-NULL put here a pointer to the AVOption
145 * @param alloc this parameter is currently ignored
146 * @return 0 if the value has been set, or an AVERROR code in case of
148 * AVERROR_OPTION_NOT_FOUND if no matching option exists
149 * AVERROR(ERANGE) if the value is out of range
150 * AVERROR(EINVAL) if the value is not valid
151 * @deprecated use av_opt_set()
154 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
156 attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
157 attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
158 attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
160 attribute_deprecated double av_get_double(void *obj, const char *name, const AVOption **o_out);
161 attribute_deprecated AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
162 attribute_deprecated int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
163 attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
164 attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
168 * Show the obj options.
170 * @param req_flags requested flags for the options to show. Show only the
171 * options for which it is opt->flags & req_flags.
172 * @param rej_flags rejected flags for the options to show. Show only the
173 * options for which it is !(opt->flags & req_flags).
174 * @param av_log_obj log context to use for showing the options
176 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
179 * Set the values of all AVOption fields to their default values.
181 * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
183 void av_opt_set_defaults(void *s);
185 #if FF_API_OLD_AVOPTIONS
187 void av_opt_set_defaults2(void *s, int mask, int flags);
191 * Parse the key/value pairs list in opts. For each key/value pair
192 * found, stores the value in the field in ctx that is named like the
193 * key. ctx must be an AVClass context, storing is done using
196 * @param opts options string to parse, may be NULL
197 * @param key_val_sep a 0-terminated list of characters used to
198 * separate key from value
199 * @param pairs_sep a 0-terminated list of characters used to separate
200 * two pairs from each other
201 * @return the number of successfully set key/value pairs, or a negative
202 * value corresponding to an AVERROR code in case of error:
203 * AVERROR(EINVAL) if opts cannot be parsed,
204 * the error code issued by av_set_string3() if a key/value pair
207 int av_set_options_string(void *ctx, const char *opts,
208 const char *key_val_sep, const char *pairs_sep);
211 * Free all string and binary options in obj.
213 void av_opt_free(void *obj);
216 * Check whether a particular flag is set in a flags field.
218 * @param field_name the name of the flag field option
219 * @param flag_name the name of the flag to check
220 * @return non-zero if the flag is set, zero if the flag isn't set,
221 * isn't of the right type, or the flags field doesn't exist.
223 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
226 * Set all the options from a given dictionary on an object.
228 * @param obj a struct whose first element is a pointer to AVClass
229 * @param options options to process. This dictionary will be freed and replaced
230 * by a new one containing all options not found in obj.
231 * Of course this new dictionary needs to be freed by caller
232 * with av_dict_free().
234 * @return 0 on success, a negative AVERROR if some option was found in obj,
235 * but could not be set.
237 * @see av_dict_copy()
239 int av_opt_set_dict(void *obj, struct AVDictionary **options);
242 * @defgroup opt_eval_funcs Evaluating option strings
244 * This group of functions can be used to evaluate option strings
245 * and get numbers out of them. They do the same thing as av_opt_set(),
246 * except the result is written into the caller-supplied pointer.
248 * @param obj a struct whose first element is a pointer to AVClass.
249 * @param o an option for which the string is to be evaluated.
250 * @param val string to be evaluated.
251 * @param *_out value of the string will be written here.
253 * @return 0 on success, a negative number on failure.
255 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
256 int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
257 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
258 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
259 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
260 int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
265 #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
266 given object first. */
268 * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
269 * instead of a required pointer to a struct containing AVClass. This is
270 * useful for searching for options without needing to allocate the corresponding
273 #define AV_OPT_SEARCH_FAKE_OBJ 0x0002
276 * Look for an option in an object. Consider only options which
277 * have all the specified flags set.
279 * @param[in] obj A pointer to a struct whose first element is a
280 * pointer to an AVClass.
281 * Alternatively a double pointer to an AVClass, if
282 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
283 * @param[in] name The name of the option to look for.
284 * @param[in] unit When searching for named constants, name of the unit
286 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
287 * @param search_flags A combination of AV_OPT_SEARCH_*.
289 * @return A pointer to the option found, or NULL if no option
292 * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
293 * directly with av_set_string3(). Use special calls which take an options
294 * AVDictionary (e.g. avformat_open_input()) to set options found with this
297 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
298 int opt_flags, int search_flags);
301 * Look for an option in an object. Consider only options which
302 * have all the specified flags set.
304 * @param[in] obj A pointer to a struct whose first element is a
305 * pointer to an AVClass.
306 * Alternatively a double pointer to an AVClass, if
307 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
308 * @param[in] name The name of the option to look for.
309 * @param[in] unit When searching for named constants, name of the unit
311 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
312 * @param search_flags A combination of AV_OPT_SEARCH_*.
313 * @param[out] target_obj if non-NULL, an object to which the option belongs will be
314 * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
315 * in search_flags. This parameter is ignored if search_flags contain
316 * AV_OPT_SEARCH_FAKE_OBJ.
318 * @return A pointer to the option found, or NULL if no option
321 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
322 int opt_flags, int search_flags, void **target_obj);
325 * Iterate over all AVOptions belonging to obj.
327 * @param obj an AVOptions-enabled struct or a double pointer to an
328 * AVClass describing it.
329 * @param prev result of the previous call to av_opt_next() on this object
331 * @return next AVOption or NULL
333 const AVOption *av_opt_next(void *obj, const AVOption *prev);
336 * Iterate over AVOptions-enabled children of obj.
338 * @param prev result of a previous call to this function or NULL
339 * @return next AVOptions-enabled child or NULL
341 void *av_opt_child_next(void *obj, void *prev);
344 * Iterate over potential AVOptions-enabled children of parent.
346 * @param prev result of a previous call to this function or NULL
347 * @return AVClass corresponding to next potential child or NULL
349 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
352 * @defgroup opt_set_funcs Option setting functions
354 * Those functions set the field of obj with the given name to value.
356 * @param[in] obj A struct whose first element is a pointer to an AVClass.
357 * @param[in] name the name of the field to set
358 * @param[in] val The value to set. In case of av_opt_set() if the field is not
359 * of a string type, then the given string is parsed.
360 * SI postfixes and some named scalars are supported.
361 * If the field is of a numeric type, it has to be a numeric or named
362 * scalar. Behavior with more than one scalar and +- infix operators
364 * If the field is of a flags type, it has to be a sequence of numeric
365 * scalars or named flags separated by '+' or '-'. Prefixing a flag
366 * with '+' causes it to be set without affecting the other flags;
367 * similarly, '-' unsets a flag.
368 * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
369 * is passed here, then the option may be set on a child of obj.
371 * @return 0 if the value has been set, or an AVERROR code in case of
373 * AVERROR_OPTION_NOT_FOUND if no matching option exists
374 * AVERROR(ERANGE) if the value is out of range
375 * AVERROR(EINVAL) if the value is not valid
377 int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
378 int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
379 int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
380 int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
386 * @defgroup opt_get_funcs Option getting functions
388 * Those functions get a value of the option with the given name from an object.
390 * @param[in] obj a struct whose first element is a pointer to an AVClass.
391 * @param[in] name name of the option to get.
392 * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
393 * is passed here, then the option may be found in a child of obj.
394 * @param[out] out_val value of the option will be written here
395 * @return 0 on success, a negative error code otherwise
398 * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
400 int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
401 int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
402 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
403 int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
408 #endif /* AVUTIL_OPT_H */