diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2010-02-07 16:26:50 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2010-02-07 16:26:50 +0000 |
commit | 78b0182375e5d4eb27b044d976d40b3b5cd4c60d (patch) | |
tree | 57c2ba5545836eb254adc23cadab56b3ebbf278e | |
parent | 9e5381a21b2106a012b92c1878886c5af4e1a932 (diff) | |
download | ffmpeg-78b0182375e5d4eb27b044d976d40b3b5cd4c60d.tar.gz |
av_compare_ts()
Originally committed as revision 21671 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavutil/mathematics.c | 8 | ||||
-rw-r--r-- | libavutil/mathematics.h | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index 9988baae9c..91b76f3aaf 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -136,6 +136,14 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); } +int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){ + int64_t a= tb_a.num * (int64_t)tb_b.den; + int64_t b= tb_b.num * (int64_t)tb_a.den; + if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1; + if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1; + return 0; +} + #ifdef TEST #include "integer.h" #undef printf diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h index 12cd369036..29b13f77ed 100644 --- a/libavutil/mathematics.h +++ b/libavutil/mathematics.h @@ -80,4 +80,13 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons */ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; +/** + * Compares 2 timestamps each in its own timebases. + * The result of the function is undefined if one of the timestamps + * is outside the int64_t range when represented in the others timebase. + * @returns -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position + */ +int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b); + + #endif /* AVUTIL_MATHEMATICS_H */ |