diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-01-03 17:30:50 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-01-04 15:10:09 +0100 |
commit | b317f9459f4c8f96b01bf20ce33a7f243d33a02c (patch) | |
tree | aa3e9a013f26401df286356058bd3ed858214c0f /libavutil/mathematics.c | |
parent | de5b6c736bcba27357b98782afdc642128cf1f89 (diff) | |
download | ffmpeg-b317f9459f4c8f96b01bf20ce33a7f243d33a02c.tar.gz |
avutil/mathematics: add av_add_stable()
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavutil/mathematics.c')
-rw-r--r-- | libavutil/mathematics.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index 2e0cf0cbd4..30963aa07b 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -174,3 +174,17 @@ simple_round: return av_rescale_q(this, fs_tb, out_tb); } + +int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc) +{ + AVRational step = av_mul_q(inc_tb, (AVRational) {inc, 1}); + + if (av_cmp_q(step, ts_tb) < 0) { + //increase step is too small for even 1 step to be representable + return ts; + } else { + int64_t old = av_rescale_q(ts, ts_tb, step); + int64_t old_ts = av_rescale_q(old, step, ts_tb); + return av_rescale_q(old + 1, step, ts_tb) + (ts - old_ts); + } +} |