|
|
|
@ -50,21 +50,28 @@ const uint8_t av_reverse[256]={ |
|
|
|
|
}; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
int64_t av_gcd(int64_t a, int64_t b){ |
|
|
|
|
if(b) return av_gcd(b, a%b); |
|
|
|
|
else return a; |
|
|
|
|
int64_t av_gcd(int64_t a, int64_t b) |
|
|
|
|
{ |
|
|
|
|
if (b) |
|
|
|
|
return av_gcd(b, a % b); |
|
|
|
|
else |
|
|
|
|
return a; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ |
|
|
|
|
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd) |
|
|
|
|
{ |
|
|
|
|
int64_t r = 0; |
|
|
|
|
|
|
|
|
|
if (c <= 0 || b < 0 || rnd == 4 || rnd > 5) |
|
|
|
|
return INT64_MIN; |
|
|
|
|
|
|
|
|
|
if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); |
|
|
|
|
if (a < 0 && a != INT64_MIN) |
|
|
|
|
return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd >> 1) & 1)); |
|
|
|
|
|
|
|
|
|
if(rnd==AV_ROUND_NEAR_INF) r= c/2; |
|
|
|
|
else if(rnd&1) r= c-1; |
|
|
|
|
if (rnd == AV_ROUND_NEAR_INF) |
|
|
|
|
r = c / 2; |
|
|
|
|
else if (rnd & 1) |
|
|
|
|
r = c - 1; |
|
|
|
|
|
|
|
|
|
if (b <= INT_MAX && c <= INT_MAX) { |
|
|
|
|
if (a <= INT_MAX) |
|
|
|
@ -87,10 +94,9 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ |
|
|
|
|
a1 += a0 < r; |
|
|
|
|
|
|
|
|
|
for (i = 63; i >= 0; i--) { |
|
|
|
|
// int o= a1 & 0x8000000000000000ULL;
|
|
|
|
|
a1 += a1 + ((a0 >> i) & 1); |
|
|
|
|
t1 += t1; |
|
|
|
|
if(/*o || */c <= a1){ |
|
|
|
|
if (c <= a1) { |
|
|
|
|
a1 -= c; |
|
|
|
|
t1++; |
|
|
|
|
} |
|
|
|
@ -107,7 +113,8 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int64_t av_rescale(int64_t a, int64_t b, int64_t c){ |
|
|
|
|
int64_t av_rescale(int64_t a, int64_t b, int64_t c) |
|
|
|
|
{ |
|
|
|
|
return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -124,15 +131,19 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) |
|
|
|
|
return av_rescale_q_rnd(a, bq, cq, AV_ROUND_NEAR_INF); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){ |
|
|
|
|
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; |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){ |
|
|
|
|
int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod) |
|
|
|
|
{ |
|
|
|
|
int64_t c = (a - b) & (mod - 1); |
|
|
|
|
if (c > (mod >> 1)) |
|
|
|
|
c -= mod; |
|
|
|
|