mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 18:40:46 +00:00
Make MP3 app timeout after a couple of seconds of no audio
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@884 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -68,6 +68,22 @@ static int mp3play(char *filename, int fd)
|
|||||||
return -1;
|
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)
|
static int mp3_exec(struct ast_channel *chan, void *data)
|
||||||
{
|
{
|
||||||
int res=0;
|
int res=0;
|
||||||
@@ -132,7 +148,7 @@ static int mp3_exec(struct ast_channel *chan, void *data)
|
|||||||
}
|
}
|
||||||
ast_frfree(f);
|
ast_frfree(f);
|
||||||
} else {
|
} else {
|
||||||
res = read(fds[0], myf.frdata, sizeof(myf.frdata));
|
res = timed_read(fds[0], myf.frdata, sizeof(myf.frdata));
|
||||||
if (res > 0) {
|
if (res > 0) {
|
||||||
myf.f.frametype = AST_FRAME_VOICE;
|
myf.f.frametype = AST_FRAME_VOICE;
|
||||||
myf.f.subclass = AST_FORMAT_SLINEAR;
|
myf.f.subclass = AST_FORMAT_SLINEAR;
|
||||||
|
Reference in New Issue
Block a user