[asterisk-dev] Solution to the Codec Negotiation Problem

Chan Kwang Mien kwangmien at asgent-tech.com
Mon Sep 11 20:42:08 MST 2006


Hi,

There was much discussion on the codec negotiation problem, i.e.

		sip1 <--> Asterisk <--> sip2

sip1 supports only g729 and g711
sip2 supports only g711

In sip.conf

[sip1]
allow = g729
allow = g711

[sip2] 
allow = g711

sip1 could not talk to sip2 because sip1's preferred codec is g729 while
sip2 preferred codec is g711.

In order to solve this problem, I have made modifications to the
sip_new(..) function in chan_sip.c to prevent Asterisk from selecting a
preferred codec. 


static struct ast_channel *sip_new(struct sip_pvt *i, int state, char
*title)
{

   ...........
   ...........

       if (i->jointcapability)
                tmp->nativeformats = ast_codec_choose(&i->prefs,
i->jointcapability, 1);
        else if (i->capability)
                tmp->nativeformats = ast_codec_choose(&i->prefs,
i->capability, 1);
        else
                tmp->nativeformats = ast_codec_choose(&i->prefs,
global_capability, 1);
        fmt = ast_best_codec(tmp->nativeformats);

// Added Lines
fmt = i->jointcapability;
tmp->nativeformats=i->jointcapability;
// Added Lines

    ..........
    ..........

}

sip1 was able to talk to sip2 after the modification was made. Can
anyone comment on this modification ? 

Thank you.

regards,
Kwang Mien




More information about the asterisk-dev mailing list