making SIP calls over TCP using PJSIP

7.5k views Asked by At

I'm using a PJSIP's pjsua dialer (based on pjsua_app.c, PJSIP 2.0.1) with TCP transport and a SIP trunk to make calls to a mobile phone. The dialer registers with a SIP Server over TCP and also sends out INVITES over TCP. UDP transport is not being used.

The environment is something like this -

PJSIP (behind NAT)<--- SIP over TCP ---> SIP Server <--- SIP trunk --> SIP trunk Provider <-- PSTN/Mobile Gateway-->Mobile phone

All calls are made from PJSIP over TCP to the mobile. To disable UDP transport creation I inserted a line "cfg->no_udp = true;" at the end of the function

"static void default_config(struct app_config *cfg)" in pjsua_app.c

I followed the instructions given here to make calls over TCP.

The problem is that we don't receive audio sent from the mobile end into the PJSIP dialer. But RTP packets from the PJSIP dialer reach the mobile side just fine. We can hear audio in the mobile when the call is established.

We found from packet traces that the reason we dont receive media in the PJSIP dialer is that the SIP server is sending RTP packets received over the SIP trunk to a private IP address.

But when we switch to UDP for registration and send INVITES over TCP the call works fine (audio at both ends).

The wireshark packet capture shows the following -

    1. PJSIP registers with server over TCP.
    2. Server sends 401 with PJ's public IP and port in VIA
    3. PJ registers again but inserts its public ip and port in the 
       contact header in the next REGISTER message sequence.
    So far so good. Same sequence of messages seen when UDP is used to REGISTER.
    4. INVITE sent over TCP. Dialog establishment works fine.
        But in the record-route header nat=yes is missing.
    5. Server sends media to private IP. No media received at PJSIP.

Is this a bug in PJSIP? If so how can this be fixed. Wireshark packet traces are available on request. Your help and inputs are much appreciated.

3

There are 3 answers

0
radu_paun On

Try to use port other than 5060 in both client and server, and/or reducing the SIP message size.

It seams this is a know issue for sending INVITE request over TCP in PJSIP.

Also you can find here some advices for reducing the SIP message size.

0
Shane Powell On

Your question doesn't actually make sense as the transport of the signalling between the sip endpoint and the sip server (either UDP or TCP) has no bearing on the media transport between the two sip endpoints (most likely UDP). So there must be something else going on.

Since your talking about private IP addresses, I'm assuming you are coming from a behind a NAT over the internet to a "public" sip server.

In these types of environments I would recommend you setup STUN, TURN and ICE on the sip endpoint.

I would guess the UDP setup you where talking about has the STUN server setup and the TCP setup you where talking about doesn't.

Without further information I can't help much more.

0
anilkumarthumma On

Please make sure that allow_contact_rewrite is set to true so that the media will be received to your end.

I think my answer is too late but this may help some other folks