I'm using self hosted livekit for my telephony app...
# ask-ai
n
I'm using self hosted livekit for my telephony application now the problem is at times while I'm connecting over sip calls in UDP protocol, the audio is breaking. How can I resolve this ?
t
Thanks for reaching out, Hrithik. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm here to help you with the audio breaking issue during SIP calls over UDP. To get a better understanding and assist you more effectively, could you please share a bit more about your setup? For example: • Are you using a specific SIP gateway or server? • What’s your network environment like? Is there high latency or packet loss? • Have you had a chance to try other protocols like TCP or TLS to see if the problem still occurs? • Have you noticed any error logs or particular patterns when the audio cuts out? These details will really help us pinpoint the cause and find the best solution together.
n
I'm using a specific self hosted sip gateway. In terms of network environment I'm facing both of them now since I'm using a custom sip provider, I can't test with other transport protocols like tcp and tls. In terms of error logs I'm not able to find any pattern as well
t
I understand how frustrating audio breaking issues during SIP calls over UDP can be, and I’m here to help you work through this. These problems often come from network-related factors like packet loss, jitter, or latency, which UDP is a bit sensitive to. Let’s try a few steps together to troubleshoot and hopefully resolve this: • First, please check that your network allows UDP traffic on the RTP ports set in your LiveKit configuration (for example,
rtcconfig.PortRange
). Also, make sure that firewalls or NATs aren’t dropping any packets. • Try enabling debug logging in your LiveKit setup by setting the
SIP_DEBUG
environment variable. This can give us valuable clues about issues like MTU-related congestion or packet fragmentation. • It’s worth checking if the MTU size might be causing packet loss. LiveKit defaults to an MTU size of 1500 bytes, and if packets are oversized, they might get fragmented or lost. The debug logs can show warnings if this is happening. • Using packet capture tools like Wireshark can be really helpful to analyze the media path and spot any patterns of packet loss or misrouting. • Lastly, if you have access to LiveKit’s RTPStats, monitoring metrics such as packet loss rate, jitter, and drift can provide great insights into the media quality. These steps should guide you toward identifying and fixing the root cause of the audio breaking. Please don’t hesitate to reach out if you’d like me to walk you through any of these steps or if you have any other questions—I’m here to support you! Sources: SIP troubleshooting guide | LiveKit Docs | livekit-protocol/src/livekit.rs | pkg/sip/media_port_test.go | server_test.go | protobufs/livekit_models.proto
n
how can I access RTPStats ?
t
I'm glad you're interested in accessing RTPStats in LiveKit to keep an eye on important metrics like packet loss, jitter, and drift. Here’s a friendly guide to help you retrieve these statistics: • Server-Side (Go): You can find RTPStats within the SFU internals. Using the
toProto
method, you’ll be able to get valuable data such as
packets_lost
,
jitter_current
, and drift values. This is especially handy if you’re customizing or extending LiveKit services. • Client SDKs: Most client SDKs offer APIs that let you fetch RTPStats for specific tracks, making it easier to monitor performance on the client side: • Flutter (Dart): Simply call
track.getStats()
to get RTPStats. Here’s a quick example:
Copy code
RTPStats stats = await track.getStats();
print('Packets Lost: ${stats.packetsLost}');
print('Jitter Current: ${stats.jitterCurrent} µs');
• Python: You can use
track.get_stats()
to access these metrics. Here’s how it looks:
Copy code
stats = await track.get_stats()
print(f"Jitter: {stats.jitter_current} µs")
print(f"Packet Loss %: {stats.packet_loss_percentage}")
• Node.js: The
ReceivedRtpStreamStats
interface helps you get jitter and packet loss stats, though drift metrics might not be fully available just yet. If you’d like, I’m here to provide specific examples or help you with a particular SDK. Just let me know how I can support you! Sources: livekit-ffi/protocol/stats.proto | livekit/livekit_models.pb.go | pkg/sfu/rtpstats/rtpstats_receiver_test.go | lib/src/proto/livekit_models.pb.dart | livekit-protocol/livekit/protocol/models.pyi
n
How can I get the track in python ?