--- trunk/app_fax.c 2010/03/22 14:24:14 2 +++ trunk/app_fax.c 2010/03/22 15:19:52 3 @@ -51,6 +51,7 @@ "The option string may contain zero or more of the following characters:\n" " 'a' - makes the application behave as an answering machine\n" " The default behaviour is to behave as a calling machine.\n" +" 't(x) - sets the response timeout to x seconds.\n" "\n" "This application uses following variables:\n" " LOCALSTATIONID to identify itself to the remote end.\n" @@ -313,7 +314,7 @@ /* === Transmission === */ -static int transmit_audio(fax_session *s) +static int transmit_audio(fax_session *s, int resp_timeout) { int res = -1; int original_read_fmt = AST_FORMAT_SLINEAR; @@ -327,6 +328,7 @@ int last_state = 0; struct timeval now, start, state_change; enum ast_control_t38 t38control; + int transmit_started = 0; #if SPANDSP_RELEASE_DATE >= 20081012 /* for spandsp shaphots 0.0.6 and higher */ @@ -396,6 +398,12 @@ break; } + if (!transmit_started && resp_timeout && ast_tvdiff_sec(now, start) > resp_timeout) { + ast_debug(1, "No FAX response\n"); + res = -1; + break; + } + res = ast_waitfor(s->chan, 50); if (res > 0) res = 0; @@ -447,6 +455,7 @@ if (last_state != t30state->state) { state_change = ast_tvnow(); last_state = t30state->state; + transmit_started = 1; } } else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass == AST_CONTROL_T38 && inf->datalen == sizeof(enum ast_control_t38)) { @@ -498,7 +507,7 @@ } -static int transmit_t38(fax_session *s) +static int transmit_t38(fax_session *s, int resp_timeout) { int res = 0; t38_terminal_state_t t38; @@ -506,6 +515,7 @@ int last_state = 0; struct timeval now, start, state_change, last_frame; enum ast_control_t38 t38control; + int transmit_started = 0; t30_state_t *t30state; t38_core_state_t *t38state; @@ -550,6 +560,12 @@ break; } + if (!transmit_started && resp_timeout && ast_tvdiff_sec(now, start) > resp_timeout) { + ast_debug(1, "No FAX response\n"); + res = -1; + break; + } + res = ast_waitfor(s->chan, 20); if (res < 0) break; @@ -579,6 +595,7 @@ if (last_state != t30state->state) { state_change = ast_tvnow(); last_state = t30state->state; + transmit_started = 1; } } else if (inf->frametype == AST_FRAME_CONTROL && inf->subclass == AST_CONTROL_T38 && inf->datalen == sizeof(enum ast_control_t38)) { @@ -607,7 +624,7 @@ return res; } -static int transmit(fax_session *s) +static int transmit(fax_session *s, int resp_timeout) { int res = 0; @@ -636,7 +653,7 @@ if (s->t38state != T38_STATE_NEGOTIATED) { /* T38 is not negotiated on the channel yet. First start regular transmission. If it switches to T38, follow */ pbx_builtin_setvar_helper(s->chan, "FAXMODE", "audio"); - res = transmit_audio(s); + res = transmit_audio(s, resp_timeout); if (res > 0) { /* transmit_audio reports switchover to T38. Update t38state */ s->t38state = ast_channel_get_t38_state(s->chan); @@ -648,7 +665,7 @@ if (s->t38state == T38_STATE_NEGOTIATED) { pbx_builtin_setvar_helper(s->chan, "FAXMODE", "T38"); - res = transmit_t38(s); + res = transmit_t38(s, resp_timeout); } if (res) { @@ -670,6 +687,7 @@ int res = 0; char *parse; fax_session session; + int resp_timeout = 0; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(file_name); @@ -696,6 +714,7 @@ if (args.options) { if (strchr(args.options, 'a')) session.caller_mode = FALSE; + sscanf( args.options, "t(%d)", &resp_timeout); } /* Done parsing */ @@ -704,7 +723,7 @@ session.chan = chan; session.finished = 0; - res = transmit(&session); + res = transmit(&session, resp_timeout); return res; } @@ -748,7 +767,7 @@ session.chan = chan; session.finished = 0; - res = transmit(&session); + res = transmit(&session, 0); return res; }