diff options
Diffstat (limited to 'apps/app_mp3.c')
-rwxr-xr-x | apps/app_mp3.c | 30 |
1 files changed, 4 insertions, 26 deletions
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) { |