Abhishek Singh Bailoo

Weblog

Feb 1

G.729 Codec FreeSWITCH

Intel G.729 Codec on FreeSWITCH

           





== Introduction ==

Intel Primive Performance (IPP) Library is available at no cost for educational, research and non-commercial purpose.

We compile a new FreeSWITCH module for G729 codec based on IPP libraries.




== Method ==

Install Required Packages
  sudo apt-get install build-essential uuid-dev

The G729 IPP module for Asterisk is better maintained than that of FS. Therefore, we can use asterisk-g72x configure script and resulting Makefile to get proper compile flags for FS.

  hg clone https://bitbucket.org/arkadi/asterisk-g72x
  cd asterisk-g72x
  ./configure —with-ipp=/opt/intel/ipp
  make all

Once we are sure that this compiles without errors, we can use LDFLAGS and other flags from the Makefile for fsg729 module.

  hg clone https://code.google.com/p/fs-g729/
  cd fs-g729
  Change the Makefile to this
  $cat Makefile
    IPPARCH=x86_64
    LARCH=$(IPPARCH)
    CC=cc
    FSBASE=/usr/local/freeswitch
    IPPBASE=/opt/intel
    IPPCORE=m7

    CC_OPT=-fPIC -O3 -DIPPCORE_STATIC_INIT -DG729A_ENABLE -fomit-frame-pointer -march=native -fno-exceptions

    INCLUDE=-I$(IPPBASE)/ipp/include -include “$(IPPBASE)/ipp/tools/intel64/staticlib/ipp_$(IPPCORE).h” -I$(FSBASE)/include -I$(FSBASE)/libs/libteletone/src


    LDFLAGS =-Wl,-static -L”$(IPPBASE)/ipp/lib/intel64” -L”$(IPPBASE)/lib/intel64” -avoid-version -module  -lippsc_l -lipps_l -lippcore_l

    all : decg729.o encg729.o owng729.o vadg729.o aux_tbls.o libg729.o mod_ipp_g729.o
    $(CC) $(INCLUDE) -shared -O2 -Wall -Xlinker -x -o mod_ipp_g729.so  \
        mod_ipp_g729.o libg729.o decg729.o encg729.o owng729.o vadg729.o aux_tbls.o \
       -lm $(LDFLAGS) -L/usr/local/lib -Wl,-Bdynamic $(FSBASE)/lib/libfreeswitch.so -pthread -lrt -luuid -lcrypt


    decg729.o : decg729.c
     $(CC) $(CC_OPT) -c decg729.c $(INCLUDE)
    encg729.o : encg729.c
     $(CC) $(CC_OPT) -c encg729.c $(INCLUDE)
    owng729.o : owng729.c
     $(CC) $(CC_OPT) -c owng729.c $(INCLUDE)
    vadg729.o : vadg729.c
     $(CC) $(CC_OPT) -c vadg729.c $(INCLUDE)
    aux_tbls.o : aux_tbls.c
    $(CC) $(CC_OPT) -c aux_tbls.c $(INCLUDE)

    libg729.o: libg729.c
     $(CC) $(CC_OPT) -c libg729.c $(INCLUDE)
    mod_ipp_g729.o: mod_ipp_g729.c
     $(CC) $(CC_OPT) -c mod_ipp_g729.c $(INCLUDE)

    clean:
     rm -rf *.o *.so

    make clean
    make all

This should compile without errors.

After compiling module fs-g729, you will get mod_ipp_g729.so
This is dynamically linked shared object file with the following linking dependencies

  $ ldd mod_ipp_g729.so
  linux-vdso.so.1 =>  (0x00007fff72da8000)
  libm.so.6 => /lib/libm.so.6 (0x00007f9387a77000)
  libfreeswitch.so.1 => not found
  librt.so.1 => /lib/librt.so.1 (0x00007f938786e000)
  libuuid.so.1 => /lib/libuuid.so.1 (0x00007f9387669000)
  libcrypt.so.1 => /lib/libcrypt.so.1 (0x00007f9387430000)
  libpthread.so.0 => /lib/libpthread.so.0 (0x00007f9387212000)
  libc.so.6 => /lib/libc.so.6 (0x00007f9386e8f000)
  /lib64/ld-linux-x86-64.so.2 (0x00007f9387f86000)

As can be seen the dependency of libfreeswitch.so.1 is not satisfied. This is because although libfreeswitch.so.1 is present in /usr/local/freeswitch/lib but this directory is not present in the link library path.
Put export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/freeswitch/lib” in .bashrc
After that, check again with ldd to confirm that all linking dependencies are satisfied. If anything is still missing, you may need to apt-get install the concerned development library. For instance, sudo apt-get install build-essential uuid-dev etc.


  cp mod_ipp_g729.so /usr/local/freeswith/mod
  chown -R freeswitch.freeswith /usr/local/freeswith
  fs_cli>reload mod_ipp_g729.so
  fs_cli>show codec
 
The result shold contain

  codec,G.729 IPP Based,mod_ipp_g729
  codec,G.729 for broken devices (G729A SDP),mod_ipp_g729




== Intel IPP Samples: G729 Encoder and Decoder ==

  tar xvzf l_ipp-samples_p_7.0.6.046.tgz
  cd ipp-samples/
  cd speech-codecs/
  export IPPROOT=”/opt/intel/ipp”
  export LD_LIBRARY_PATH=”/opt/intel/ipp/lib/intel64/:/opt/intel/lib/intel64/”
  ldconfig (or sudo ldconfig)
  ./build_intel64.sh
  export PATH=”$PATH:$HOME/g729/ipp-samples/speech-codecs/_bin/intel64_gcc4/bin/”

To encode to G729A
  usc_speech_codec -n -format IPP_G729A foo.wav foo.g729a

To decode from G729A
  usc_speech_codec -n foo.g729a foo.wav

There is a 10x reduction in size form wav to g729a
  ivr-welcome_to_freeswitch.wav 41840
  ivr-welcome_to_freeswitch.g729a 4224

ISSUE: This does not seem to work, the resulting g729 coded files are not being played by the ipp_g729 module in FS.









== Results ==

You will see the following in the logs
  v=0
  o=FreeSWITCH 1326125840 1326125841 IN IP4 10.251.139.73
  s=FreeSWITCH
  c=IN IP4 10.251.139.73
  t=0 0
  m=audio 29294 RTP/AVP 18 96
  a=rtpmap:18 G729/8000
  a=fmtp:18 annexb=no
  a=rtpmap:96 telephone-event/8000
  a=fmtp:96 0-16
  a=silenceSupp:off - - - -
  a=ptime:20
  a=sendrecv

  sofia_glue.c:4727 Audio Codec Compare [G729:18:8000:20:8000]/[G7221:115:32000:20:48000]
  sofia_glue.c:4727 Audio Codec Compare [G729:18:8000:20:8000]/[G7221:107:16000:20:32000]
  sofia_glue.c:4727 Audio Codec Compare [G729:18:8000:20:8000]/[G729:18:8000:20:8000]
  switch_core_state_machine.c:380 (sofia/external/+6285368033158@10.251.138.4) State NEW
  sofia_glue.c:2848 Set Codec sofia/external/+6285368033158@10.251.138.4 G729/8000 20 ms 160 samples 8000 bits


Tested on Quad core AMD machine with 2 GB RAM for 750 concurrent calls.


== More Work ==




== References ==

https://code.google.com/p/fs-g729/

http://code.google.com/p/fsg729/

https://bitbucket.org/arkadi/asterisk-g72x

http://asterisk.hosting.lv/

http://www.readytechnology.co.uk/open/ipp-codecs-g729-g723.1/