2016年7月6日 星期三

PJSIP with WebRTC AEC on embedded Linux

While studying open source AEC (Acoustic Echo Cancellation) on the internet, I found that google release an open source project called WebRTC can do good job. There are more good news that PJSIP can work with WebRTC AEC. Then I found there are few information about how to get them work. After some research, finally it works. Below is my procedure.

1.Software

pjproject-2.5.1
http://www.pjsip.org/release/2.5.1/pjproject-2.5.1.tar.bz2

webrtc-audio-processing
https://www.freedesktop.org/software/pulseaudio/webrtc-audio-processing/#download

The "offical" WebRTC needs a lot of other tools to compile (No autoconf / Makefile) and makes everything difficult.

2.Environment
iMX6 / arm-cortex A9
Embedded Linux / buildroot

3.Compile webrtc-audio-processing

# cd webrtc-audio-processing
# ./autogen.sh
# CFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -O2" CXXFLAGS="-march=armv7-a -mfpu=neon -mfloat-abi=softfp -O2" CC=arm-buildroot-linux-gnueabi-gcc CXX=arm-buildroot-linux-gnueabi-g++ AR=arm-buildroot-linux-gnueabi-ar ./configure --host=arm-linux --target=arm-linux --prefix=/home/gigijoe/imx6sabre/sysroot --cache-file=/dev/null
# make

Copy ./webrtc/modules/audio_processing/.libs/libwebrtc_audio_processing.so.1.0.0 to your target

4.Compile PJSIP

Patch pjproject-2.5.1/aconfigure

##################################################

--- ./pjproject-2.5.1.original/aconfigure 2016-05-18 00:01:59.000000000 +0800
+++ pjproject-2.5.1/aconfigure 2016-07-05 21:27:12.514799348 +0800
@@ -7438,7 +7438,8 @@
   if test "x$with_webrtc" != "xno" -a "x$with_webrtc" != "x"; then
         WEBRTC_PREFIX=$with_webrtc
-   WEBRTC_CFLAGS="-I$WEBRTC_PREFIX/src"
+   #WEBRTC_CFLAGS="-I$WEBRTC_PREFIX/src"
+ WEBRTC_CFLAGS="-I$WEBRTC_PREFIX"
  case $target in
     *-apple-darwin_ios*)
@@ -7453,8 +7454,10 @@
  esac
  ;;
     *mingw* | *cygw* | *win32* | *w32* | *darwin* | *linux* | *android*)
-        WEBRTC_LDFLAGS="-L$WEBRTC_PREFIX/src/out/Release"
-        WEBRTC_LIBS="-laudio_processing_sse2"
+        #WEBRTC_LDFLAGS="-L$WEBRTC_PREFIX/src/out/Release"
+ WEBRTC_LDFLAGS="-L$WEBRTC_PREFIX/webrtc/modules/audio_processing/.libs"
+        #WEBRTC_LIBS="-laudio_processing_sse2"
+ WEBRTC_LIBS="-lwebrtc_audio_processing"
  ;;
     *)
  ;;
@@ -7467,7 +7470,7 @@
  WEBRTC_LDFLAGS=""
   fi
-  WEBRTC_LIBS="$WEBRTC_LIBS -laudio_processing -lcommon_audio -lsystem_wrappers"
+  #WEBRTC_LIBS="$WEBRTC_LIBS -laudio_processing -lcommon_audio -lsystem_wrappers"
   SAVED_LIBS="$LIBS"
   SAVED_LDFLAGS="$LDFLAGS"

##################################################

# cd pjproject-2.5.1
# ac_cv_lib_audio_processing_WebRtcAec_Process=yes CC=arm-buildroot-linux-gnueabi-gcc CXX=arm-buildroot-linux-gnueabi-g++ AR=arm-buildroot-linux-gnueabi-ar ./configure --host=arm-linux --target=arm-linux --prefix=/home/gigijoe/imx6sabre/sysroot --with-webrtc=$PWD/../webrtc-audio-processing --cache-file=/dev/null
# make

Copy ./pjsip-apps/bin/pjsua-arm-unknown-linux-gnu to your target

5.Running and test
pjsua-arm-unknown-linux-gnu --ec-opt=3 --ec-tail=30

Then make a call to test

6.AEC performance 

This is the best result of echo cancellation among open source AEC I have ever tested.
Very close to commerical product.

By enabling NEON hardware floating, the CUP usage while talking (G.711 uLaw) is around 2% ~ 20%