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