yading@11
|
1 /*
|
yading@11
|
2 * AVOptions
|
yading@11
|
3 * copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
|
yading@11
|
4 *
|
yading@11
|
5 * This file is part of FFmpeg.
|
yading@11
|
6 *
|
yading@11
|
7 * FFmpeg is free software; you can redistribute it and/or
|
yading@11
|
8 * modify it under the terms of the GNU Lesser General Public
|
yading@11
|
9 * License as published by the Free Software Foundation; either
|
yading@11
|
10 * version 2.1 of the License, or (at your option) any later version.
|
yading@11
|
11 *
|
yading@11
|
12 * FFmpeg is distributed in the hope that it will be useful,
|
yading@11
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
yading@11
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
yading@11
|
15 * Lesser General Public License for more details.
|
yading@11
|
16 *
|
yading@11
|
17 * You should have received a copy of the GNU Lesser General Public
|
yading@11
|
18 * License along with FFmpeg; if not, write to the Free Software
|
yading@11
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
yading@11
|
20 */
|
yading@11
|
21
|
yading@11
|
22 #ifndef AVUTIL_OPT_H
|
yading@11
|
23 #define AVUTIL_OPT_H
|
yading@11
|
24
|
yading@11
|
25 /**
|
yading@11
|
26 * @file
|
yading@11
|
27 * AVOptions
|
yading@11
|
28 */
|
yading@11
|
29
|
yading@11
|
30 #include "rational.h"
|
yading@11
|
31 #include "avutil.h"
|
yading@11
|
32 #include "dict.h"
|
yading@11
|
33 #include "log.h"
|
yading@11
|
34 #include "pixfmt.h"
|
yading@11
|
35 #include "samplefmt.h"
|
yading@11
|
36
|
yading@11
|
37 /**
|
yading@11
|
38 * @defgroup avoptions AVOptions
|
yading@11
|
39 * @ingroup lavu_data
|
yading@11
|
40 * @{
|
yading@11
|
41 * AVOptions provide a generic system to declare options on arbitrary structs
|
yading@11
|
42 * ("objects"). An option can have a help text, a type and a range of possible
|
yading@11
|
43 * values. Options may then be enumerated, read and written to.
|
yading@11
|
44 *
|
yading@11
|
45 * @section avoptions_implement Implementing AVOptions
|
yading@11
|
46 * This section describes how to add AVOptions capabilities to a struct.
|
yading@11
|
47 *
|
yading@11
|
48 * All AVOptions-related information is stored in an AVClass. Therefore
|
yading@11
|
49 * the first member of the struct should be a pointer to an AVClass describing it.
|
yading@11
|
50 * The option field of the AVClass must be set to a NULL-terminated static array
|
yading@11
|
51 * of AVOptions. Each AVOption must have a non-empty name, a type, a default
|
yading@11
|
52 * value and for number-type AVOptions also a range of allowed values. It must
|
yading@11
|
53 * also declare an offset in bytes from the start of the struct, where the field
|
yading@11
|
54 * associated with this AVOption is located. Other fields in the AVOption struct
|
yading@11
|
55 * should also be set when applicable, but are not required.
|
yading@11
|
56 *
|
yading@11
|
57 * The following example illustrates an AVOptions-enabled struct:
|
yading@11
|
58 * @code
|
yading@11
|
59 * typedef struct test_struct {
|
yading@11
|
60 * AVClass *class;
|
yading@11
|
61 * int int_opt;
|
yading@11
|
62 * char *str_opt;
|
yading@11
|
63 * uint8_t *bin_opt;
|
yading@11
|
64 * int bin_len;
|
yading@11
|
65 * } test_struct;
|
yading@11
|
66 *
|
yading@11
|
67 * static const AVOption options[] = {
|
yading@11
|
68 * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt),
|
yading@11
|
69 * AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX },
|
yading@11
|
70 * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt),
|
yading@11
|
71 * AV_OPT_TYPE_STRING },
|
yading@11
|
72 * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt),
|
yading@11
|
73 * AV_OPT_TYPE_BINARY },
|
yading@11
|
74 * { NULL },
|
yading@11
|
75 * };
|
yading@11
|
76 *
|
yading@11
|
77 * static const AVClass test_class = {
|
yading@11
|
78 * .class_name = "test class",
|
yading@11
|
79 * .item_name = av_default_item_name,
|
yading@11
|
80 * .option = options,
|
yading@11
|
81 * .version = LIBAVUTIL_VERSION_INT,
|
yading@11
|
82 * };
|
yading@11
|
83 * @endcode
|
yading@11
|
84 *
|
yading@11
|
85 * Next, when allocating your struct, you must ensure that the AVClass pointer
|
yading@11
|
86 * is set to the correct value. Then, av_opt_set_defaults() can be called to
|
yading@11
|
87 * initialize defaults. After that the struct is ready to be used with the
|
yading@11
|
88 * AVOptions API.
|
yading@11
|
89 *
|
yading@11
|
90 * When cleaning up, you may use the av_opt_free() function to automatically
|
yading@11
|
91 * free all the allocated string and binary options.
|
yading@11
|
92 *
|
yading@11
|
93 * Continuing with the above example:
|
yading@11
|
94 *
|
yading@11
|
95 * @code
|
yading@11
|
96 * test_struct *alloc_test_struct(void)
|
yading@11
|
97 * {
|
yading@11
|
98 * test_struct *ret = av_malloc(sizeof(*ret));
|
yading@11
|
99 * ret->class = &test_class;
|
yading@11
|
100 * av_opt_set_defaults(ret);
|
yading@11
|
101 * return ret;
|
yading@11
|
102 * }
|
yading@11
|
103 * void free_test_struct(test_struct **foo)
|
yading@11
|
104 * {
|
yading@11
|
105 * av_opt_free(*foo);
|
yading@11
|
106 * av_freep(foo);
|
yading@11
|
107 * }
|
yading@11
|
108 * @endcode
|
yading@11
|
109 *
|
yading@11
|
110 * @subsection avoptions_implement_nesting Nesting
|
yading@11
|
111 * It may happen that an AVOptions-enabled struct contains another
|
yading@11
|
112 * AVOptions-enabled struct as a member (e.g. AVCodecContext in
|
yading@11
|
113 * libavcodec exports generic options, while its priv_data field exports
|
yading@11
|
114 * codec-specific options). In such a case, it is possible to set up the
|
yading@11
|
115 * parent struct to export a child's options. To do that, simply
|
yading@11
|
116 * implement AVClass.child_next() and AVClass.child_class_next() in the
|
yading@11
|
117 * parent struct's AVClass.
|
yading@11
|
118 * Assuming that the test_struct from above now also contains a
|
yading@11
|
119 * child_struct field:
|
yading@11
|
120 *
|
yading@11
|
121 * @code
|
yading@11
|
122 * typedef struct child_struct {
|
yading@11
|
123 * AVClass *class;
|
yading@11
|
124 * int flags_opt;
|
yading@11
|
125 * } child_struct;
|
yading@11
|
126 * static const AVOption child_opts[] = {
|
yading@11
|
127 * { "test_flags", "This is a test option of flags type.",
|
yading@11
|
128 * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX },
|
yading@11
|
129 * { NULL },
|
yading@11
|
130 * };
|
yading@11
|
131 * static const AVClass child_class = {
|
yading@11
|
132 * .class_name = "child class",
|
yading@11
|
133 * .item_name = av_default_item_name,
|
yading@11
|
134 * .option = child_opts,
|
yading@11
|
135 * .version = LIBAVUTIL_VERSION_INT,
|
yading@11
|
136 * };
|
yading@11
|
137 *
|
yading@11
|
138 * void *child_next(void *obj, void *prev)
|
yading@11
|
139 * {
|
yading@11
|
140 * test_struct *t = obj;
|
yading@11
|
141 * if (!prev && t->child_struct)
|
yading@11
|
142 * return t->child_struct;
|
yading@11
|
143 * return NULL
|
yading@11
|
144 * }
|
yading@11
|
145 * const AVClass child_class_next(const AVClass *prev)
|
yading@11
|
146 * {
|
yading@11
|
147 * return prev ? NULL : &child_class;
|
yading@11
|
148 * }
|
yading@11
|
149 * @endcode
|
yading@11
|
150 * Putting child_next() and child_class_next() as defined above into
|
yading@11
|
151 * test_class will now make child_struct's options accessible through
|
yading@11
|
152 * test_struct (again, proper setup as described above needs to be done on
|
yading@11
|
153 * child_struct right after it is created).
|
yading@11
|
154 *
|
yading@11
|
155 * From the above example it might not be clear why both child_next()
|
yading@11
|
156 * and child_class_next() are needed. The distinction is that child_next()
|
yading@11
|
157 * iterates over actually existing objects, while child_class_next()
|
yading@11
|
158 * iterates over all possible child classes. E.g. if an AVCodecContext
|
yading@11
|
159 * was initialized to use a codec which has private options, then its
|
yading@11
|
160 * child_next() will return AVCodecContext.priv_data and finish
|
yading@11
|
161 * iterating. OTOH child_class_next() on AVCodecContext.av_class will
|
yading@11
|
162 * iterate over all available codecs with private options.
|
yading@11
|
163 *
|
yading@11
|
164 * @subsection avoptions_implement_named_constants Named constants
|
yading@11
|
165 * It is possible to create named constants for options. Simply set the unit
|
yading@11
|
166 * field of the option the constants should apply to to a string and
|
yading@11
|
167 * create the constants themselves as options of type AV_OPT_TYPE_CONST
|
yading@11
|
168 * with their unit field set to the same string.
|
yading@11
|
169 * Their default_val field should contain the value of the named
|
yading@11
|
170 * constant.
|
yading@11
|
171 * For example, to add some named constants for the test_flags option
|
yading@11
|
172 * above, put the following into the child_opts array:
|
yading@11
|
173 * @code
|
yading@11
|
174 * { "test_flags", "This is a test option of flags type.",
|
yading@11
|
175 * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" },
|
yading@11
|
176 * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" },
|
yading@11
|
177 * @endcode
|
yading@11
|
178 *
|
yading@11
|
179 * @section avoptions_use Using AVOptions
|
yading@11
|
180 * This section deals with accessing options in an AVOptions-enabled struct.
|
yading@11
|
181 * Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or
|
yading@11
|
182 * AVFormatContext in libavformat.
|
yading@11
|
183 *
|
yading@11
|
184 * @subsection avoptions_use_examine Examining AVOptions
|
yading@11
|
185 * The basic functions for examining options are av_opt_next(), which iterates
|
yading@11
|
186 * over all options defined for one object, and av_opt_find(), which searches
|
yading@11
|
187 * for an option with the given name.
|
yading@11
|
188 *
|
yading@11
|
189 * The situation is more complicated with nesting. An AVOptions-enabled struct
|
yading@11
|
190 * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag
|
yading@11
|
191 * to av_opt_find() will make the function search children recursively.
|
yading@11
|
192 *
|
yading@11
|
193 * For enumerating there are basically two cases. The first is when you want to
|
yading@11
|
194 * get all options that may potentially exist on the struct and its children
|
yading@11
|
195 * (e.g. when constructing documentation). In that case you should call
|
yading@11
|
196 * av_opt_child_class_next() recursively on the parent struct's AVClass. The
|
yading@11
|
197 * second case is when you have an already initialized struct with all its
|
yading@11
|
198 * children and you want to get all options that can be actually written or read
|
yading@11
|
199 * from it. In that case you should call av_opt_child_next() recursively (and
|
yading@11
|
200 * av_opt_next() on each result).
|
yading@11
|
201 *
|
yading@11
|
202 * @subsection avoptions_use_get_set Reading and writing AVOptions
|
yading@11
|
203 * When setting options, you often have a string read directly from the
|
yading@11
|
204 * user. In such a case, simply passing it to av_opt_set() is enough. For
|
yading@11
|
205 * non-string type options, av_opt_set() will parse the string according to the
|
yading@11
|
206 * option type.
|
yading@11
|
207 *
|
yading@11
|
208 * Similarly av_opt_get() will read any option type and convert it to a string
|
yading@11
|
209 * which will be returned. Do not forget that the string is allocated, so you
|
yading@11
|
210 * have to free it with av_free().
|
yading@11
|
211 *
|
yading@11
|
212 * In some cases it may be more convenient to put all options into an
|
yading@11
|
213 * AVDictionary and call av_opt_set_dict() on it. A specific case of this
|
yading@11
|
214 * are the format/codec open functions in lavf/lavc which take a dictionary
|
yading@11
|
215 * filled with option as a parameter. This allows to set some options
|
yading@11
|
216 * that cannot be set otherwise, since e.g. the input file format is not known
|
yading@11
|
217 * before the file is actually opened.
|
yading@11
|
218 */
|
yading@11
|
219
|
yading@11
|
220 enum AVOptionType{
|
yading@11
|
221 AV_OPT_TYPE_FLAGS,
|
yading@11
|
222 AV_OPT_TYPE_INT,
|
yading@11
|
223 AV_OPT_TYPE_INT64,
|
yading@11
|
224 AV_OPT_TYPE_DOUBLE,
|
yading@11
|
225 AV_OPT_TYPE_FLOAT,
|
yading@11
|
226 AV_OPT_TYPE_STRING,
|
yading@11
|
227 AV_OPT_TYPE_RATIONAL,
|
yading@11
|
228 AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
|
yading@11
|
229 AV_OPT_TYPE_CONST = 128,
|
yading@11
|
230 AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers
|
yading@11
|
231 AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P','F','M','T'),
|
yading@11
|
232 AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'),
|
yading@11
|
233 AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational
|
yading@11
|
234 AV_OPT_TYPE_DURATION = MKBETAG('D','U','R',' '),
|
yading@11
|
235 #if FF_API_OLD_AVOPTIONS
|
yading@11
|
236 FF_OPT_TYPE_FLAGS = 0,
|
yading@11
|
237 FF_OPT_TYPE_INT,
|
yading@11
|
238 FF_OPT_TYPE_INT64,
|
yading@11
|
239 FF_OPT_TYPE_DOUBLE,
|
yading@11
|
240 FF_OPT_TYPE_FLOAT,
|
yading@11
|
241 FF_OPT_TYPE_STRING,
|
yading@11
|
242 FF_OPT_TYPE_RATIONAL,
|
yading@11
|
243 FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length
|
yading@11
|
244 FF_OPT_TYPE_CONST=128,
|
yading@11
|
245 #endif
|
yading@11
|
246 };
|
yading@11
|
247
|
yading@11
|
248 /**
|
yading@11
|
249 * AVOption
|
yading@11
|
250 */
|
yading@11
|
251 typedef struct AVOption {
|
yading@11
|
252 const char *name;
|
yading@11
|
253
|
yading@11
|
254 /**
|
yading@11
|
255 * short English help text
|
yading@11
|
256 * @todo What about other languages?
|
yading@11
|
257 */
|
yading@11
|
258 const char *help;
|
yading@11
|
259
|
yading@11
|
260 /**
|
yading@11
|
261 * The offset relative to the context structure where the option
|
yading@11
|
262 * value is stored. It should be 0 for named constants.
|
yading@11
|
263 */
|
yading@11
|
264 int offset;
|
yading@11
|
265 enum AVOptionType type;
|
yading@11
|
266
|
yading@11
|
267 /**
|
yading@11
|
268 * the default value for scalar options
|
yading@11
|
269 */
|
yading@11
|
270 union {
|
yading@11
|
271 int64_t i64;
|
yading@11
|
272 double dbl;
|
yading@11
|
273 const char *str;
|
yading@11
|
274 /* TODO those are unused now */
|
yading@11
|
275 AVRational q;
|
yading@11
|
276 } default_val;
|
yading@11
|
277 double min; ///< minimum valid value for the option
|
yading@11
|
278 double max; ///< maximum valid value for the option
|
yading@11
|
279
|
yading@11
|
280 int flags;
|
yading@11
|
281 #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding
|
yading@11
|
282 #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding
|
yading@11
|
283 #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ...
|
yading@11
|
284 #define AV_OPT_FLAG_AUDIO_PARAM 8
|
yading@11
|
285 #define AV_OPT_FLAG_VIDEO_PARAM 16
|
yading@11
|
286 #define AV_OPT_FLAG_SUBTITLE_PARAM 32
|
yading@11
|
287 #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering
|
yading@11
|
288 //FIXME think about enc-audio, ... style flags
|
yading@11
|
289
|
yading@11
|
290 /**
|
yading@11
|
291 * The logical unit to which the option belongs. Non-constant
|
yading@11
|
292 * options and corresponding named constants share the same
|
yading@11
|
293 * unit. May be NULL.
|
yading@11
|
294 */
|
yading@11
|
295 const char *unit;
|
yading@11
|
296 } AVOption;
|
yading@11
|
297
|
yading@11
|
298 /**
|
yading@11
|
299 * A single allowed range of values, or a single allowed value.
|
yading@11
|
300 */
|
yading@11
|
301 typedef struct AVOptionRange {
|
yading@11
|
302 const char *str;
|
yading@11
|
303 double value_min, value_max; ///< For string ranges this represents the min/max length, for dimensions this represents the min/max pixel count
|
yading@11
|
304 double component_min, component_max; ///< For string this represents the unicode range for chars, 0-127 limits to ASCII
|
yading@11
|
305 int is_range; ///< if set to 1 the struct encodes a range, if set to 0 a single value
|
yading@11
|
306 } AVOptionRange;
|
yading@11
|
307
|
yading@11
|
308 /**
|
yading@11
|
309 * List of AVOptionRange structs
|
yading@11
|
310 */
|
yading@11
|
311 typedef struct AVOptionRanges {
|
yading@11
|
312 AVOptionRange **range;
|
yading@11
|
313 int nb_ranges;
|
yading@11
|
314 } AVOptionRanges;
|
yading@11
|
315
|
yading@11
|
316
|
yading@11
|
317 #if FF_API_FIND_OPT
|
yading@11
|
318 /**
|
yading@11
|
319 * Look for an option in obj. Look only for the options which
|
yading@11
|
320 * have the flags set as specified in mask and flags (that is,
|
yading@11
|
321 * for which it is the case that opt->flags & mask == flags).
|
yading@11
|
322 *
|
yading@11
|
323 * @param[in] obj a pointer to a struct whose first element is a
|
yading@11
|
324 * pointer to an AVClass
|
yading@11
|
325 * @param[in] name the name of the option to look for
|
yading@11
|
326 * @param[in] unit the unit of the option to look for, or any if NULL
|
yading@11
|
327 * @return a pointer to the option found, or NULL if no option
|
yading@11
|
328 * has been found
|
yading@11
|
329 *
|
yading@11
|
330 * @deprecated use av_opt_find.
|
yading@11
|
331 */
|
yading@11
|
332 attribute_deprecated
|
yading@11
|
333 const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags);
|
yading@11
|
334 #endif
|
yading@11
|
335
|
yading@11
|
336 #if FF_API_OLD_AVOPTIONS
|
yading@11
|
337 /**
|
yading@11
|
338 * Set the field of obj with the given name to value.
|
yading@11
|
339 *
|
yading@11
|
340 * @param[in] obj A struct whose first element is a pointer to an
|
yading@11
|
341 * AVClass.
|
yading@11
|
342 * @param[in] name the name of the field to set
|
yading@11
|
343 * @param[in] val The value to set. If the field is not of a string
|
yading@11
|
344 * type, then the given string is parsed.
|
yading@11
|
345 * SI postfixes and some named scalars are supported.
|
yading@11
|
346 * If the field is of a numeric type, it has to be a numeric or named
|
yading@11
|
347 * scalar. Behavior with more than one scalar and +- infix operators
|
yading@11
|
348 * is undefined.
|
yading@11
|
349 * If the field is of a flags type, it has to be a sequence of numeric
|
yading@11
|
350 * scalars or named flags separated by '+' or '-'. Prefixing a flag
|
yading@11
|
351 * with '+' causes it to be set without affecting the other flags;
|
yading@11
|
352 * similarly, '-' unsets a flag.
|
yading@11
|
353 * @param[out] o_out if non-NULL put here a pointer to the AVOption
|
yading@11
|
354 * found
|
yading@11
|
355 * @param alloc this parameter is currently ignored
|
yading@11
|
356 * @return 0 if the value has been set, or an AVERROR code in case of
|
yading@11
|
357 * error:
|
yading@11
|
358 * AVERROR_OPTION_NOT_FOUND if no matching option exists
|
yading@11
|
359 * AVERROR(ERANGE) if the value is out of range
|
yading@11
|
360 * AVERROR(EINVAL) if the value is not valid
|
yading@11
|
361 * @deprecated use av_opt_set()
|
yading@11
|
362 */
|
yading@11
|
363 attribute_deprecated
|
yading@11
|
364 int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out);
|
yading@11
|
365
|
yading@11
|
366 attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n);
|
yading@11
|
367 attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n);
|
yading@11
|
368 attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n);
|
yading@11
|
369
|
yading@11
|
370 double av_get_double(void *obj, const char *name, const AVOption **o_out);
|
yading@11
|
371 AVRational av_get_q(void *obj, const char *name, const AVOption **o_out);
|
yading@11
|
372 int64_t av_get_int(void *obj, const char *name, const AVOption **o_out);
|
yading@11
|
373 attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len);
|
yading@11
|
374 attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last);
|
yading@11
|
375 #endif
|
yading@11
|
376
|
yading@11
|
377 /**
|
yading@11
|
378 * Show the obj options.
|
yading@11
|
379 *
|
yading@11
|
380 * @param req_flags requested flags for the options to show. Show only the
|
yading@11
|
381 * options for which it is opt->flags & req_flags.
|
yading@11
|
382 * @param rej_flags rejected flags for the options to show. Show only the
|
yading@11
|
383 * options for which it is !(opt->flags & req_flags).
|
yading@11
|
384 * @param av_log_obj log context to use for showing the options
|
yading@11
|
385 */
|
yading@11
|
386 int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags);
|
yading@11
|
387
|
yading@11
|
388 /**
|
yading@11
|
389 * Set the values of all AVOption fields to their default values.
|
yading@11
|
390 *
|
yading@11
|
391 * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass)
|
yading@11
|
392 */
|
yading@11
|
393 void av_opt_set_defaults(void *s);
|
yading@11
|
394
|
yading@11
|
395 #if FF_API_OLD_AVOPTIONS
|
yading@11
|
396 attribute_deprecated
|
yading@11
|
397 void av_opt_set_defaults2(void *s, int mask, int flags);
|
yading@11
|
398 #endif
|
yading@11
|
399
|
yading@11
|
400 /**
|
yading@11
|
401 * Parse the key/value pairs list in opts. For each key/value pair
|
yading@11
|
402 * found, stores the value in the field in ctx that is named like the
|
yading@11
|
403 * key. ctx must be an AVClass context, storing is done using
|
yading@11
|
404 * AVOptions.
|
yading@11
|
405 *
|
yading@11
|
406 * @param opts options string to parse, may be NULL
|
yading@11
|
407 * @param key_val_sep a 0-terminated list of characters used to
|
yading@11
|
408 * separate key from value
|
yading@11
|
409 * @param pairs_sep a 0-terminated list of characters used to separate
|
yading@11
|
410 * two pairs from each other
|
yading@11
|
411 * @return the number of successfully set key/value pairs, or a negative
|
yading@11
|
412 * value corresponding to an AVERROR code in case of error:
|
yading@11
|
413 * AVERROR(EINVAL) if opts cannot be parsed,
|
yading@11
|
414 * the error code issued by av_set_string3() if a key/value pair
|
yading@11
|
415 * cannot be set
|
yading@11
|
416 */
|
yading@11
|
417 int av_set_options_string(void *ctx, const char *opts,
|
yading@11
|
418 const char *key_val_sep, const char *pairs_sep);
|
yading@11
|
419
|
yading@11
|
420 /**
|
yading@11
|
421 * Parse the key-value pairs list in opts. For each key=value pair found,
|
yading@11
|
422 * set the value of the corresponding option in ctx.
|
yading@11
|
423 *
|
yading@11
|
424 * @param ctx the AVClass object to set options on
|
yading@11
|
425 * @param opts the options string, key-value pairs separated by a
|
yading@11
|
426 * delimiter
|
yading@11
|
427 * @param shorthand a NULL-terminated array of options names for shorthand
|
yading@11
|
428 * notation: if the first field in opts has no key part,
|
yading@11
|
429 * the key is taken from the first element of shorthand;
|
yading@11
|
430 * then again for the second, etc., until either opts is
|
yading@11
|
431 * finished, shorthand is finished or a named option is
|
yading@11
|
432 * found; after that, all options must be named
|
yading@11
|
433 * @param key_val_sep a 0-terminated list of characters used to separate
|
yading@11
|
434 * key from value, for example '='
|
yading@11
|
435 * @param pairs_sep a 0-terminated list of characters used to separate
|
yading@11
|
436 * two pairs from each other, for example ':' or ','
|
yading@11
|
437 * @return the number of successfully set key=value pairs, or a negative
|
yading@11
|
438 * value corresponding to an AVERROR code in case of error:
|
yading@11
|
439 * AVERROR(EINVAL) if opts cannot be parsed,
|
yading@11
|
440 * the error code issued by av_set_string3() if a key/value pair
|
yading@11
|
441 * cannot be set
|
yading@11
|
442 *
|
yading@11
|
443 * Options names must use only the following characters: a-z A-Z 0-9 - . / _
|
yading@11
|
444 * Separators must use characters distinct from option names and from each
|
yading@11
|
445 * other.
|
yading@11
|
446 */
|
yading@11
|
447 int av_opt_set_from_string(void *ctx, const char *opts,
|
yading@11
|
448 const char *const *shorthand,
|
yading@11
|
449 const char *key_val_sep, const char *pairs_sep);
|
yading@11
|
450 /**
|
yading@11
|
451 * Free all string and binary options in obj.
|
yading@11
|
452 */
|
yading@11
|
453 void av_opt_free(void *obj);
|
yading@11
|
454
|
yading@11
|
455 /**
|
yading@11
|
456 * Check whether a particular flag is set in a flags field.
|
yading@11
|
457 *
|
yading@11
|
458 * @param field_name the name of the flag field option
|
yading@11
|
459 * @param flag_name the name of the flag to check
|
yading@11
|
460 * @return non-zero if the flag is set, zero if the flag isn't set,
|
yading@11
|
461 * isn't of the right type, or the flags field doesn't exist.
|
yading@11
|
462 */
|
yading@11
|
463 int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name);
|
yading@11
|
464
|
yading@11
|
465 /**
|
yading@11
|
466 * Set all the options from a given dictionary on an object.
|
yading@11
|
467 *
|
yading@11
|
468 * @param obj a struct whose first element is a pointer to AVClass
|
yading@11
|
469 * @param options options to process. This dictionary will be freed and replaced
|
yading@11
|
470 * by a new one containing all options not found in obj.
|
yading@11
|
471 * Of course this new dictionary needs to be freed by caller
|
yading@11
|
472 * with av_dict_free().
|
yading@11
|
473 *
|
yading@11
|
474 * @return 0 on success, a negative AVERROR if some option was found in obj,
|
yading@11
|
475 * but could not be set.
|
yading@11
|
476 *
|
yading@11
|
477 * @see av_dict_copy()
|
yading@11
|
478 */
|
yading@11
|
479 int av_opt_set_dict(void *obj, struct AVDictionary **options);
|
yading@11
|
480
|
yading@11
|
481 /**
|
yading@11
|
482 * Extract a key-value pair from the beginning of a string.
|
yading@11
|
483 *
|
yading@11
|
484 * @param ropts pointer to the options string, will be updated to
|
yading@11
|
485 * point to the rest of the string (one of the pairs_sep
|
yading@11
|
486 * or the final NUL)
|
yading@11
|
487 * @param key_val_sep a 0-terminated list of characters used to separate
|
yading@11
|
488 * key from value, for example '='
|
yading@11
|
489 * @param pairs_sep a 0-terminated list of characters used to separate
|
yading@11
|
490 * two pairs from each other, for example ':' or ','
|
yading@11
|
491 * @param flags flags; see the AV_OPT_FLAG_* values below
|
yading@11
|
492 * @param rkey parsed key; must be freed using av_free()
|
yading@11
|
493 * @param rval parsed value; must be freed using av_free()
|
yading@11
|
494 *
|
yading@11
|
495 * @return >=0 for success, or a negative value corresponding to an
|
yading@11
|
496 * AVERROR code in case of error; in particular:
|
yading@11
|
497 * AVERROR(EINVAL) if no key is present
|
yading@11
|
498 *
|
yading@11
|
499 */
|
yading@11
|
500 int av_opt_get_key_value(const char **ropts,
|
yading@11
|
501 const char *key_val_sep, const char *pairs_sep,
|
yading@11
|
502 unsigned flags,
|
yading@11
|
503 char **rkey, char **rval);
|
yading@11
|
504
|
yading@11
|
505 enum {
|
yading@11
|
506
|
yading@11
|
507 /**
|
yading@11
|
508 * Accept to parse a value without a key; the key will then be returned
|
yading@11
|
509 * as NULL.
|
yading@11
|
510 */
|
yading@11
|
511 AV_OPT_FLAG_IMPLICIT_KEY = 1,
|
yading@11
|
512 };
|
yading@11
|
513
|
yading@11
|
514 /**
|
yading@11
|
515 * @defgroup opt_eval_funcs Evaluating option strings
|
yading@11
|
516 * @{
|
yading@11
|
517 * This group of functions can be used to evaluate option strings
|
yading@11
|
518 * and get numbers out of them. They do the same thing as av_opt_set(),
|
yading@11
|
519 * except the result is written into the caller-supplied pointer.
|
yading@11
|
520 *
|
yading@11
|
521 * @param obj a struct whose first element is a pointer to AVClass.
|
yading@11
|
522 * @param o an option for which the string is to be evaluated.
|
yading@11
|
523 * @param val string to be evaluated.
|
yading@11
|
524 * @param *_out value of the string will be written here.
|
yading@11
|
525 *
|
yading@11
|
526 * @return 0 on success, a negative number on failure.
|
yading@11
|
527 */
|
yading@11
|
528 int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out);
|
yading@11
|
529 int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out);
|
yading@11
|
530 int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out);
|
yading@11
|
531 int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out);
|
yading@11
|
532 int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out);
|
yading@11
|
533 int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out);
|
yading@11
|
534 /**
|
yading@11
|
535 * @}
|
yading@11
|
536 */
|
yading@11
|
537
|
yading@11
|
538 #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the
|
yading@11
|
539 given object first. */
|
yading@11
|
540 /**
|
yading@11
|
541 * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass
|
yading@11
|
542 * instead of a required pointer to a struct containing AVClass. This is
|
yading@11
|
543 * useful for searching for options without needing to allocate the corresponding
|
yading@11
|
544 * object.
|
yading@11
|
545 */
|
yading@11
|
546 #define AV_OPT_SEARCH_FAKE_OBJ 0x0002
|
yading@11
|
547
|
yading@11
|
548 /**
|
yading@11
|
549 * Look for an option in an object. Consider only options which
|
yading@11
|
550 * have all the specified flags set.
|
yading@11
|
551 *
|
yading@11
|
552 * @param[in] obj A pointer to a struct whose first element is a
|
yading@11
|
553 * pointer to an AVClass.
|
yading@11
|
554 * Alternatively a double pointer to an AVClass, if
|
yading@11
|
555 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
|
yading@11
|
556 * @param[in] name The name of the option to look for.
|
yading@11
|
557 * @param[in] unit When searching for named constants, name of the unit
|
yading@11
|
558 * it belongs to.
|
yading@11
|
559 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
|
yading@11
|
560 * @param search_flags A combination of AV_OPT_SEARCH_*.
|
yading@11
|
561 *
|
yading@11
|
562 * @return A pointer to the option found, or NULL if no option
|
yading@11
|
563 * was found.
|
yading@11
|
564 *
|
yading@11
|
565 * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable
|
yading@11
|
566 * directly with av_set_string3(). Use special calls which take an options
|
yading@11
|
567 * AVDictionary (e.g. avformat_open_input()) to set options found with this
|
yading@11
|
568 * flag.
|
yading@11
|
569 */
|
yading@11
|
570 const AVOption *av_opt_find(void *obj, const char *name, const char *unit,
|
yading@11
|
571 int opt_flags, int search_flags);
|
yading@11
|
572
|
yading@11
|
573 /**
|
yading@11
|
574 * Look for an option in an object. Consider only options which
|
yading@11
|
575 * have all the specified flags set.
|
yading@11
|
576 *
|
yading@11
|
577 * @param[in] obj A pointer to a struct whose first element is a
|
yading@11
|
578 * pointer to an AVClass.
|
yading@11
|
579 * Alternatively a double pointer to an AVClass, if
|
yading@11
|
580 * AV_OPT_SEARCH_FAKE_OBJ search flag is set.
|
yading@11
|
581 * @param[in] name The name of the option to look for.
|
yading@11
|
582 * @param[in] unit When searching for named constants, name of the unit
|
yading@11
|
583 * it belongs to.
|
yading@11
|
584 * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG).
|
yading@11
|
585 * @param search_flags A combination of AV_OPT_SEARCH_*.
|
yading@11
|
586 * @param[out] target_obj if non-NULL, an object to which the option belongs will be
|
yading@11
|
587 * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present
|
yading@11
|
588 * in search_flags. This parameter is ignored if search_flags contain
|
yading@11
|
589 * AV_OPT_SEARCH_FAKE_OBJ.
|
yading@11
|
590 *
|
yading@11
|
591 * @return A pointer to the option found, or NULL if no option
|
yading@11
|
592 * was found.
|
yading@11
|
593 */
|
yading@11
|
594 const AVOption *av_opt_find2(void *obj, const char *name, const char *unit,
|
yading@11
|
595 int opt_flags, int search_flags, void **target_obj);
|
yading@11
|
596
|
yading@11
|
597 /**
|
yading@11
|
598 * Iterate over all AVOptions belonging to obj.
|
yading@11
|
599 *
|
yading@11
|
600 * @param obj an AVOptions-enabled struct or a double pointer to an
|
yading@11
|
601 * AVClass describing it.
|
yading@11
|
602 * @param prev result of the previous call to av_opt_next() on this object
|
yading@11
|
603 * or NULL
|
yading@11
|
604 * @return next AVOption or NULL
|
yading@11
|
605 */
|
yading@11
|
606 const AVOption *av_opt_next(void *obj, const AVOption *prev);
|
yading@11
|
607
|
yading@11
|
608 /**
|
yading@11
|
609 * Iterate over AVOptions-enabled children of obj.
|
yading@11
|
610 *
|
yading@11
|
611 * @param prev result of a previous call to this function or NULL
|
yading@11
|
612 * @return next AVOptions-enabled child or NULL
|
yading@11
|
613 */
|
yading@11
|
614 void *av_opt_child_next(void *obj, void *prev);
|
yading@11
|
615
|
yading@11
|
616 /**
|
yading@11
|
617 * Iterate over potential AVOptions-enabled children of parent.
|
yading@11
|
618 *
|
yading@11
|
619 * @param prev result of a previous call to this function or NULL
|
yading@11
|
620 * @return AVClass corresponding to next potential child or NULL
|
yading@11
|
621 */
|
yading@11
|
622 const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev);
|
yading@11
|
623
|
yading@11
|
624 /**
|
yading@11
|
625 * @defgroup opt_set_funcs Option setting functions
|
yading@11
|
626 * @{
|
yading@11
|
627 * Those functions set the field of obj with the given name to value.
|
yading@11
|
628 *
|
yading@11
|
629 * @param[in] obj A struct whose first element is a pointer to an AVClass.
|
yading@11
|
630 * @param[in] name the name of the field to set
|
yading@11
|
631 * @param[in] val The value to set. In case of av_opt_set() if the field is not
|
yading@11
|
632 * of a string type, then the given string is parsed.
|
yading@11
|
633 * SI postfixes and some named scalars are supported.
|
yading@11
|
634 * If the field is of a numeric type, it has to be a numeric or named
|
yading@11
|
635 * scalar. Behavior with more than one scalar and +- infix operators
|
yading@11
|
636 * is undefined.
|
yading@11
|
637 * If the field is of a flags type, it has to be a sequence of numeric
|
yading@11
|
638 * scalars or named flags separated by '+' or '-'. Prefixing a flag
|
yading@11
|
639 * with '+' causes it to be set without affecting the other flags;
|
yading@11
|
640 * similarly, '-' unsets a flag.
|
yading@11
|
641 * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
|
yading@11
|
642 * is passed here, then the option may be set on a child of obj.
|
yading@11
|
643 *
|
yading@11
|
644 * @return 0 if the value has been set, or an AVERROR code in case of
|
yading@11
|
645 * error:
|
yading@11
|
646 * AVERROR_OPTION_NOT_FOUND if no matching option exists
|
yading@11
|
647 * AVERROR(ERANGE) if the value is out of range
|
yading@11
|
648 * AVERROR(EINVAL) if the value is not valid
|
yading@11
|
649 */
|
yading@11
|
650 int av_opt_set (void *obj, const char *name, const char *val, int search_flags);
|
yading@11
|
651 int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags);
|
yading@11
|
652 int av_opt_set_double(void *obj, const char *name, double val, int search_flags);
|
yading@11
|
653 int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags);
|
yading@11
|
654 int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags);
|
yading@11
|
655 int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags);
|
yading@11
|
656 int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags);
|
yading@11
|
657 int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags);
|
yading@11
|
658 int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags);
|
yading@11
|
659
|
yading@11
|
660 /**
|
yading@11
|
661 * Set a binary option to an integer list.
|
yading@11
|
662 *
|
yading@11
|
663 * @param obj AVClass object to set options on
|
yading@11
|
664 * @param name name of the binary option
|
yading@11
|
665 * @param val pointer to an integer list (must have the correct type with
|
yading@11
|
666 * regard to the contents of the list)
|
yading@11
|
667 * @param term list terminator (usually 0 or -1)
|
yading@11
|
668 * @param flags search flags
|
yading@11
|
669 */
|
yading@11
|
670 #define av_opt_set_int_list(obj, name, val, term, flags) \
|
yading@11
|
671 (av_int_list_length(val, term) > INT_MAX / sizeof(*(val)) ? \
|
yading@11
|
672 AVERROR(EINVAL) : \
|
yading@11
|
673 av_opt_set_bin(obj, name, (const uint8_t *)(val), \
|
yading@11
|
674 av_int_list_length(val, term) * sizeof(*(val)), flags))
|
yading@11
|
675 /**
|
yading@11
|
676 * @}
|
yading@11
|
677 */
|
yading@11
|
678
|
yading@11
|
679 /**
|
yading@11
|
680 * @defgroup opt_get_funcs Option getting functions
|
yading@11
|
681 * @{
|
yading@11
|
682 * Those functions get a value of the option with the given name from an object.
|
yading@11
|
683 *
|
yading@11
|
684 * @param[in] obj a struct whose first element is a pointer to an AVClass.
|
yading@11
|
685 * @param[in] name name of the option to get.
|
yading@11
|
686 * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN
|
yading@11
|
687 * is passed here, then the option may be found in a child of obj.
|
yading@11
|
688 * @param[out] out_val value of the option will be written here
|
yading@11
|
689 * @return 0 on success, a negative error code otherwise
|
yading@11
|
690 */
|
yading@11
|
691 /**
|
yading@11
|
692 * @note the returned string will av_malloc()ed and must be av_free()ed by the caller
|
yading@11
|
693 */
|
yading@11
|
694 int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val);
|
yading@11
|
695 int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val);
|
yading@11
|
696 int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val);
|
yading@11
|
697 int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val);
|
yading@11
|
698 int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out);
|
yading@11
|
699 int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt);
|
yading@11
|
700 int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt);
|
yading@11
|
701 int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val);
|
yading@11
|
702 /**
|
yading@11
|
703 * @}
|
yading@11
|
704 */
|
yading@11
|
705 /**
|
yading@11
|
706 * Gets a pointer to the requested field in a struct.
|
yading@11
|
707 * This function allows accessing a struct even when its fields are moved or
|
yading@11
|
708 * renamed since the application making the access has been compiled,
|
yading@11
|
709 *
|
yading@11
|
710 * @returns a pointer to the field, it can be cast to the correct type and read
|
yading@11
|
711 * or written to.
|
yading@11
|
712 */
|
yading@11
|
713 void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name);
|
yading@11
|
714
|
yading@11
|
715 /**
|
yading@11
|
716 * Free an AVOptionRanges struct and set it to NULL.
|
yading@11
|
717 */
|
yading@11
|
718 void av_opt_freep_ranges(AVOptionRanges **ranges);
|
yading@11
|
719
|
yading@11
|
720 /**
|
yading@11
|
721 * Get a list of allowed ranges for the given option.
|
yading@11
|
722 *
|
yading@11
|
723 * The returned list may depend on other fields in obj like for example profile.
|
yading@11
|
724 *
|
yading@11
|
725 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
|
yading@11
|
726 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
|
yading@11
|
727 *
|
yading@11
|
728 * The result must be freed with av_opt_freep_ranges.
|
yading@11
|
729 *
|
yading@11
|
730 * @return >= 0 on success, a negative errro code otherwise
|
yading@11
|
731 */
|
yading@11
|
732 int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags);
|
yading@11
|
733
|
yading@11
|
734 /**
|
yading@11
|
735 * Get a default list of allowed ranges for the given option.
|
yading@11
|
736 *
|
yading@11
|
737 * This list is constructed without using the AVClass.query_ranges() callback
|
yading@11
|
738 * and can be used as fallback from within the callback.
|
yading@11
|
739 *
|
yading@11
|
740 * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored
|
yading@11
|
741 * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance
|
yading@11
|
742 *
|
yading@11
|
743 * The result must be freed with av_opt_free_ranges.
|
yading@11
|
744 *
|
yading@11
|
745 * @return >= 0 on success, a negative errro code otherwise
|
yading@11
|
746 */
|
yading@11
|
747 int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags);
|
yading@11
|
748
|
yading@11
|
749 /**
|
yading@11
|
750 * @}
|
yading@11
|
751 */
|
yading@11
|
752
|
yading@11
|
753 #endif /* AVUTIL_OPT_H */
|