Browse code

av_compare_ts()

Originally committed as revision 21671 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2010/02/08 01:26:50
Showing 2 changed files
... ...
@@ -136,6 +136,14 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
136 136
     return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
137 137
 }
138 138
 
139
+int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
140
+    int64_t a= tb_a.num * (int64_t)tb_b.den;
141
+    int64_t b= tb_b.num * (int64_t)tb_a.den;
142
+    if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1;
143
+    if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return  1;
144
+    return 0;
145
+}
146
+
139 147
 #ifdef TEST
140 148
 #include "integer.h"
141 149
 #undef printf
... ...
@@ -80,4 +80,13 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons
80 80
  */
81 81
 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
82 82
 
83
+/**
84
+ * Compares 2 timestamps each in its own timebases.
85
+ * The result of the function is undefined if one of the timestamps
86
+ * is outside the int64_t range when represented in the others timebase.
87
+ * @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
88
+ */
89
+int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
90
+
91
+
83 92
 #endif /* AVUTIL_MATHEMATICS_H */