[PATCH 02/13] Make av_d2q() manage the case in which the value to convert is inf.

Stefano Sabatini stefano.sabatini-lala
Fri Oct 1 23:52:15 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 efed674..956b939 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -100,6 +100,8 @@ AVRational av_d2q(double d, int max){
     int64_t den;
     if (isnan(d))
         return (AVRational){0,0};
+    if (isinf(d))
+        return (AVRational){1,0};
     exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0);
     den = 1LL << (61 - exponent);
     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


--BOKacYhQ+x31HxR3--



More information about the ffmpeg-devel mailing list