Enforcing codecs to prevent transcoding

I’d like to minimize transcoding on our system (FreePX 10.13.66)
My extensions allow either g729 or ulaw but not both. Trunks allow both g729 & ulaw but even though there are matching codecs on both sides that could be used, it does not work out that way.

When I call out from a ulaw extension, the outbound trunk uses g729 instead of matching the ulaw codec. Is there any way to force Asterisk to match the outbound trunk codec to the extension codec but still allow g729&ulaw on the trunk?

ATA = ulaw
trunk = g729&ulaw
call = ulaw : g729
why does the trunk not use ulaw?

ATA = g729
trunk = g729&ulaw
call = g729 : g729

bump…
Anyone?

https://issues.asterisk.org/jira/plugins/servlet/mobile#issue/ASTERISK-18887

Explains how the preferred codec is chosen,

Thanks. So I could setup my system to select only ulaw trunks for ulaw extensions and g729 trunks for g729 extensions or I could maybe modify the outbound route with Set(_SIP_CODEC_OUTBOUND=ulaw) to force a given codec and use the module extension settings to chose ulaw routes for ulaw extensions, etc… Would that work? Is there an easier way? I have an example below.

[outrt-2] ; TATA
include => outrt-2-custom
exten => _.,1,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _.,n,Gosub(sub-record-check,s,1(out,${EXTEN},never))
exten => _.,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?none:${MOHCLASS})})
exten => _.,n,Set(_NODEST=)
exten => _.,n,Macro(dialout-trunk,4,${EXTEN},,off)
exten => _.,n,Macro(outisbusy,)

[outrt-2-custom]
exten => _.,1,NoOP(CODEC selection)
exten => _.,n,Set(_SIP_CODEC_OUTBOUND=ulaw)
exten => _.,n,Macro(outisbusy,)

Probably not necessary, it’s all in the order you prefer them, asterisk and ATA both.

allow= g729&ulaw

is not the same as

allow= ulaw&g729

same concept different process for your ATA

@dcitelecom

Did that work?

No. This wouldn’t work for me
but thanks for asking though.

I have 2 types of ATAs. One allows only g729 and the other allows only ulaw. In the trunk I could play with the preference (allow= g729&ulaw OR allow= ulaw&g729) but all that would do is that one ATA would match and the other would always transcode. I believe I’ll need to either create 2 trunks for the same provider but with different codecs or modify the outbound route to force the codec.