Opened 9 years ago
Last modified 8 years ago
#1888 closed enhancement
Support for WebRtc Accoustic Echo Cancellation — at Version 1
Reported by: | ming | Owned by: | nanang |
---|---|---|---|
Priority: | normal | Milestone: | release-2.5 |
Component: | pjmedia | Version: | trunk |
Keywords: | Cc: | ||
Backport to 1.x milestone: | Backported: | no |
Description (last modified by ming)
How to build WebRTC
Mac
Refer to WebRtc development guide here.
Then configure PJSIP with:
./configure --with-webrtc=/Users/me/webrtc-mac
iOS (ARM)
Refer to WebRtc development guide here.
PJSIP's auto configuration will look for the library in out_ios/Release folder, so make sure you set the output dir properly when building WebRtc
export GYP_GENERATOR_FLAGS="output_dir=out_ios" ninja -C out_ios/Release
Then configure PJSIP with:
./configure --with-webrtc=/Users/me/webrtc-iphone
Android (ARM)
Android development is only supported on Linux (reference here), so if you use other platforms, you need to set up a Linux virtual machine.
Alternatively, you can build the stripped down version of WebRtc instead, which will only build the required AEC module and its required dependencies. These steps below are tested on a Mac machine:
- Create a working directory, for example: webrtc-android, and create a jni/ folder inside it.
- Copy Application.mk and Android.mk (provided in the ticket attachment below) into the jni directory.
- Create src/ folder inside the jni directory.
- Copy the entire webrtc folder from another platform's WebRtc installation (such as from Mac or iOS), which should be located in [webrtc_work_dir]/src, into webrtc-android/jni/src. In the end of this step, you should have both .mk files in jni folder and a full WebRtc source inside jni/src/webrtc.
- Go to jni folder and run ndk-build.
- Copy the resulting .so files from ../libs/[target_architecture] into your Android application project directory, for example:
cp ../libs/armeabi/*.so /Users/me/pjproject/pjsip-apps/src/swig/java/android/libs/armeabi
- Add this in PJSIP's user.mak, located inside PJSIP's work dir:
export CFLAGS += -I"/Users/me/webrtc-android/src" -DPJMEDIA_HAS_WEBRTC_AEC=1 -DPJMEDIA_WEBRTC_AEC_USE_MOBILE=1 export LDFLAGS += -L"/Users/me/webrtc-android/libs/armeabi" -lwebrtc
Rebuild PJSIP.
For other architectures
(or custom WebRTC installation undetected by configure script)
You can customize PJSIP's user.mak file, located inside PJSIP's work dir:
export CFLAGS += -I"/Users/me/webrtc/src" -DPJMEDIA_HAS_WEBRTC_AEC=1 # Uncomment below if you are on mobile platform # export CFLAGS += -DPJMEDIA_WEBRTC_AEC_USE_MOBILE=1 export LDFLAGS += -L/Users/me/webrtc/[WebRTC_lib_path] -laudio_processing -lcommon_audio -lsystem_wrappers # If you build for ARM architecture, uncomment below # export LDFLAGS += -laudio_processing_neon -lcommon_audio_neon # Or else, if you build for MIPS architecture, uncomment below # export LDFLAGS += -laudio_processing_neon -lcommon_audio_neon # Or else, if your machine supports SSE2, uncomment below # export LDFLAGS += -laudio_processing_sse2
Then rebuild PJSIP.
How to use WebRtc AEC
To use WebRtc AEC, specify the value PJMEDIA_ECHO_WEBRTC in pjsua_media_config.ec_options (MediaConfig.ecOptions for PJSUA2), and specify the delay estimate for sound card and system buffers in pjsua_media_config.ec_tail_len (MediaConfig.ecTailLen for PJSUA2). WebRtc AEC's performance is very dependent on this delay calculation. A poor estimate, even by as little as 40ms, may affect the echo cancellation results greatly. Our WebRtc wrapper has enabled the delay agnostic feature, which will adjust the delay accordingly, however it may take some time (5-10s or more) for the Aec module to learn the optimal delay, thus a good initial estimate is necessary for good EC quality in the beginning of a call.
In PJSUA sample application, run it with the options --ec-opt=3 and specify the delay estimate in --ec-tail options. For example:
./pjsua --ec-opt=3 --ec-tail=40
Poor WebRtc EC quality
Change the definition of SHOW_DELAY_METRICS in pjmedia/src/pjmedia/echo_webrtc.c to a non-zero value. For example, if you set to 250, with ptime 20ms, it will print the delay metrics stats every 5 seconds or so.
#define SHOW_DELAY_METRICS 250
What you need to see in the log is the line:
fraction of poor delays=%f
Which is a value between 0 and 1. The closer the value to 1, the poorer the EC quality, try adjusting the EC tail value to the median value to achieve better quality.