Early codec selection / negotiation

Home » Asterisk Users » Early codec selection / negotiation
Asterisk Users 2 Comments

Hi,

This seems to be a fairly common question, but I have Googled for this quite
a bit and looked at the Asterisk documentation/book and haven’t been able to
find an answer.

My question is:

Can I get my IP phone to select a different codec depending on the final
destination of each call?

I’ve got these things connected to my Asterisk box:

– Snom 300 phone (supports g729 and ulaw)
– PSTN Peer (supports g729 and ulaw)
– Remote Asterisk Peer (supports speex and ulaw)

Currently, it’s configured like this:

[snom300]
disallow=all
allow=ulaw

[pstnpeer]
disallow=all
allow=ulaw

[asteriskpeer]
disallow=all
allow=speex

which translates to this:

Snom300 —ulaw—> (pass-thru) —ulaw—-> PSTNPeer
Snom300 —ulaw—> (transcode) —speex—> AsteriskPeer

In other words, my Snom phone always talks to my Asterisk box using the ulaw
codec. My Asterisk box then makes PSTN calls using ulaw and Asterisk calls
using speex (transcoding in the case of speex).

What I’d like to get is this:

(1) Snom300 —g729—> (pass-thru) —g729—-> PSTNPeer
(2) Snom300 —ulaw—> (transcode) —speex—> AsteriskPeer

I can get (1) by using this config:

[snom300]
disallow=all
allow=g729 ; only allow g729

[pstnpeer]
disallow=all
allow=g729

and I can get (2) by using this config:

[snom300]
disallow=all
allow=ulaw ; only allow ulaw

[asteriskpeer]
disallow=all
allow=speex

but I can’t get both of them to work at the same time since the Snom phone
always connects to my Asterisk box using its prefferred codec.

If I configure the phone like this:

[snom300]
disallow=all
allow=g729 ; preferred codec
allow=ulaw

then (2) will fail because it’s trying to do this:

Snom300 —g729—> (transcode) —speex—> AsteriskPeer

and it can’t transcode g729 to speex without a patent license.

If I configure the phone like this:

[snom300]
disallow=all
allow=ulaw ; preferred codec
allow=g729

then (1) will fail because it’s trying to do this:

Snom300 —ulaw—> (transcode) —g729—-> PSTNPeer

This is the best description of the problem I’ve found online:

http://fonality.com/trixbox/forums/trixbox-forums/open-discussion/codec-selection-negotiation-and-tweaking

but unfortunately it doesn’t come with a solution.

Is there a way to prevent my IP phone from always connecting to my Asterisk
box using its preferred codec or is that simply impossible?

Cheers,
Francois

2 thoughts on - Early codec selection / negotiation

  • If you dialout call without answering and allow all codec for both peers
    then codec negotiation will be direct between endpoints and asterisk will
    only do media pass-through.

  • Hi Faisal,

    Thanks for your note.

    Now, if I understand you correctly, you are saying that my dialplan:

    exten => _1800NXXXXXX,1,Set(CALLERPRES()=allowed)
    exten => _1800NXXXXXX,n,Set(CALLERID(all)=Francois Marier <12345>)
    exten => _1800NXXXXXX,n,Dial(IAX2/username:password@pstnpeer/${EXTEN})

    exten => 1000,1,Dial(IAX2/guest@asteriskpeer/123)

    is causing my asterisk box to “answer” the calls before passing them on?

    I guess I’m not quite sure what you mean by “dialout call without
    answering”.

    Does it have to do with the “canreinvite” or “directrtpsetup” in sip.conf?

    Cheers,
    Francois