@ -432,14 +432,28 @@ 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 , 20 ) ) < 0 ) {
break ;
else if ( res > 0 )
res = 0 ;
}
/* if nothing arrived, check the watchdog timers */
if ( res = = 0 ) {
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 ;
} else {
/* timers have not triggered, loop around to wait
* again
*/
continue ;
}
}
inf = ast_read ( s - > chan ) ;
if ( inf = = NULL ) {
if ( ! ( inf = ast_read ( s - > chan ) ) ) {
ast_debug ( 1 , " Channel hangup \n " ) ;
res = - 1 ;
break ;
@ -473,7 +487,7 @@ static int transmit_audio(fax_session *s)
/* 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 chan el format
that a frame in old format was already queued before we set chan n el 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 . ptr , inf - > samples ) < 0 ) {
@ -482,8 +496,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 ;
@ -517,15 +529,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 ) ;
@ -617,19 +620,31 @@ static int transmit_t38(fax_session *s)
now = start = state_change = ast_tvnow ( ) ;
while ( ! s - > finished ) {
res = ast_waitfor ( s - > chan , 20 ) ;
if ( res < 0 )
inf = NULL ;
if ( ( res = ast_waitfor ( s - > chan , 20 ) ) < 0 ) {
break ;
else if ( res > 0 )
res = 0 ;
}
last_frame = now ;
now = ast_tvnow ( ) ;
/* if nothing arrived, check the watchdog timers */
if ( res = = 0 ) {
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 ;
} else {
/* timers have not triggered, loop around to wait
* again
*/
t38_terminal_send_timeout ( & t38 , ast_tvdiff_us ( now , last_frame ) / ( 1000000 / 8000 ) ) ;
continue ;
}
}
t38_terminal_send_timeout ( & t38 , ast_tvdiff_us ( now , last_frame ) / ( 1000000 / 8000 ) ) ;
inf = ast_read ( s - > chan ) ;
if ( inf = = NULL ) {
if ( ! ( inf = ast_read ( s - > chan ) ) ) {
ast_debug ( 1 , " Channel hangup \n " ) ;
res = - 1 ;
break ;
@ -639,8 +654,6 @@ static int transmit_t38(fax_session *s)
if ( inf - > frametype = = AST_FRAME_MODEM & & inf - > subclass = = AST_MODEM_T38 ) {
t38_core_rx_ifp_packet ( t38state , inf - > data . ptr , inf - > datalen , inf - > seqno ) ;
/* Watchdog */
if ( last_state ! = t30state - > state ) {
state_change = ast_tvnow ( ) ;
last_state = t30state - > state ;
@ -654,14 +667,6 @@ static int transmit_t38(fax_session *s)
}
ast_frfree ( inf ) ;
inf = NULL ;
/* Watchdog */
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 ) ;