Asterisk 20.6, AudioSocket audio flow not consistent, RTP ok ish

Hi everyone,

I am dealing with a difficult and intermittent media issue in Asterisk 20.6 (installed via Ubuntu apt). I am using chan_sip and the built-in chan_audiosocket module. Calls are originated using Local channels (two-leg call: SIP trunk + AudioSocket).

This issue does not happen on every call. Some calls work perfectly from start to finish. Others show the problem described below. The behavior is inconsistent.

The issue is intermittent:

  • Some calls: completely normal

  • Some calls: require a kick then become normal

  • Some calls: never stabilize

  • No consistent pattern

Summary of the problem with bad calls:

  1. During ringing: RTP flows normally from the SIP trunk into Asterisk. Ringing sound sometimes gets passed to the AS.

  2. When the call is answered OR when the AudioSocket leg connects: No more RTP packets appear in “rtp set debug”.

  3. If I send even a tiny amount of audio back through the AudioSocket connection (“kick start”): RTP immediately resumes flowing from the SIP trunk.

  4. After RTP resumes: the call either stabilise or not, inconsistent

Environment:

  • Asterisk 20.6.0

  • Installed from Ubuntu apt repository

  • SIP driver: chan_sip

  • Media: alaw

  • AudioSocket: built-in chan_audiosocket

  • OS: Ubuntu Linux

  • AudioSocket connects to localhost (127.0.0.1) TCP ports 4501–4532

  • No firewall involvement (local traffic; INPUT ACCEPT policy)

System architecture:
SIP Trunk Provider → Asterisk → audiosocket → My AS Server

Call origination:
from python:
cli_cmd = [
“sudo”, “-S”, “asterisk”, “-rx”,
f"channel originate Local/{source_number}-{number}-{as_port}@outbound_audiosocket/n "
f"extension {source_number}-{number}-{as_port}@outbound_siptrunk"
]

sip.conf: (censored the host ips)

[general]
context=from-internal
udpbindaddr=0.0.0.0
transport=udp
nat=force_rport
canreinvite=no
directmedia=no
externip=149.106.251.5
localnet=192.168.1.0/255.255.255.0
localnet=10.0.0.0/255.255.255.0
disallow=all
allow=alaw
allowguest=no
alwaysauthreject=yes
silentreject=yes
autodomain=no
deny=0.0.0.0/0.0.0.0
permit=….
permit=….
permit=192.168.1.0/255.255.255.0
permit=10.0.0.0/255.255.255.0
externrefresh=10
rtpkeepalive=5
tcpenable=no
sipdebug=no

[trunk_provider_2]
type=peer
host=…
port=5060
insecure=port,invite
qualify=yes
qualifyfreq=60
nat=no
context=from-trunk
disallow=all
allow=alaw
canreinvite=no
directmedia=no

[trunk_provider_1]
type=peer
host=…
port=5060
insecure=port,invite
qualify=yes
qualifyfreq=60
nat=no
context=from-trunk
disallow=all
allow=alaw
canreinvite=no
directmedia=no

extentions.conf:

[general]
static=yes
writeprotect=no

[outbound_siptrunk]
; Leg that dials the destination via SIP trunk
; EXTEN format: source_number-number-audio_port
exten => _X-X-X.,1,NoOp([outbound_siptrunk] Outbound SIP trunk leg - EXTEN: ${EXTEN})
same => n,Verbose(1,[outbound_siptrunk] Answer() SIP leg)
same => n,Answer()

; Parse parts from EXTEN
same => n,Set(source_number=${CUT(EXTEN,-,1)})
same => n,Set(phone_number=${CUT(EXTEN,-,2)})
same => n,Verbose(1,[outbound_siptrunk] Dialing ${phone_number} from source ${source_number})

; Caller ID
same => n,Set(CALLERID(all)=“${source_number}” <${source_number}>)
same => n,Verbose(1,[outbound_siptrunk] Running Dial() to trunk_provider_1)

; Dial via trunk
same => n,Dial(SIP/${phone_number}@trunk_provider_1,60)

same => n,Verbose(1,[outbound_siptrunk] Hangup())
same => n,Hangup()

[outbound_audiosocket]
; Leg that connects to AudioSocket
; EXTEN format: source_number-number-audio_port
exten => _X-X-X.,1,NoOp([outbound_audiosocket] AudioSocket leg - EXTEN: ${EXTEN})
same => n,Verbose(1,[outbound_audiosocket] Answer() AudioSocket leg)
same => n,Answer()

; (If you still need your keepalive/timer logic, you can put it here)
; same => n,Set(timer=$[${timer} + ${step}])
; same => n,GotoIf($[${timer} < ${loop_time}]?loop_alive)

; Parse the AudioSocket port
same => n,Set(audiosocket_port=${CUT(EXTEN,-,3)})
same => n,Verbose(1,[outbound_audiosocket] audiosocket_port=${audiosocket_port})

; Generate UUID
same => n,Set(uuid=${SHELL(uuidgen | tr -d ‘\n\r’)})
same => n,Verbose(1,[outbound_audiosocket] uuid=${uuid})

; Connect to AudioSocket
same => n,Verbose(1,[outbound_audiosocket] Connect to AudioSocket)
same => n,AudioSocket(${uuid},127.0.0.1:${audiosocket_port})

same => n,Verbose(1,[outbound_audiosocket] Hangup())
same => n,Hangup()

minimal timeline according to logs:

  1. outbound audio socket legs start and goes to answer function.
  2. outbound sip trunk goes now and work up to Dial.
    - at this pont rtp will start flowing, and I can record the beeping sounds on my AS server (future problem to fix)
  3. outbound audio socket continue after answer funciton and connect to Audio Socket.
    • rtp flow can stop here
  4. phone start ringing.
    • rtp flow can stop here also
  5. call is established at this point and no more logs untill hangup.
    • at this point if rpt “from” and “sent” are flowing then call is ok, but sometime it will not
  6. when rtp not flowing I ususly do the “kickstart” of sending audio from AS server to asterisk.
    • sometimes it fixes sometimes it doesnt.
    • when it doesnt fixed you can see rtp coming in but not msgs recived on the AS server side. and the call remain dead,

For some reason I can still send audio from AS server to asterisk and it will get to phone, regardless of broken call or not.

Any insight from people familiar with Asterisk media handling or chan_audiosocket would be very helpful. This is extremely difficult to debug because it only happens on some calls and produces no errors.

Thank you.

Be aware that Debian, and Ubuntu, includes patches that are not included in normal Asterisk - one of which we had to revert because it broke faxing. There have been past posts on here from people using the package where their audio doesn’t flow due to one of the patches. Building Asterisk from source then resolves the issue[1]. I would highly suggest trying that first and eliminating it as a factor.

[1] SSRC change + bridging

I tried building 20.17 and I recall it had the same problem.

I will try again tomorrow.

the reason I came back to 20.6 is the codec amr-wb support that was missing for me in the 20.17, but since nothing is working right Ig I will stay on alaw and try to build again.

On Monday 24 November 2025 at 20:31:23, hilawolf1002 via Asterisk Community
wrote:

  1. When the call is answered OR when the AudioSocket leg connects: No more
    RTP packets appear in “rtp set debug”.

  2. If I send even a tiny amount of audio back through the AudioSocket
    connection (“kick start”): RTP immediately resumes flowing from the SIP
    trunk.

externip=149.106.251.5
localnet=192.168.1.0/255.255.255.0

This looks strongly to me like a router problem. You said that there is no
firewall involved, however you clearly have a NAT router between Asterisk and
the external provider.

  1. Does this router have a “SIP helper” or “SIP ALG” (Application Layer
    Gateway)? If so, turn it OFF.

  2. Can you capture RTP packets on the router itself (and on both its internal
    and external interfaces), to see whether there is traffic coming from the
    external provider, but not being routed through to Asterisk until you “kick”
    the process by sending RTP out to the provider?

  3. You say that the problem is intermittent - does it only happen when you
    have just a single call between Asterisk and the external provider, but if
    there is another call already in progress, a call which gets set up at the
    same time works perfectly normally?

I suggest that latter because it could be that the first ongoing call keeps the
connection (and the reverse reply connection) through the router open, whereas
if there is no continuous traffic, a new call might get the problem if the
router doesn’t accept the reverse reply traffic until it sees some outbound
traffic first.

Antony.


The difference between theory and practice is that in theory there is no
difference, whereas in practice there is.

It’s the next day.
Cleaned and uninstalled the old Asterisk 20.6, built and installed 20.17.
As per your advice, I found SIP ALG in the router and turned it off.
Made the minimal adjustments necessary for the extensions.conf, and switched to using pjsip.conf instead of sip.conf.
Seems to be working now. Hooray!
Tested a single call, a call right after restart, calls one after another straight away — did about 10 calls total, tested 2 calls at the same time. All works now.
If the problem comes back in the future I will let you guys know.
Thank you so much for the help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.