Commit 275a5d4a authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

ASF: thread-safe pseudo-random numbers

parent 6268a229
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#endif #endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_rand.h>
#include "asf.h" #include "asf.h"
#include "buffer.h" #include "buffer.h"
...@@ -47,18 +48,10 @@ static int CmpGuid( const guid_t *p_guid1, const guid_t *p_guid2 ) ...@@ -47,18 +48,10 @@ static int CmpGuid( const guid_t *p_guid1, const guid_t *p_guid2 )
void GenerateGuid ( guid_t *p_guid ) void GenerateGuid ( guid_t *p_guid )
{ {
int i;
srand( mdate() & 0xffffffff );
/* FIXME should be generated using random data */
p_guid->v1 = 0xbabac001; p_guid->v1 = 0xbabac001;
p_guid->v2 = ( (uint64_t)rand() << 16 ) / RAND_MAX; vlc_rand_bytes(&p_guid->v2, sizeof(p_guid->v2));
p_guid->v3 = ( (uint64_t)rand() << 16 ) / RAND_MAX; vlc_rand_bytes(&p_guid->v3, sizeof(p_guid->v3));
for( i = 0; i < 8; i++ ) vlc_rand_bytes(p_guid->v4, sizeof(p_guid->v4));
{
p_guid->v4[i] = ( (uint64_t)rand() * 256 ) / RAND_MAX;
}
} }
void asf_HeaderParse ( asf_header_t *hdr, void asf_HeaderParse ( asf_header_t *hdr,
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <vlc_block.h> #include <vlc_block.h>
#include <vlc_codecs.h> #include <vlc_codecs.h>
#include <vlc_arrays.h> #include <vlc_arrays.h>
#include <vlc_rand.h>
typedef GUID guid_t; typedef GUID guid_t;
...@@ -228,14 +229,10 @@ static int Open( vlc_object_t *p_this ) ...@@ -228,14 +229,10 @@ static int Open( vlc_object_t *p_this )
p_sys->i_packet_count= 0; p_sys->i_packet_count= 0;
/* Generate a random fid */ /* Generate a random fid */
srand( mdate() & 0xffffffff );
p_sys->fid.Data1 = 0xbabac001; p_sys->fid.Data1 = 0xbabac001;
p_sys->fid.Data2 = ( (uint64_t)rand() << 16 ) / RAND_MAX; vlc_rand_bytes(&p_sys->fid.Data2, sizeof(p_sys->fid.Data2));
p_sys->fid.Data3 = ( (uint64_t)rand() << 16 ) / RAND_MAX; vlc_rand_bytes(&p_sys->fid.Data3, sizeof(p_sys->fid.Data3));
for( i = 0; i < 8; i++ ) vlc_rand_bytes(p_sys->fid.Data4, sizeof(p_sys->fid.Data4));
{
p_sys->fid.Data4[i] = ( (uint64_t)rand() << 8 ) / RAND_MAX;
}
/* Meta data */ /* Meta data */
p_sys->psz_title = var_GetString( p_mux, SOUT_CFG_PREFIX "title" ); p_sys->psz_title = var_GetString( p_mux, SOUT_CFG_PREFIX "title" );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment