aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rwxr-xr-xapps/app_alarmreceiver.c10
-rwxr-xr-xapps/app_disa.c19
-rwxr-xr-xapps/app_dumpchan.c2
-rwxr-xr-xapps/app_forkcdr.c2
-rwxr-xr-xapps/app_mp3.c30
-rwxr-xr-xapps/app_nbscat.c29
-rwxr-xr-xapps/app_readfile.c2
-rwxr-xr-xapps/app_sayunixtime.c2
-rwxr-xr-xapps/app_sms.c2
-rwxr-xr-xapps/app_talkdetect.c8
-rwxr-xr-xapps/app_test.c8
-rwxr-xr-xapps/app_voicemail.c2
12 files changed, 28 insertions, 88 deletions
diff --git a/apps/app_alarmreceiver.c b/apps/app_alarmreceiver.c
index da6db49d2..9fead22da 100755
--- a/apps/app_alarmreceiver.c
+++ b/apps/app_alarmreceiver.c
@@ -235,14 +235,12 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int
int i = 0;
int r;
struct ast_frame *f;
- struct timeval now, lastdigittime;
+ struct timeval lastdigittime;
- gettimeofday(&lastdigittime,NULL);
+ lastdigittime = ast_tvnow();
for(;;){
- gettimeofday(&now,NULL);
-
/* if outa time, leave */
- if (ast_tvdiff_ms(&now, &lastdigittime) >
+ if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
((i > 0) ? sdto : fdto)){
if(option_verbose >= 4)
ast_verbose(VERBOSE_PREFIX_4 "AlarmReceiver: DTMF Digit Timeout on %s\n", chan->name);
@@ -287,7 +285,7 @@ static int receive_dtmf_digits(struct ast_channel *chan, char *digit_string, int
if(i >= length)
break;
- gettimeofday(&lastdigittime,NULL);
+ lastdigittime = ast_tvnow();
}
digit_string[i] = '\0'; /* Nul terminate the end of the digit string */
diff --git a/apps/app_disa.c b/apps/app_disa.c
index dadb4d17c..8b934638d 100755
--- a/apps/app_disa.c
+++ b/apps/app_disa.c
@@ -90,15 +90,6 @@ STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
-static int ms_diff(struct timeval *tv1, struct timeval *tv2)
-{
-int ms;
-
- ms = (tv1->tv_sec - tv2->tv_sec) * 1000;
- ms += (tv1->tv_usec - tv2->tv_usec) / 1000;
- return(ms);
-}
-
static void play_dialtone(struct ast_channel *chan, char *mailbox)
{
const struct tone_zone_sound *ts = NULL;
@@ -121,7 +112,7 @@ static int disa_exec(struct ast_channel *chan, void *data)
char tmp[256],arg2[256]="",exten[AST_MAX_EXTENSION],acctcode[20]="";
char *ourcontext,*ourcallerid,ourcidname[256],ourcidnum[256],*mailbox;
struct ast_frame *f;
- struct timeval lastout, now, lastdigittime;
+ struct timeval lastdigittime;
int res;
time_t rstart;
FILE *fp;
@@ -142,7 +133,6 @@ static int disa_exec(struct ast_channel *chan, void *data)
ast_log(LOG_WARNING, "Unable to set read format to Mu-law on %s\n",chan->name);
return -1;
}
- lastout.tv_sec = lastout.tv_usec = 0;
if (!data || !strlen((char *)data)) {
ast_log(LOG_WARNING, "disa requires an argument (passcode/passcode file)\n");
return -1;
@@ -187,15 +177,14 @@ static int disa_exec(struct ast_channel *chan, void *data)
k |= 1; /* We have the password */
ast_log(LOG_DEBUG, "DISA no-password login success\n");
}
- gettimeofday(&lastdigittime,NULL);
+ lastdigittime = ast_tvnow();
play_dialtone(chan, mailbox);
for(;;)
{
- gettimeofday(&now,NULL);
/* if outa time, give em reorder */
- if (ms_diff(&now,&lastdigittime) >
+ if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) >
((k&2) ? digittimeout : firstdigittimeout))
{
ast_log(LOG_DEBUG,"DISA %s entry timeout on chan %s\n",
@@ -238,7 +227,7 @@ static int disa_exec(struct ast_channel *chan, void *data)
k|=2; /* We have the first digit */
ast_playtones_stop(chan);
}
- gettimeofday(&lastdigittime,NULL);
+ lastdigittime = ast_tvnow();
/* got a DTMF tone */
if (i < AST_MAX_EXTENSION) /* if still valid number of digits */
{
diff --git a/apps/app_dumpchan.c b/apps/app_dumpchan.c
index 6b43bfa5d..6c36aac7c 100755
--- a/apps/app_dumpchan.c
+++ b/apps/app_dumpchan.c
@@ -51,7 +51,7 @@ static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
char cgrp[256];
char pgrp[256];
- gettimeofday(&now, NULL);
+ now = ast_tvnow();
memset(buf,0,size);
if (!c)
return 0;
diff --git a/apps/app_forkcdr.c b/apps/app_forkcdr.c
index 1452b0e4b..9300dc257 100755
--- a/apps/app_forkcdr.c
+++ b/apps/app_forkcdr.c
@@ -46,7 +46,7 @@ static void ast_cdr_clone(struct ast_cdr *cdr)
struct ast_cdr *newcdr = ast_cdr_alloc();
memcpy(newcdr,cdr,sizeof(struct ast_cdr));
ast_cdr_append(cdr,newcdr);
- gettimeofday(&newcdr->start, NULL);
+ newcdr->start = ast_tvnow();
memset(&newcdr->answer, 0, sizeof(newcdr->answer));
memset(&newcdr->varshead, 0, sizeof(newcdr->varshead));
ast_cdr_copy_vars(newcdr, cdr);
diff --git a/apps/app_mp3.c b/apps/app_mp3.c
index 1b21d333f..b4d7a1f6b 100755
--- a/apps/app_mp3.c
+++ b/apps/app_mp3.c
@@ -109,7 +109,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
int pid = -1;
int owriteformat;
int timeout = 2000;
- struct timeval now, next;
+ struct timeval next;
struct ast_frame *f;
struct myframe {
struct ast_frame f;
@@ -134,35 +134,20 @@ static int mp3_exec(struct ast_channel *chan, void *data)
return -1;
}
- gettimeofday(&now, NULL);
res = mp3play((char *)data, fds[1]);
if (!strncasecmp((char *)data, "http://", 7)) {
timeout = 10000;
}
/* Wait 1000 ms first */
- next = now;
+ next = ast_tvnow();
next.tv_sec += 1;
if (res >= 0) {
pid = res;
/* Order is important -- there's almost always going to be mp3... we want to prioritize the
user */
for (;;) {
- gettimeofday(&now, NULL);
- ms = (next.tv_sec - now.tv_sec) * 1000;
- ms += (next.tv_usec - now.tv_usec) / 1000;
-#if 0
- printf("ms: %d\n", ms);
-#endif
+ ms = ast_tvdiff_ms(next, ast_tvnow());
if (ms <= 0) {
-#if 0
- {
- static struct timeval last;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- printf("Since last: %ld\n", (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
- last = tv;
- }
-#endif
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata), timeout);
if (res > 0) {
myf.f.frametype = AST_FRAME_VOICE;
@@ -184,14 +169,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
res = 0;
break;
}
- next.tv_usec += res / 2 * 125;
- if (next.tv_usec >= 1000000) {
- next.tv_usec -= 1000000;
- next.tv_sec++;
- }
-#if 0
- printf("Next: %d\n", ms);
-#endif
+ next = ast_tvadd(next, ast_samp2tv(myf.f.samples, 8000));
} else {
ms = ast_waitfor(chan, ms);
if (ms < 0) {
diff --git a/apps/app_nbscat.c b/apps/app_nbscat.c
index aa5e44d8e..9227a92ff 100755
--- a/apps/app_nbscat.c
+++ b/apps/app_nbscat.c
@@ -99,7 +99,7 @@ static int NBScat_exec(struct ast_channel *chan, void *data)
int ms = -1;
int pid = -1;
int owriteformat;
- struct timeval now, next;
+ struct timeval next;
struct ast_frame *f;
struct myframe {
struct ast_frame f;
@@ -122,29 +122,15 @@ static int NBScat_exec(struct ast_channel *chan, void *data)
res = NBScatplay(fds[1]);
/* Wait 1000 ms first */
- next = now;
+ next = ast_tvnow();
next.tv_sec += 1;
if (res >= 0) {
pid = res;
/* Order is important -- there's almost always going to be mp3... we want to prioritize the
user */
for (;;) {
- gettimeofday(&now, NULL);
- ms = (next.tv_sec - now.tv_sec) * 1000;
- ms += (next.tv_usec - now.tv_usec) / 1000;
-#if 0
- printf("ms: %d\n", ms);
-#endif
+ ms = ast_tvdiff_ms(next, ast_tvnow());
if (ms <= 0) {
-#if 0
- {
- static struct timeval last;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- printf("Since last: %ld\n", (tv.tv_sec - last.tv_sec) * 1000 + (tv.tv_usec - last.tv_usec) / 1000);
- last = tv;
- }
-#endif
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
if (res > 0) {
myf.f.frametype = AST_FRAME_VOICE;
@@ -166,14 +152,7 @@ static int NBScat_exec(struct ast_channel *chan, void *data)
res = 0;
break;
}
- next.tv_usec += res / 2 * 125;
- if (next.tv_usec >= 1000000) {
- next.tv_usec -= 1000000;
- next.tv_sec++;
- }
-#if 0
- printf("Next: %d\n", ms);
-#endif
+ next = ast_tvadd(next, ast_samp2tv(myf.f.samples, 8000));
} else {
ms = ast_waitfor(chan, ms);
if (ms < 0) {
diff --git a/apps/app_readfile.c b/apps/app_readfile.c
index 0930ec14e..405ceb70a 100755
--- a/apps/app_readfile.c
+++ b/apps/app_readfile.c
@@ -83,7 +83,7 @@ static int readfile_exec(struct ast_channel *chan, void *data)
if(len < strlen(returnvar))
returnvar[len]='\0';
else
- ast_log(LOG_WARNING,"%s is longer than %d, and %zd \n", file, len, strlen(returnvar));
+ ast_log(LOG_WARNING,"%s is longer than %d, and %d \n", file, len, (int)strlen(returnvar));
}
pbx_builtin_setvar_helper(chan, varname, returnvar);
free(returnvar);
diff --git a/apps/app_sayunixtime.c b/apps/app_sayunixtime.c
index a641779d4..06091911e 100755
--- a/apps/app_sayunixtime.c
+++ b/apps/app_sayunixtime.c
@@ -69,7 +69,7 @@ static int sayunixtime_exec(struct ast_channel *chan, void *data)
LOCAL_USER_ADD(u);
- gettimeofday(&tv,NULL);
+ tv = ast_tvnow();
unixtime = (time_t)tv.tv_sec;
if( !strcasecmp(chan->language, "da" ) ) {
diff --git a/apps/app_sms.c b/apps/app_sms.c
index c2ffa4a09..ad9a167bd 100755
--- a/apps/app_sms.c
+++ b/apps/app_sms.c
@@ -1176,7 +1176,7 @@ static int sms_generate (struct ast_channel *chan, void *data, int len, int samp
int i;
if (len > sizeof (buf)) {
- ast_log (LOG_WARNING, "Only doing %zd bytes (%d bytes requested)\n", sizeof (buf) / sizeof (signed short), len);
+ ast_log (LOG_WARNING, "Only doing %d bytes (%d bytes requested)\n", (int)(sizeof (buf) / sizeof (signed short)), len);
len = sizeof (buf);
#ifdef OUTALAW
samples = len;
diff --git a/apps/app_talkdetect.c b/apps/app_talkdetect.c
index 117b835bd..e60f3a8e9 100755
--- a/apps/app_talkdetect.c
+++ b/apps/app_talkdetect.c
@@ -59,7 +59,7 @@ static int background_detect_exec(struct ast_channel *chan, void *data)
char *stringp;
struct ast_frame *fr;
int notsilent=0;
- struct timeval start = { 0, 0}, end = {0, 0};
+ struct timeval start = { 0, 0};
int sil = 1000;
int min = 100;
int max = -1;
@@ -143,9 +143,7 @@ static int background_detect_exec(struct ast_channel *chan, void *data)
/* We've been quiet a little while */
if (notsilent) {
/* We had heard some talking */
- gettimeofday(&end, NULL);
- ms = (end.tv_sec - start.tv_sec) * 1000;
- ms += (end.tv_usec - start.tv_usec) / 1000;
+ ms = ast_tvdiff_ms(ast_tvnow(), start);
ms -= sil;
if (ms < 0)
ms = 0;
@@ -171,7 +169,7 @@ static int background_detect_exec(struct ast_channel *chan, void *data)
} else {
if (!notsilent) {
/* Heard some audio, mark the begining of the token */
- gettimeofday(&start, NULL);
+ start = ast_tvnow();
ast_log(LOG_DEBUG, "Start of voice token!\n");
notsilent = 1;
}
diff --git a/apps/app_test.c b/apps/app_test.c
index bbb54c192..44508063a 100755
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -55,7 +55,7 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
int samples=0;
int x;
short *foo;
- struct timeval start, tv;
+ struct timeval start;
struct ast_frame *f;
int rformat;
rformat = chan->readformat;
@@ -63,11 +63,9 @@ static int measurenoise(struct ast_channel *chan, int ms, char *who)
ast_log(LOG_NOTICE, "Unable to set to linear mode!\n");
return -1;
}
- gettimeofday(&start, NULL);
+ start = ast_tvnow();
for(;;) {
- gettimeofday(&tv, NULL);
- mssofar = (tv.tv_sec - start.tv_sec) * 1000;
- mssofar += (tv.tv_usec - start.tv_usec) / 1000;
+ mssofar = ast_tvdiff_ms(ast_tvnow(), start);
if (mssofar > ms)
break;
res = ast_waitfor(chan, ms - mssofar);
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index a20bf730a..e5a52f06d 100755
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -3295,7 +3295,7 @@ static int play_message_datetime(struct ast_channel *chan, struct ast_vm_user *v
#if 0
/* Set the DIFF_* variables */
localtime_r(&t, &time_now);
- gettimeofday(&tv_now,NULL);
+ tv_now = ast_tvnow();
tnow = tv_now.tv_sec;
localtime_r(&tnow,&time_then);