[Asterisk-Dev] SIP - how does * decide codec order of preference

Alex Zeffertt ajz at cambridgebroadband.com
Thu Sep 30 07:50:52 MST 2004


On Tue, 28 Sep 2004 16:58:34 +0100
"Kevin Walsh" <kevin at cursor.biz> wrote:
> Rob Gagnon [rob at networkip.net] wrote:
> > They are sent out based on which Codec bits are on or off.
> > 
> > Each codec is assigned one bit of a 32-bit integer.  That integer is
> > parsed in order to produce the list in the SIP message.  Of course,
> > doing it that way leaves no method for setting the order.
> > 
> > This is a constant topic in the list.  Maybe someone would want to
> > recode that to use an ordered list?  :-)
> > 
> See sip_codec_choose() and ast_best_codec() in "channels/chan_sip.c".

I see the problem now... when the PBX intiates a SIP call it
specifies its preferred codec in an argument to sip_request().  For a
call originating on an E1 this will be alaw.  This codec
will be put at the top of the list when building the INVITE - irrespective
of the preference order specified in sip.conf!  My problem is that I want
the codec order specified in sip.conf to be respected when making INVITEs
(because I care more about not wasting network bandwidth than about
reducing the load on asterisk.)

The following patch seems to do this:

diff -u -r1.510 chan_sip.c
--- channels/chan_sip.c 28 Sep 2004 12:55:08 -0000      1.510
+++ channels/chan_sip.c 30 Sep 2004 14:41:53 -0000
@@ -3422,6 +3422,7 @@
        snprintf(t, sizeof(t), "t=0 0\r\n");
        snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port));
        snprintf(m2, sizeof(m2), "m=video %d RTP/AVP", ntohs(vdest.sin_port));
+#if 0 /* We don't care what codec the PBX prefers - we want to list the codecs in the order they appear in sip.conf */
        if (capability & p->prefcodec) {
                if (debug)
                        ast_verbose("Answering/Requesting with root capability %d\n", p->prefcodec);
@@ -3440,6 +3441,7 @@
                }
                alreadysent |= p->prefcodec;
        }
+#endif
        /* Start by sending our preferred codecs */
        cur = prefs;
        while(cur) {


I am not suggesting that this patch goes into CVS.  However, it would
be nice if there was an option in sip.conf that allowed you to specify
whether you wanted asterisk to list first the codec that minimised its
load, or to respect always the order of codecs in sip.conf.  Say

offerlowestloadcodecfirst=yes|no

Comments?

Alex



More information about the asterisk-dev mailing list