From patchwork Fri Feb 23 13:58:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 46496 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:26a3:b0:19e:cdac:8cce with SMTP id h35csp997738pze; Fri, 23 Feb 2024 06:41:55 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXnx7q9d/2hsxhMLNO0hcwxxznDwDfBmx1hiSktqQpQhRuL04W+3JVSxqRa37bz1Anm4gScS+SgMB9Fxg+YlHzj5utoaB7wxqQVhA== X-Google-Smtp-Source: AGHT+IH/o/H7HmlbRMNV4rlAy3vSRC1a8mMkfiPFhITMgk+npvpbCWmbJcaE2nfza5jvQN+FCuZG X-Received: by 2002:a50:9549:0:b0:565:4b6e:7f71 with SMTP id v9-20020a509549000000b005654b6e7f71mr28062eda.3.1708699314971; Fri, 23 Feb 2024 06:41:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708699314; cv=none; d=google.com; s=arc-20160816; b=I/WfS0cI4u6+cJ5cvd/JSgCKxFxQ/zgnvrX7FemoKj3c/dqgOflJzjPheXsnYTQkq6 von6IcvIDXg5tyz6909Zm/SNR25Q8PvoJr2m0MTdkzm9G8zPIIFZ0l17l0RT/TWguqiG OXcwj8iY1FIe+PVsd/uwFiQCCPPZwRc9h+8vJVOHXXDqQ0q74MOjDgOTjJTVIG+yw9mH shgrGg1ZcCQxi5UxU/ZeHcDrxaSEOctFbQdltA2kAsR7Pj1J4mAtMWoQROrnATStTpew /M03TzpqEf2+4mT4JqW296csNeulmwPloopCO55qI78PZC/cmg0hRbk2EU9Ueic722zB Lo5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=W9PoXwySiSVJouVln+CAeh7eIl/wXsi7LtV0IxxUfAo=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=E8hOoT/L8Pqb6ODCL5D9K9hckDoc0vhAQIYqKGu14hNpGCZ6I7OPfNN/2YLu8DLwBC Mbi3gdIQFh5hp6waq0gamNIZQq7Rm9RFXbCtRF5QWphlXbqgOga0CxZ3z2tVAwR+ItPK tIuL9oeylGAnc2ZCdq4WlOWhwwX/NKnm8sLAW6aeMPiwKTegiiYZO3AygRrH0+gGqQM4 D3SKc4xq8MI082hDH/SFpU5y1NmCl/x7t5UsLa/U/1p+HoCVXOfWyQWLR4bIcV3wRFOz nlwYyqzm8LUfCOr1lelUDSxbHHCSUhSmyiRFAHEf7dZrVz3msXTz4STqVoKfoC56yB9a b8FA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=iahQfbFC; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id dz20-20020a0564021d5400b0056575a72210si499606edb.74.2024.02.23.06.41.54; Fri, 23 Feb 2024 06:41:54 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@khirnov.net header.s=mail header.b=iahQfbFC; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 806AC68C692; Fri, 23 Feb 2024 16:41:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail1.khirnov.net (quelana.khirnov.net [94.230.150.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 972F468C678 for ; Fri, 23 Feb 2024 16:41:21 +0200 (EET) Authentication-Results: mail1.khirnov.net; dkim=pass (2048-bit key; unprotected) header.d=khirnov.net header.i=@khirnov.net header.a=rsa-sha256 header.s=mail header.b=iahQfbFC; dkim-atps=neutral Received: from localhost (mail1.khirnov.net [IPv6:::1]) by mail1.khirnov.net (Postfix) with ESMTP id 473EC448A for ; Fri, 23 Feb 2024 15:41:21 +0100 (CET) Received: from mail1.khirnov.net ([IPv6:::1]) by localhost (mail1.khirnov.net [IPv6:::1]) (amavis, port 10024) with ESMTP id Qt6vp1CweIf8 for ; Fri, 23 Feb 2024 15:41:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=khirnov.net; s=mail; t=1708699279; bh=8e/icOLdTBa1/VP1MgDhxPKTvK/DEUI/hWvYZ0BXRQs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iahQfbFC9+fPCDXr5iyAGwq8yweciWSy3Hk102H9is1x/xHlXAY/tfms7I2wtiDsC fbo2iPnOnjTVOTZRFGsNe+ey7so8S7cFXQF9X0gyUvoovEaixdjXvL7In0Mu5SnKX5 MtGy8bSdlIp2kEQT1cRKFaMnYTiXjfXwwz0wt+ZAzFn/ikbzExJyQP5M23Ac6NluVC vElYSFx6IQ5M/cr1+aHzTiVMtr7vD4tNkqNWsWqx9ByxAHXs1759Q9C60ei9fcTMNM KNQV8oWR6KZWpZf6TDnomc+vFz0kZTyPFrdDhGpiRXmdDHLnmMvMzcTBXUODroZFaM wOEW4wHv/r4Ow== Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail1.khirnov.net (Postfix) with ESMTPS id C28864CFF for ; Fri, 23 Feb 2024 15:41:19 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 0073C3A0C79 for ; Fri, 23 Feb 2024 15:31:22 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 23 Feb 2024 14:58:26 +0100 Message-ID: <20240223143115.16521-5-anton@khirnov.net> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240223143115.16521-1-anton@khirnov.net> References: <20240223143115.16521-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/38] lavu/opt: cosmetics, group (un)init and management functions together X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: RzaTD9Nb0SsU --- 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