aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_mp3.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-04-23 04:39:18 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-04-23 04:39:18 +0000
commit839ec506b8a27b0f06fe53f7b6046ed4aa364362 (patch)
tree5b7900ea1bf716270b20a5b427398fef1b696e4f /apps/app_mp3.c
parentb31c000c19ddf6e221f927998e1abec191bebce1 (diff)
Make MP3 app timeout after a couple of seconds of no audio
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@884 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_mp3.c')
-rwxr-xr-xapps/app_mp3.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/apps/app_mp3.c b/apps/app_mp3.c
index b2bddb7fd..791840106 100755
--- a/apps/app_mp3.c
+++ b/apps/app_mp3.c
@@ -68,6 +68,22 @@ static int mp3play(char *filename, int fd)
return -1;
}
+static int timed_read(int fd, void *data, int datalen)
+{
+ int res;
+ fd_set fds;
+ struct timeval tv = { 2, 0 }; /* Wait no more than 2 seconds */
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ res = select(fd + 1, &fds, NULL, NULL, &tv);
+ if (res < 1) {
+ ast_log(LOG_NOTICE, "Selected timed out/errored out with %d\n", res);
+ return -1;
+ }
+ return read(fd, data, datalen);
+
+}
+
static int mp3_exec(struct ast_channel *chan, void *data)
{
int res=0;
@@ -132,7 +148,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
}
ast_frfree(f);
} else {
- res = read(fds[0], myf.frdata, sizeof(myf.frdata));
+ res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
if (res > 0) {
myf.f.frametype = AST_FRAME_VOICE;
myf.f.subclass = AST_FORMAT_SLINEAR;