[FFmpeg-cvslog] r24102 - trunk/libavutil/random_seed.c
Måns Rullgård
mans
Thu Jul 8 17:57:09 CEST 2010
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.
--
M?ns Rullg?rd
mans at mansr.com
More information about the ffmpeg-cvslog
mailing list