OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> | 2 * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at> |
3 * | 3 * |
4 * This file is part of FFmpeg. | 4 * This file is part of FFmpeg. |
5 * | 5 * |
6 * FFmpeg is free software; you can redistribute it and/or | 6 * FFmpeg is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | 7 * modify it under the terms of the GNU Lesser General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2.1 of the License, or (at your option) any later version. | 9 * version 2.1 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 int64_t av_rescale(int64_t a, int64_t b, int64_t c){ | 129 int64_t av_rescale(int64_t a, int64_t b, int64_t c){ |
130 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); | 130 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
131 } | 131 } |
132 | 132 |
133 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ | 133 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ |
134 int64_t b= bq.num * (int64_t)cq.den; | 134 int64_t b= bq.num * (int64_t)cq.den; |
135 int64_t c= cq.num * (int64_t)bq.den; | 135 int64_t c= cq.num * (int64_t)bq.den; |
136 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); | 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 #ifdef TEST | 147 #ifdef TEST |
140 #include "integer.h" | 148 #include "integer.h" |
141 #undef printf | 149 #undef printf |
142 int main(void){ | 150 int main(void){ |
143 int64_t a,b,c,d,e; | 151 int64_t a,b,c,d,e; |
144 | 152 |
145 for(a=7; a<(1LL<<62); a+=a/3+1){ | 153 for(a=7; a<(1LL<<62); a+=a/3+1){ |
146 for(b=3; b<(1LL<<62); b+=b/4+1){ | 154 for(b=3; b<(1LL<<62); b+=b/4+1){ |
147 for(c=9; c<(1LL<<62); c+=(c*2)/5+3){ | 155 for(c=9; c<(1LL<<62); c+=(c*2)/5+3){ |
148 int64_t r= c/2; | 156 int64_t r= c/2; |
149 AVInteger ai; | 157 AVInteger ai; |
150 ai= av_mul_i(av_int2i(a), av_int2i(b)); | 158 ai= av_mul_i(av_int2i(a), av_int2i(b)); |
151 ai= av_add_i(ai, av_int2i(r)); | 159 ai= av_add_i(ai, av_int2i(r)); |
152 | 160 |
153 d= av_i2int(av_div_i(ai, av_int2i(c))); | 161 d= av_i2int(av_div_i(ai, av_int2i(c))); |
154 | 162 |
155 e= av_rescale(a,b,c); | 163 e= av_rescale(a,b,c); |
156 | 164 |
157 if((double)a * (double)b / (double)c > (1LL<<63)) | 165 if((double)a * (double)b / (double)c > (1LL<<63)) |
158 continue; | 166 continue; |
159 | 167 |
160 if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId
64"\n", a, b, c, d, e); | 168 if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId
64"\n", a, b, c, d, e); |
161 } | 169 } |
162 } | 170 } |
163 } | 171 } |
164 return 0; | 172 return 0; |
165 } | 173 } |
166 #endif | 174 #endif |
OLD | NEW |