Force codec for certain incoming call

Is there a way in Asterisk to force a codec for a specific incoming number? Or should I ask my provider to do this? (The provider offers both G.711 and G.729 in the INVITE.) We have a phone number for modems to dial into that we’d like to use G.711 for. This number will dial an ATA from within the dialplan. For all the other numbers, we want to use G.729. I’ve set the trunk to allow both but it seems like G.729 is chosen before it even gets to the dialplan.

Here is our codecs:


exten => 1231234567,1,NoOp()
        ; No luck setting these, SIP/trunk still uses G.729.
        same => n,Set(SIP_CODEC=ulaw)
        same => n,Set(SIP_CODEC_INBOUND=ulaw)
        same => n,Set(SIP_CODEC_OUTBOUND=ulaw)
        same => n,Dial(SIP/ata,30)

The ata channel uses ulaw, but the trunk channel always wants to use G.729. :frowning: Any ideas? Thanks as always!

Codec negotiation for incoming calls is that 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.

You can try the preferred_codec_only=yes

this Respond to a SIP invite with the single most preferred codec rather than advertising all joint codec capabilities. Thislimits the other side’s codec choice to exactly what we prefer.

Thanks for the reply. Looks like you are right, it is using G.711 in the RTP packets. I was getting hung up on NativeFormats: (g729) from core show channel and creating a problem when there was none.