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:
-
During ringing: RTP flows normally from the SIP trunk into Asterisk. Ringing sound sometimes gets passed to the AS.
-
When the call is answered OR when the AudioSocket leg connects: No more RTP packets appear in “rtp set debug”.
-
If I send even a tiny amount of audio back through the AudioSocket connection (“kick start”): RTP immediately resumes flowing from the SIP trunk.
-
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:
- outbound audio socket legs start and goes to answer function.
- 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) - outbound audio socket continue after answer funciton and connect to Audio Socket.
- rtp flow can stop here
- phone start ringing.
- rtp flow can stop here also
- 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
- 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.