Originally committed as revision 24102 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -21,6 +21,7 @@ |
| 21 | 21 |
#include <unistd.h> |
| 22 | 22 |
#include <fcntl.h> |
| 23 | 23 |
#include "timer.h" |
| 24 |
+#include "time.h" |
|
| 24 | 25 |
#include "random_seed.h" |
| 25 | 26 |
#include "avutil.h" |
| 26 | 27 |
|
| ... | ... |
@@ -37,6 +38,38 @@ static int read_random(uint32_t *dst, const char *file) |
| 37 | 37 |
return err; |
| 38 | 38 |
} |
| 39 | 39 |
|
| 40 |
+static uint32_t get_generic_seed(void) |
|
| 41 |
+{
|
|
| 42 |
+ int last_t=0; |
|
| 43 |
+ int bits=0; |
|
| 44 |
+ uint64_t random=0; |
|
| 45 |
+ int i; |
|
| 46 |
+ int s=0; |
|
| 47 |
+ |
|
| 48 |
+ for(i=0;bits<64;i++){
|
|
| 49 |
+ int t= clock()>>s; |
|
| 50 |
+ if(last_t && t != last_t){
|
|
| 51 |
+ if(i<10000U && s<24){
|
|
| 52 |
+ s++; |
|
| 53 |
+ i=t=0; |
|
| 54 |
+ }else{
|
|
| 55 |
+ random= 2*random + (i&1); |
|
| 56 |
+ bits++; |
|
| 57 |
+ } |
|
| 58 |
+ } |
|
| 59 |
+ last_t= t; |
|
| 60 |
+ } |
|
| 61 |
+#ifdef AV_READ_TIME |
|
| 62 |
+ random ^= AV_READ_TIME(); |
|
| 63 |
+#else |
|
| 64 |
+ random ^= clock(); |
|
| 65 |
+#endif |
|
| 66 |
+ |
|
| 67 |
+ random += random>>32; |
|
| 68 |
+ |
|
| 69 |
+ return random; |
|
| 70 |
+} |
|
| 71 |
+ |
|
| 40 | 72 |
uint32_t av_get_random_seed(void) |
| 41 | 73 |
{
|
| 42 | 74 |
uint32_t seed; |
| ... | ... |
@@ -45,12 +78,7 @@ uint32_t av_get_random_seed(void) |
| 45 | 45 |
return seed; |
| 46 | 46 |
if (read_random(&seed, "/dev/random") == sizeof(seed)) |
| 47 | 47 |
return seed; |
| 48 |
- |
|
| 49 |
-#ifdef AV_READ_TIME |
|
| 50 |
- seed = AV_READ_TIME(); |
|
| 51 |
-#endif |
|
| 52 |
- // XXX what to do ? |
|
| 53 |
- return seed; |
|
| 48 |
+ return get_generic_seed(); |
|
| 54 | 49 |
} |
| 55 | 50 |
|
| 56 | 51 |
#if LIBAVUTIL_VERSION_MAJOR < 51 |