You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-07-16 22:42:38 +02:00
avutil/random_seed: Improve get_generic_seed() with higher precission clock()
Tested-by: Thomas Turner <thomastdt@googlemail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit da73d95bad
)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@ -67,6 +67,7 @@ static uint32_t get_generic_seed(void)
|
|||||||
uint8_t tmp[120];
|
uint8_t tmp[120];
|
||||||
struct AVSHA *sha = (void*)tmp;
|
struct AVSHA *sha = (void*)tmp;
|
||||||
clock_t last_t = 0;
|
clock_t last_t = 0;
|
||||||
|
clock_t last_td = 0;
|
||||||
static uint64_t i = 0;
|
static uint64_t i = 0;
|
||||||
static uint32_t buffer[512] = { 0 };
|
static uint32_t buffer[512] = { 0 };
|
||||||
unsigned char digest[20];
|
unsigned char digest[20];
|
||||||
@ -86,11 +87,12 @@ static uint32_t get_generic_seed(void)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
clock_t t = clock();
|
clock_t t = clock();
|
||||||
|
if (last_t + 2*last_td + 1 >= t) {
|
||||||
if (last_t == t) {
|
last_td = t - last_t;
|
||||||
buffer[i & 511]++;
|
buffer[i & 511] = 1664525*buffer[i & 511] + 1013904223 + (last_td % 3294638521U);
|
||||||
} else {
|
} else {
|
||||||
buffer[++i & 511] += (t - last_t) % 3294638521U;
|
last_td = t - last_t;
|
||||||
|
buffer[++i & 511] += last_td % 3294638521U;
|
||||||
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
|
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user