[FFmpeg-devel] [PATCH 2/3] avutil/opt: Add AV_OPT_TYPE_UINT64
Andreas Cadhalpun
andreas.cadhalpun at googlemail.com
Sun Nov 20 21:55:44 EET 2016
On 20.11.2016 12:57, Michael Niedermayer wrote:
> Requested-by: wm4 ([FFmpeg-devel] [PATCH] avutil/opt: Support max > INT64_MAX in write_number() with AV_OPT_TYPE_INT64)
> Requested-by: ronald ([FFmpeg-devel] [PATCH] avutil/opt: Support max > INT64_MAX in write_number() with AV_OPT_TYPE_INT64)
> Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> ---
> libavutil/opt.c | 29 +++++++++++++++++++++++++++++
> libavutil/opt.h | 1 +
> 2 files changed, 30 insertions(+)
>
> diff --git a/libavutil/opt.c b/libavutil/opt.c
> index 6669356..b6b4d9f 100644
> --- a/libavutil/opt.c
> +++ b/libavutil/opt.c
> @@ -74,6 +74,7 @@ static int read_number(const AVOption *o, const void *dst, double *num, int *den
> case AV_OPT_TYPE_CHANNEL_LAYOUT:
> case AV_OPT_TYPE_DURATION:
> case AV_OPT_TYPE_INT64:
> + case AV_OPT_TYPE_UINT64:
> *intnum = *(int64_t *)dst;
> return 0;
> case AV_OPT_TYPE_FLOAT:
> @@ -131,6 +132,20 @@ static int write_number(void *obj, const AVOption *o, void *dst, double num, int
> if (intnum == 1 && d == (double)INT64_MAX) *(int64_t *)dst = INT64_MAX;
> else *(int64_t *)dst = llrint(d) * intnum;
> break;}
> + case AV_OPT_TYPE_UINT64:{
> + double d = num / den;
> + // We must special case uint64_t here as llrint() does not support values
> + // outside the int64_t range and there is no portable function which does
> + // "INT64_MAX + 1ULL" is used as it is representable exactly as IEEE double
> + // while INT64_MAX is not
> + if (intnum == 1 && d == (double)UINT64_MAX) {
> + *(int64_t *)dst = UINT64_MAX;
Is there a reason why this uses int64_t,
> + } else if (o->max > INT64_MAX + 1ULL && d > INT64_MAX + 1ULL) {
> + *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) + (INT64_MAX + 1ULL))*intnum;
but this uint64_t,
> + } else {
> + *(int64_t *)dst = llrint(d) * intnum;
and this again int64_t?
Best regards,
Andreas
More information about the ffmpeg-devel
mailing list