Send RTP keepalive packets to keep call from dropping

We are using Twilio service as a call platform and I want to use Asterisk to monitor the calls between the parties so I’ve set up an Asterisk 13 server using MixMonitor and a very simple extension. It looks like this:

[from-sip-external]
exten => _X.,1,Set(__FROM_DID=${EXTEN})
exten => _X.,n,Goto(s,1)
exten => s,1,MixMonitor(${MIXMON_DIR}${STRFTIME(${EPOCH},%Y%m%d-%H%M%S)}${UNIQUEID}.wav,${MONITOR_OPTIONS},/bin/mv ${MIXMON_DIR}${STRFTIME(${EPOCH},%Y%m%d-%H%M%S)}${UNIQUEID}.wav /record/)
exten => s,n,Answer(10)

The way it works is once the call has been established between the two parties, Twilio initiates a third leg of the call to my server. My server answers the call and immediately begins to record the audio to a file in the default /var/spool/asterisk/monitor directory. When the call completes the file is moved to the /record directory and processed. This all works as expected.

The problem I am having is that Twilio expects to receive audio back from my server periodically or it thinks that the channel is dead and since this server is only recording the incoming audio and sending nothing back Twilio terminates the entire call at the one minute mark. I need to find a way to send some kind of keepalive RTP packet back to Twilio every 30 seconds so that they think there is audio and won’t kill the channel.

Is there a way to do what I need? I thought maybe I could use something like ChanSpy to initiate white noise every 30 seconds but I’ve not found a way to do this in a loop. I wouldn’t even mind having Asterisk play a .gsm or .wav file with 1 second of white noise every so often but I’m not sure how to do that or if it is even possible.

Any suggestions would be appreciated.

Both chan_sip and chan_pjsip have keepalive options which send an RTP keepalive packet periodically. In the case of chan_sip it’s named keepalive, and in the case of chan_pjsip it is rtp_keepalive.

1 Like

Thank you! That did solve the problem of the call dropping at the one minute mark. However, it now drops at the minute and a half mark with about 50 of these errors:

[2017-08-03 20:37:03] WARNING[4612][C-00000011]: channel.c:1142 __ast_queue_frame: Exceptionally long voice queue length queuing to SIP/Azure-00000011

followed by:

-- Executing [s@from-sip-external:3] Set("SIP/Azure-00000011", "CHANNEL(language)=") in new stack
-- Executing [s@from-sip-external:4] Goto("SIP/Azure-00000011", "from-trunk,,1") in new stack
-- Goto (from-trunk,s,1)
-- Executing [s@from-trunk:1] NoOp("SIP/Azure-00000011", "No DID or CID Match") in new stack
-- Executing [s@from-trunk:2] Answer("SIP/Azure-00000011", "") in new stack
-- Executing [s@from-trunk:3] Log("SIP/Azure-00000011", "WARNING,Friendly Scanner from 10.253.254.121") in new stack

[2017-08-03 20:37:04] WARNING[4612][C-00000011]: Ext. s:3 @ from-trunk: Friendly Scanner from 10.253.254.121
– Executing [s@from-trunk:4] Wait(“SIP/Azure-00000011”, “2”) in new stack
– Executing [s@from-trunk:5] Playback(“SIP/Azure-0000000d”, “ss-noservice”) in new stack
– <SIP/Azure-0000000d> Playing ‘ss-noservice.gsm’ (language ‘’)
– Executing [s@from-trunk:5] Playback(“SIP/Azure-0000000e”, “ss-noservice”) in new stack
– <SIP/Azure-0000000e> Playing ‘ss-noservice.gsm’ (language ‘’)
– Executing [s@from-trunk:5] Playback(“SIP/Azure-0000000f”, “ss-noservice”) in new stack
– <SIP/Azure-0000000f> Playing ‘ss-noservice.gsm’ (language ‘’)
– Executing [s@from-trunk:5] Playback(“SIP/Azure-00000010”, “ss-noservice”) in new stack
– <SIP/Azure-00000010> Playing ‘ss-noservice.gsm’ (language ‘’)

and the call drops.

Do you have internal timing enabled? This could be due to the lack of that.