Get Asterisk to Use the G.729a Codec

I’m using Asterisk 1.8.5 under FreePBX 2.8.1.4. My endpoints (Polycom IP430 phone, SPA3102 ATA) and my ITSP all support the G.729a codec. I wanted to test audio quality using this compressed codec.

G.729a requires that you purchase a license if you are converting (transcoding) the audio to another codec. Although the licenses are inexpensive, I preferred to avoid the overhead of transcoding by simply passing through the G.729a packets.

“Passing through” means that both legs of the call must use G.729a. At first I hoped to be able to use the standard ulaw (G.711u) codec for all calls except those going to my ITSP. However, I eventually found that if the first leg of a call prefers ulaw, and the second leg requires G.729a, Asterisk will not go back and reinvite the first leg using G.729a (see my comment in this thread). Bottom line:  we need to set up the PBX to use G.729a on all calls, internal and external.

Setting It Up

Once that was clear, the setup was fairly simple:

  1. Download the current g729 sound files from Digium:
    asterisk-core-sounds-en-g729-current.tar.gz
    asterisk-extra-sounds-en-g729-current.tar.gz

    These are required for the voicemail system to work after converting to G.729.
  2. On the Asterisk machine, under /var/lib/asterisk/sounds, rename the en directory to en.gsm.
  3. Create a new en directory and extract the new sounds there. Recursively change the group and Owner to asterisk and the permissions to 775 to match the original “en” directory.
  4. In the FreePBX admin panel, go to Tools > Config Edit. Add the following lines to sip_general_custom.conf:
    disallow=all
    allow=g729
    allow=ulaw
    allow=alaw
    allow=gsm

    That puts g729 as the first priority for the whole system.
  5. From the console, open the Asterisk CLI (asterisk –r). Make a call and type sip show channels. You should see the g729 codec on both legs of the call, whether you call internally or externally. Do try all combinations to make sure that G.729a is supported throughout. If not, the call will fail and you’ll see a corresponding message in the log (Tools > Asterisk Logfiles). (Or if you a the G.729a license, the call will succeed but will be transcoded.)

Update:  Still Need to Transcode

November 5, 2011: Alas, not as easy as I thought. The above did set up G.729a pass-through on outbound calls. However, some problems remained:

  • Inbound calls through the SPA3102 were still in G.711u format. Since Asterisk tried to use G.729a for the second leg, the call failed without a transcoder. Changing the SPA3102’s Preferred Codec to G729a solved that problem.
  • Voicemail greetings are not available in .g729 format. Converting from .WAV to .g729, or even creating new greetings in .g729, seems to require a transcoder.
  • Voicemail messages are not stored in .g729. This can be remedied by adding g729 to the list of formats in voicemail.conf, but still seems to have trouble without a transcoder.
  • Rod Montgomery, Directory of Services at Digium, writes in this thread that without a transcoder, Asterisk will not be able to process audio, e.g. DTMF codes for IVR and voicemail. I’m not sure about this one—it seemed to handle the DTMF when I called internally anyway.

Bottom line, it still makes sense to set up pass-through for actual phone calls, but there are so many places that audio conversion is needed that it makes sense to get the transcoder. As Mr. Montgomery says in the post linked above, you only need as many licenses as you have simultaneous channels doing transcoding. So if you are making all calls in pass-through mode, you only need a few licenses for receiving and accessing voicemail, and possibly for IVR.

Info on transcoder licensing is available here. For testing purposes, open-source binaries are available here.

2 thoughts on “Get Asterisk to Use the G.729a Codec

  1. Mark Berry Post author

    I’m no longer using any in-house server–I just connect my IP phone directly to the ITSP. I am still maintaining Asterisk (PBX in a Flash) for a client. That client upgraded their Internet connection so was able to go back to G.711u.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.