{"id":18,"date":"2009-11-21T04:00:41","date_gmt":"2009-11-21T04:00:41","guid":{"rendered":"http:\/\/chillingsilence.wordpress.com\/?p=18"},"modified":"2011-09-19T11:04:06","modified_gmt":"2011-09-18T23:04:06","slug":"ilbc-vs-g729-the-quick-guide-to-using-compressed-codecs-in-elastix","status":"publish","type":"post","link":"http:\/\/www.c2s.co.nz\/blog\/ilbc-vs-g729-the-quick-guide-to-using-compressed-codecs-in-elastix\/","title":{"rendered":"iLBC vs g729 &#8212; The quick guide to using compressed codecs in Elastix"},"content":{"rendered":"<div class=\"8781ca4f97038dd0d58a1ad8af045721\" data-index=\"3\" style=\"float: none; margin:10px 0 10px 0; text-align:center;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-6411751809866006\";\r\n\/* BlogHorizontalSlim *\/\r\ngoogle_ad_slot = \"6442664612\";\r\ngoogle_ad_width = 468;\r\ngoogle_ad_height = 60;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n<p><strong>Updated Sept 2011 for Elastix-2.* and Asterisk-1.6+ as well as the broken links since Google seems to have taken over GIPS<\/strong><\/p>\n<p>We all know that g711 (alaw \/ ulaw) is meant to sound the best. It&#8217;s uncompressed and equivalent quality to ISDN, which most businesses are used to with their traditional PABX System.<\/p>\n<p>However, it comes at a price, 64kbps + overheads means around <a title=\"Asterisk Bandwidth Calc\" href=\"http:\/\/site.asteriskguide.com\/bandcalc\/bandcalc.php\" target=\"_blank\">111kbps<\/a> when you factor in everything else over an ADSL PPPoA \/ PPPoE connection.<\/p>\n<p>Now that&#8217;s a LOT when you think about it, considering on a standard ADSL2+ line you&#8217;re going to max out at around 5-7 SIP lines, especially if it&#8217;s a shared connection. This is where a compressed codec such as (My personal favorite) iLBC, or g729, can be incredibly cost effective, as you can load up around 15-20 on the same sort of bandwidth. When you&#8217;re a small business, that means with the right kind of QoS, you can share your ADSL Broadband connection and still have 5-10 concurrent phone calls, all happily living together.<\/p>\n<p>So do away with expensive BRI interfaces and monthly charges, and go SIP!<\/p>\n<p>We&#8217;re going to look at a few things very briefly:<\/p>\n<p>1) MOS &#8211; What is it and why do I care?<\/p>\n<p>2) Which codec is right for me?<\/p>\n<p>3) g729 &#8211; Installation<\/p>\n<p>4) iLBC &#8211; Installation<\/p>\n<p>5) Trunk and Extension setup<\/p>\n<p>6) Testing the codecs<\/p>\n<p><!--more--><\/p>\n<p style=\"text-align: center;\"><strong>1) MOS &#8211; What is it and why do I care?<\/strong><\/p>\n<p style=\"text-align: left;\">MOS stands for &#8220;<a title=\"Wikipedia MOS article\" href=\"http:\/\/en.wikipedia.org\/wiki\/Mean_Opinion_Score\" target=\"_blank\">Mean Opinion Score<\/a>&#8220;, and in a nutshell it&#8217;s a way of determining out of 5 how good a particular codec (Read: Phone call) will sound. The Wikipedia article is a good overview of MOS, each codecs ratings, and some phrases you can use to test the compression yourself and see if words become difficult to understand.<\/p>\n<p style=\"text-align: left;\">Now, we all want a nice good MOS, because at the end of the day if you&#8217;re using a PBX system, there&#8217;s nothing worse than it sounding like a VoIPBuster call to some exotic island. Personally I aim for higher quality, this is why iLBC stands out well for me. That said, the choice is yours, try a few out and see what sound you personally (And quite possibly the person who writes your paycheck) are happy with.<\/p>\n<p style=\"text-align: center;\"><strong>2) Which codec is right for me?<\/strong><\/p>\n<p style=\"text-align: left;\">Well that is a very good question, and that&#8217;s something that you&#8217;re going to have to answer for yourself. Lets look at some of the benefits of each:<\/p>\n<table style=\"text-align: center;\" width=\"600\" border=\"1\" cellspacing=\"1\" cellpadding=\"2\">\n<tbody>\n<tr>\n<th scope=\"row\">iLBC Pros<\/th>\n<th scope=\"row\">iLBC Cons<\/th>\n<th scope=\"row\">g729 Pros<\/th>\n<th scope=\"row\">g729 Cons<\/th>\n<\/tr>\n<tr>\n<td>Free!<\/td>\n<td>Generally installed from Source code<\/td>\n<td>Most physical devices support it<\/td>\n<td>Costs $ per-channel<\/td>\n<\/tr>\n<tr>\n<td>Better MOS than g729<\/td>\n<td>&#8220;Interesting&#8221; license<\/td>\n<td>Requires less CPU than iLBC for encoding \/ decoding<br \/> (Good for low-powered or highly loaded PBXs)<\/td>\n<td>Not many free Softphones support g729<\/td>\n<\/tr>\n<tr>\n<td>Handles packet loss better than g729 &amp; g711<\/td>\n<td>Less physical devices support it than g729<\/td>\n<td>More common than iLBC<\/td>\n<td>Easier to pick up the compression vs iLBC<\/td>\n<\/tr>\n<tr>\n<td>Many open-source softphones support it<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>\u00c2\u00a0<\/td>\n<td>Many different version<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: left;\">It&#8217;s not difficult to see there could be benefits for either. If you&#8217;re looking for low-cost deployment, or over a shaky ADSL connection you can&#8217;t seem to QoS well (Or perhaps Wireless?) then iLBC is probably the way to go. If you&#8217;re doing a larger installation, or an installation for a customer then it&#8217;s worth investigating g729, especially if you&#8217;re running underpowered hardware or have a large number of Exts or lots of expected concurrent calls.<\/p>\n<p style=\"text-align: left;\">Please keep in mind that you do not have to stick with just one codec, feel free to mix and match box on a per-customer level, or on a per-machine level also.<\/p>\n<p style=\"text-align: center;\"><strong>3) g729 &#8211; Installation<\/strong><\/p>\n<p style=\"text-align: left;\">OK so I&#8217;m going to cheat here and direct you to Digium. Yes, there are &#8220;free&#8221; binaries out there, but at the price of $10 per-channel surely it&#8217;s not that expensive if you&#8217;re going to add it to your PBX&#8217;s you deploy.<\/p>\n<p style=\"text-align: left;\">Anyway if you&#8217;re downloading a &#8220;free&#8221; version, simply pop it in \/usr\/lib\/asterisk\/modules and chmod 755 the file. 64-bit versions go in \/usr\/lib64\/asterisk\/modules<\/p>\n<p style=\"text-align: left;\">Other than that, follow Digiums excellent instructions here, it should take you less than 5 minutes: <a href=\"http:\/\/kb.digium.com\/entry\/5\/\">http:\/\/kb.digium.com\/entry\/5\/<\/a><\/p>\n<p style=\"text-align: center;\"><strong>4) iLBC &#8211; Installation<\/strong><\/p>\n<p style=\"text-align: left;\">We&#8217;re going to be compiling this from source. Lucky for us Elastix makes this nice and easy! We won&#8217;t be installing a complete asterisk system, we don&#8217;t want to break the RPM&#8217;s because, let&#8217;s face it, it&#8217;s the easiest way to keep a system updated \/ secure.<\/p>\n<p style=\"text-align: left;\">First off, download Asterisk from here: <a href=\"http:\/\/www.asterisk.org\/downloads\">http:\/\/www.asterisk.org\/downloads<\/a><\/p>\n<p style=\"text-align: left;\">Get it to your elastix box any way you want (SCP \/ SSH \/ local terminal) and pop it in \/usr\/src<\/p>\n<p style=\"text-align: left;\">Now, run:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">tar xvzf asterisk-1.6.*.tar.gz<\/p>\n<p style=\"text-align: left;\">change in to the newly created &#8220;asterisk&#8221; directory and run:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">.\/contrib\/scripts\/get_ilbc_source.sh<\/p>\n<p style=\"text-align: left;\">Press &#8220;Enter&#8221; after it displays the warning presuming you&#8217;ve read the documentation (Which I&#8217;m also going to assume you&#8217;ve done) and shortly after you&#8217;ll get a lovely message telling you &#8220;The iLBC source code download is complete.&#8221;<\/p>\n<p style=\"text-align: left;\">You need to then run:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">ls -la .\/codecs\/ilbc<\/p>\n<p style=\"text-align: left;\">Check and make sure that everything has a size. The <a href=\"http:\/\/www.c2s.co.nz\/files\/ilbc\/extract-cfile.awk\">extract-cfile.awk<\/a> has been known to go AWOL. Luckily I found an old copy so you can edit the file and pop in these details (if it&#8217;s zero bytes):<\/p>\n<pre>BEGIN { srcname = \"nothing\"; }\r\n{ if (\/^A\\.[0-9][0-9]*\\.* *[a-zA-Z][a-zA-Z_0-9]*\\.[ch]\/) {\r\n    if (srcname != \"nothing\")\r\n      close(srcname);\r\n    srcname = $2;\r\n    printf(\"creating source file %s\\n\", srcname);\r\n  }else if (srcname != \"nothing\") {\r\n    if (\/Andersen,* *et* *al\\.\/) \r\n      printf(\"skipping %s\\n\", $0);\r\n    else if (\/\f\/)\r\n      printf(\"skipping2 %s\\n\", $0);\r\n    else if (\/Internet Low Bit Rate Codec *December 2004\/)\r\n      printf(\"skipping3 %s\\n\", $0);\r\n    else if (\/Authors' *Addresses\/){\r\n      close(srcname);\r\n      exit;}\r\n    else\r\n      print $0 &gt;&gt; srcname;\r\n  }\r\n}\r\nEND {\r\n  printf(\"ending file %s\\n\", srcname);\r\n  close(srcname);\r\n}<\/pre>\n<p style=\"text-align: left;\">Now, run:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">.\/configure &#8211;disable-xmldoc<\/p>\n<p style=\"text-align: left;\">That should run through without any issues, so now we&#8217;re going to tell Asterisk that we only want to build a very basic system (for the sake of time) and we want the iLBC codec. To enable the iLBC Codec you need to ensure in &#8220;4. Codec Translators&#8221; that &#8220;codec_ilbc&#8221; is checked.<\/p>\n<p style=\"text-align: left;\"><strong>Note:<\/strong> When you press &#8220;Esc&#8221; to quit &#8220;make menuconfig&#8221;, make sure you press <strong><span style=\"text-decoration: underline;\">S<\/span><\/strong> to save changes.<\/p>\n<p style=\"text-align: left;\">Now, just type &#8220;make&#8221; and watch the system build! As soon as you see codec_ilbc you can press Ctrl + C to stop it building. You&#8217;ll notice codec_ilbc being built just after all the app_ files, so it&#8217;s safest to stop the build process when you see the format_ files being built. Either that or let it run right the way through. It&#8217;s OK, nothing will *actually* be installed, so it doesn&#8217;t matter if you let it finish, it&#8217;s not going to harm your system in any way.<\/p>\n<p style=\"text-align: left;\">Almost done now, you just need to copy\u00c2\u00a0.\/codecs\/codec_ilbc.so to \/usr\/lib\/asterisk\/modules (or \/usr\/lib64\/asterisk\/modules on a 64-bit system) and chmod 755\u00c2\u00a0<span style=\"background-color: #ffffff;\">\/usr\/lib\/asterisk\/modules\/codec_ilbc.so<\/span><\/p>\n<p style=\"text-align: left;\">\u00c2\u00a0<\/p>\n<p style=\"text-align: center;\"><strong>5) Trunk and Extension setup<\/strong><\/p>\n<p style=\"text-align: left;\">Now depending on if you want your Ext or SIP Trunk to use the codec, it may be desirable to &#8220;force&#8221; the system to only use that codec.<\/p>\n<p style=\"text-align: left;\"><strong>To setup a Trunk:<\/strong> Open the SIP \/ IAX2 Trunk that you wish to limit in Elastix to the particular codec. In the PEER Details add an additional two lines:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">disallow=all<br \/> <span style=\"background-color: #ffffff;\">allow=g729&amp;ilbc<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"background-color: #ffffff;\">You may want to opt for something such as &#8220;allow=g729&amp;g711&#8221; or perhaps &#8220;allow=ilbc&amp;alaw&#8221; for example. Review your needs and act appropriately. Save and submit the changes.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"background-color: #ffffff;\"><strong>To setup an Ext:<\/strong> Open the Ext that you wish to limit the particular codec on. Scroll down to &#8220;disallow&#8221; and enter in &#8220;all&#8221;. Next in the &#8220;allow&#8221; field enter in something such as &#8220;g729&#8221; or &#8220;ilbc&#8221;, or perhaps &#8220;ilbc&amp;alaw&#8221; as above with the Trunk.\u00c2\u00a0Save and submit the changes when done.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"background-color: #ffffff;\"><strong>Notes:<\/strong> Try and avoid transcoding where possible. It&#8217;s nice that asterisk does it so well, however it does add marginal delay to your calls, not to mention CPU overheads etc.<\/span><\/p>\n<p style=\"text-align: left;\"><span style=\"background-color: #ffffff;\">Also keep in mind that if you limit the codecs, say to just g729, and a particular device is unable to use g729, the call will simply fail.<\/span><\/p>\n<p style=\"text-align: left;\">\u00c2\u00a0<\/p>\n<p style=\"text-align: center;\"><strong>6) Testing the codecs<\/strong><\/p>\n<p style=\"text-align: left;\">The best part, testing! Hopefully everything has gone according to plan thus far. You&#8217;ve got one or two new codecs setup and you&#8217;re dying to test them out (In a development \/ testing environment naturally and not on your companies production PBX). Now you need to ssh in to your asterisk system and run:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">asterisk -r<\/p>\n<p style=\"text-align: left;\">This brings up the asterisk console. Now, make a call on one of your new Ext&#8217;s that should be using iLBC \/ g729, or over the trunk that should be compressed.<\/p>\n<p style=\"text-align: left;\">While that call is active, rush back over to your ssh session and in the asterisk console type:<\/p>\n<p style=\"text-align: left; padding-left: 30px;\">sip show channels<\/p>\n<p style=\"text-align: left;\">You should see something like this:<\/p>\n<pre style=\"padding-left: 30px;\">x.x.x.x   09xxxxxxx   2408517b625  00101\/00102  0x400 (ilbc)     No       Rx: ACK<\/pre>\n<p style=\"text-align: left;\">If you&#8217;re making a pure SIP call, you&#8217;ll see one line for the Ext -&gt; Asterisk, and one line from Asterisk -&gt; your SIP Provider.<\/p>\n<p style=\"text-align: left;\">Success!<\/p>\n<p style=\"text-align: left;\">Thanks for reading, and if you have any questions please feel free to leave comments or post in the Elastix forums.<\/p>\n<p style=\"text-align: left;\">Please also keep in mind that whilst g729 \/ iLBC are not the only codecs, almost every device that supports compression is likely to support one of them, or if not it will support GSM.<\/p>\n<p style=\"text-align: left;\">Hopefully as you&#8217;re reading this you&#8217;re happily making calls via iLBC or g729. Enjoy!<\/p>\n<p style=\"text-align: left;\"><strong>Files for reference:<\/strong><\/p>\n<p style=\"text-align: left;\">extract-cfile.awk mirror: <a href=\"http:\/\/www.c2s.co.nz\/blog\/files\/ilbc\/extract-cfile.awk\">http:\/\/www.c2s.co.nz\/blog\/files\/ilbc\/extract-cfile.awk<\/a><\/p>\n<p style=\"text-align: left;\">iLBC Source code extracted from\u00c2\u00a0rfc3951.txt (Extract to your Asterisk source &#8216;codecs&#8217; directory and it&#8217;ll create the &#8216;ilbc&#8217; dir needed): <a href=\"http:\/\/www.c2s.co.nz\/blog\/files\/ilbc-src.tar.bz2\">http:\/\/www.c2s.co.nz\/blog\/files\/ilbc-src.tar.bz2<\/a><\/p>\n<p style=\"text-align: left;\">\u00c2\u00a0i686 compiled iLBC on Elastix-2.0 running asterisk-1.6.2.13: <a href=\"http:\/\/www.c2s.co.nz\/blog\/files\/codec_ilbc.so\">http:\/\/www.c2s.co.nz\/blog\/files\/codec_ilbc.so<\/a><\/p>\n\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Updated Sept 2011 for Elastix-2.* and Asterisk-1.6+ as well as the broken links since Google seems to have taken over GIPS We all know that g711 (alaw \/ ulaw) is meant to sound the best. It&#8217;s uncompressed and equivalent quality to ISDN, which most businesses are used to with their traditional PABX System. However, it [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[3],"tags":[11,20,23,42,43,55,74,77,91,95,157,187,188],"class_list":["post-18","post","type-post","status-publish","format-standard","hentry","category-elastix-org-blog","tag-adsl","tag-asterisk","tag-bandwidth","tag-codecs","tag-compression","tag-elastix","tag-g729","tag-gsm","tag-ilbc","tag-intraoffice","tag-sip-bandwidth","tag-voip","tag-voip-bandwidth"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pWi3e-i","jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/posts\/18","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=18"}],"version-history":[{"count":4,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions"}],"predecessor-version":[{"id":811,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/posts\/18\/revisions\/811"}],"wp:attachment":[{"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=18"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=18"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.c2s.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=18"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}