trixbox and the g729 audio codec for smaller bandwidth utilization

trixbox CE (formerly asterisk@home) is a great and easy to use linux based VOIP phone server.  It takes some great open source projects like asterisk, freePBX and others, and ties it all together under a nice easy to use web GUI interface.  

trixbox also makes installing your phone server a snap;  All that's required is for you to have a clean server ready for install, and to download one of their .iso images.  Then just pop it in the drive, follow the on-screen prompts, and you'll have a trixbox phone server set up in no time!

When using any VOIP solution, it's important to use an audio codec that makes the most of your bandwidth, while not sacrificing audio quality.  Compress too much, and the phone call sounds "tinny" or just all together strange, but not enough compression can lead you with stuttering and dropped calls if you start to max out your internet connection's bandwidth.

Quality of Service (QoS) settings in your router can help to alleviate this issue, but if your'e just using more bandwidth than you have available, then better compression is the way to go.

By default, trixbox uses the "ulaw" codec to compress its audio.  ulaw offers acceptable call quality, but doesn't really do a whole lot actually compressing the data in order to use up less of your bandwidth.  If you have multiple users making phone calls at the same time, you may run into quality issues using ulaw when you start maxing out your internet capacity.

Luckily, trixbox allows us to install any codecs that we want, and there's one called "g729" that uses significantly less bandwidth than ulaw, while keeping voice quality.  g729 was originally created by Digium, and you can still buy licenses for the codec from them if you want.  However, the open source community has come up with a free and open g729 codec that you can use for free!

To install this codec on your trixbox machine, there's a couple things you'll need to do:

  • Download and install the actual codec
  • Configure trixbox to use the codec for your phone calls and extensions

 

Download and install the g729 codec

You can downlod the g729 codec from http://asterisk.hosting.lv/

They provide pre-compiled binaries for many different architectures and asterisk versions, as well as source code if there isn't a binary available for your system.

For this article, we're going to use a pre-compiled binary.  The list of binaries available can be found at http://asterisk.hosting.lv/#bin

For this example, the test trixbox machine looks like this:

  • Pentium 3 class processor
  • trixbox 2.8.0.4 (asterisk 1.6.0.26)

To find the codec you need for your machine, browse to the link above, to the list of binaries.  Then click your asterisk version in the right-hand column to expand the list of modules available for that particular version of asterisk.  In our example, we would click on Asterisk 1.6 since we're running asterisk 1.6.0.26.

Then find the codec in the list that's the right one for your processor architecture.  For our example, we want to download the codec called: codec_g729-ast16-gcc4-glibc-pentium3.so

You'll want to find the codec that's named similarly for your processor architecture (ie codec_g729-ast<asterisk-version>-gcc4-glibc-<processor-arch>.so)

 

Once you've found the appropriate codec for your system, you need to upload it to your trixbox server.  You can do this via SSH / SFTP, upload the file to the directory /usr/lib/asterisk/modules.  Then log into your trixbox as root via SSH.  Issue the following commands to install and load the asterisk module:

(Adjust the module name below the whichever one you downloaded; only type the commands in bold, the beginning characters represent the prompts you might see on your system)

  1. #  asterisk -r
  2. *CLI>  load codec_g729-ast16-gcc4-glibc-pentium3.so

You should then see something like:

Loaded /usr/lib/asterisk/modules/codec_g729-ast16-gcc4-glibc-pentium3.so => (G729/PCM16 (signed linear) Codec Translator, based on IPP)

== Registered translator 'g729tolin' from format g729 to slin, cost 1
== Registered translator 'lintog729' from format slin to g729, cost 6
 
  1. *CLI> quit

To exit the asterisk command line interface (CLI).

If the above "load" command doesn't work, or asterisk gives you some error about an unknown command, just restart your asterisk server instead:

# service asterisk restart or # /etc/init.d/asterisk restart Should do it.

 

Now that the codec is installed, you need to configure trixbox to use it.  If you want to verify that the codec is loaded, you can issue a "core show codecs" command from the CLI before you type quit.  g729 should be in that list if the codec was loaded properly.

 

Configuring trixbox to use the g729 codec

There are a couple places that trixbox needs to be configured to use the g729 codec.  Generally you want to at least set it to be used on your outbound trunk.  You can also configure trixbox so that your extensions utilize the g729 codec instead of ulaw when communicating with your trixbox server.

Configuring the outbound trunk

  1. Connect to your trixbox web interface by typeing the IP address of your trixbox server into your web browser
  2. In the upper right hand corner, next to where it says User Mode, click on the switch link to switch to admin mode
  3. Type in maint for the user and the password you set up for your main account
  4. Click on the PBX menu > PBX Settings
  5. In the left-hand column, click on Trunks
  6. Find the outbound trunk you want to configure in the list on the right side of the page and click on it
  7. In the PEER Details section, look for lines that say something similar to:

disallow=all

allow=ulaw

  1. and change it to:

disallow=all

allow=g729

  1. Click on tthe Submit Changes button at the bottom
  2. Now you should see an orange link near the top of the page, under the menu that says Apply Configuration Changes
  3. Click on that link, and an orange screen will pop up asking you to confirm the restart
  4. Confirm the restart, and now your calls that are placed through that outgoing trunk should be using g729!

To confirm that g729 is being used, start a phone call from one of your extensions.  While the call is still active, login to your trixbox server using SSH, and connect to the asterisk CLI using the asterisk -r command.  Once in the CLI, issue the following command to see the status of your current active calls:

*CLI> sip show channels

And you should see something like:

a.b.c.d    19899770645      6692ab3b7a0a280  0x100 (g729)     No       Tx: INVITE

e.f.g.h      300              000427f6-067d00  0x100 (g729)     No       Rx: INVITE
 
If you see (g729) in that list, g729 is being used as your codec!
 
Now, if you want to use g729 for all communications between the trixbox server and your extensions, you need to configure that through the web GUI as well.
 
Configuring extensions to use g729
  1. Get back into the web GUI, switch to admin mode, go to PBXPBX Settings
  2. In the left hand column, click on Extension
  3. Find the extension you want to midify in the list on the right hand side of the page and click on it
  4. Scroll down until you find the Device Options section
  5. Enter all in the disallow field
  6. Enter g729 in the allow field
  7. Click Submit to save your changes
  8. When you're all done modifying extensions, don't forget to click the orange Apply Configuration Changes link so that your changes take effect

That should be it.  Now the extension(s) should use g729 to communicate w/the trixbox server as well.  You can verify this using the sip show all command from the asterisk CLI.

 

Now your trixbox phone server should be using less of your bandwidth and maintaining a better quality call!