From: <bc...@us...> - 2008-01-14 18:02:57
|
Revision: 1330 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1330&view=rev Author: bcholew Date: 2008-01-14 10:03:00 -0800 (Mon, 14 Jan 2008) Log Message: ----------- Move local gettimeofday() implementation from winfuncs.c to new function iax_now() in libiax2 (different semantics). Use iax_now() in place of gettimeofday() throughout code. Add config-time check for gettimeofday() for unix builds. Move iax_seed_random() and iax_random() out of DEBUG_SUPPORT section. Remove small C99-ism to keep msoft happy. Modified Paths: -------------- trunk/configure.ac trunk/lib/audio_encode.c trunk/lib/iaxclient_lib.c trunk/lib/iaxclient_lib.h trunk/lib/libiax2/src/iax-client.h trunk/lib/libiax2/src/iax.c trunk/lib/video.c trunk/lib/winfuncs.c Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/configure.ac 2008-01-14 18:03:00 UTC (rev 1330) @@ -47,6 +47,7 @@ AC_CHECK_FUNCS([vsnprintf _vsnprintf]) AC_CHECK_FUNCS([srandomdev srandom srand48 random lrand48]) +AC_CHECK_FUNCS(gettimeofday) ACX_PTHREAD Modified: trunk/lib/audio_encode.c =================================================================== --- trunk/lib/audio_encode.c 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/audio_encode.c 2008-01-14 18:03:00 UTC (rev 1330) @@ -71,7 +71,7 @@ float input_db; float output_db; - gettimeofday(&now, 0); + now = iax_now(); if ( last.tv_sec != 0 && iaxci_usecdiff(&now, &last) < 100000 ) return 0; @@ -261,7 +261,7 @@ int insize = samples; /* update last input timestamp */ - gettimeofday( &timeLastInput, NULL ) ; + timeLastInput = iax_now(); silent = input_postprocess(data, insize, 8000); @@ -342,7 +342,7 @@ int insize = len; int outsize = *samples; - gettimeofday( &timeLastOutput, NULL ) ; + timeLastOutput = iax_now(); if ( format == 0 ) { Modified: trunk/lib/iaxclient_lib.c =================================================================== --- trunk/lib/iaxclient_lib.c 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/iaxclient_lib.c 2008-01-14 18:03:00 UTC (rev 1330) @@ -733,7 +733,7 @@ { if ( callNo < 0 ) return; - gettimeofday(&calls[callNo].last_activity, NULL); + calls[callNo].last_activity = iax_now(); } static void iaxc_refresh_registrations() @@ -741,7 +741,7 @@ struct iaxc_registration *cur; struct timeval now; - gettimeofday(&now,NULL); + now = iax_now(); for ( cur = registrations; cur != NULL; cur = cur->next ) { @@ -1264,7 +1264,7 @@ return -1; } - gettimeofday(&newreg->last,NULL); + newreg->last = iax_now(); newreg->refresh = refresh; strncpy(newreg->host, host, 256); Modified: trunk/lib/iaxclient_lib.h =================================================================== --- trunk/lib/iaxclient_lib.h 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/iaxclient_lib.h 2008-01-14 18:03:00 UTC (rev 1330) @@ -32,7 +32,6 @@ #include <string.h> #if defined(WIN32) || defined(_WIN32_WCE) -void gettimeofday(struct timeval *tv, void /*struct timezone*/ *tz); #include <winsock.h> #if !defined(_WIN32_WCE) #include <process.h> Modified: trunk/lib/libiax2/src/iax-client.h =================================================================== --- trunk/lib/libiax2/src/iax-client.h 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/libiax2/src/iax-client.h 2008-01-14 18:03:00 UTC (rev 1330) @@ -200,6 +200,8 @@ extern void iax_enable_debug(void); extern void iax_disable_debug(void); +extern struct timeval iax_now(void); + /* For attended transfer, application create a new session, * make a call on the new session. * On answer of the new session, call iax_setup_transfer and wait for Modified: trunk/lib/libiax2/src/iax.c =================================================================== --- trunk/lib/libiax2/src/iax.c 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/libiax2/src/iax.c 2008-01-14 18:03:00 UTC (rev 1330) @@ -34,6 +34,9 @@ #include <stdio.h> #include <limits.h> +#if !defined(_WIN32_WCE) +#include <sys/timeb.h> +#endif #define snprintf _snprintf @@ -47,7 +50,7 @@ #ifdef __cplusplus extern "C" { #endif -void gettimeofday(struct timeval *tv, void /*struct timezone*/ *tz); +struct timeval iax_now(void); #ifdef __cplusplus } #endif @@ -278,30 +281,6 @@ s->sendto = ptr; } -void iax_seed_random() -{ -#if defined(HAVE_SRANDOMDEV) - srandomdev(); -#elif defined(HAVE_SRANDOM) - srandom((unsigned int)time(0)); -#elif defined(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 -} - /* This is a little strange, but to debug you call DEBU(G "Hello World!\n"); */ #if defined(WIN32) || defined(_WIN32_WCE) #define G __FILE__, __LINE__, @@ -346,6 +325,30 @@ #define G #endif +void iax_seed_random() +{ +#if defined(HAVE_SRANDOMDEV) + srandomdev(); +#elif defined(HAVE_SRANDOM) + srandom((unsigned int)time(0)); +#elif defined(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 +} + typedef void (*sched_func)(void *); struct iax_sched { @@ -393,7 +396,7 @@ sched = (struct iax_sched*)malloc(sizeof(struct iax_sched)); if (sched) { memset(sched, 0, sizeof(struct iax_sched)); - gettimeofday(&sched->when, NULL); + sched->when = iax_now(); sched->when.tv_sec += (ms / 1000); ms = ms % 1000; sched->when.tv_usec += (ms * 1000); @@ -460,7 +463,7 @@ /* If there are no pending events, we don't need to timeout */ if (!cur) return -1; - gettimeofday(&tv, NULL); + tv = iax_now(); while(cur) { ms = (cur->when.tv_sec - tv.tv_sec) * 1000 + (cur->when.tv_usec - tv.tv_usec) / 1000; @@ -595,7 +598,7 @@ /* If this is the first packet we're sending, get our offset now. */ if (!session->offset.tv_sec && !session->offset.tv_usec) - gettimeofday(&session->offset, NULL); + session->offset = iax_now(); /* If the timestamp is specified, just use their specified timestamp no matter what. Usually this is done for @@ -608,7 +611,7 @@ } /* Otherwise calculate the timestamp from the current time */ - gettimeofday(&tv, NULL); + tv = iax_now(); /* Calculate the number of milliseconds since we sent the first packet */ ms = (tv.tv_sec - session->offset.tv_sec) * 1000 + @@ -1419,12 +1422,12 @@ struct iax_session *s0 = org_session; struct iax_session *s1 = new_session; + int transfer_id = 1 + (int)(32767.0 * (iax_random() / (RAND_MAX + 1.0))); + 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); @@ -2227,9 +2230,9 @@ int ms; if (!session->rxcore.tv_sec && !session->rxcore.tv_usec) { - gettimeofday(&session->rxcore, NULL); + session->rxcore = iax_now(); } - gettimeofday(&tv, NULL); + tv = iax_now(); ms = (tv.tv_sec - session->rxcore.tv_sec) * 1000 + (tv.tv_usec - session->rxcore.tv_usec) / 1000; @@ -3260,7 +3263,7 @@ struct iax_sched *cur; struct iax_session *session; - gettimeofday(&tv, NULL); + tv = iax_now(); while((cur = iax_get_sched(tv))) { @@ -3486,3 +3489,21 @@ return send_command(session, AST_FRAME_IAX, IAX_COMMAND_QUELCH, 0, ied.buf, ied.pos, -1); } + +struct timeval iax_now(void) +{ + struct timeval tv; + +#ifdef HAVE_GETTIMEOFDAY + gettimeofday(&tv, 0); +#elif defined(_MSC_VER) + struct _timeb curSysTime; + + _ftime(&curSysTime); + tv.tv_sec = (long)curSysTime.time; + tv.tv_usec = curSysTime.millitm * 1000; +#else +#error no gettimeofday or equivalent available +#endif + return tv; +} Modified: trunk/lib/video.c =================================================================== --- trunk/lib/video.c 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/video.c 2008-01-14 18:03:00 UTC (rev 1330) @@ -139,7 +139,7 @@ return; memset(&vcodec->video_stats, 0, sizeof(struct iaxc_video_stats)); - gettimeofday(&vcodec->video_stats.start_time, 0); + vcodec->video_stats.start_time = iax_now(); } static void reset_video_stats(struct iaxc_call * call) @@ -200,9 +200,9 @@ return -1; if ( video_stats_start.tv_sec == 0 && video_stats_start.tv_usec == 0 ) - gettimeofday(&video_stats_start, 0); + video_stats_start = iax_now(); - gettimeofday(&now, 0); + now = iax_now(); if ( iaxci_msecdiff(&now, &video_stats_start) > video_stats_interval ) { @@ -732,7 +732,7 @@ /* Gather statistics */ call->vencoder->video_stats.outbound_frames++; - gettimeofday(&now, 0); + now = iax_now(); time_delta = iaxci_msecdiff(&now, &call->vencoder->video_stats.start_time); @@ -1296,7 +1296,7 @@ } /* Statistics */ - gettimeofday(&now, 0); + now = iax_now(); time = iaxci_msecdiff(&now, &call->vdecoder->video_stats.start_time); call->vdecoder->video_stats.received_slices++; call->vdecoder->video_stats.acc_recv_size += encoded_video_len; @@ -1776,9 +1776,9 @@ return -1; if ( video_stats_start.tv_sec == 0 && video_stats_start.tv_usec == 0 ) - gettimeofday(&video_stats_start, 0); + video_stats_start = iax_now(); - gettimeofday(&now, 0); + now = iax_now(); if ( iaxci_msecdiff(&now, &video_stats_start) > video_stats_interval ) { Modified: trunk/lib/winfuncs.c =================================================================== --- trunk/lib/winfuncs.c 2008-01-09 07:59:40 UTC (rev 1329) +++ trunk/lib/winfuncs.c 2008-01-14 18:03:00 UTC (rev 1330) @@ -19,33 +19,6 @@ #include <stdio.h> -#if !defined(_WIN32_WCE) -#include <sys/timeb.h> - -/* Win-doze doesnt have gettimeofday(). This sux. So, what we did is -provide some gettimeofday-like functionality that works for our purposes. */ - -/* - changed 'struct timezone*' to 'void*' since - timezone is defined as a long in MINGW and caused compile-time warnings. - this should be okay since we don't use the passed value. -*/ - - -/* - * functions implementations - */ - -void gettimeofday( struct timeval* tv, void* tz ) -{ - struct _timeb curSysTime; - - _ftime(&curSysTime); - tv->tv_sec = (long)curSysTime.time; - tv->tv_usec = curSysTime.millitm * 1000; -} -#endif - void os_init(void) { WSADATA wsd; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |