Monday, May 16, 2011

Answer monitoring when the PSTN side does not support reverse polarity

In many circumstances, we need to know whether a pstn call is answered or not after dial out, for example, to start billing.
It would be a simple case when both pstn side and our fxo gateway support reverse polarity such that we could literally obtain a correct asterisk variable ${DIALSTATUS}.  As illustrated below,
exten => _X,n,dial(sip/gw/${EXTEN},g)
exten => _X.n,noop(${DIALSTATUS}
After the call is finished (use of the 'g' option), in the next priority in the dial plan, we check the ${DIALSTATUS} for ANSWER,BUSY,NOANSWER,CONGESTION, etc.
However, we sometimes see cases where DIALSTATUS is always ANSWER because reverse polarity is not supported in either parties and the fxo gateway just returns 200 OK at every callout regardless whether call is actually answered.
To circumvent this situation, we could use BackgroundDetect as an approximate answer detection mechanism.  It is approximate because call answer is not determined by circuit signal, but by detecting human answer pattern.
For instance, If we initiate outbound calls via call file, we could bridge the always answered call to BackgroundDetect.
Channel: SIP/gw/XXXXXXXX
Context: outbound
Extension: answer_monitor
exten => answer_monitor,n,BackgroundDetect(silence/10,1000,50,4000)
exten => answer_monitor,n,noop('machine')
exten => talk,1,noop('human')
In our scenario, the application BackgroundDetect plays a silence of 10s during which noise is monitored in the receiving direction.  If it detects any noise period of length between 50ms and 4000ms, followed by a silence of 1000ms, it jumps to the talk extension.  The figures above are assumed to reflect typical human 'hello'.

No comments:

Post a Comment