dect
/
asterisk
Archived
13
0
Fork 0

First pass at restoring festival operation

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1323 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
markster 2003-08-14 15:58:55 +00:00
parent 9d95cf1953
commit 18ecda6b7d
1 changed files with 26 additions and 47 deletions

View File

@ -125,9 +125,9 @@ static int send_waveform_to_fd(char *waveform, int length, int fd) {
static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length) { static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length) {
int res=0; int res=0;
int fds[2]; int fds[2];
int rfds[1 + AST_MAX_FDS];
int ms = -1; int ms = -1;
int pid = -1; int pid = -1;
int needed = 0;
int us; int us;
int exception; int exception;
int owriteformat; int owriteformat;
@ -135,10 +135,11 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
struct timeval last; struct timeval last;
struct ast_frame *f; struct ast_frame *f;
int x; int x;
struct ast_frame *winner;
struct myframe { struct myframe {
struct ast_frame f; struct ast_frame f;
char offset[AST_FRIENDLY_OFFSET]; char offset[AST_FRIENDLY_OFFSET];
char frdata[160]; char frdata[2048];
} myf; } myf;
last.tv_usec = 0; last.tv_usec = 0;
last.tv_sec = 0; last.tv_sec = 0;
@ -162,53 +163,34 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
pid = res; pid = res;
/* Order is important -- there's almost always going to be mp3... we want to prioritize the /* Order is important -- there's almost always going to be mp3... we want to prioritize the
user */ user */
rfds[AST_MAX_FDS] = fds[0];
for (;;) { for (;;) {
CHECK_BLOCKING(chan); ms = 1000;
for (x=0;x<AST_MAX_FDS;x++) res = ast_waitfor(chan, ms);
rfds[x] = chan->fds[x];
res = ast_waitfor_n_fd(rfds, AST_MAX_FDS+1, &ms, &exception);
chan->blocking = 0;
if (res < 1) { if (res < 1) {
ast_log(LOG_DEBUG, "Hangup detected\n");
res = -1; res = -1;
break; break;
} }
for(x=0;x<AST_MAX_FDS;x++) f = ast_read(chan);
if (res == chan->fds[x]) if (!f) {
break; ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
res = -1;
if (x < AST_MAX_FDS) { break;
if (exception) }
chan->exception = 1; if (f->frametype == AST_FRAME_DTMF) {
f = ast_read(chan); ast_log(LOG_DEBUG, "User pressed a key\n");
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); ast_frfree(f);
} else if (res == fds[0]) { res = 0;
gettimeofday(&tv, NULL); break;
if (last.tv_sec || last.tv_usec) { }
/* We should wait at least a frame length */ if (f->frametype == AST_FRAME_VOICE) {
us = sizeof(myf.frdata) / 16 * 1000; /* Treat as a generator */
/* Subtract 1,000,000 us for each second late we've passed */ needed = f->sample * 2;
us -= (tv.tv_sec - last.tv_sec) * 1000000; if (needed > sizeof(myf.frdata)) {
/* And one for each us late we've passed */ ast_log(LOG_WARNING, "Only able to deliver %d of %d requested samples\n",
us -= (tv.tv_usec - last.tv_usec); sizeof(myf.frdata) / 2, needed/2);
/* Sleep that long if needed */ needed = sizeof(myf.frdata);
if (us > 0)
usleep(us);
} }
last = tv; res = read(fds[0], myf.frdata, needed);
res = 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;
@ -222,7 +204,7 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
res = -1; res = -1;
break; break;
} }
if (res < sizeof(myf.frdata)) { // last frame if (res < needed) { // last frame
ast_log(LOG_WARNING, "Last frame\n"); ast_log(LOG_WARNING, "Last frame\n");
res=0; res=0;
break; break;
@ -231,11 +213,8 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
ast_log(LOG_WARNING, "No more waveform\n"); ast_log(LOG_WARNING, "No more waveform\n");
res = 0; res = 0;
} }
} else {
ast_log(LOG_DEBUG, "HuhHHH?\n");
res = -1;
break;
} }
ast_frfree(f);
} }
} }
close(fds[0]); close(fds[0]);