diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-15 23:00:47 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-07-15 23:00:47 +0000 |
commit | ff15e0fa53156b9994da3f726bfe91232de6195a (patch) | |
tree | 896015cada90b49858e1bf6503d9583704a56179 /apps/app_nbscat.c | |
parent | c05cf07847cb384ba66aa29d5eda580eda413ffb (diff) |
add a library of timeval manipulation functions, and change a large number of usses to use the new functions (bug #4504)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6146 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_nbscat.c')
-rwxr-xr-x | apps/app_nbscat.c | 29 |
1 files changed, 4 insertions, 25 deletions
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) { |