]> git.sesse.net Git - casparcg/blob - ffmpeg 0.8/include/libavutil/opt.h
95ce12c6a7dccea03f2b3ff395c3354c33b74fc1
[casparcg] / ffmpeg 0.8 / include / libavutil / opt.h
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
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"
32 #include "dict.h"
33
34 enum 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  */
49 typedef 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      */
68     union {
69         double dbl;
70         const char *str;
71         /* TODO those are unused now */
72         int64_t i64;
73         AVRational q;
74     } default_val;
75     double min;                 ///< minimum valid value for the option
76     double max;                 ///< maximum valid value for the option
77
78     int flags;
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
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;
93 } AVOption;
94
95 #if FF_API_FIND_OPT
96 /**
97  * Look for an option in obj. Look only for the options which
98  * have the flags set as specified in mask and flags (that is,
99  * for which it is the case that opt->flags & mask == flags).
100  *
101  * @param[in] obj a pointer to a struct whose first element is a
102  * pointer to an AVClass
103  * @param[in] name the name of the option to look for
104  * @param[in] unit the unit of the option to look for, or any if NULL
105  * @return a pointer to the option found, or NULL if no option
106  * has been found
107  *
108  * @deprecated use av_opt_find.
109  */
110 attribute_deprecated
111 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
112 #endif
113
114 /**
115  * Set the field of obj with the given name to value.
116  *
117  * @param[in] obj A struct whose first element is a pointer to an
118  * AVClass.
119  * @param[in] name the name of the field to set
120  * @param[in] val The value to set. If the field is not of a string
121  * type, then the given string is parsed.
122  * SI postfixes and some named scalars are supported.
123  * If the field is of a numeric type, it has to be a numeric or named
124  * scalar. Behavior with more than one scalar and +- infix operators
125  * is undefined.
126  * If the field is of a flags type, it has to be a sequence of numeric
127  * scalars or named flags separated by '+' or '-'. Prefixing a flag
128  * with '+' causes it to be set without affecting the other flags;
129  * similarly, '-' unsets a flag.
130  * @param[out] o_out if non-NULL put here a pointer to the AVOption
131  * found
132  * @param alloc when 1 then the old value will be av_freed() and the
133  *                     new av_strduped()
134  *              when 0 then no av_free() nor av_strdup() will be used
135  * @return 0 if the value has been set, or an AVERROR code in case of
136  * error:
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  */
141 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
142
143 const AVOption *av_set_double(void *obj, const char *name, double n);
144 const AVOption *av_set_q(void *obj, const char *name, AVRational n);
145 const AVOption *av_set_int(void *obj, const char *name, int64_t n);
146 double av_get_double(void *obj, const char *name, const AVOption **o_out);
147 AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
148 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
149 const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
150 const AVOption *av_next_option(void *obj, const AVOption *last);
151
152 /**
153  * Show the obj options.
154  *
155  * @param req_flags requested flags for the options to show. Show only the
156  * options for which it is opt->flags & req_flags.
157  * @param rej_flags rejected flags for the options to show. Show only the
158  * options for which it is !(opt->flags & req_flags).
159  * @param av_log_obj log context to use for showing the options
160  */
161 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
162
163 /**
164  * Set the values of all AVOption fields to their default values.
165  *
166  * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
167  */
168 void av_opt_set_defaults(void *s);
169
170 #if FF_API_OLD_AVOPTIONS
171 attribute_deprecated
172 void av_opt_set_defaults2(void *s, int mask, int flags);
173 #endif
174
175 /**
176  * Parse the key/value pairs list in opts. For each key/value pair
177  * found, stores the value in the field in ctx that is named like the
178  * key. ctx must be an AVClass context, storing is done using
179  * AVOptions.
180  *
181  * @param opts options string to parse, may be NULL
182  * @param key_val_sep a 0-terminated list of characters used to
183  * separate key from value
184  * @param pairs_sep a 0-terminated list of characters used to separate
185  * two pairs from each other
186  * @return the number of successfully set key/value pairs, or a negative
187  * value corresponding to an AVERROR code in case of error:
188  * AVERROR(EINVAL) if opts cannot be parsed,
189  * the error code issued by av_set_string3() if a key/value pair
190  * cannot be set
191  */
192 int av_set_options_string(void *ctx, const char *opts,
193                           const char *key_val_sep, const char *pairs_sep);
194
195 /**
196  * Free all string and binary options in obj.
197  */
198 void av_opt_free(void *obj);
199
200 /**
201  * Check whether a particular flag is set in a flags field.
202  *
203  * @param field_name the name of the flag field option
204  * @param flag_name the name of the flag to check
205  * @return non-zero if the flag is set, zero if the flag isn't set,
206  *         isn't of the right type, or the flags field doesn't exist.
207  */
208 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
209
210 /*
211  * Set all the options from a given dictionary on an object.
212  *
213  * @param obj a struct whose first element is a pointer to AVClass
214  * @param options options to process. This dictionary will be freed and replaced
215  *                by a new one containing all options not found in obj.
216  *                Of course this new dictionary needs to be freed by caller
217  *                with av_dict_free().
218  *
219  * @return 0 on success, a negative AVERROR if some option was found in obj,
220  *         but could not be set.
221  *
222  * @see av_dict_copy()
223  */
224 int av_opt_set_dict(void *obj, struct AVDictionary **options);
225
226 #define AV_OPT_SEARCH_CHILDREN   0x0001 /**< Search in possible children of the
227                                              given object first. */
228 /**
229  *  The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
230  *  instead of a required pointer to a struct containing AVClass. This is
231  *  useful for searching for options without needing to allocate the corresponding
232  *  object.
233  */
234 #define AV_OPT_SEARCH_FAKE_OBJ   0x0002
235
236 /**
237  * Look for an option in an object. Consider only options which
238  * have all the specified flags set.
239  *
240  * @param[in] obj A pointer to a struct whose first element is a
241  *                pointer to an AVClass.
242  *                Alternatively a double pointer to an AVClass, if
243  *                AV_OPT_SEARCH_FAKE_OBJ search flag is set.
244  * @param[in] name The name of the option to look for.
245  * @param[in] unit When searching for named constants, name of the unit
246  *                 it belongs to.
247  * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
248  * @param search_flags A combination of AV_OPT_SEARCH_*.
249  *
250  * @return A pointer to the option found, or NULL if no option
251  *         was found.
252  *
253  * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
254  * directly with av_set_string3(). Use special calls which take an options
255  * AVDictionary (e.g. avformat_open_input()) to set options found with this
256  * flag.
257  */
258 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
259                             int opt_flags, int search_flags);
260
261 #endif /* AVUTIL_OPT_H */