Order of codecs in outgoing SDP (PJSIP)


#1

Hi all,

I have Asterisk 13.21 with PJSIP endpoints A and B.
In order to enable all the supported audio and video codecs, allow=all parameter is set for both endpoints.
A call is coming from endpoint A and is routed to endpoint B according to the dialplan.

Could you clarify in which order codecs in outgoing INVITE towards endpoint B are announced:

  • Asterisk respects the order in SDP received from endpoint A, or

  • Asterisk sends codecs in some fixed order?

If the latter is correct, where is this order defined?

Thank you.


#2

The codec negotiation for chan_sip was the following


; Codec negotiation
;
; When Asterisk is receiving a call, the codec will initially be set to the
; first codec in the allowed codecs defined for the user receiving the call
; that the caller also indicates that it supports. But, after the caller
; starts sending RTP, Asterisk will switch to using whatever codec the caller
; is sending.
;
; When Asterisk is placing a call, the codec used will be the first codec in
; the allowed codecs that the callee indicates that it supports. Asterisk will
; *not* switch to whatever codec the callee is sending.

it is documented on the sip sample file, I dont know if for pjsip it is the same , it will be needed a sip trace to determine it


#3

Thank you @ambiorixg12
The first thing (as you noticed) is that this instruction is related to chan_sip.
The other is that "When Asterisk is placing a call, the codec used will be the first codec in the allowed codecs " - but what is the order if allow=all parameter is set?

If no-one knows it for sure, I will set up this simple config in a lab and collect traces.


#4

I don’t think there really is a defined/documented/guaranteed order for “allow=all”. For most people you should explicitly specify codecs, which defines the preference order.


#5

I remember years a go there was a no desired behavior when allow=all was set in the codec selection, of course it was an old version of Asterisk


#6

Thank you @jcolp
So, to allow all the codecs in a predictable order, I should take them from core show codecs and list explicitly?
Is there any way to respect the order of the codecs received from the originating party? Or Asterisk as a pure B2BUA will not respect it?


#7

The preference order of Asterisk is what is used. If you don’t see an option to change that in the wiki documentation, then it doesn’t exist.


#8

I thought the A side preferred codec was put to the front of the list on the B side.


#9

For outgoing that may be correct these days - there were times where it flip flopped back and forth as things developed. They are still independently negotiated, though.