Reducing SIP message size
PJSIP automatically switches transport to TCP when request size is larger than (default MTU) 1300 bytes, hence message size shouldn’t be an issue. See ticket #831 for more info.
See also Using SIP with TCP/TLS. TCP/TLS are probably better too in terms of NAT traversal and security issues.
This article provides several guidelines to reduce SIP message size.
Configure PJSIP to send compact form of SIP headers. This will reduce SIP message size by approximately 50 bytes.
extern pj_bool_t pjsip_use_compact_form; // enable compact form pjsip_use_compact_form = PJ_TRUE;
Suppress the inclusion of Allow header in outgoing requests, by setting
PJSIP_INCLUDE_ALLOW_HDR_IN_DLGmacro to 0 in config_site.h. This will reduce SIP message size by approximately 86 bytes.
Suppress the inclusion of SDP
rtpmapattribute for static payload types, by setting
PJMEDIA_ADD_RTPMAP_FOR_STATIC_PTmacro to 0 in config_site.h. This should not cause bad effects since SDP
rtpmapattributes for static payload types are optional. This will reduce SIP message size by approximately 65 bytes.
Disable RTCP (advertisement) in SDP, by setting
PJMEDIA_ADVERTISE_RTCPmacro to 0 in config_site.h. When RTCP is disabled, no RTCP packets will be sent or received, and this will cause some RTCP TX statistics (including RTT report) to be unavailable. Other RTCP statistics such as RX statistics, as well as number of TX packets, will still be available since these values are generated locally. Disabling RTCP will reduce SIP message size by approximately 235 bytes for ICE with three candidates.
Disable bandwidth modifier in SDP, by setting
PJMEDIA_ADD_BANDWIDTH_TIAS_IN_SDPmacro to 0 in config_site.h. See the macro documentation for more info. This will reduce SIP message size by approximately 14 bytes.
If DTMF via RFC2833/
telephone-eventis not needed, it can be disabled by setting
PJMEDIA_RTP_PT_TELEPHONE_EVENTSmacro to 0 in config_site.h. This will reduce SIP message size by approximately 53 bytes.
Disable some unused network interfaces in the system to reduce the number of ICE candidates advertised in SDP. It’s quite common to have some loopback network interfaces which probably are unused.
In pjsua, you can use
--use-compact-formoption to reduce the message size.