For some time, I have wanted to log RTP stats at the end of every call, to assist in troubleshooting. rtpqos sometimes works, but as Trev mentioned in the other thread, its usefulness is limited. Sometimes it returns zero for everything, and I haven't been able to correct that.
Fortunately, my phone includes RTP stats in a special X-RTP-Stat header that it sends to Asterisk at the end of the call. It looks like this:
PS=211,OS=36292,PR=212,OR=36464,PL=0,JI=0,DU=4,EN=G711U,DE=G711U
Since my Asterisk PBX is configured not to proxy audio, these figures should be accurate. Many phones and ATAs do a similar thing, sometimes with a different header name. The trick is accessing it. If the far end hangs up first, the h extension runs before my phone sends the SIP packet with the X-RTP-Stat header.
A reliable way to access this SIP header is with the Dial options F (when caller hangs up, transfer called party), U (execute Gosub on called channel), g (continue with the dial plan after called party hangs up), and applying hangup handlers to the near side of the call.
[rtp-stats-test]exten => inbound,1,NoOp(Simulated inbound call) same => n,Dial(SIP/DeskPhone,,F(other-side-hung-up-first,1)U(add-hangup-for-other-side)) exten => outbound,1,NoOp(Simulated outbound call) same => n,Set(CHANNEL(hangup_handler_push)=hangup,1) same => n,Dial(SIP/some-external-destination,,g) same => n,Goto(other-side-hung-up-first,1) exten => other-side-hung-up-first,1,NoOp(Allow time for the near end to hang up.) same => n,Wait(15) same => n,Playtones(500*100/250,0/250) same => n,Wait(60) exten => hangup,1,NoOp(${SIP_HEADER(X-RTP-Stat)}) [add-hangup-for-other-side]exten => s,1,Set(CHANNEL(hangup_handler_push)=rtp-stats-test,hangup,1)
The above code works for both inbound and outbound calls, regardless of which end hangs up first.
↧