Opened 9 years ago

Last modified 8 years ago

#1888 closed enhancement

Support for WebRtc Accoustic Echo Cancellation — at Version 2

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:

  1. Create a working directory, for example: webrtc-android.
  2. Go to the work dir and unzip webrtc-android-jni.zip (provided in the ticket attachment below).
  3. Go to jni folder and run ndk-build.
  4. 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
    
  5. 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 want to use the lighter, mobile-optimized version
# 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

Disable PJMEDIA_WEBRTC_AEC_USE_MOBILE (set it to 0), then 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:

median=%d, std=%d, fraction of poor delays=%f

Fraction of poor delays is a value between 0 and 1. The closer the value to 1, the poorer the EC quality.

To improve the EC quality, here are a few things you can try:

  • Adjust the EC tail value to the median value.
  • Activate noise suppression (pass the options when creating EC with flag PJMEDIA_ECHO_USE_NOISE_SUPPRESSOR).
  • Increase EC aggressiveness (pass the options when creating EC with flag PJMEDIA_ECHO_AGGRESSIVENESS_AGGRESSIVE).
  • Disable the mobile version by setting PJMEDIA_WEBRTC_AEC_USE_MOBILE to 0 (by doing this, AEC will operate in floating-point mode (instead of integer), which may decrease performance).

Change History (3)

comment:1 Changed 9 years ago by ming

  • Description modified (diff)

comment:2 Changed 9 years ago by ming

  • Description modified (diff)

Changed 9 years ago by ming

WebRtc AEC for Android

Note: See TracTickets for help on using tickets.