<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="State"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="City"/>
<o:SmartTagType namespaceuri="urn:schemas-microsoft-com:office:smarttags"
name="place"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Very Nice! This has been a big issues
with asterisk. I look forward to seeing it in the Bug tracker..<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Doug<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>
asterisk-dev-bounces@lists.digium.com
[mailto:asterisk-dev-bounces@lists.digium.com] <b><span style='font-weight:
bold'>On Behalf Of </span></b>Andrey Sofronov<br>
<b><span style='font-weight:bold'>Sent:</span></b> Tuesday, January 29, 2008
11:39 AM<br>
<b><span style='font-weight:bold'>To:</span></b> asterisk-dev@lists.digium.com<br>
<b><span style='font-weight:bold'>Subject:</span></b> [asterisk-dev] Patch:
SIP: choosing common codec and select "free"codec for transcoding</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>Hello all!<br>
<br>
In my network there are a lot of hardware VoIP gateways and softphones and I
have to make then work. Most of all hardware VoIP gateways support G.711, G.723
and G.729 codecs and the softphones support G.711, GSM, iLBC etc codecs. All
endpoints are SIP peers. All traffic should pass through my asterisk server(s).
In "vanilla" asterisk there is a limitation - it is unable to select
a common codec for 2 peers using some algorithm (less bandwidth etc) or if
jointcapability = 0 select codecs for both endpoints that could be transcoded
"for free".<br>
<br>
<b><span style='font-weight:bold'>1st example</span></b>:<br>
<br>
sip.conf<br>
<br>
[210]<br>
disallow=all<br>
allow=alaw,ulaw,g723,g729<br>
...<br>
<br>
[220]<br>
disallow=all<br>
allow=alaw,ulaw,g723,g729<br>
...<br>
<br>
[255]<br>
disallow=all<br>
allow=gsm<br>
...<br>
<br>
210 calls 220:<br>
sip show channels<br>
Peer
User/ANR Call ID Seq
(Tx/Rx)
Format
Hold Last Message<br>
10.xx.xx.xx
220 10aa3d3754b
00102/00000 0x8 (alaw)
No Init: INVITE<br>
10.xx.xx.xx
210 a983a543-52
00101/00939 0x8 (alaw)
No Rx: INVITE<br>
<br>
Works, but alaw is a high-bandwidth codec!<br>
<br>
210 calls 255:<br>
sip show channels<br>
Peer
User/ANR Call ID Seq
(Tx/Rx)
Format
Hold Last Message<br>
10.xx.xx.xx 255
504c907f5b7 00102/00000 0x2
(gsm) No
Init: INVITE<br>
10.xx.xx.xx
210 5f84a543-9c
00101/00943 0x8 (alaw)
No Rx: INVITE<br>
<br>
Works here...<br>
<br>
<b><span style='font-weight:bold'>2nd example</span></b>:<br>
<br>
sip.conf<br>
<br>
[210]<br>
disallow=all<br>
allow=g729,alaw,ulaw,g723<br>
...<br>
<br>
[220]<br>
disallow=all<br>
allow=g729,alaw,ulaw,g723<br>
...<br>
<br>
[255]<br>
disallow=all<br>
allow=gsm<br>
...<br>
<br>
210 calls 220:<br>
sip show channels<br>
Peer
User/ANR Call ID Seq
(Tx/Rx)
Format
Hold Last Message<br>
10.xx.xx.xx
220 572052d8348
00102/00000 0x100 (g729) <st1:place w:st="on"><st1:City
w:st="on">No</st1:City> <st1:State w:st="on">Tx</st1:State></st1:place>:
ACK<br>
10.xx.xx.xx
210 0486a543-2e
00101/00946 0x100 (g729)
No Rx: ACK<br>
<br>
Good work - g729 pass-through!<br>
<br>
210 calls 255:<br>
WARNING[8424]: chan_sip.c:3001 sip_call: No audio format found to offer.
Cancelling call to 255<br>
<br>
All codecs are same, but their order was changed.<br>
<br>
It's a simple example, just to point a problem.<br>
<br>
I'm not a professional C/C++ programmer, but the feature was necessary so I
created a small patch (for asterisk 1.4.17).<br>
<br>
In brief:<br>
1) set sip_pvt->prefcodec = 0!<br>
2) Thanks to 1) asterisk continues execution and calls
ast_channel_make_compatible function.<br>
3) In "ast_channel_make_compatible" we recalculate peers' codec
capabilities and sip_pvt->prefs.<br>
<br>
Result - the order of the codecs in "allow=" parameter does not
matter anymore. Asterisk will select most efficient codec for pass-through and
if jointcapability = 0 will select free and ecomonic codec for transcoding.<br>
<br>
My patch is not excellent (maybe even awful, but i'm not a programmer and it
works for me fine!) but if anybody get an idea, you can make it better. Also it
would be nice to implement that feature as configuration parameter.<br>
<br>
Please see patch in attachment! Thanks! <o:p></o:p></span></font></p>
</div>
</body>
</html>