[FFmpeg-devel] [PATCH 01/12] Make av_d2q() manage the case where d is infinite.
Stefano Sabatini
stefano.sabatini-lala
Fri Oct 1 18:08:49 CEST 2010
---
libavutil/rational.c | 2 ++
libavutil/rational.h | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 0e0571e..b5af28e 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -98,6 +98,8 @@ AVRational av_d2q(double d, int max){
#define LOG2 0.69314718055994530941723212145817656807550013436025
int exponent= FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
int64_t den= 1LL << (61 - exponent);
+ if (isinf(d))
+ return (AVRational){1,0};
if (isnan(d))
return (AVRational){0,0};
av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max);
diff --git a/libavutil/rational.h b/libavutil/rational.h
index 7c6605c..1e7c03c 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -107,6 +107,8 @@ AVRational av_sub_q(AVRational b, AVRational c) av_const;
/**
* Convert a double precision floating point number to a rational.
+ * inf is expressed as {1,0}.
+ *
* @param d double to convert
* @param max the maximum allowed numerator and denominator
* @return (AVRational) d
--
1.7.1
More information about the ffmpeg-devel
mailing list