[FFmpeg-devel] [PATCH 06/29] lavu/opt: add array options
Marton Balint
cus at passwd.hu
Mon Mar 4 23:32:21 EET 2024
On Mon, 4 Mar 2024, Anton Khirnov wrote:
> ---
> doc/APIchanges | 3 +
> libavutil/opt.c | 362 +++++++++++++++++++++++++++++++++++++-----
> libavutil/opt.h | 62 +++++++-
> libavutil/tests/opt.c | 51 ++++++
> tests/ref/fate/opt | 35 +++-
> 5 files changed, 468 insertions(+), 45 deletions(-)
>
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 7d46ebb006..3209614ed6 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09
>
> API changes, most recent first:
>
> +2024-02-xx - xxxxxxxxxx - lavu 58.xx.100 - opt.h
> + Add AV_OPT_TYPE_FLAG_ARRAY and AVOptionArrayDef.
> +
> 2024-02-28 - xxxxxxxxxx - swr 4.14.100 - swresample.h
> swr_convert() now accepts arrays of const pointers (to input and output).
[...]
> diff --git a/libavutil/opt.h b/libavutil/opt.h
> index e402f6a0a0..77797b3fbe 100644
> --- a/libavutil/opt.h
> +++ b/libavutil/opt.h
> @@ -253,6 +253,17 @@ enum AVOptionType{
> #endif
> AV_OPT_TYPE_BOOL,
> AV_OPT_TYPE_CHLAYOUT,
> +
> + /**
> + * May be combined with another regular option type to declare an array
> + * option.
> + *
> + * For array options, @ref AVOption.offset should refer to a pointer
> + * corresponding to the option type. The pointer should be immediately
> + * followed by an unsigned int that will store the number of elements in the
> + * array.
> + */
> + AV_OPT_TYPE_FLAG_ARRAY = (1 << 16),
> };
>
> /**
> @@ -298,6 +309,46 @@ enum AVOptionType{
> */
> #define AV_OPT_FLAG_CHILD_CONSTS (1 << 18)
>
> +/**
> + * Must be set as default_val for AV_OPT_TYPE_FLAG_ARRAY options.
> + */
> +typedef struct AVOptionArrayDef {
> + /**
> + * Must be set to sizeof(AVOptionArrayDef), in order to allow extending this
> + * struct without breaking ABI.
> + */
> + size_t sizeof_self;
> +
> + /**
> + * Native access only.
> + *
> + * Default value of the option, as would be serialized by av_opt_get() (i.e.
> + * using the value of sep as the separator).
> + */
> + const char *def;
> +
> + /**
> + * Minimum number of elements in the array. When this field is non-zero, def
> + * must be non-NULL and contain at least this number of elements.
> + */
> + unsigned size_min;
> + /**
> + * Maximum number of elements in the array, 0 when unlimited.
> + */
> + unsigned size_max;
> +
> + /**
> + * Separator between array elements in string representations of this
> + * option, used by av_opt_set() and av_opt_get(). It must be a printable
> + * ASCII character, excluding alphanumeric and the backslash. A comma is
> + * used when sep=0.
> + *
> + * The separator and the backslash must be backslash-escaped in order to
> + * appear in string representations of the option value.
> + */
> + uint8_t sep;
> +} AVOptionArrayDef;
> +
> /**
> * AVOption
> */
> @@ -320,8 +371,7 @@ typedef struct AVOption {
> enum AVOptionType type;
>
> /**
> - * Native access only.
> - *
> + * Native access only, except when documented otherwise.
> * the default value for scalar options
> */
> union {
> @@ -330,6 +380,14 @@ typedef struct AVOption {
> const char *str;
> /* TODO those are unused now */
> AVRational q;
> +
> + /**
> + * Used for AV_OPT_TYPE_FLAG_ARRAY options. May be NULL.
This contradicts with the documentation of AVOptionArrayDef above, because
there you write that default_val MUST be set.
> + *
> + * Foreign access to some members allowed, as noted in AVOptionArrayDef
> + * documentation.
> + */
> + const AVOptionArrayDef *arr;
> } default_val;
Regards,
Marton
More information about the ffmpeg-devel
mailing list