SIP_CODEC Without Early Media Causes Odd Transcoding

Asterisk 13.14.0

Our office phones are configured to prefer G722 for intercom. Our ITSP completes calls using G711u. Without forcing a codec it will transcode from G722 to G711u when placing an outbound call, this is expected behavior.

To avoid transcoding we have added the following dialplan to the oubound context:

exten => s,n,Set(SIP_CODEC_INBOUND=ulaw)
exten => s,n,Set(SIP_CODEC_OUTBOUND=ulaw)
...
exten => s,n,Dial(...)

This works for most outbound calls. Resulting in the following output for “core show channel” on both legs:

NativeFormats: (ulaw)
WriteFormat: ulaw
ReadFormat: ulaw
WriteTranscode: No
ReadTranscode: No

On some outbound calls, specifically an auto answering join.me conference line (860) 970-0010 we get this output on both legs:

NativeFormats: (ulaw)
WriteFormat: slin16
ReadFormat: slin16
WriteTranscode: Yes (slin@16000)->(slin@8000)->(ulaw@8000)
ReadTranscode: Yes (ulaw@8000)->(slin@8000)->(slin@16000)

It’s almost as if the bridge itself remained in slin16 mode, while both endpoints switched to G711u.

The call that doesn’t transcode the ITSP indicated “183 Session Progress” and early media in SDP. While the call that does transcode the ITSP only indicated “200 OK” and the actual media for the call in SDP.

I was able to work around this issue by forcing early media to occur locally instead of on the remote side:

exten => s,n,Set(SIP_CODEC_INBOUND=ulaw)
exten => s,n,Set(SIP_CODEC_OUTBOUND=ulaw)
exten => s,n,Progress() ;force early media
...
exten => s,n,Dial(...)

This fixed the issue. Another quirk to note is that Progress() has to be put after the SIP_CODEC statements, putting them before the statements did not help. The media has to change after the statements.

Is this a bug or an inherent limitation?

If the conference bridge is on Asterisk, it will need to use some variation of slin, as you cannot add G.711 samples directly together and get a sensible result.

The Dial application normally creates a simple bridge between the two channels. If both channels use the same media then no mixing/transcoding should occur. A multiparty bridge or confbridge is a different matter, this is not one of those.

See: https://wiki.asterisk.org/wiki/display/AST/Bridges

It’d be one thing if both were transcoding to slin8 but slin16 suggests that something thinks that the codec is G722, which neither endpoint is using once the G711u is forced.