In an ideal world all media would go direct from one endpoint to another.
But it’s not an ideal world and relaying RTP / media streams is as much a necessary evil as transcoding and NAT in the real world.
The Setup
We’ll assume you’ve already got a rtpengine instance on your local machine running, if you don’t check out my previous post on installation & setup.
We’ll need to load the rtpengine module and set it’s parameters, luckily that’s two lines in our Kamailio file:
loadmodule "rtpengine.so"
...
modparam("rtpengine", "rtpengine_sock", "udp:localhost:2223")
Now we’ll restart Kamailio and use kamcmd to check the status of our rtpengine instance:
kamcmd rtpengine.show all
All going well you’ll see something like this showing your instance:
Putting it into Practice
If you’ve ever had experience with the other RTP proxies out there you’ll know you’ve had to offer, rewrite SDP and accept the streams in Kamailio.
Luckily rtpengine makes this a bit easier, we need to call rtpengine_manage(); when the initial INVITE is sent and when a response is received with SDP (Like a 200 OK).
So for calling on the INVITE I’ve done it in the route[relay] route which I’m using:
And for the reply I’ve simply put a conditional in the onreply_route[MANAGE_REPLY] for if it has SDP:
route[RELAY]{
...
rtpengine_manage();
...
}
onreply_route[MANAGE_REPLY] {
xdbg("incoming reply\n");
if(status=~"[12][0-9][0-9]") {
route(NATMANAGE);
}
rtpengine_manage();
}
And that’s it, now our calls will get RTP relayed through our Kamailio box.
Advanced Usage
There’s a bunch of more cool features you can use rtpengine for than just relay, for example:
- IPv4 <-> IPv6 translation for Media
- ICE Bridging
- SRTP / Encrypted RTP to clear RTP bridging
- Transcoding
- Repacketization
- Media Playback
- Call Recording
I’ll cover some of these in future posts.
Here’s a copy of my running config on GitHub.
For more in-depth info on the workings of RTP check out my post RTP – More than you wanted to Know
Thank you for sharing all these tutorials about Kamailio, they are really great 🙂
I saw your example kamailio config you posted and had a question.
Shouldn’t AUTH be done for ALL methods and not just register?
if(method==”REGISTER”){
route(AUTH);
route(REGISTRAR);
}
Hey Andrew,
You’re totally right,
You probably don’t want to be using these examples unmodified in production, a lot of the boilerplate stuff that handles proper security has been removed to keep them on point and simple,
Cheers,
Nick
Your sample config/script is neglecting to issue a “delete” to rtpengine for closed calls. In the simplest case you should also call “rtpengine_manage” for BYE and CANCEL methods.
Hi Nick,
Thanks for the information
Can you share example for RTPENGINE with SIP to Webrtc and opposite ?
Hi Nick,
Thanks for all documention.
I install rtpengine but RTP media always goes over the server.
is there any way use rtpengine only if P2P communication fails?