yading@11: /* yading@11: * AVOptions yading@11: * copyright (c) 2005 Michael Niedermayer yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVUTIL_OPT_H yading@11: #define AVUTIL_OPT_H yading@11: yading@11: /** yading@11: * @file yading@11: * AVOptions yading@11: */ yading@11: yading@11: #include "rational.h" yading@11: #include "avutil.h" yading@11: #include "dict.h" yading@11: #include "log.h" yading@11: #include "pixfmt.h" yading@11: #include "samplefmt.h" yading@11: yading@11: /** yading@11: * @defgroup avoptions AVOptions yading@11: * @ingroup lavu_data yading@11: * @{ yading@11: * AVOptions provide a generic system to declare options on arbitrary structs yading@11: * ("objects"). An option can have a help text, a type and a range of possible yading@11: * values. Options may then be enumerated, read and written to. yading@11: * yading@11: * @section avoptions_implement Implementing AVOptions yading@11: * This section describes how to add AVOptions capabilities to a struct. yading@11: * yading@11: * All AVOptions-related information is stored in an AVClass. Therefore yading@11: * the first member of the struct should be a pointer to an AVClass describing it. yading@11: * The option field of the AVClass must be set to a NULL-terminated static array yading@11: * of AVOptions. Each AVOption must have a non-empty name, a type, a default yading@11: * value and for number-type AVOptions also a range of allowed values. It must yading@11: * also declare an offset in bytes from the start of the struct, where the field yading@11: * associated with this AVOption is located. Other fields in the AVOption struct yading@11: * should also be set when applicable, but are not required. yading@11: * yading@11: * The following example illustrates an AVOptions-enabled struct: yading@11: * @code yading@11: * typedef struct test_struct { yading@11: * AVClass *class; yading@11: * int int_opt; yading@11: * char *str_opt; yading@11: * uint8_t *bin_opt; yading@11: * int bin_len; yading@11: * } test_struct; yading@11: * yading@11: * static const AVOption options[] = { yading@11: * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt), yading@11: * AV_OPT_TYPE_INT, { .i64 = -1 }, INT_MIN, INT_MAX }, yading@11: * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt), yading@11: * AV_OPT_TYPE_STRING }, yading@11: * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt), yading@11: * AV_OPT_TYPE_BINARY }, yading@11: * { NULL }, yading@11: * }; yading@11: * yading@11: * static const AVClass test_class = { yading@11: * .class_name = "test class", yading@11: * .item_name = av_default_item_name, yading@11: * .option = options, yading@11: * .version = LIBAVUTIL_VERSION_INT, yading@11: * }; yading@11: * @endcode yading@11: * yading@11: * Next, when allocating your struct, you must ensure that the AVClass pointer yading@11: * is set to the correct value. Then, av_opt_set_defaults() can be called to yading@11: * initialize defaults. After that the struct is ready to be used with the yading@11: * AVOptions API. yading@11: * yading@11: * When cleaning up, you may use the av_opt_free() function to automatically yading@11: * free all the allocated string and binary options. yading@11: * yading@11: * Continuing with the above example: yading@11: * yading@11: * @code yading@11: * test_struct *alloc_test_struct(void) yading@11: * { yading@11: * test_struct *ret = av_malloc(sizeof(*ret)); yading@11: * ret->class = &test_class; yading@11: * av_opt_set_defaults(ret); yading@11: * return ret; yading@11: * } yading@11: * void free_test_struct(test_struct **foo) yading@11: * { yading@11: * av_opt_free(*foo); yading@11: * av_freep(foo); yading@11: * } yading@11: * @endcode yading@11: * yading@11: * @subsection avoptions_implement_nesting Nesting yading@11: * It may happen that an AVOptions-enabled struct contains another yading@11: * AVOptions-enabled struct as a member (e.g. AVCodecContext in yading@11: * libavcodec exports generic options, while its priv_data field exports yading@11: * codec-specific options). In such a case, it is possible to set up the yading@11: * parent struct to export a child's options. To do that, simply yading@11: * implement AVClass.child_next() and AVClass.child_class_next() in the yading@11: * parent struct's AVClass. yading@11: * Assuming that the test_struct from above now also contains a yading@11: * child_struct field: yading@11: * yading@11: * @code yading@11: * typedef struct child_struct { yading@11: * AVClass *class; yading@11: * int flags_opt; yading@11: * } child_struct; yading@11: * static const AVOption child_opts[] = { yading@11: * { "test_flags", "This is a test option of flags type.", yading@11: * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX }, yading@11: * { NULL }, yading@11: * }; yading@11: * static const AVClass child_class = { yading@11: * .class_name = "child class", yading@11: * .item_name = av_default_item_name, yading@11: * .option = child_opts, yading@11: * .version = LIBAVUTIL_VERSION_INT, yading@11: * }; yading@11: * yading@11: * void *child_next(void *obj, void *prev) yading@11: * { yading@11: * test_struct *t = obj; yading@11: * if (!prev && t->child_struct) yading@11: * return t->child_struct; yading@11: * return NULL yading@11: * } yading@11: * const AVClass child_class_next(const AVClass *prev) yading@11: * { yading@11: * return prev ? NULL : &child_class; yading@11: * } yading@11: * @endcode yading@11: * Putting child_next() and child_class_next() as defined above into yading@11: * test_class will now make child_struct's options accessible through yading@11: * test_struct (again, proper setup as described above needs to be done on yading@11: * child_struct right after it is created). yading@11: * yading@11: * From the above example it might not be clear why both child_next() yading@11: * and child_class_next() are needed. The distinction is that child_next() yading@11: * iterates over actually existing objects, while child_class_next() yading@11: * iterates over all possible child classes. E.g. if an AVCodecContext yading@11: * was initialized to use a codec which has private options, then its yading@11: * child_next() will return AVCodecContext.priv_data and finish yading@11: * iterating. OTOH child_class_next() on AVCodecContext.av_class will yading@11: * iterate over all available codecs with private options. yading@11: * yading@11: * @subsection avoptions_implement_named_constants Named constants yading@11: * It is possible to create named constants for options. Simply set the unit yading@11: * field of the option the constants should apply to to a string and yading@11: * create the constants themselves as options of type AV_OPT_TYPE_CONST yading@11: * with their unit field set to the same string. yading@11: * Their default_val field should contain the value of the named yading@11: * constant. yading@11: * For example, to add some named constants for the test_flags option yading@11: * above, put the following into the child_opts array: yading@11: * @code yading@11: * { "test_flags", "This is a test option of flags type.", yading@11: * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, INT_MIN, INT_MAX, "test_unit" }, yading@11: * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { .i64 = 16 }, 0, 0, "test_unit" }, yading@11: * @endcode yading@11: * yading@11: * @section avoptions_use Using AVOptions yading@11: * This section deals with accessing options in an AVOptions-enabled struct. yading@11: * Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or yading@11: * AVFormatContext in libavformat. yading@11: * yading@11: * @subsection avoptions_use_examine Examining AVOptions yading@11: * The basic functions for examining options are av_opt_next(), which iterates yading@11: * over all options defined for one object, and av_opt_find(), which searches yading@11: * for an option with the given name. yading@11: * yading@11: * The situation is more complicated with nesting. An AVOptions-enabled struct yading@11: * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag yading@11: * to av_opt_find() will make the function search children recursively. yading@11: * yading@11: * For enumerating there are basically two cases. The first is when you want to yading@11: * get all options that may potentially exist on the struct and its children yading@11: * (e.g. when constructing documentation). In that case you should call yading@11: * av_opt_child_class_next() recursively on the parent struct's AVClass. The yading@11: * second case is when you have an already initialized struct with all its yading@11: * children and you want to get all options that can be actually written or read yading@11: * from it. In that case you should call av_opt_child_next() recursively (and yading@11: * av_opt_next() on each result). yading@11: * yading@11: * @subsection avoptions_use_get_set Reading and writing AVOptions yading@11: * When setting options, you often have a string read directly from the yading@11: * user. In such a case, simply passing it to av_opt_set() is enough. For yading@11: * non-string type options, av_opt_set() will parse the string according to the yading@11: * option type. yading@11: * yading@11: * Similarly av_opt_get() will read any option type and convert it to a string yading@11: * which will be returned. Do not forget that the string is allocated, so you yading@11: * have to free it with av_free(). yading@11: * yading@11: * In some cases it may be more convenient to put all options into an yading@11: * AVDictionary and call av_opt_set_dict() on it. A specific case of this yading@11: * are the format/codec open functions in lavf/lavc which take a dictionary yading@11: * filled with option as a parameter. This allows to set some options yading@11: * that cannot be set otherwise, since e.g. the input file format is not known yading@11: * before the file is actually opened. yading@11: */ yading@11: yading@11: enum AVOptionType{ yading@11: AV_OPT_TYPE_FLAGS, yading@11: AV_OPT_TYPE_INT, yading@11: AV_OPT_TYPE_INT64, yading@11: AV_OPT_TYPE_DOUBLE, yading@11: AV_OPT_TYPE_FLOAT, yading@11: AV_OPT_TYPE_STRING, yading@11: AV_OPT_TYPE_RATIONAL, yading@11: AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length yading@11: AV_OPT_TYPE_CONST = 128, yading@11: AV_OPT_TYPE_IMAGE_SIZE = MKBETAG('S','I','Z','E'), ///< offset must point to two consecutive integers yading@11: AV_OPT_TYPE_PIXEL_FMT = MKBETAG('P','F','M','T'), yading@11: AV_OPT_TYPE_SAMPLE_FMT = MKBETAG('S','F','M','T'), yading@11: AV_OPT_TYPE_VIDEO_RATE = MKBETAG('V','R','A','T'), ///< offset must point to AVRational yading@11: AV_OPT_TYPE_DURATION = MKBETAG('D','U','R',' '), yading@11: #if FF_API_OLD_AVOPTIONS yading@11: FF_OPT_TYPE_FLAGS = 0, yading@11: FF_OPT_TYPE_INT, yading@11: FF_OPT_TYPE_INT64, yading@11: FF_OPT_TYPE_DOUBLE, yading@11: FF_OPT_TYPE_FLOAT, yading@11: FF_OPT_TYPE_STRING, yading@11: FF_OPT_TYPE_RATIONAL, yading@11: FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length yading@11: FF_OPT_TYPE_CONST=128, yading@11: #endif yading@11: }; yading@11: yading@11: /** yading@11: * AVOption yading@11: */ yading@11: typedef struct AVOption { yading@11: const char *name; yading@11: yading@11: /** yading@11: * short English help text yading@11: * @todo What about other languages? yading@11: */ yading@11: const char *help; yading@11: yading@11: /** yading@11: * The offset relative to the context structure where the option yading@11: * value is stored. It should be 0 for named constants. yading@11: */ yading@11: int offset; yading@11: enum AVOptionType type; yading@11: yading@11: /** yading@11: * the default value for scalar options yading@11: */ yading@11: union { yading@11: int64_t i64; yading@11: double dbl; yading@11: const char *str; yading@11: /* TODO those are unused now */ yading@11: AVRational q; yading@11: } default_val; yading@11: double min; ///< minimum valid value for the option yading@11: double max; ///< maximum valid value for the option yading@11: yading@11: int flags; yading@11: #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding yading@11: #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding yading@11: #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ... yading@11: #define AV_OPT_FLAG_AUDIO_PARAM 8 yading@11: #define AV_OPT_FLAG_VIDEO_PARAM 16 yading@11: #define AV_OPT_FLAG_SUBTITLE_PARAM 32 yading@11: #define AV_OPT_FLAG_FILTERING_PARAM (1<<16) ///< a generic parameter which can be set by the user for filtering yading@11: //FIXME think about enc-audio, ... style flags yading@11: yading@11: /** yading@11: * The logical unit to which the option belongs. Non-constant yading@11: * options and corresponding named constants share the same yading@11: * unit. May be NULL. yading@11: */ yading@11: const char *unit; yading@11: } AVOption; yading@11: yading@11: /** yading@11: * A single allowed range of values, or a single allowed value. yading@11: */ yading@11: typedef struct AVOptionRange { yading@11: const char *str; yading@11: 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: double component_min, component_max; ///< For string this represents the unicode range for chars, 0-127 limits to ASCII yading@11: int is_range; ///< if set to 1 the struct encodes a range, if set to 0 a single value yading@11: } AVOptionRange; yading@11: yading@11: /** yading@11: * List of AVOptionRange structs yading@11: */ yading@11: typedef struct AVOptionRanges { yading@11: AVOptionRange **range; yading@11: int nb_ranges; yading@11: } AVOptionRanges; yading@11: yading@11: yading@11: #if FF_API_FIND_OPT yading@11: /** yading@11: * Look for an option in obj. Look only for the options which yading@11: * have the flags set as specified in mask and flags (that is, yading@11: * for which it is the case that opt->flags & mask == flags). yading@11: * yading@11: * @param[in] obj a pointer to a struct whose first element is a yading@11: * pointer to an AVClass yading@11: * @param[in] name the name of the option to look for yading@11: * @param[in] unit the unit of the option to look for, or any if NULL yading@11: * @return a pointer to the option found, or NULL if no option yading@11: * has been found yading@11: * yading@11: * @deprecated use av_opt_find. yading@11: */ yading@11: attribute_deprecated yading@11: const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags); yading@11: #endif yading@11: yading@11: #if FF_API_OLD_AVOPTIONS yading@11: /** yading@11: * Set the field of obj with the given name to value. yading@11: * yading@11: * @param[in] obj A struct whose first element is a pointer to an yading@11: * AVClass. yading@11: * @param[in] name the name of the field to set yading@11: * @param[in] val The value to set. If the field is not of a string yading@11: * type, then the given string is parsed. yading@11: * SI postfixes and some named scalars are supported. yading@11: * If the field is of a numeric type, it has to be a numeric or named yading@11: * scalar. Behavior with more than one scalar and +- infix operators yading@11: * is undefined. yading@11: * If the field is of a flags type, it has to be a sequence of numeric yading@11: * scalars or named flags separated by '+' or '-'. Prefixing a flag yading@11: * with '+' causes it to be set without affecting the other flags; yading@11: * similarly, '-' unsets a flag. yading@11: * @param[out] o_out if non-NULL put here a pointer to the AVOption yading@11: * found yading@11: * @param alloc this parameter is currently ignored yading@11: * @return 0 if the value has been set, or an AVERROR code in case of yading@11: * error: yading@11: * AVERROR_OPTION_NOT_FOUND if no matching option exists yading@11: * AVERROR(ERANGE) if the value is out of range yading@11: * AVERROR(EINVAL) if the value is not valid yading@11: * @deprecated use av_opt_set() yading@11: */ yading@11: attribute_deprecated yading@11: int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out); yading@11: yading@11: attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n); yading@11: attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n); yading@11: attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n); yading@11: yading@11: double av_get_double(void *obj, const char *name, const AVOption **o_out); yading@11: AVRational av_get_q(void *obj, const char *name, const AVOption **o_out); yading@11: int64_t av_get_int(void *obj, const char *name, const AVOption **o_out); yading@11: attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len); yading@11: attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last); yading@11: #endif yading@11: yading@11: /** yading@11: * Show the obj options. yading@11: * yading@11: * @param req_flags requested flags for the options to show. Show only the yading@11: * options for which it is opt->flags & req_flags. yading@11: * @param rej_flags rejected flags for the options to show. Show only the yading@11: * options for which it is !(opt->flags & req_flags). yading@11: * @param av_log_obj log context to use for showing the options yading@11: */ yading@11: int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags); yading@11: yading@11: /** yading@11: * Set the values of all AVOption fields to their default values. yading@11: * yading@11: * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass) yading@11: */ yading@11: void av_opt_set_defaults(void *s); yading@11: yading@11: #if FF_API_OLD_AVOPTIONS yading@11: attribute_deprecated yading@11: void av_opt_set_defaults2(void *s, int mask, int flags); yading@11: #endif yading@11: yading@11: /** yading@11: * Parse the key/value pairs list in opts. For each key/value pair yading@11: * found, stores the value in the field in ctx that is named like the yading@11: * key. ctx must be an AVClass context, storing is done using yading@11: * AVOptions. yading@11: * yading@11: * @param opts options string to parse, may be NULL yading@11: * @param key_val_sep a 0-terminated list of characters used to yading@11: * separate key from value yading@11: * @param pairs_sep a 0-terminated list of characters used to separate yading@11: * two pairs from each other yading@11: * @return the number of successfully set key/value pairs, or a negative yading@11: * value corresponding to an AVERROR code in case of error: yading@11: * AVERROR(EINVAL) if opts cannot be parsed, yading@11: * the error code issued by av_set_string3() if a key/value pair yading@11: * cannot be set yading@11: */ yading@11: int av_set_options_string(void *ctx, const char *opts, yading@11: const char *key_val_sep, const char *pairs_sep); yading@11: yading@11: /** yading@11: * Parse the key-value pairs list in opts. For each key=value pair found, yading@11: * set the value of the corresponding option in ctx. yading@11: * yading@11: * @param ctx the AVClass object to set options on yading@11: * @param opts the options string, key-value pairs separated by a yading@11: * delimiter yading@11: * @param shorthand a NULL-terminated array of options names for shorthand yading@11: * notation: if the first field in opts has no key part, yading@11: * the key is taken from the first element of shorthand; yading@11: * then again for the second, etc., until either opts is yading@11: * finished, shorthand is finished or a named option is yading@11: * found; after that, all options must be named yading@11: * @param key_val_sep a 0-terminated list of characters used to separate yading@11: * key from value, for example '=' yading@11: * @param pairs_sep a 0-terminated list of characters used to separate yading@11: * two pairs from each other, for example ':' or ',' yading@11: * @return the number of successfully set key=value pairs, or a negative yading@11: * value corresponding to an AVERROR code in case of error: yading@11: * AVERROR(EINVAL) if opts cannot be parsed, yading@11: * the error code issued by av_set_string3() if a key/value pair yading@11: * cannot be set yading@11: * yading@11: * Options names must use only the following characters: a-z A-Z 0-9 - . / _ yading@11: * Separators must use characters distinct from option names and from each yading@11: * other. yading@11: */ yading@11: int av_opt_set_from_string(void *ctx, const char *opts, yading@11: const char *const *shorthand, yading@11: const char *key_val_sep, const char *pairs_sep); yading@11: /** yading@11: * Free all string and binary options in obj. yading@11: */ yading@11: void av_opt_free(void *obj); yading@11: yading@11: /** yading@11: * Check whether a particular flag is set in a flags field. yading@11: * yading@11: * @param field_name the name of the flag field option yading@11: * @param flag_name the name of the flag to check yading@11: * @return non-zero if the flag is set, zero if the flag isn't set, yading@11: * isn't of the right type, or the flags field doesn't exist. yading@11: */ yading@11: int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name); yading@11: yading@11: /** yading@11: * Set all the options from a given dictionary on an object. yading@11: * yading@11: * @param obj a struct whose first element is a pointer to AVClass yading@11: * @param options options to process. This dictionary will be freed and replaced yading@11: * by a new one containing all options not found in obj. yading@11: * Of course this new dictionary needs to be freed by caller yading@11: * with av_dict_free(). yading@11: * yading@11: * @return 0 on success, a negative AVERROR if some option was found in obj, yading@11: * but could not be set. yading@11: * yading@11: * @see av_dict_copy() yading@11: */ yading@11: int av_opt_set_dict(void *obj, struct AVDictionary **options); yading@11: yading@11: /** yading@11: * Extract a key-value pair from the beginning of a string. yading@11: * yading@11: * @param ropts pointer to the options string, will be updated to yading@11: * point to the rest of the string (one of the pairs_sep yading@11: * or the final NUL) yading@11: * @param key_val_sep a 0-terminated list of characters used to separate yading@11: * key from value, for example '=' yading@11: * @param pairs_sep a 0-terminated list of characters used to separate yading@11: * two pairs from each other, for example ':' or ',' yading@11: * @param flags flags; see the AV_OPT_FLAG_* values below yading@11: * @param rkey parsed key; must be freed using av_free() yading@11: * @param rval parsed value; must be freed using av_free() yading@11: * yading@11: * @return >=0 for success, or a negative value corresponding to an yading@11: * AVERROR code in case of error; in particular: yading@11: * AVERROR(EINVAL) if no key is present yading@11: * yading@11: */ yading@11: int av_opt_get_key_value(const char **ropts, yading@11: const char *key_val_sep, const char *pairs_sep, yading@11: unsigned flags, yading@11: char **rkey, char **rval); yading@11: yading@11: enum { yading@11: yading@11: /** yading@11: * Accept to parse a value without a key; the key will then be returned yading@11: * as NULL. yading@11: */ yading@11: AV_OPT_FLAG_IMPLICIT_KEY = 1, yading@11: }; yading@11: yading@11: /** yading@11: * @defgroup opt_eval_funcs Evaluating option strings yading@11: * @{ yading@11: * This group of functions can be used to evaluate option strings yading@11: * and get numbers out of them. They do the same thing as av_opt_set(), yading@11: * except the result is written into the caller-supplied pointer. yading@11: * yading@11: * @param obj a struct whose first element is a pointer to AVClass. yading@11: * @param o an option for which the string is to be evaluated. yading@11: * @param val string to be evaluated. yading@11: * @param *_out value of the string will be written here. yading@11: * yading@11: * @return 0 on success, a negative number on failure. yading@11: */ yading@11: int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out); yading@11: int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out); yading@11: int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out); yading@11: int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out); yading@11: int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out); yading@11: int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out); yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the yading@11: given object first. */ yading@11: /** yading@11: * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass yading@11: * instead of a required pointer to a struct containing AVClass. This is yading@11: * useful for searching for options without needing to allocate the corresponding yading@11: * object. yading@11: */ yading@11: #define AV_OPT_SEARCH_FAKE_OBJ 0x0002 yading@11: yading@11: /** yading@11: * Look for an option in an object. Consider only options which yading@11: * have all the specified flags set. yading@11: * yading@11: * @param[in] obj A pointer to a struct whose first element is a yading@11: * pointer to an AVClass. yading@11: * Alternatively a double pointer to an AVClass, if yading@11: * AV_OPT_SEARCH_FAKE_OBJ search flag is set. yading@11: * @param[in] name The name of the option to look for. yading@11: * @param[in] unit When searching for named constants, name of the unit yading@11: * it belongs to. yading@11: * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG). yading@11: * @param search_flags A combination of AV_OPT_SEARCH_*. yading@11: * yading@11: * @return A pointer to the option found, or NULL if no option yading@11: * was found. yading@11: * yading@11: * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable yading@11: * directly with av_set_string3(). Use special calls which take an options yading@11: * AVDictionary (e.g. avformat_open_input()) to set options found with this yading@11: * flag. yading@11: */ yading@11: const AVOption *av_opt_find(void *obj, const char *name, const char *unit, yading@11: int opt_flags, int search_flags); yading@11: yading@11: /** yading@11: * Look for an option in an object. Consider only options which yading@11: * have all the specified flags set. yading@11: * yading@11: * @param[in] obj A pointer to a struct whose first element is a yading@11: * pointer to an AVClass. yading@11: * Alternatively a double pointer to an AVClass, if yading@11: * AV_OPT_SEARCH_FAKE_OBJ search flag is set. yading@11: * @param[in] name The name of the option to look for. yading@11: * @param[in] unit When searching for named constants, name of the unit yading@11: * it belongs to. yading@11: * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG). yading@11: * @param search_flags A combination of AV_OPT_SEARCH_*. yading@11: * @param[out] target_obj if non-NULL, an object to which the option belongs will be yading@11: * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present yading@11: * in search_flags. This parameter is ignored if search_flags contain yading@11: * AV_OPT_SEARCH_FAKE_OBJ. yading@11: * yading@11: * @return A pointer to the option found, or NULL if no option yading@11: * was found. yading@11: */ yading@11: const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, yading@11: int opt_flags, int search_flags, void **target_obj); yading@11: yading@11: /** yading@11: * Iterate over all AVOptions belonging to obj. yading@11: * yading@11: * @param obj an AVOptions-enabled struct or a double pointer to an yading@11: * AVClass describing it. yading@11: * @param prev result of the previous call to av_opt_next() on this object yading@11: * or NULL yading@11: * @return next AVOption or NULL yading@11: */ yading@11: const AVOption *av_opt_next(void *obj, const AVOption *prev); yading@11: yading@11: /** yading@11: * Iterate over AVOptions-enabled children of obj. yading@11: * yading@11: * @param prev result of a previous call to this function or NULL yading@11: * @return next AVOptions-enabled child or NULL yading@11: */ yading@11: void *av_opt_child_next(void *obj, void *prev); yading@11: yading@11: /** yading@11: * Iterate over potential AVOptions-enabled children of parent. yading@11: * yading@11: * @param prev result of a previous call to this function or NULL yading@11: * @return AVClass corresponding to next potential child or NULL yading@11: */ yading@11: const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev); yading@11: yading@11: /** yading@11: * @defgroup opt_set_funcs Option setting functions yading@11: * @{ yading@11: * Those functions set the field of obj with the given name to value. yading@11: * yading@11: * @param[in] obj A struct whose first element is a pointer to an AVClass. yading@11: * @param[in] name the name of the field to set yading@11: * @param[in] val The value to set. In case of av_opt_set() if the field is not yading@11: * of a string type, then the given string is parsed. yading@11: * SI postfixes and some named scalars are supported. yading@11: * If the field is of a numeric type, it has to be a numeric or named yading@11: * scalar. Behavior with more than one scalar and +- infix operators yading@11: * is undefined. yading@11: * If the field is of a flags type, it has to be a sequence of numeric yading@11: * scalars or named flags separated by '+' or '-'. Prefixing a flag yading@11: * with '+' causes it to be set without affecting the other flags; yading@11: * similarly, '-' unsets a flag. yading@11: * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN yading@11: * is passed here, then the option may be set on a child of obj. yading@11: * yading@11: * @return 0 if the value has been set, or an AVERROR code in case of yading@11: * error: yading@11: * AVERROR_OPTION_NOT_FOUND if no matching option exists yading@11: * AVERROR(ERANGE) if the value is out of range yading@11: * AVERROR(EINVAL) if the value is not valid yading@11: */ yading@11: int av_opt_set (void *obj, const char *name, const char *val, int search_flags); yading@11: int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags); yading@11: int av_opt_set_double(void *obj, const char *name, double val, int search_flags); yading@11: int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags); yading@11: int av_opt_set_bin (void *obj, const char *name, const uint8_t *val, int size, int search_flags); yading@11: int av_opt_set_image_size(void *obj, const char *name, int w, int h, int search_flags); yading@11: int av_opt_set_pixel_fmt (void *obj, const char *name, enum AVPixelFormat fmt, int search_flags); yading@11: int av_opt_set_sample_fmt(void *obj, const char *name, enum AVSampleFormat fmt, int search_flags); yading@11: int av_opt_set_video_rate(void *obj, const char *name, AVRational val, int search_flags); yading@11: yading@11: /** yading@11: * Set a binary option to an integer list. yading@11: * yading@11: * @param obj AVClass object to set options on yading@11: * @param name name of the binary option yading@11: * @param val pointer to an integer list (must have the correct type with yading@11: * regard to the contents of the list) yading@11: * @param term list terminator (usually 0 or -1) yading@11: * @param flags search flags yading@11: */ yading@11: #define av_opt_set_int_list(obj, name, val, term, flags) \ yading@11: (av_int_list_length(val, term) > INT_MAX / sizeof(*(val)) ? \ yading@11: AVERROR(EINVAL) : \ yading@11: av_opt_set_bin(obj, name, (const uint8_t *)(val), \ yading@11: av_int_list_length(val, term) * sizeof(*(val)), flags)) yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: /** yading@11: * @defgroup opt_get_funcs Option getting functions yading@11: * @{ yading@11: * Those functions get a value of the option with the given name from an object. yading@11: * yading@11: * @param[in] obj a struct whose first element is a pointer to an AVClass. yading@11: * @param[in] name name of the option to get. yading@11: * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN yading@11: * is passed here, then the option may be found in a child of obj. yading@11: * @param[out] out_val value of the option will be written here yading@11: * @return 0 on success, a negative error code otherwise yading@11: */ yading@11: /** yading@11: * @note the returned string will av_malloc()ed and must be av_free()ed by the caller yading@11: */ yading@11: int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val); yading@11: int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val); yading@11: int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val); yading@11: int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val); yading@11: int av_opt_get_image_size(void *obj, const char *name, int search_flags, int *w_out, int *h_out); yading@11: int av_opt_get_pixel_fmt (void *obj, const char *name, int search_flags, enum AVPixelFormat *out_fmt); yading@11: int av_opt_get_sample_fmt(void *obj, const char *name, int search_flags, enum AVSampleFormat *out_fmt); yading@11: int av_opt_get_video_rate(void *obj, const char *name, int search_flags, AVRational *out_val); yading@11: /** yading@11: * @} yading@11: */ yading@11: /** yading@11: * Gets a pointer to the requested field in a struct. yading@11: * This function allows accessing a struct even when its fields are moved or yading@11: * renamed since the application making the access has been compiled, yading@11: * yading@11: * @returns a pointer to the field, it can be cast to the correct type and read yading@11: * or written to. yading@11: */ yading@11: void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name); yading@11: yading@11: /** yading@11: * Free an AVOptionRanges struct and set it to NULL. yading@11: */ yading@11: void av_opt_freep_ranges(AVOptionRanges **ranges); yading@11: yading@11: /** yading@11: * Get a list of allowed ranges for the given option. yading@11: * yading@11: * The returned list may depend on other fields in obj like for example profile. yading@11: * yading@11: * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored yading@11: * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance yading@11: * yading@11: * The result must be freed with av_opt_freep_ranges. yading@11: * yading@11: * @return >= 0 on success, a negative errro code otherwise yading@11: */ yading@11: int av_opt_query_ranges(AVOptionRanges **, void *obj, const char *key, int flags); yading@11: yading@11: /** yading@11: * Get a default list of allowed ranges for the given option. yading@11: * yading@11: * This list is constructed without using the AVClass.query_ranges() callback yading@11: * and can be used as fallback from within the callback. yading@11: * yading@11: * @param flags is a bitmask of flags, undefined flags should not be set and should be ignored yading@11: * AV_OPT_SEARCH_FAKE_OBJ indicates that the obj is a double pointer to a AVClass instead of a full instance yading@11: * yading@11: * The result must be freed with av_opt_free_ranges. yading@11: * yading@11: * @return >= 0 on success, a negative errro code otherwise yading@11: */ yading@11: int av_opt_query_ranges_default(AVOptionRanges **, void *obj, const char *key, int flags); yading@11: yading@11: /** yading@11: * @} yading@11: */ yading@11: yading@11: #endif /* AVUTIL_OPT_H */