[FFmpeg-cvslog] avutil/mathematics: add av_add_stable()
Michael Niedermayer
git at videolan.org
Sat Jan 4 15:22:33 CET 2014
ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Jan 3 17:30:50 2014 +0100| [b317f9459f4c8f96b01bf20ce33a7f243d33a02c] | committer: Michael Niedermayer
avutil/mathematics: add av_add_stable()
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b317f9459f4c8f96b01bf20ce33a7f243d33a02c
---
doc/APIchanges | 3 +++
libavutil/mathematics.c | 14 ++++++++++++++
libavutil/mathematics.h | 14 ++++++++++++++
libavutil/version.h | 2 +-
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 21a8c4c..fe6ddce 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2012-10-22
API changes, most recent first:
+2014-01-04 - xxxxxxx - lavu 52.60.100 - mathematics.h
+ Add av_add_stable() function.
+
2013-12-22 - xxxxxxx - lavu 52.59.100 - avstring.h
Add av_strnlen() function.
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c
index 2e0cf0c..30963aa 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);
+ }
+}
diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h
index bfb5414..a8b1d8e 100644
--- a/libavutil/mathematics.h
+++ b/libavutil/mathematics.h
@@ -141,6 +141,20 @@ int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod);
int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int duration, int64_t *last, AVRational out_tb);
/**
+ * Add a value to a timestamp.
+ *
+ * This function gurantees that when the same value is repeatly added that
+ * no accumulation of rounding errors occurs.
+ *
+ * @param ts Input timestamp
+ * @param ts_tb Input timestamp timebase
+ * @param inc value to add to ts
+ * @param inc_tb inc timebase
+ */
+int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc);
+
+
+ /**
* @}
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index adbe230..833d4ee 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -56,7 +56,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 52
-#define LIBAVUTIL_VERSION_MINOR 59
+#define LIBAVUTIL_VERSION_MINOR 60
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
More information about the ffmpeg-cvslog
mailing list