libavutil/random_seed: Ensure that get_generic_seed() spends at least 1/32 sec gather...
authorMichael Niedermayer <michael@niedermayer.cc>
Wed, 28 Dec 2016 23:34:57 +0000 (00:34 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 31 Dec 2016 16:20:06 +0000 (17:20 +0100)
This may fix the failures on windows

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavutil/random_seed.c

index 0c58c8f..d1c9a3f 100644 (file)
@@ -68,6 +68,7 @@ static uint32_t get_generic_seed(void)
     struct AVSHA *sha = (void*)tmp;
     clock_t last_t  = 0;
     clock_t last_td = 0;
+    clock_t init_t = 0;
     static uint64_t i = 0;
     static uint32_t buffer[512] = { 0 };
     unsigned char digest[20];
@@ -93,10 +94,13 @@ static uint32_t get_generic_seed(void)
         } else {
             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)
-                break;
+            if ((t - init_t) >= CLOCKS_PER_SEC>>5)
+                if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
+                    break;
         }
         last_t = t;
+        if (!init_t)
+            init_t = t;
     }
 
     if(TEST) {