diff options
author | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-05-01 14:03:37 +0000 |
---|---|---|
committer | markster <markster@f38db490-d61c-443f-a65b-d21fe96a405b> | 2004-05-01 14:03:37 +0000 |
commit | 9211e2eb211161f98f3e4ccce94572f6e31dfb21 (patch) | |
tree | 6dea498b22026e50ae53b62cb81ef344995d4347 /apps/app_mp3.c | |
parent | 4af43a84cb10ddab3b26d6e8b120058f0cc0d9c7 (diff) |
Improve mp3 player quality (bug #1527)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@2840 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_mp3.c')
-rwxr-xr-x | apps/app_mp3.c | 65 |
1 files changed, 39 insertions, 26 deletions
diff --git a/apps/app_mp3.c b/apps/app_mp3.c index 7432d90d0..98803a3c1 100755 --- a/apps/app_mp3.c +++ b/apps/app_mp3.c @@ -104,15 +104,14 @@ static int mp3_exec(struct ast_channel *chan, void *data) int ms = -1; int pid = -1; int owriteformat; - struct timeval last; + struct timeval now, next; struct ast_frame *f; struct myframe { struct ast_frame f; char offset[AST_FRIENDLY_OFFSET]; short frdata[160]; } myf; - last.tv_usec = 0; - last.tv_sec = 0; + if (!data) { ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n"); return -1; @@ -131,35 +130,23 @@ static int mp3_exec(struct ast_channel *chan, void *data) return -1; } + gettimeofday(&now, NULL); res = mp3play((char *)data, fds[1]); /* Wait 1000 ms first */ - ms = 1000; + next = now; + 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 (;;) { - ms = ast_waitfor(chan, ms); - if (ms < 0) { - ast_log(LOG_DEBUG, "Hangup detected\n"); - res = -1; - break; - } - if (ms > 40) { - f = ast_read(chan); - if (!f) { - ast_log(LOG_DEBUG, "Null frame == hangup() detected\n"); - res = -1; - break; - } - if (f->frametype == AST_FRAME_DTMF) { - ast_log(LOG_DEBUG, "User pressed a key\n"); - ast_frfree(f); - res = 0; - break; - } - ast_frfree(f); - } else { + 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 + if (ms <= 0) { #if 0 { static struct timeval last; @@ -190,10 +177,36 @@ static int mp3_exec(struct ast_channel *chan, void *data) res = 0; break; } - ms += res / 16; + 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 + } else { + ms = ast_waitfor(chan, ms); + if (ms < 0) { + ast_log(LOG_DEBUG, "Hangup detected\n"); + res = -1; + break; + } + if (ms) { + f = ast_read(chan); + if (!f) { + ast_log(LOG_DEBUG, "Null frame == hangup() detected\n"); + res = -1; + break; + } + if (f->frametype == AST_FRAME_DTMF) { + ast_log(LOG_DEBUG, "User pressed a key\n"); + ast_frfree(f); + res = 0; + break; + } + ast_frfree(f); + } } } } |