[FFmpeg-cvslog] r24102 - trunk/libavutil/random_seed.c

Måns Rullgård mans
Thu Jul 8 01:58:23 CEST 2010


michael <subversion at mplayerhq.hu> writes:

> Author: michael
> Date: Thu Jul  8 01:47:48 2010
> New Revision: 24102
>
> Log:
> get_generic_seed() for the cases without /dev/random and AV_READ_TIME

Thanks.

> Modified:
>    trunk/libavutil/random_seed.c
>
> Modified: trunk/libavutil/random_seed.c
> ==============================================================================
> --- trunk/libavutil/random_seed.c	Thu Jul  8 01:41:42 2010	(r24101)
> +++ trunk/libavutil/random_seed.c	Thu Jul  8 01:47:48 2010	(r24102)
> @@ -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, co
>      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;

What about systems without a functioning clock() call?  This is
allowed by the specs:

  If the processor time used is not available or its value cannot be
  represented, the function shall return the value (clock_t)-1.

If clock() always returns -1, this loop will run forever.

> +        if(last_t && t != last_t){
> +            if(i<10000U && s<24){

Why the U suffix?

> +                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;
> +}

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-cvslog mailing list