Merge commit '01d245ef4392152dbdc78a6ba4dfa0a6e8b08e6f'

* commit '01d245ef4392152dbdc78a6ba4dfa0a6e8b08e6f':
  random_seed: Rewrite the generic clock() based seed code

Conflicts:
	libavutil/random_seed.c

See: 66531c75d3
Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2014-01-06 22:09:14 +01:00
commit 00f25e0a99

View File

@ -33,10 +33,10 @@
#include <string.h>
#include "avassert.h"
#include "internal.h"
#include "intreadwrite.h"
#include "timer.h"
#include "random_seed.h"
#include "sha.h"
#include "intreadwrite.h"
#ifndef TEST
#define TEST 0
@ -65,7 +65,7 @@ static uint32_t get_generic_seed(void)
struct AVSHA *sha = (void*)tmp;
clock_t last_t = 0;
static uint64_t i = 0;
static uint32_t buffer[512] = {0};
static uint32_t buffer[512] = { 0 };
unsigned char digest[20];
uint64_t last_i = i;
@ -84,11 +84,11 @@ static uint32_t get_generic_seed(void)
for (;;) {
clock_t t = clock();
if(last_t == t){
buffer[i&511]++;
}else{
buffer[++i&511]+= (t-last_t) % 3294638521U;
if(last_i && i-last_i > 4 || i-last_i > 64 || TEST && i-last_i > 8)
if (last_t == t) {
buffer[i & 511]++;
} else {
buffer[++i & 511] += (t - last_t) % 3294638521U;
if (last_i && i - last_i > 4 || i - last_i > 64 || TEST && i - last_i > 8)
break;
}
last_t = t;
@ -98,9 +98,9 @@ static uint32_t get_generic_seed(void)
buffer[0] = buffer[1] = 0;
av_sha_init(sha, 160);
av_sha_update(sha, (uint8_t*)buffer, sizeof(buffer));
av_sha_update(sha, (const uint8_t *)buffer, sizeof(buffer));
av_sha_final(sha, digest);
return AV_RB32(digest) + AV_RB32(digest+16);
return AV_RB32(digest) + AV_RB32(digest + 16);
}
uint32_t av_get_random_seed(void)