Which Codecs does 3CX support and when?

Introduction

Which codecs does 3CX support? And how does it negotiate a codec? This document answers these questions as well as how the SDP is structured and where 3CX gets the information from.

Supported Codecs

3CX Supports the following codecs:

  • G.711a / 8000Hz / payload type 8
  • G.711u / 8000Hz / payload type 0
  • G.722 / 8000Hz / payload type 9
  • G.729a / 8000Hz / payload type 18
  • GSM-FR / 8000Hz / payload type 3
  • iLBC / 8000Hz / payload type 111
  • Speex / 8000Hz / payload type 97
  • opus / 48000Hz / payload type 112
  • telephone-event 96-127 / 8000Hz

Codec Priority & Negotiation

The codec priority in 3CX can be configured on a per SIP Trunk basis and is done from the “Options” tab in the SIP Trunks settings, in the “Codec Priority” section. From here, codecs can be removed, added and have their order changed.

Outgoing Calls Codec Negotiation

When creating the INVITE message for an outgoing call through a SIP Trunk, 3CX will place the codecs in the SDP in the exact order they have been configured in the “Codec Priority” section. If the provider in the 200 OK responds with one or more codecs, 3CX will use the topmost codec found in the 200 OK.

Apart from the audio codecs, 3CX will also add the telephone-event 101 codec to the SDP for the transmission of DTMF tones over RFC2833. If the SIP trunk does not support telephone events then the DTMF will be delivered in-band.

Incoming Calls Codec Negotiation

Upon receiving an INVITE from a SIP Trunk provider, 3CX will analyze the order of the codecs in the INVITE and will use the topmost codec in the received INVITE, as long as it is also listed in the available codecs in the SIP Trunk settings. Therefore, for incoming calls, the priority in the SIP Trunk settings does not matter.

In regards to DTMF, 3CX accepts all telephone-events from 96-127 for RFC2833. If the provider does not send a telephone-event codec, then 3CX will not accept any RFC2833 DTMF tones, but it will still accept in-band DTMF tones.

If the INVITE from the SIP Trunk provider does not contain any codec that 3CX supports, or there is no common codec between those in the INVITE and the ones listed in Codecs in the SIP Trunk settings, then 3CX will reply with a 200 OK with no codecs listed and with SDP Port 0.

SDP Connection Address & Ports

For the SDP connection address, 3CX will decide which IP to use in the same way it decides the IP address in the “Contact” header for the REGISTER messages. In the INVITE and 200 OK messages, first 3CX will check if in the “Options” tab, there is an IP address entered in the “Select which IP to use in ‘Contact’ and ‘Connection’ fields” option. If so, this will be used.

If this option is set to “Use Default Settings” then 3CX will use the default Public IP address that it has been configured to use. This is set under the Advanced → Network → External IP configuration” section.

The Local RTP port 3CX will use on each call is a random port in the range of 9000-10999. This cannot be changed. There is no limitation however on which port the SIP Trunk providers Media Servers are using.

Does 3CX transcode a call via a SIP Trunk?

Yes. Because we cannot establish a direct RTP stream between trunk and endpoint (phone) because direct stream requires renegotiation when the endpoint destination  is changed, for example for a transfer or to provide music on hold during a call.

Does transcoding affect Audio quality?

No. Transcoding will preserve the quality of the codec preferred by parties. If the codecs are using different quality, then the quality of the lowest codec will be used.

Example:  "My phone prefers opus and the trunk PCMU, what will happen?

In the case if PCMU is used by trunk RTP stream and opus is used by the phone RTP stream, the quality of audio will be PCMU because: the content delivered by PCMU from trunk will arrive as PCMU audio encoded by opus = the quality of PCMU will arrive on phone side the content delivered by opus will "degrade" to PCMU quality when will be encoded with PCMU. (downsampling from 16kHz to 8 kHz). So trunk side will also hear PCMU.

Example: Which Codec will 3CX use?

Assume External Call out via SIP Trunk which supports codecs XY

Endpoint codec ZY

Assume X, Y and Z are codecs.

If priority SIP trunk is XY and ZY for Endpoint?

3CX will use X for SIP trunk and Z for Endpoint and it will transcode from X to Z

If priority SIP Trunk is YX and Endpoint YZ?

3CX will use Y for SIP trunk and Y for Endpoint so it will not change codec because it will be both Y

But in both cases it will transcode because its transcoding the RTP stream (for reliability)

Last Updated

This document was last updated on 25 July 2024

https://www.3cx.com/docs/sip-trunk-codecs-sdp/