aboutsummaryrefslogtreecommitdiffstats
path: root/apps/app_fax.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-26 15:46:28 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2009-10-26 15:46:28 +0000
commit37e2fe327da69f8182b20c11dfd52f3867b22580 (patch)
tree30b8409839397786a0fef1cd8cb345f4e7623080 /apps/app_fax.c
parentfb48feade2efb94c016aa0991cf51ba392fd85cf (diff)
Backport audio handling loop fixes from trunk version of app_fax.
This backport resolves some issues handling audio frames during FAX processing, and ensures that the FAX application doesn't accidentally get notified of a T.38 switchover at the end of a successful FAX. (issue #16127) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@225869 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps/app_fax.c')
-rw-r--r--apps/app_fax.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/apps/app_fax.c b/apps/app_fax.c
index de66777f6..70a1bdd3a 100644
--- a/apps/app_fax.c
+++ b/apps/app_fax.c
@@ -445,14 +445,30 @@ static int transmit_audio(fax_session *s)
ast_activate_generator(s->chan, &generator, &fax);
while (!s->finished) {
- res = ast_waitfor(s->chan, 20);
- if (res < 0)
+ inf = NULL;
+
+ if ((res = ast_waitfor(s->chan, 25)) < 0) {
+ ast_debug(1, "Error waiting for a frame\n");
break;
- else if (res > 0)
- res = 0;
+ }
- inf = ast_read(s->chan);
- if (inf == NULL) {
+ /* Watchdog */
+ now = ast_tvnow();
+ if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
+ ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
+ res = -1;
+ break;
+ }
+
+ if (!res) {
+ /* There was timeout waiting for a frame. Loop around and wait again */
+ continue;
+ }
+
+ /* There is a frame available. Get it */
+ res = 0;
+
+ if (!(inf = ast_read(s->chan))) {
ast_debug(1, "Channel hangup\n");
res = -1;
break;
@@ -461,7 +477,7 @@ static int transmit_audio(fax_session *s)
ast_debug(10, "frame %d/%d, len=%d\n", inf->frametype, inf->subclass, inf->datalen);
/* Check the frame type. Format also must be checked because there is a chance
- that a frame in old format was already queued before we set chanel format
+ that a frame in old format was already queued before we set channel format
to slinear so it will still be received by ast_read */
if (inf->frametype == AST_FRAME_VOICE && inf->subclass == AST_FORMAT_SLINEAR) {
if (fax_rx(&fax, inf->data, inf->samples) < 0) {
@@ -470,8 +486,6 @@ static int transmit_audio(fax_session *s)
res = -1;
break;
}
-
- /* Watchdog */
if (last_state != t30state->state) {
state_change = ast_tvnow();
last_state = t30state->state;
@@ -498,15 +512,6 @@ static int transmit_audio(fax_session *s)
}
ast_frfree(inf);
- inf = NULL;
-
- /* Watchdog */
- now = ast_tvnow();
- if (ast_tvdiff_sec(now, start) > WATCHDOG_TOTAL_TIMEOUT || ast_tvdiff_sec(now, state_change) > WATCHDOG_STATE_TIMEOUT) {
- ast_log(LOG_WARNING, "It looks like we hung. Aborting.\n");
- res = -1;
- break;
- }
}
ast_debug(1, "Loop finished, res=%d\n", res);