From: <do...@us...> - 2007-11-28 04:08:04
|
Revision: 1285 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1285&view=rev Author: dohpaz Date: 2007-11-27 20:08:06 -0800 (Tue, 27 Nov 2007) Log Message: ----------- Add iax_seed_random() and iax_random() that will use the best random number generation I can find on a particular platform. Fall back to rand() in desperation. Lower 12 bits of rand() are not very random on many platforms, one should NEVER do a straight modulus of it's return value. Add myself to contributors for various files I've contributed to. Modified Paths: -------------- branches/team/elbunce/iaxclient/AUTHORS branches/team/elbunce/iaxclient/configure.ac branches/team/elbunce/iaxclient/lib/audio_encode.c branches/team/elbunce/iaxclient/lib/audio_portaudio.c branches/team/elbunce/iaxclient/lib/iaxclient_lib.c branches/team/elbunce/iaxclient/lib/libiax2/src/iax-client.h branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c branches/team/elbunce/iaxclient/lib/video.c Modified: branches/team/elbunce/iaxclient/AUTHORS =================================================================== --- branches/team/elbunce/iaxclient/AUTHORS 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/AUTHORS 2007-11-28 04:08:06 UTC (rev 1285) @@ -9,7 +9,7 @@ Steve Underwood <st...@co...> [PLC implementation from spandsp] Jean-Denis Girard <jd....@sy...> [URL Receive implementation] Panfilov Dmitry <di...@bd...> [Basic ALSA-native audio driver] -Erik Bunce <kd...@bu...> [Assorted fixes/tweaks, Documentation] +Erik Bunce <kd...@bu...> [Assorted fixes/tweaks/features, Documentation] Mihai Balea <mihai at hates dot ms> Bill Welch <welch1820 at gmail dot com> [Project files for several MS development environments] Peter Grayson <jpg...@gm...> Modified: branches/team/elbunce/iaxclient/configure.ac =================================================================== --- branches/team/elbunce/iaxclient/configure.ac 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/configure.ac 2007-11-28 04:08:06 UTC (rev 1285) @@ -46,6 +46,7 @@ AC_TYPE_SIZE_T AC_CHECK_FUNCS([vsnprintf _vsnprintf]) +AC_CHECK_FUNCS([srandomdev srandom srand48 random lrand48]) ACX_PTHREAD Modified: branches/team/elbunce/iaxclient/lib/audio_encode.c =================================================================== --- branches/team/elbunce/iaxclient/lib/audio_encode.c 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/audio_encode.c 2007-11-28 04:08:06 UTC (rev 1285) @@ -327,7 +327,7 @@ if(iax_send_voice(call->session,format, outbuf, sizeof(outbuf) - outsize, samples-insize) == -1) { - puts("Failed to send voice!"); + fprintf(stderr, "Failed to send voice! %s\n", iax_errstr); return -1; } Modified: branches/team/elbunce/iaxclient/lib/audio_portaudio.c =================================================================== --- branches/team/elbunce/iaxclient/lib/audio_portaudio.c 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/audio_portaudio.c 2007-11-28 04:08:06 UTC (rev 1285) @@ -9,6 +9,7 @@ * Steve Kann <st...@st...> * Michael Van Donselaar <mv...@va...> * Shawn Lawrence <sha...@te...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. Modified: branches/team/elbunce/iaxclient/lib/iaxclient_lib.c =================================================================== --- branches/team/elbunce/iaxclient/lib/iaxclient_lib.c 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/iaxclient_lib.c 2007-11-28 04:08:06 UTC (rev 1285) @@ -13,6 +13,7 @@ * Mihai Balea <mihai AT hates DOT ms> * Peter Grayson <jpg...@gm...> * Bill Cholewka <bc...@gm...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. Modified: branches/team/elbunce/iaxclient/lib/libiax2/src/iax-client.h =================================================================== --- branches/team/elbunce/iaxclient/lib/libiax2/src/iax-client.h 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/libiax2/src/iax-client.h 2007-11-28 04:08:06 UTC (rev 1285) @@ -245,6 +245,10 @@ /* Fine tune jitterbuffer */ extern void iax_set_jb_target_extra( long value ); +/* Portable 'decent' random number generation */ +void iax_seed_random(); +int iax_random(); + #if defined(__cplusplus) } #endif Modified: branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c =================================================================== --- branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c 2007-11-28 04:08:06 UTC (rev 1285) @@ -314,9 +314,31 @@ static struct iax_sched *schedq = NULL; static struct iax_session *sessions = NULL; static int callnums = 1; -static int transfer_id = 1; /* for attended transfer */ +void iax_seed_random() +{ +#if defined(HAVE_SRANDOMDEV) + srandomdev(); +#elif defined(HAVE_SRANDOM) + srandom((unsigned int)time(0)); +#elif define(HAVE_SRAND48) + srand48((long int)time(0)); +#else + srand((unsigned int)time(0)); +#endif +} +int iax_random() +{ +#if defined(HAVE_RANDOM) + return (int)random(); +#elif defined(HAVE_LRAND48) + return (int)lrand48(); +#else + return rand(); +#endif +} + void iax_set_private(struct iax_session *s, void *ptr) { s->pvt = ptr; @@ -979,9 +1001,8 @@ DEBU(G "Started on port %d\n", portno); } - srand((unsigned int)time(0)); - callnums = rand() % 32767 + 1; - transfer_id = rand() % 32767 + 1; + iax_seed_random(); + callnums = 1 + (int)(32767.0 * (iax_random() / (RAND_MAX + 1.0))); return portno; } @@ -1373,8 +1394,11 @@ struct iax_session *s1 = new_session; memset(&ied0, 0, sizeof(ied0)); + memset(&ied1, 0, sizeof(ied1)); + int transfer_id = 1 + (int)(32767.0 * (iax_random() / (RAND_MAX + 1.0))); + /* reversed setup */ iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &s1->peeraddr); iax_ie_append_short(&ied0, IAX_IE_CALLNO, s1->peercallno); @@ -1399,11 +1423,8 @@ s0->transferpeer = s1->callno; s1->transferpeer = s0->callno; - transfer_id++; + DEBU(G fprintf(stderr, "iax_setup_transfer(%d, %d) transfer_id=%d\n", s0->callno, s1->callno, transfer_id); - if (transfer_id > 32767) - transfer_id = 1; - res = send_command(s0, AST_FRAME_IAX, IAX_COMMAND_TXREQ, 0, ied0.buf, ied0.pos, -1); if (res < 0) { return -1; Modified: branches/team/elbunce/iaxclient/lib/video.c =================================================================== --- branches/team/elbunce/iaxclient/lib/video.c 2007-11-26 22:02:43 UTC (rev 1284) +++ branches/team/elbunce/iaxclient/lib/video.c 2007-11-28 04:08:06 UTC (rev 1285) @@ -9,6 +9,7 @@ * Steve Kann <st...@st...> * Mihai Balea <mihai AT hates DOT ms> * Peter Grayson <jpg...@gm...> + * Erik Bunce <kd...@bu...> * * This program is free software, distributed under the terms of * the GNU Lesser (Library) General Public License. @@ -1789,8 +1790,8 @@ ) == -1 ) { - fprintf(stderr, "Failed to send a slice, call %d, size %d\n", - selected_call, slice_set.size[i]); + fprintf(stderr, "Failed to send a slice, call %d, size %d: %s\n", + selected_call, slice_set.size[i], iax_errstr); return -1; } @@ -1801,8 +1802,8 @@ size, 0, 0) == -1 ) { fprintf(stderr, "iaxc_push_video: failed to send " - "video frame of size %d on call %d\n", - size, selected_call); + "video frame of size %d on call %d: %s\n", + size, selected_call, iax_errstr); return -1; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |