[FFmpeg-cvslog] av_add_stable: Add fast special case where step can be represented exactly

Michael Niedermayer git at videolan.org
Mon Jun 2 19:18:25 CEST 2014


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Mon Jun  2 19:00:18 2014 +0200| [e9add0d85b38db8efebd53bed83125945103e11f] | committer: Michael Niedermayer

av_add_stable: Add fast special case where step can be represented exactly

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e9add0d85b38db8efebd53bed83125945103e11f
---

 libavutil/mathematics.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index c8f1e1c..df7d0d8 100644
--- a/libavutil/mathematics.c
+++ b/libavutil/mathematics.c
@@ -188,9 +188,17 @@ simple_round:
 
 int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc)
 {
+    int64_t m, d;
+
     if (inc != 1)
         inc_tb = av_mul_q(inc_tb, (AVRational) {inc, 1});
 
+    m = inc_tb.num * (int64_t)ts_tb.den;
+    d = inc_tb.den * (int64_t)ts_tb.num;
+
+    if (m % d == 0)
+        return ts + m / d;
+
     if (av_cmp_q(inc_tb, ts_tb) < 0) {
         //increase step is too small for even 1 step to be representable
         return ts;



More information about the ffmpeg-cvslog mailing list