presets: update libx264 ffpresets
[libav.git] / libavutil / opt.h
CommitLineData
6ed04040
MN
1/*
2 * AVOptions
3 * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
4 *
2912e87a 5 * This file is part of Libav.
6ed04040 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
6ed04040
MN
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
6ed04040
MN
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
6ed04040
MN
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef AVUTIL_OPT_H
23#define AVUTIL_OPT_H
24
25/**
26 * @file
27 * AVOptions
28 */
29
30#include "rational.h"
31#include "avutil.h"
7e83e1c5 32#include "dict.h"
641c7afe 33#include "log.h"
6ed04040
MN
34
35enum AVOptionType{
145f741e
AK
36 AV_OPT_TYPE_FLAGS,
37 AV_OPT_TYPE_INT,
38 AV_OPT_TYPE_INT64,
39 AV_OPT_TYPE_DOUBLE,
40 AV_OPT_TYPE_FLOAT,
41 AV_OPT_TYPE_STRING,
42 AV_OPT_TYPE_RATIONAL,
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,
6ed04040
MN
47 FF_OPT_TYPE_INT,
48 FF_OPT_TYPE_INT64,
49 FF_OPT_TYPE_DOUBLE,
50 FF_OPT_TYPE_FLOAT,
51 FF_OPT_TYPE_STRING,
52 FF_OPT_TYPE_RATIONAL,
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,
145f741e 55#endif
6ed04040
MN
56};
57
58/**
59 * AVOption
60 */
61typedef struct AVOption {
62 const char *name;
63
64 /**
65 * short English help text
66 * @todo What about other languages?
67 */
68 const char *help;
69
70 /**
71 * The offset relative to the context structure where the option
72 * value is stored. It should be 0 for named constants.
73 */
74 int offset;
75 enum AVOptionType type;
76
77 /**
78 * the default value for scalar options
79 */
6ed04040
MN
80 union {
81 double dbl;
82 const char *str;
b6675279
AK
83 /* TODO those are unused now */
84 int64_t i64;
85 AVRational q;
6ed04040 86 } default_val;
6ed04040
MN
87 double min; ///< minimum valid value for the option
88 double max; ///< maximum valid value for the option
89
90 int flags;
6ed04040
MN
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
6ed04040
MN
97//FIXME think about enc-audio, ... style flags
98
99 /**
100 * The logical unit to which the option belongs. Non-constant
101 * options and corresponding named constants share the same
102 * unit. May be NULL.
103 */
104 const char *unit;
b6675279 105} AVOption;
6ed04040 106
dc59ec5e 107#if FF_API_FIND_OPT
6ed04040
MN
108/**
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).
112 *
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
118 * has been found
dc59ec5e
AK
119 *
120 * @deprecated use av_opt_find.
6ed04040 121 */
dc59ec5e 122attribute_deprecated
6ed04040 123const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
dc59ec5e 124#endif
6ed04040 125
dac66da6 126#if FF_API_OLD_AVOPTIONS
6ed04040
MN
127/**
128 * Set the field of obj with the given name to value.
129 *
130 * @param[in] obj A struct whose first element is a pointer to an
131 * AVClass.
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
138 * is undefined.
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
144 * found
c8d787d2 145 * @param alloc this parameter is currently ignored
6ed04040
MN
146 * @return 0 if the value has been set, or an AVERROR code in case of
147 * error:
e955a682 148 * AVERROR_OPTION_NOT_FOUND if no matching option exists
6ed04040
MN
149 * AVERROR(ERANGE) if the value is out of range
150 * AVERROR(EINVAL) if the value is not valid
dac66da6 151 * @deprecated use av_opt_set()
6ed04040 152 */
dac66da6 153attribute_deprecated
6ed04040
MN
154int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
155
dac66da6
AK
156attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
157attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
158attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
dac66da6 159
41d9d51a
AK
160attribute_deprecated double av_get_double(void *obj, const char *name, const AVOption **o_out);
161attribute_deprecated AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
162attribute_deprecated int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
163attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
8c5dcaad 164attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
41d9d51a 165#endif
6ed04040
MN
166
167/**
168 * Show the obj options.
169 *
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
175 */
176int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
177
a7e2b2cc
AK
178/**
179 * Set the values of all AVOption fields to their default values.
180 *
181 * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
182 */
6ed04040 183void av_opt_set_defaults(void *s);
79eff913
AK
184
185#if FF_API_OLD_AVOPTIONS
186attribute_deprecated
6ed04040 187void av_opt_set_defaults2(void *s, int mask, int flags);
79eff913 188#endif
6ed04040 189
c85eef4e
SS
190/**
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
194 * AVOptions.
195 *
196 * @param key_val_sep a 0-terminated list of characters used to
197 * separate key from value
198 * @param pairs_sep a 0-terminated list of characters used to separate
199 * two pairs from each other
200 * @return the number of successfully set key/value pairs, or a negative
201 * value corresponding to an AVERROR code in case of error:
202 * AVERROR(EINVAL) if opts cannot be parsed,
203 * the error code issued by av_set_string3() if a key/value pair
204 * cannot be set
205 */
206int av_set_options_string(void *ctx, const char *opts,
207 const char *key_val_sep, const char *pairs_sep);
208
b39b0623
AK
209/**
210 * Free all string and binary options in obj.
211 */
212void av_opt_free(void *obj);
213
cb7c11cc
MS
214/**
215 * Check whether a particular flag is set in a flags field.
216 *
217 * @param field_name the name of the flag field option
218 * @param flag_name the name of the flag to check
219 * @return non-zero if the flag is set, zero if the flag isn't set,
220 * isn't of the right type, or the flags field doesn't exist.
221 */
222int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
223
7e83e1c5
AK
224/*
225 * Set all the options from a given dictionary on an object.
226 *
227 * @param obj a struct whose first element is a pointer to AVClass
228 * @param options options to process. This dictionary will be freed and replaced
229 * by a new one containing all options not found in obj.
230 * Of course this new dictionary needs to be freed by caller
231 * with av_dict_free().
232 *
233 * @return 0 on success, a negative AVERROR if some option was found in obj,
234 * but could not be set.
235 *
236 * @see av_dict_copy()
237 */
238int av_opt_set_dict(void *obj, struct AVDictionary **options);
239
dca055be
AK
240/**
241 * @defgroup opt_eval_funcs Evaluating option strings
242 * @{
243 * This group of functions can be used to evaluate option strings
244 * and get numbers out of them. They do the same thing as av_opt_set(),
245 * except the result is written into the caller-supplied pointer.
246 *
247 * @param obj a struct whose first element is a pointer to AVClass.
248 * @param o an option for which the string is to be evaluated.
249 * @param val string to be evaluated.
250 * @param *_out value of the string will be written here.
251 *
252 * @return 0 on success, a negative number on failure.
253 */
254int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
255int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
256int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
257int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
258int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
259int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
260/**
261 * @}
262 */
263
dc59ec5e
AK
264#define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
265 given object first. */
c11fb828
AK
266/**
267 * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
268 * instead of a required pointer to a struct containing AVClass. This is
269 * useful for searching for options without needing to allocate the corresponding
270 * object.
271 */
272#define AV_OPT_SEARCH_FAKE_OBJ 0x0002
dc59ec5e
AK
273
274/**
275 * Look for an option in an object. Consider only options which
276 * have all the specified flags set.
277 *
278 * @param[in] obj A pointer to a struct whose first element is a
279 * pointer to an AVClass.
c11fb828
AK
280 * Alternatively a double pointer to an AVClass, if
281 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
dc59ec5e
AK
282 * @param[in] name The name of the option to look for.
283 * @param[in] unit When searching for named constants, name of the unit
284 * it belongs to.
285 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
286 * @param search_flags A combination of AV_OPT_SEARCH_*.
287 *
288 * @return A pointer to the option found, or NULL if no option
289 * was found.
290 *
291 * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
292 * directly with av_set_string3(). Use special calls which take an options
293 * AVDictionary (e.g. avformat_open_input()) to set options found with this
294 * flag.
295 */
296const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
297 int opt_flags, int search_flags);
298
641c7afe
AK
299/**
300 * Look for an option in an object. Consider only options which
301 * have all the specified flags set.
302 *
303 * @param[in] obj A pointer to a struct whose first element is a
304 * pointer to an AVClass.
305 * Alternatively a double pointer to an AVClass, if
306 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
307 * @param[in] name The name of the option to look for.
308 * @param[in] unit When searching for named constants, name of the unit
309 * it belongs to.
310 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
311 * @param search_flags A combination of AV_OPT_SEARCH_*.
312 * @param[out] target_obj if non-NULL, an object to which the option belongs will be
313 * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
314 * in search_flags. This parameter is ignored if search_flags contain
315 * AV_OPT_SEARCH_FAKE_OBJ.
316 *
317 * @return A pointer to the option found, or NULL if no option
318 * was found.
319 */
320const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
321 int opt_flags, int search_flags, void **target_obj);
322
323/**
8c5dcaad
AK
324 * Iterate over all AVOptions belonging to obj.
325 *
326 * @param obj an AVOptions-enabled struct or a double pointer to an
327 * AVClass describing it.
328 * @param prev result of the previous call to av_opt_next() on this object
329 * or NULL
330 * @return next AVOption or NULL
331 */
332const AVOption *av_opt_next(void *obj, const AVOption *prev);
333
334/**
641c7afe
AK
335 * Iterate over AVOptions-enabled children of obj.
336 *
337 * @param prev result of a previous call to this function or NULL
338 * @return next AVOptions-enabled child or NULL
339 */
340void *av_opt_child_next(void *obj, void *prev);
341
342/**
343 * Iterate over potential AVOptions-enabled children of parent.
344 *
345 * @param prev result of a previous call to this function or NULL
346 * @return AVClass corresponding to next potential child or NULL
347 */
348const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
349
dac66da6
AK
350/**
351 * @defgroup opt_set_funcs Option setting functions
352 * @{
353 * Those functions set the field of obj with the given name to value.
354 *
355 * @param[in] obj A struct whose first element is a pointer to an AVClass.
356 * @param[in] name the name of the field to set
357 * @param[in] val The value to set. In case of av_opt_set() if the field is not
358 * of a string type, then the given string is parsed.
359 * SI postfixes and some named scalars are supported.
360 * If the field is of a numeric type, it has to be a numeric or named
361 * scalar. Behavior with more than one scalar and +- infix operators
362 * is undefined.
363 * If the field is of a flags type, it has to be a sequence of numeric
364 * scalars or named flags separated by '+' or '-'. Prefixing a flag
365 * with '+' causes it to be set without affecting the other flags;
366 * similarly, '-' unsets a flag.
367 * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
368 * is passed here, then the option may be set on a child of obj.
369 *
370 * @return 0 if the value has been set, or an AVERROR code in case of
371 * error:
372 * AVERROR_OPTION_NOT_FOUND if no matching option exists
373 * AVERROR(ERANGE) if the value is out of range
374 * AVERROR(EINVAL) if the value is not valid
375 */
376int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
377int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
378int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
379int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
380/**
381 * @}
382 */
383
41d9d51a
AK
384/**
385 * @defgroup opt_get_funcs Option getting functions
386 * @{
387 * Those functions get a value of the option with the given name from an object.
388 *
389 * @param[in] obj a struct whose first element is a pointer to an AVClass.
390 * @param[in] name name of the option to get.
391 * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
392 * is passed here, then the option may be found in a child of obj.
393 * @param[out] out_val value of the option will be written here
394 * @return 0 on success, a negative error code otherwise
395 */
396/**
397 * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
398 */
399int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
400int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
401int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
402int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
403/**
404 * @}
405 */
406
6ed04040 407#endif /* AVUTIL_OPT_H */