sip icon indicating copy to clipboard operation
sip copied to clipboard

LiveKit SIP + Asterisk: "Media Timeout" Error When Receiving Calls

Open haitham-ramadan opened this issue 9 months ago • 7 comments

📞 Issue with LiveKit SIP + Asterisk: "Media Timeout" Error When Receiving Calls

Hey everyone,

I’ve configured Asterisk and LiveKit SIP on my server (Docker version), and I'm currently facing a frustrating issue.

When I try to make a call to a LiveKit SIP endpoint:

  • The call reaches LiveKit (I see it coming in),
  • But the agent does not respond,
  • And after a few seconds, I get a Media Timeout error.

Here’s a log snippet from livekit_sip:

sip_1 | 2025-04-21T23:34:19.883Z   WARN    sip     sip/inbound.go:721      Closing inbound call with error {"nodeID": "NE_JKTvPFRB8F4C", "callID": "SCL_AnxXXHcbPbJx", "fromIP": "197.60.191.230", "toIP": "167.71.48.30:5060", "fromHost": "167.71.48.30", "fromUser": "123", "toHost": "167.71.48.30", "toUser": "15105550100", "sipTag": "as0a5b1942", "sipCallID": "[email protected]:5060", "sipRule": "SDR_wchirf4FN4DF", "room": "test_room", "participant": "sip_123", "participantName": "Phone 123", "reason": "media-timeout"}

🔍 I’ve looked through this related issue but haven’t had success:
👉 https://github.com/livekit/sip/issues/231

I’ve double-checked:

  • SIP registration is correct
  • Asterisk and LiveKit are configured correctly
  • Room exists and credentials are right

Still can’t figure out why the media is not being negotiated or received. Any tips?

Thanks in advance 🙏 Image Image

haitham-ramadan avatar Apr 21 '25 23:04 haitham-ramadan

The problem is likely that something is blocking RTP traffic between the two services. Are these deployed on the same host?

dennwc avatar Apr 22 '25 17:04 dennwc

I have the same issue , but I am using livekit cloud. I have verified that RTP packets from asterisk have been sent to the livekit server but i have no way of verifying it if have been recieved there and I am not getting any incoming traffic. I have checked this with Wireshark.

KTarun003 avatar Apr 28 '25 11:04 KTarun003

My issue has been resolved, my server was in a private network hence I had to add NAT rule and add externip in sip.conf.

Like this:

[general]
externip=<ip>

KTarun003 avatar Apr 29 '25 11:04 KTarun003

Hi @KTarun003 and team, I'm following up on this issue because I implemented your NAT solution but now I'm getting a different error. Actual issue while the LiveKit-Asterisk integration is not getting audio back from LiveKit to SIP client.

My Setup:

  • Asterisk Server: 192.168.1.X (private), XXX.XXX.XXX.XXX (public IP via NAT)
  • LiveKit SIP URI: xxxxxxxxxx.sip.livekit.cloud
  • Internal Extensions: 1001, 1002 → calling → 2000 (LiveKit agent)

Error After NAT Configuration:

  • ERROR[90626]: res_rtp_asterisk.c:4067 rtp_allocate_transport: Oh dear... we couldn't allocate a port for RTP instance '0x7f44067e88'
  • ERROR[90626]: res_pjsip_sdp_rtp.c:271 create_rtp: Unable to create RTP instance using RTP engine 'asterisk'
  • ERROR[90626]: res_pjsip_session.c:5251 create_local_sdp: PJSIP/livekit-trunk-00000007: Couldn't add sdp streams for stream 0:audio-0:audio:sendrecv (ulaw)

My PJSIP Configuration:

Transport (with your NAT fix):
**[transport-tcp]**
type=transport
protocol=tcp
bind=0.0.0.0
allow_reload=yes
external_media_address=XXX.XXX.XXX.XXX
external_signaling_address=XXX.XXX.XXX.XXX
local_net=192.168.0.0/16

LiveKit Trunk Endpoint:

**[livekit-trunk]**
type=endpoint
aors=livekit-trunk-aor
context=from-internal
disallow=all
allow=ulaw
direct_media=no
transport=transport-tcp
rtp_symmetric=yes
force_rport=yes
rewrite_contact=yes
dtmf_mode=rfc4733
ice_support=no
rtp_timeout=0
rtp_timeout_hold=0

**[livekit-trunk-aor]**
type=aor
contact=sip:xxxxxxxxxx.sip.livekit.cloud;transport=tcp

**[livekit-trunk-identify]**
type=identify
endpoint=livekit-trunk
match=xxxxxxxxxx.sip.livekit.cloud

LiveKit SIP Trunk Configuration (inbound-trunk.json):

{ "sipTrunkId": "ST_xxxxxxxxxxxxx", "name": "LiveKitConnection", "numbers": ["2000"], "allowedAddresses": ["XXX.XXX.XXX.XXX"], "headers": { "X-LiveKit-MediaMode": "relay", "X-LiveKit-RTP-Mode": "force" }, "transport": "tcp", "ringingTimeout": 30, "maxCallDuration": 3600 }

Extensions Configuration:

[from-internal] exten => 2000,1,NoOp(Calling LiveKit Agent) exten => 2000,2,Set(CALLERID(name)=Internal Call) exten => 2000,3,Dial(PJSIP/2000@livekit-trunk,30) exten => 2000,4,Playback(sorry-cant-connect) exten => 2000,5,Hangup()

  • Did you encounter RTP allocation issues when implementing your NAT fix?
  • Do I need additional RTP configuration (like rtp.conf settings) for this to work?
  • Should I avoid forcing RTP binding to the external IP and let the transport handle it?
  • Are there any firewall/iptables rules I need for RTP port ranges?

What Works: ✅ Internal calls (1001 ↔ 1002) work perfectly ✅ SIP signaling reaches LiveKit (no authentication errors) ✅ LiveKit agent connects and can hear my audio and getting LLM output on terminal

What Doesn't Work: ❌ RTP port allocation fails when calling LiveKit trunk ❌ Agent audio doesn't reach caller (Not getting audio back)

System Info: Asterisk 20.14.1 LiveKit Cloud (Japan region)

Thanks in advance! 🙏

ashiknizarofficial avatar Jun 05 '25 17:06 ashiknizarofficial

My issue has been resolved, my server was in a private network hence I had to add NAT rule and add externip in sip.conf.

Like this:

[general]
externip=<ip>

Hello could you share your asterisk config please ? I am also trying to link asterisk to a self hosted docker sip.

kim-gtek avatar Jul 02 '25 12:07 kim-gtek

Hi, I had a similar issue and was able to resolve it. Here's what my setup looked like:

  • I was using self-hosted LiveKit with Asterisk (PJSIP) on the same local network (no NAT).

  • Inbound SIP calls from Asterisk to LiveKit connected, but:

    • I could hear the AI agent, but my audio wasn’t reaching LiveKit
    • Call dropped after ~30 seconds with a "media-timeout" error
  • I already had:

    • livekit and sip server self hosted
    • created inbound sip trunk
    • created dispatch rule
    • rtp ports (10000-20000) open
  • Fix: I added to the pjsip.conf

rtp_symmetric=yes
  • After that, audio worked in both directions and the media-timeout was resolved.

bpgatchalian avatar Jul 10 '25 03:07 bpgatchalian

Hi, I had a similar issue and was able to resolve it. Here's what my setup looked like:

  • I was using self-hosted LiveKit with Asterisk (PJSIP) on the same local network (no NAT).

  • Inbound SIP calls from Asterisk to LiveKit connected, but:

    • I could hear the AI agent, but my audio wasn’t reaching LiveKit
    • Call dropped after ~30 seconds with a "media-timeout" error
  • I already had:

    • livekit and sip server self hosted
    • created inbound sip trunk
    • created dispatch rule
    • rtp ports (10000-20000) open
  • Fix: I added to the pjsip.conf

rtp_symmetric=yes

  • After that, audio worked in both directions and the media-timeout was resolved.

I’m having the same issue. I have added rtp_symmetric=yes in my pjsip.conf, but the connection is still one-directional. I can hear the voice from my agent, but I’m unable to send my voice to the agent.

Siam456 avatar Sep 18 '25 13:09 Siam456