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

Michael Niedermayer michaelni
Thu Jul 8 20:13:59 CEST 2010


On Thu, Jul 08, 2010 at 04:57:09PM +0100, M?ns Rullg?rd wrote:
> Michael Niedermayer <michaelni at gmx.at> writes:
> 
> > On Thu, Jul 08, 2010 at 12:58:23AM +0100, M?ns Rullg?rd wrote:
> >> 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.
> >
> > what else is giving us reasonable precission (1 tick per second
> > would need 2 minutes per seed) and is portable?
> 
> There is nothing absolutely reliable.  Most platforms have _some_ kind
> of timer tick or cycle counter, but no standard interface is available
> everywhere.
> 
> >> > +        if(last_t && t != last_t){
> >> > +            if(i<10000U && s<24){
> >> 
> >> Why the U suffix?
> >
> > for unsigned compare, otherwise if i becomes negative this could behave odd
> 
> If i becoming negative is a problem, why not declare it unsigned?
> That expresses the intent more clearly IMO.

should be all fixed

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Dictatorship naturally arises out of democracy, and the most aggravated
form of tyranny and slavery out of the most extreme liberty. -- Plato
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-cvslog/attachments/20100708/c8f8aa36/attachment.pgp>



More information about the ffmpeg-cvslog mailing list