Ticket #1888 (closed enhancement: fixed)

Opened 18 months ago

Last modified 6 months ago

Support for WebRTC Acoustic Echo Cancellation

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) (diff)

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.

The delay should be at least as much as frame time (by default, ptime is 20ms) + PJMEDIA_WSOLA_DELAY_MSEC (the default is 5ms).

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=30

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).

Problem with EC quality on Mac

The problem with echo on Mac and negative delay has been reported by several of our users and seems to be a known issue, as documented in Chrome M45 WebRTC Release Notes and Issue 3929: AEC on Mac can be put in non-causal state. Unfortunately, there's no known workaround as of now.



*Starting from release 2.6, the build instructions below is no longer required since WebRTC has been integrated into third_party. For more details, please refer to ticket #1954 instead.*

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

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.

Compatibility issue

There is a known compatibility issue with recent WebRTC version, so we'd recommend to use an older WebRTC version, e.g: about October 2015 version.

Attachments

webrtc-android-jni.zip (355.2 KB) - added by ming 18 months ago.
WebRtc AEC for Android

Change History

comment:1 Changed 18 months ago by ming

  • Description modified (diff)

comment:2 Changed 18 months ago by ming

  • Description modified (diff)

Changed 18 months ago by ming

WebRtc AEC for Android

comment:3 Changed 18 months ago by ming

  • Status changed from new to closed
  • Resolution set to fixed

In 5186:

Fixed #1888: Support for WebRtc? AEC

comment:4 Changed 18 months ago by ming

  • Description modified (diff)

comment:5 Changed 18 months ago by ismangil

  • Description modified (diff)
  • Summary changed from Support for WebRtc Accoustic Echo Cancellation to Support for WebRTC Accoustic Echo Cancellation

comment:6 Changed 18 months ago by ismangil

  • Summary changed from Support for WebRTC Accoustic Echo Cancellation to Support for WebRTC Acoustic Echo Cancellation

comment:7 Changed 18 months ago by ismangil

  • Description modified (diff)

comment:8 Changed 18 months ago by ismangil

  • Description modified (diff)

comment:9 Changed 9 months ago by nanang

  • Description modified (diff)

comment:10 Changed 7 months ago by ming

  • Description modified (diff)

comment:11 Changed 6 months ago by ming

  • Description modified (diff)
Note: See TracTickets for help on using tickets.