From: Stefano Sabatini <stefasab@gmail.com>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH 2/2] avutil/opt: add an unsigned option type
Date: Sun, 3 Mar 2024 17:29:30 +0100
Message-ID: <ZeSlavTOs7ZWYcGu@mariano> (raw)
In-Reply-To: <20240227135947.503-2-jamrial@gmail.com>
On date Tuesday 2024-02-27 10:59:47 -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavutil/opt.c | 20 ++++++++++++++++++++
> libavutil/opt.h | 1 +
> libavutil/tests/opt.c | 9 +++++++++
> tests/ref/fate/opt | 32 ++++++++++++++++++++++++++++++--
> 4 files changed, 60 insertions(+), 2 deletions(-)
Use case?
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 0681b19896..45d6aa5849 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -72,6 +72,9 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den
> case AV_OPT_TYPE_INT:
> *intnum = *(int *)dst;
> return 0;
> + case AV_OPT_TYPE_UINT:
> + *intnum = *(unsigned *)dst;
> + return 0;
> #if FF_API_OLD_CHANNEL_LAYOUT
> FF_DISABLE_DEPRECATION_WARNINGS
> case AV_OPT_TYPE_CHANNEL_LAYOUT:
> @@ -130,6 +133,9 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
> case AV_OPT_TYPE_INT:
> *(int *)dst = llrint(num / den) * intnum;
> break;
> + case AV_OPT_TYPE_UINT:
> + *(unsigned *)dst = llrint(num / den) * intnum;
> + break;
> case AV_OPT_TYPE_DURATION:
> #if FF_API_OLD_CHANNEL_LAYOUT
> FF_DISABLE_DEPRECATION_WARNINGS
> @@ -231,6 +237,7 @@ static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **d
> opt->type == AV_OPT_TYPE_UINT64 || \
> opt->type == AV_OPT_TYPE_CONST || \
> opt->type == AV_OPT_TYPE_FLAGS || \
> + opt->type == AV_OPT_TYPE_UINT || \
> opt->type == AV_OPT_TYPE_INT) \
> ? opt->default_val.i64 \
> : opt->default_val.dbl)
> @@ -529,6 +536,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> return set_string_binary(obj, o, val, dst);
> case AV_OPT_TYPE_FLAGS:
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_INT64:
> case AV_OPT_TYPE_UINT64:
> case AV_OPT_TYPE_FLOAT:
> @@ -871,6 +879,9 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
> case AV_OPT_TYPE_INT:
> ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
> break;
> + case AV_OPT_TYPE_UINT:
> + ret = snprintf(buf, sizeof(buf), "%u", *(unsigned int *)dst);
> + break;
> case AV_OPT_TYPE_INT64:
> ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
> break;
> @@ -1276,6 +1287,9 @@ static void opt_list(void *obj, void *av_log_obj, const char *unit,
> case AV_OPT_TYPE_INT:
> av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int>");
> break;
> + case AV_OPT_TYPE_UINT:
> + av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<unsigned>");
> + break;
> case AV_OPT_TYPE_INT64:
> av_log(av_log_obj, AV_LOG_INFO, "%-12s ", "<int64>");
> break;
> @@ -1358,6 +1372,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> if (av_opt_query_ranges(&r, obj, opt->name, AV_OPT_SEARCH_FAKE_OBJ) >= 0) {
> switch (opt->type) {
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_INT64:
> case AV_OPT_TYPE_UINT64:
> case AV_OPT_TYPE_DOUBLE:
> @@ -1405,6 +1420,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
> av_log(av_log_obj, AV_LOG_INFO, "%s", buf);
> break;
> }
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_INT:
> case AV_OPT_TYPE_UINT64:
> case AV_OPT_TYPE_INT64: {
> @@ -1490,6 +1506,7 @@ void av_opt_set_defaults2(void *s, int mask, int flags)
> case AV_OPT_TYPE_BOOL:
> case AV_OPT_TYPE_FLAGS:
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_INT64:
> case AV_OPT_TYPE_UINT64:
> case AV_OPT_TYPE_DURATION:
> @@ -1858,6 +1875,7 @@ static int opt_size(enum AVOptionType type)
> switch(type) {
> case AV_OPT_TYPE_BOOL:
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_FLAGS:
> return sizeof(int);
> case AV_OPT_TYPE_DURATION:
> @@ -1997,6 +2015,7 @@ int av_opt_query_ranges_default(AVOptionRanges **ranges_arg, void *obj, const ch
> switch (field->type) {
> case AV_OPT_TYPE_BOOL:
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> case AV_OPT_TYPE_INT64:
> case AV_OPT_TYPE_UINT64:
> case AV_OPT_TYPE_PIXEL_FMT:
> @@ -2089,6 +2108,7 @@ int av_opt_is_set_to_default(void *obj, const AVOption *o)
> case AV_OPT_TYPE_PIXEL_FMT:
> case AV_OPT_TYPE_SAMPLE_FMT:
> case AV_OPT_TYPE_INT:
> + case AV_OPT_TYPE_UINT:
> #if FF_API_OLD_CHANNEL_LAYOUT
> FF_DISABLE_DEPRECATION_WARNINGS
> case AV_OPT_TYPE_CHANNEL_LAYOUT:
> diff --git a/libavutil/opt.h b/libavutil/opt.h
> index 461b5d3b6b..9fec1b0509 100644
> --- a/libavutil/opt.h
> +++ b/libavutil/opt.h
> @@ -243,6 +243,7 @@ enum AVOptionType{
> #endif
> AV_OPT_TYPE_BOOL,
> AV_OPT_TYPE_CHLAYOUT,
> + AV_OPT_TYPE_UINT,
> };
>
> /**
> diff --git a/libavutil/tests/opt.c b/libavutil/tests/opt.c
> index a914d0359a..747042896f 100644
> --- a/libavutil/tests/opt.c
> +++ b/libavutil/tests/opt.c
> @@ -31,6 +31,7 @@
> typedef struct TestContext {
> const AVClass *class;
> int num;
> + unsigned unum;
> int toggle;
> char *string;
> int flags;
> @@ -67,6 +68,7 @@ typedef struct TestContext {
>
> static const AVOption test_options[]= {
> {"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, 100, 1 },
> + {"unum", "set unum", OFFSET(unum), AV_OPT_TYPE_UINT, { .i64 = 1 }, 0, INT_MAX + 1U, 1 },
Do we have additional checks in case the validity interval includes
signed values? What happens in that case?
_______________________________________________
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-03-03 16:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 13:59 [FFmpeg-devel] [PATCH 1/2] avutil/tests/opt: test negative values for INT and INT64 types James Almer
2024-02-27 13:59 ` [FFmpeg-devel] [PATCH 2/2] avutil/opt: add an unsigned option type James Almer
2024-03-03 16:29 ` Stefano Sabatini [this message]
2024-03-03 16:24 ` [FFmpeg-devel] [PATCH 1/2] avutil/tests/opt: test negative values for INT and INT64 types Stefano Sabatini
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=ZeSlavTOs7ZWYcGu@mariano \
--to=stefasab@gmail.com \
--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