Audio delay of 2s for incoming calls - "Answer() before Dial()" fixed it!?

Hi, I’m running a fresh Asterisk 16.13.0 install. The Asterisk server is behind double NAT in a local LAN. The phones are in the same LAN. I’ve multiple sip accounts and sip providers.
Problem: If I receive a call on one of my sip accounts, the audio from the external caller to the local phone is delayed by about 2s. Audio from local phone to external caller is not delayed!

I thought this is a firewall/NAT problem but looks like I was wrong. Adding an Answer() before Dial() the local phone fixes the problem.

; extension with 2s delay for incoming pstn-call
[sipprovider-in]
exten = _X.,1,NoOp(Provider 1)
same = n,Dial(PJSIP/201,20)
same = n,Hangup()

Here is the log for the delayed example:

– Executing [xxxxxxxxxx@sipprovider-in:2] Dial(“PJSIP/sipprovider-0000003a”, “PJSIP/201,20”) in new stack
– Called PJSIP/201
– PJSIP/201-0000003b is ringing
– PJSIP/201-0000003b is ringing
0x7fee8001b7f0 – Strict RTP learning after remote address set to: 192.168.1.14:12528
– PJSIP/201-0000003b answered PJSIP/sipprovider-0000003a
0x7fee80093680 – Strict RTP learning after remote address set to: 62.xxx.xxx.xxx:17810

As you can see, the second strict RTP happens after the answered-line. This seems to cause the 2s delay in the audio stream from external caller to local phone.

Accidentally, I found a simple solution.

; extension without 2s delay for incoming pstn-call
[sipprovider-in]
exten = _X.,1,NoOp(Provider 1)
same = n,Answer()
same = n,Dial(PJSIP/201,20)
same = n,Hangup()

Here is the log for the non-delayed example:

– Executing [xxxxxxxxxx@sipprovider-in:3] Dial(“PJSIP/sipprovider-00000038”, “PJSIP/201,20”) in new stack
– Called PJSIP/201
– PJSIP/201-00000039 is ringing
– PJSIP/201-00000039 is ringing
0x7fee8006dec0 – Strict RTP switching to RTP target address 62.xxx.xxx.xxx:17832 as source
0x7fee8008a7d0 – Strict RTP learning after remote address set to: 192.168.1.14:12526
– PJSIP/201-00000039 answered PJSIP/sipprovider-00000038

Both strict RTP happen before the answered-line and magically there is no delay.

Question: Any idea why this happens and what a cleaner solution might be?

Thanks in advance.

I use SIP not PJSIP, and have noticed the same. I have multiple incoming providers, so it is definately on the asterisk end. Also Calling to the Echo Test for example I experience the same delay so the call is ansered to hear “…about to enter an echo test” and the “You are” is never heard. I had to set an intentional 2 second delay to an IVR menu on one inbound route too.

Answering the call is not a good solution and is only valid for inbounds. I was wondering if forcing the bridge type might make the connection happen faster, but do not know how to do this.

Interestingly, the echo test does not send any audio unless I answer the external call explicitly. Internal calls on the other hand can use the echo test without Answer() before Echo().

Interesting idea to force the bridge somehow. I’ll have a look. If I find a solution, I’ll post back. I consider answering every call to my sip accounts as not ideal, too.
Best

That’s not surprising. Providers don’t like giving away free services and charging only normally starts when the call is answered. Consequently, it would be very surprising for early media to work when going through a provider.

That sounds reasonable @david551 :wink: