PJSIP: Asterisk Can’t Decide Which Codec To Use
I’m facing completely choppy sound. The wireshark trace shows, that there are a lot of codec changes without any trigger (means no options or reinvite or any other package).
Please note: PJSIP is a free and open source multimedia communication library written in C language implementing standard based protocols such as SIP, SDP, RTP, STUN, TURN, and ICE. It combines signaling protocol (SIP) with rich multimedia framework and NAT traversal functionality into high level API that is portable and suitable for almost any type of systems ranging from desktops, embedded systems, to mobile handsets.
Background:
The call is initiated by asterisk and is received by the same asterisk conference room via Phone extension -> asterisk -> provider A -> provider B -> asterisk.
Asterisk initially sends invites using g722 and g711 and gets exactly this invite back as incoming call. The answer is g722,g711 in the ok sdp.
Now, Asterisk can’t decide, which codec to use. It frequently changes the codec just as it likes to apparently without any visible reason.
[2017-05-11 17:28:03] DEBUG[5121][C-0000003a]: res_rtp_asterisk.c:3634 ast_rtp_write: Ooh, format changed from none to alaw
0000003a -> inbound channel (callee)
00000039 -> outbound channel (caller)
If I’m doing exactly the same call originated with another extension, there can’t be seen these frequent changes. But the strange thing is, that in both cases the part between extension and asterisk doesn’t show any codec changes … .
Deeper investigations show, that if the conference (callee) sends the first rtp package (-> g711 – should be g722), things are going choppy, if the extension (caller) sends the first package (g722), things are running stable.
Any idea to convince asterisk always to use the first codec of ok sdp or how to convince asterisk to put only one codec to ok sdp (the first).
Thanks, regards,
5 thoughts on - PJSIP: Asterisk Can’t Decide Which Codec To Use
Forgot to mention: It’s actual asterisk 13 branch from today (version before I tested, which has the same problem, was 13.15).
Regards, Michael
This is not currently an option in chan_pjsip but I’d suggest filing an issue[1] for this scenario with all available information.
[1] https://issues.asterisk.org/jira
https://issues.asterisk.org/jira/browse/ASTERISK-26996
Thanks, regards, Michael
I just tested your fix 2 times w/ using the scenario mentioned in the bug report. It has been working for me. No more flipping.
Asterisks indeed commits more than one codec in ok sdp, but always uses the first one afterwards. Hopefully the peer always handles it the same way. I would have thought that the ok sdp contains just one codec (the best).
Thanks, Michael
There’s actually a feature for just that in master, preferred_codec_only. It’ll be available in 15. The new behavior in the branches with multiple codecs in the answer mirrors that of chan_sip, so it’s pretty safe.