First pass at restoring festival operation

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1323 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2003-08-14 15:58:55 +00:00
parent 78daafd161
commit 2edde8f5a4

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,25 +163,13 @@ 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++)
if (res == chan->fds[x])
break;
if (x < AST_MAX_FDS) {
if (exception)
chan->exception = 1;
f = ast_read(chan); f = ast_read(chan);
if (!f) { if (!f) {
ast_log(LOG_DEBUG, "Null frame == hangup() detected\n"); ast_log(LOG_DEBUG, "Null frame == hangup() detected\n");
@@ -193,22 +182,15 @@ static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, in
res = 0; res = 0;
break; break;
} }
ast_frfree(f); if (f->frametype == AST_FRAME_VOICE) {
} else if (res == fds[0]) { /* Treat as a generator */
gettimeofday(&tv, NULL); needed = f->sample * 2;
if (last.tv_sec || last.tv_usec) { if (needed > sizeof(myf.frdata)) {
/* We should wait at least a frame length */ ast_log(LOG_WARNING, "Only able to deliver %d of %d requested samples\n",
us = sizeof(myf.frdata) / 16 * 1000; sizeof(myf.frdata) / 2, needed/2);
/* Subtract 1,000,000 us for each second late we've passed */ needed = sizeof(myf.frdata);
us -= (tv.tv_sec - last.tv_sec) * 1000000;
/* And one for each us late we've passed */
us -= (tv.tv_usec - last.tv_usec);
/* Sleep that long if needed */
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]);