From: Anton Khirnov <anton@khirnov.net> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 04/38] lavu/opt: cosmetics, group (un)init and management functions together Date: Fri, 23 Feb 2024 14:58:26 +0100 Message-ID: <20240223143115.16521-5-anton@khirnov.net> (raw) In-Reply-To: <20240223143115.16521-1-anton@khirnov.net> --- libavutil/opt.h | 336 +++++++++++++++++++++++++----------------------- 1 file changed, 173 insertions(+), 163 deletions(-) diff --git a/libavutil/opt.h b/libavutil/opt.h index d72d65052f..e2b6ba1f35 100644 --- a/libavutil/opt.h +++ b/libavutil/opt.h @@ -402,15 +402,9 @@ typedef struct AVOptionRanges { } AVOptionRanges; /** - * Show the obj options. - * - * @param req_flags requested flags for the options to show. Show only the - * options for which it is opt->flags & req_flags. - * @param rej_flags rejected flags for the options to show. Show only the - * options for which it is !(opt->flags & req_flags). - * @param av_log_obj log context to use for showing the options + * @defgroup opt_mng AVOption (un)initialization and inspection. + * @{ */ -int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags); /** * Set the values of all AVOption fields to their default values. @@ -430,161 +424,37 @@ void av_opt_set_defaults(void *s); */ void av_opt_set_defaults2(void *s, int mask, int flags); -/** - * Parse the key/value pairs list in opts. For each key/value pair - * found, stores the value in the field in ctx that is named like the - * key. ctx must be an AVClass context, storing is done using - * AVOptions. - * - * @param opts options string to parse, may be NULL - * @param key_val_sep a 0-terminated list of characters used to - * separate key from value - * @param pairs_sep a 0-terminated list of characters used to separate - * two pairs from each other - * @return the number of successfully set key/value pairs, or a negative - * value corresponding to an AVERROR code in case of error: - * AVERROR(EINVAL) if opts cannot be parsed, - * the error code issued by av_opt_set() if a key/value pair - * cannot be set - */ -int av_set_options_string(void *ctx, const char *opts, - const char *key_val_sep, const char *pairs_sep); - -/** - * Parse the key-value pairs list in opts. For each key=value pair found, - * set the value of the corresponding option in ctx. - * - * @param ctx the AVClass object to set options on - * @param opts the options string, key-value pairs separated by a - * delimiter - * @param shorthand a NULL-terminated array of options names for shorthand - * notation: if the first field in opts has no key part, - * the key is taken from the first element of shorthand; - * then again for the second, etc., until either opts is - * finished, shorthand is finished or a named option is - * found; after that, all options must be named - * @param key_val_sep a 0-terminated list of characters used to separate - * key from value, for example '=' - * @param pairs_sep a 0-terminated list of characters used to separate - * two pairs from each other, for example ':' or ',' - * @return the number of successfully set key=value pairs, or a negative - * value corresponding to an AVERROR code in case of error: - * AVERROR(EINVAL) if opts cannot be parsed, - * the error code issued by av_set_string3() if a key/value pair - * cannot be set - * - * Options names must use only the following characters: a-z A-Z 0-9 - . / _ - * Separators must use characters distinct from option names and from each - * other. - */ -int av_opt_set_from_string(void *ctx, const char *opts, - const char *const *shorthand, - const char *key_val_sep, const char *pairs_sep); /** * Free all allocated objects in obj. */ void av_opt_free(void *obj); /** - * Check whether a particular flag is set in a flags field. + * Iterate over all AVOptions belonging to obj. * - * @param field_name the name of the flag field option - * @param flag_name the name of the flag to check - * @return non-zero if the flag is set, zero if the flag isn't set, - * isn't of the right type, or the flags field doesn't exist. + * @param obj an AVOptions-enabled struct or a double pointer to an + * AVClass describing it. + * @param prev result of the previous call to av_opt_next() on this object + * or NULL + * @return next AVOption or NULL */ -int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name); +const AVOption *av_opt_next(const void *obj, const AVOption *prev); /** - * Set all the options from a given dictionary on an object. + * Iterate over AVOptions-enabled children of obj. * - * @param obj a struct whose first element is a pointer to AVClass - * @param options options to process. This dictionary will be freed and replaced - * by a new one containing all options not found in obj. - * Of course this new dictionary needs to be freed by caller - * with av_dict_free(). - * - * @return 0 on success, a negative AVERROR if some option was found in obj, - * but could not be set. - * - * @see av_dict_copy() + * @param prev result of a previous call to this function or NULL + * @return next AVOptions-enabled child or NULL */ -int av_opt_set_dict(void *obj, struct AVDictionary **options); - +void *av_opt_child_next(void *obj, void *prev); /** - * Set all the options from a given dictionary on an object. + * Iterate over potential AVOptions-enabled children of parent. * - * @param obj a struct whose first element is a pointer to AVClass - * @param options options to process. This dictionary will be freed and replaced - * by a new one containing all options not found in obj. - * Of course this new dictionary needs to be freed by caller - * with av_dict_free(). - * @param search_flags A combination of AV_OPT_SEARCH_*. - * - * @return 0 on success, a negative AVERROR if some option was found in obj, - * but could not be set. - * - * @see av_dict_copy() - */ -int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags); - -/** - * Extract a key-value pair from the beginning of a string. - * - * @param ropts pointer to the options string, will be updated to - * point to the rest of the string (one of the pairs_sep - * or the final NUL) - * @param key_val_sep a 0-terminated list of characters used to separate - * key from value, for example '=' - * @param pairs_sep a 0-terminated list of characters used to separate - * two pairs from each other, for example ':' or ',' - * @param flags flags; see the AV_OPT_FLAG_* values below - * @param rkey parsed key; must be freed using av_free() - * @param rval parsed value; must be freed using av_free() - * - * @return >=0 for success, or a negative value corresponding to an - * AVERROR code in case of error; in particular: - * AVERROR(EINVAL) if no key is present - * - */ -int av_opt_get_key_value(const char **ropts, - const char *key_val_sep, const char *pairs_sep, - unsigned flags, - char **rkey, char **rval); - -enum { - - /** - * Accept to parse a value without a key; the key will then be returned - * as NULL. - */ - AV_OPT_FLAG_IMPLICIT_KEY = 1, -}; - -/** - * @defgroup opt_eval_funcs Evaluating option strings - * @{ - * This group of functions can be used to evaluate option strings - * and get numbers out of them. They do the same thing as av_opt_set(), - * except the result is written into the caller-supplied pointer. - * - * @param obj a struct whose first element is a pointer to AVClass. - * @param o an option for which the string is to be evaluated. - * @param val string to be evaluated. - * @param *_out value of the string will be written here. - * - * @return 0 on success, a negative number on failure. - */ -int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out); -int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out); -int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out); -int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out); -int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out); -int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out); -/** - * @} + * @param iter a pointer where iteration state is stored. + * @return AVClass corresponding to next potential child or NULL */ +const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter); #define AV_OPT_SEARCH_CHILDREN (1 << 0) /**< Search in possible children of the given object first. */ @@ -659,31 +529,171 @@ const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, int opt_flags, int search_flags, void **target_obj); /** - * Iterate over all AVOptions belonging to obj. + * Show the obj options. * - * @param obj an AVOptions-enabled struct or a double pointer to an - * AVClass describing it. - * @param prev result of the previous call to av_opt_next() on this object - * or NULL - * @return next AVOption or NULL + * @param req_flags requested flags for the options to show. Show only the + * options for which it is opt->flags & req_flags. + * @param rej_flags rejected flags for the options to show. Show only the + * options for which it is !(opt->flags & req_flags). + * @param av_log_obj log context to use for showing the options */ -const AVOption *av_opt_next(const void *obj, const AVOption *prev); +int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags); /** - * Iterate over AVOptions-enabled children of obj. + * Extract a key-value pair from the beginning of a string. + * + * @param ropts pointer to the options string, will be updated to + * point to the rest of the string (one of the pairs_sep + * or the final NUL) + * @param key_val_sep a 0-terminated list of characters used to separate + * key from value, for example '=' + * @param pairs_sep a 0-terminated list of characters used to separate + * two pairs from each other, for example ':' or ',' + * @param flags flags; see the AV_OPT_FLAG_* values below + * @param rkey parsed key; must be freed using av_free() + * @param rval parsed value; must be freed using av_free() + * + * @return >=0 for success, or a negative value corresponding to an + * AVERROR code in case of error; in particular: + * AVERROR(EINVAL) if no key is present * - * @param prev result of a previous call to this function or NULL - * @return next AVOptions-enabled child or NULL */ -void *av_opt_child_next(void *obj, void *prev); +int av_opt_get_key_value(const char **ropts, + const char *key_val_sep, const char *pairs_sep, + unsigned flags, + char **rkey, char **rval); + +enum { + + /** + * Accept to parse a value without a key; the key will then be returned + * as NULL. + */ + AV_OPT_FLAG_IMPLICIT_KEY = 1, +}; /** - * Iterate over potential AVOptions-enabled children of parent. - * - * @param iter a pointer where iteration state is stored. - * @return AVClass corresponding to next potential child or NULL + * @} + */ + +/** + * Parse the key/value pairs list in opts. For each key/value pair + * found, stores the value in the field in ctx that is named like the + * key. ctx must be an AVClass context, storing is done using + * AVOptions. + * + * @param opts options string to parse, may be NULL + * @param key_val_sep a 0-terminated list of characters used to + * separate key from value + * @param pairs_sep a 0-terminated list of characters used to separate + * two pairs from each other + * @return the number of successfully set key/value pairs, or a negative + * value corresponding to an AVERROR code in case of error: + * AVERROR(EINVAL) if opts cannot be parsed, + * the error code issued by av_opt_set() if a key/value pair + * cannot be set + */ +int av_set_options_string(void *ctx, const char *opts, + const char *key_val_sep, const char *pairs_sep); + +/** + * Parse the key-value pairs list in opts. For each key=value pair found, + * set the value of the corresponding option in ctx. + * + * @param ctx the AVClass object to set options on + * @param opts the options string, key-value pairs separated by a + * delimiter + * @param shorthand a NULL-terminated array of options names for shorthand + * notation: if the first field in opts has no key part, + * the key is taken from the first element of shorthand; + * then again for the second, etc., until either opts is + * finished, shorthand is finished or a named option is + * found; after that, all options must be named + * @param key_val_sep a 0-terminated list of characters used to separate + * key from value, for example '=' + * @param pairs_sep a 0-terminated list of characters used to separate + * two pairs from each other, for example ':' or ',' + * @return the number of successfully set key=value pairs, or a negative + * value corresponding to an AVERROR code in case of error: + * AVERROR(EINVAL) if opts cannot be parsed, + * the error code issued by av_set_string3() if a key/value pair + * cannot be set + * + * Options names must use only the following characters: a-z A-Z 0-9 - . / _ + * Separators must use characters distinct from option names and from each + * other. + */ +int av_opt_set_from_string(void *ctx, const char *opts, + const char *const *shorthand, + const char *key_val_sep, const char *pairs_sep); + +/** + * Check whether a particular flag is set in a flags field. + * + * @param field_name the name of the flag field option + * @param flag_name the name of the flag to check + * @return non-zero if the flag is set, zero if the flag isn't set, + * isn't of the right type, or the flags field doesn't exist. + */ +int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name); + +/** + * Set all the options from a given dictionary on an object. + * + * @param obj a struct whose first element is a pointer to AVClass + * @param options options to process. This dictionary will be freed and replaced + * by a new one containing all options not found in obj. + * Of course this new dictionary needs to be freed by caller + * with av_dict_free(). + * + * @return 0 on success, a negative AVERROR if some option was found in obj, + * but could not be set. + * + * @see av_dict_copy() + */ +int av_opt_set_dict(void *obj, struct AVDictionary **options); + + +/** + * Set all the options from a given dictionary on an object. + * + * @param obj a struct whose first element is a pointer to AVClass + * @param options options to process. This dictionary will be freed and replaced + * by a new one containing all options not found in obj. + * Of course this new dictionary needs to be freed by caller + * with av_dict_free(). + * @param search_flags A combination of AV_OPT_SEARCH_*. + * + * @return 0 on success, a negative AVERROR if some option was found in obj, + * but could not be set. + * + * @see av_dict_copy() + */ +int av_opt_set_dict2(void *obj, struct AVDictionary **options, int search_flags); + +/** + * @defgroup opt_eval_funcs Evaluating option strings + * @{ + * This group of functions can be used to evaluate option strings + * and get numbers out of them. They do the same thing as av_opt_set(), + * except the result is written into the caller-supplied pointer. + * + * @param obj a struct whose first element is a pointer to AVClass. + * @param o an option for which the string is to be evaluated. + * @param val string to be evaluated. + * @param *_out value of the string will be written here. + * + * @return 0 on success, a negative number on failure. + */ +int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out); +int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out); +int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out); +int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out); +int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out); +int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out); +/** + * @} */ -const AVClass *av_opt_child_class_iterate(const AVClass *parent, void **iter); /** * @defgroup opt_set_funcs Option setting functions -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-02-23 14:41 UTC|newest] Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-02-23 13:58 [FFmpeg-devel] [PATCH] array AVOptions and side data preference Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 01/38] lavu/opt: cosmetics, change option flags to (1 << N) style Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 02/38] lavu/opt: cosmetics, move AV_OPT_FLAG_* out of AVOption Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 03/38] lavu/opt: document AVOption.flags Anton Khirnov 2024-02-23 13:58 ` Anton Khirnov [this message] 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 05/38] lavu/opt: cosmetics, group option setting function together Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 06/38] lavu/opt: cosmetics, group option reading " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 07/38] lavu/opt: simplify printing option type in opt_list() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 08/38] lavu/opt: factor out printing option default from opt_list() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 09/38] lavu/opt: drop useless handling of NULL return from get_bool_name() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 10/38] lavu/opt: drop an always-NULL argument to get_number() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 11/38] lavu/opt: simplify error handling in get_number() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 12/38] lavu/opt: get rid of useless read_number() calls Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 13/38] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 14/38] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov 2024-02-23 22:50 ` Michael Niedermayer 2024-02-24 22:41 ` James Almer 2024-03-05 23:08 ` Michael Niedermayer 2024-03-05 23:14 ` James Almer 2024-03-01 16:07 ` Anton Khirnov 2024-03-03 12:17 ` Anton Khirnov 2024-03-05 23:12 ` Michael Niedermayer 2024-03-05 23:21 ` James Almer 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 15/38] lavu/opt: add array options Anton Khirnov 2024-02-23 19:05 ` Marton Balint 2024-02-26 17:14 ` Anton Khirnov 2024-02-26 17:19 ` James Almer 2024-02-26 17:20 ` Andreas Rheinhardt 2024-02-26 19:38 ` Marton Balint 2024-03-03 14:55 ` Anton Khirnov 2024-03-03 15:53 ` Diederick C. Niehorster 2024-03-03 15:57 ` James Almer 2024-03-03 21:05 ` Marton Balint 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 16/38] lavc: add a decoder option for configuring side data preference Anton Khirnov 2024-02-23 17:51 ` Marton Balint 2024-02-23 17:53 ` James Almer 2024-02-23 18:34 ` James Almer 2024-02-26 17:08 ` Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 17/38] avcodec: add internal side data wrappers Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 18/38] lavc: add content light/mastering display " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 19/38] avcodec/av1dec: respect side data preference Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 20/38] avcodec/cri: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 21/38] avcodec/h264_slice: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 22/38] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame() Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 23/38] avcodec/hevcdec: respect side data preference Anton Khirnov 2024-02-23 19:11 ` Marton Balint 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 24/38] avcodec/libjxldec: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 25/38] avcodec/mjpegdec: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 26/38] avcodec/mpeg12dec: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 27/38] avcodec/pngdec: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 28/38] avcodec/tiff: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 29/38] avcodec/webp: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 30/38] avcodec/libdav1d: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 31/38] avcodec/dpx: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 32/38] avcodec/mpeg12dec: use ff_frame_new_side_data Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 33/38] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 34/38] avcodec/snowdec: use ff_frame_new_side_data Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 35/38] avcodec/mjpegdec: " Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 36/38] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf Anton Khirnov 2024-02-23 13:58 ` [FFmpeg-devel] [PATCH 37/38] lavc/*dec: use side data preference for mastering display/content light metadata Anton Khirnov 2024-02-23 13:59 ` [FFmpeg-devel] [PATCH 38/38] tests/fate/matroska: add tests for side data preference Anton Khirnov 2024-02-23 15:02 ` Anton Khirnov 2024-02-23 15:08 ` James Almer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240223143115.16521-5-anton@khirnov.net \ --to=anton@khirnov.net \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git