diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2010-07-07 23:47:48 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2010-07-07 23:47:48 +0000 |
commit | c84d5aa74fcb99bf570f2891c381638744b5b289 (patch) | |
tree | 657c0e46135c67eb2519aad36e0f72aa2e304f7c /libavutil | |
parent | ce1cd1cba2d15b5b899235217fea3929a8f01892 (diff) | |
download | ffmpeg-c84d5aa74fcb99bf570f2891c381638744b5b289.tar.gz |
get_generic_seed() for the cases without /dev/random and AV_READ_TIME
Originally committed as revision 24102 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/random_seed.c | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/libavutil/random_seed.c b/libavutil/random_seed.c index 86c60f3838..f8e7f83d3c 100644 --- a/libavutil/random_seed.c +++ b/libavutil/random_seed.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <fcntl.h> #include "timer.h" +#include "time.h" #include "random_seed.h" #include "avutil.h" @@ -37,6 +38,38 @@ static int read_random(uint32_t *dst, const char *file) return err; } +static uint32_t get_generic_seed(void) +{ + int last_t=0; + int bits=0; + uint64_t random=0; + int i; + int s=0; + + for(i=0;bits<64;i++){ + int t= clock()>>s; + if(last_t && t != last_t){ + if(i<10000U && s<24){ + s++; + i=t=0; + }else{ + random= 2*random + (i&1); + bits++; + } + } + last_t= t; + } +#ifdef AV_READ_TIME + random ^= AV_READ_TIME(); +#else + random ^= clock(); +#endif + + random += random>>32; + + return random; +} + uint32_t av_get_random_seed(void) { uint32_t seed; @@ -45,12 +78,7 @@ uint32_t av_get_random_seed(void) return seed; if (read_random(&seed, "/dev/random") == sizeof(seed)) return seed; - -#ifdef AV_READ_TIME - seed = AV_READ_TIME(); -#endif - // XXX what to do ? - return seed; + return get_generic_seed(); } #if LIBAVUTIL_VERSION_MAJOR < 51 |