M2 Codec Negotiation
This article explains how Codecs are negotiated in M2 system and ways to avoid transcoding.
Originator Codecs
Codec list in Originator settings define which Codecs are accepted from Originator.
Terminator Codecs
Codec list in Terminator settings define which Codecs will be offered when dialing Terminator (in the order they are listed).
Codec order
By default M2 honors Codec order in SDP from Originator and Terminator. Originator Codec order depends on Originator’s phone settings and M2 has no control over it. Terminator Codec order can be changed in Terminator settings.
Let’s take a look at two examples:
Example #1
PCMA PCMA PCMU <---> M2 <---> PCMU GSM GSM
In this example Codecs and their order coming from Originator is the same as sent from M2 to Terminator. M2 chooses PCMA Codec for both legs since these Codecs are first in list. No transcoding is needed.
Example #2
GSM PCMA PCMU <---> M2 <---> PCMU PCMA GSM
In this example Codecs in both legs are the same but Codec order coming from Originator is different. M2 honors Codec order and chooses GSM (first Codec in list) for legA and PCMA for legB. Now transcoding is needed to connect both legs.
If you want to disable transcoding in this case (example #2), enable Inherit Codec option in Originator settings.
Inherit Codec
Inherit Codec allows to take the Codec negotiated when Terminator answers and pass it to Originator so it also uses the same codec. If Originator does not support it M2 will use whatever it can from its own list.
Originator Codec order no longer matters if Inherit Codec is enabled and M2 tries to avoid transcoding by using same Codec for both legs. Note that transcoding is still possible when Inherit Codec is enabled but there will be less cases when transcoding is needed.
One example when Inherit Codec is enabled but transcoding is still needed:
GSM Speex PCMU <---> M2 <---> PCMU PCMA GSM
In this example Terminator sends back three Codecs to M2 and first in line is Speex Codec. M2 still honors Terminator Codec order and chooses this Codec for leg B. Now M2 tries to negotiate leg A Codec but Speex Codec can not be offered to Originator since it does not support. M2 chooses GSM Codec for leg A. Transcoding is needed in this case.
Inherit Codec option is available only for Origination Points.
Enforce leg A Codecs to leg B
Another option to avoid transcoding is Enforce leg A Codecs to leg B. If this option is enabled in Terminator settings, M2 will ignore selected Terminator Codecs and will offer the same Codecs (in same order) from leg A to leg B.
Terminator should hangup Call if proposed Codecs are not supported. If Codecs are supported, no transcoding will be needed in most cases.
Enforce leg A Codecs to leg B is available only for Termination Points.
Avoid transcoding
If you want to avoid transcoding entirely (hangup calls instead of transcoding them), enable both settings - Inherit Codec and Enforce leg A Codecs to leg B.
This way M2 will offer leg A Codecs to leg B and if leg B returns Codecs in different order Inherit Codec option will handle it and ensures that the same Codec is used for leg A and leg B.