The codec of incoming call

Anyone knows how to get the codec information of an incoming call in the dialplan? In CLI, I can use “sip show channels”. But I don’t know how to get such info in the dialplan. I have incoming calls with G711 or G729 and when I dial my phone, I want set “SIP_CODEC” to be the same as the incoming codec, so my asterisk box does not need to do any transcoding.

Asterisk will only transcode as a very last resort, it doesn’t want to transcode any more than you want it to
if after your preferred codecs, you put allow=all in the sip channel that it dials out on, it will attempt to use the incoming codec for the second call leg if at all possible.

I found you this link … nc+sippeer for you, to find out the codec of the incoming call. But codec negotiation is a SDP thing, I guessed its wise to leave this matter on the sip.conf of your asterisk, and preferred codec setting of the SIP client. As IronHelix put it “Asterisk will only transcode as a very last resort” so let the Asterisk do its own thing.

Hi, thanks for the replies. If I set “allow=all”, Asterisk will use the same codec as the incoming one to dial my ATA, which is good. But now, I have a new problem when I want to dial out. Since I have “allow=all”, my ATA and Asterisk will negotiate a codec first (in my case, they choose g723, don’t know why). But my VSP only suport g711. Hence, transcode from g723 to g711 has to be doen at Asterisk when I dial out.

I will try “sippeer” later to see if I can get it work.

I think you should check what codec are supported by your ATA, and its top preference. If you don’t want to use g723 why not remove all “allow=g723” on the sip.conf then do a sip reload (or another way add a “disallow=g723” before “allow=all”, this will ensure no g723 will be use. But be sure your ATA do support other codec, like g711.

In my ATA, I set the codec preference as: g711u > g729 > gsm > g723 > g711a > iLibC and in Asterisk, I set “allow=all”. But my ATA and Asterisk choose g723 when I dial out. That is why I get confused. If I remove g723, g711a, and iLibC from my ATA (I don’t use them anyway), then gsm will be choosen. I don’t see what is the rule used for choosing the audio codec.

perhaps it’s because CLI > show codecs returns g723 as #1 ???

You may be right. “show codecs” returns g723 as #1 and gsm as #2. That seems the exact way my Asterisk choose codecs. So, is there anyway I can choose the codec for dialout and at the same time, keep “allow=all”? My incoming calls may use g711, g729, and gsm. so all these three should be allowed. When I dialout, however, I want to use g711, not gsm choosen by Asterisk.

if you do

allow=other codecs you want

then it will still allow all but still not g723.