Enabling jitterbuffer between a SIP trunk and IVR


I run FreePBX on a dedicated server within LAN and it is behind NAT. I have a pretty good symmetric gigabit internet connection. My system has a single PJSIP-trunk connection to my VoIP provider and a bunch of local extensions.

Everything works fine for regular inbound and outbound phone calls through the trunk, as well as local calls between extensions work great.

However, when I enable IVR (or voicemail) for the inboud calls, some (~1 out of 5) of the calls from the trunk either have hiccups in the beginning (in the first 1-2 seconds) after the IVR picks up the line,
or, sometimes, the caller hears only several fragmentary sounds of the IVR greeting and then the audio just stops.

I can see in sngrep that in the latter case the incoming(?) RTP stream from the VoIP provider fully stops. When it happens, and if the caller stays on the line just listening silence, the inboud call eventually times out after few minutes.

To cope with hiccups I’ve added a 2 seconds silence before the IVR greeting and it partially solved the problem. But, unfirtunately, some calls coming to IVR still loose the incoming RTP stream…

I noticed that this problem mostly happens to inboud calls from cellular networks, as those packets often have higher jitter.

I’m guessing that the problem is that for regular incoming calls my VoIP phones (Cisco SPA504G) have their own jitter buffers, that’s why everything works just fine. However, for IVR the jitter buffer should be manually enabled in FreePBX between the trunk and IVR.

I have found these articles:


But it is not really clear how to enable the jitter buffer in FreePBX for the inbound route between the SIP trunk and IVR.

I guess, I need to modify /etc/asterisk/extensions_custom.conf. My SIP trunk uses from-pstn context. I tried to make my own context from-pstn-buffered, but I’m not sure it works for IVR:

exten => s,1,NoOp(From PSTN buffered)
same => n,Set(JITTERBUFFER(fixed)=210,1500)
same => n,Goto(from-pstn,${EXTEN},1)

Is it getting optimized away or should I use one of those local channels? It’s not really clear to me.

Any help would be much appreciated, thank you!

I have also read this topic but still couldn’t figure it out:

I would like to have the jitter buffer enabled only between the inboud trunk calls and IVR.

But when an external call from the trunk is further routed by IVR to an extenstion, I would like not to have the jitter buffer enabled anymore to avoid extra delay, as it will be handled by the Cisco phone itself.

Sorry, I don’t know the technical details, but when playing an IVR announcement, Asterisk should be sending samples based on its internal clock, independent of any RTP coming in. If this clock isn’t working, it falls back to sending a sample out when one comes in.

Once you fix that, a jitter buffer won’t be needed.

Ah, okay. Thank you! I have the Asterisk module res_timing_timerfd.so loaded in modules.conf and the line internal_timing=yes in asterisk.conf.

I also tried another trunk provider with a closer datacenter. The problem seems to dissapear for now.