[FFmpeg-devel] [PATCH 2/3] avutil/opt: Add AV_OPT_TYPE_UINT64
Michael Niedermayer
michael at niedermayer.cc
Sun Nov 20 16:16:52 EET 2016
On Sun, Nov 20, 2016 at 08:56:15AM -0500, Ronald S. Bultje wrote:
> Hi,
>
> On Sun, Nov 20, 2016 at 6:57 AM, Michael Niedermayer <michael at niedermayer.cc
> > wrote:
>
> > @@ -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;
> > + } else if (o->max > INT64_MAX + 1ULL && d > INT64_MAX + 1ULL) {
> > + *(uint64_t *)dst = (llrint(d - (INT64_MAX + 1ULL)) +
> > (INT64_MAX + 1ULL))*intnum;
> > + } else {
> > + *(int64_t *)dst = llrint(d) * intnum;
> > + }
> > + break;}
> > case AV_OPT_TYPE_FLOAT:
> > *(float *)dst = num * intnum / den;
> > break;
>
>
> For the stupid, like me: what does this do? More specifically, this seems
> an integer codepath, but there is a double in there. Why?
write_number() has a num/den double argument. If this is used to
set a uint64_t to UINT64_MAX things fail as double cannot exactly
represent UINT64_MAX. (the closest it can represent is "UINT64_MAX + 1"
So it needs to be handled as a special case. Otherwise it turns into 0
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20161120/e8fb8221/attachment.sig>
More information about the ffmpeg-devel
mailing list