Skip to content

Add support for WebRTC AEC3#2722

Merged
sauwming merged 20 commits intomasterfrom
webrtc-aec3
Jun 3, 2021
Merged

Add support for WebRTC AEC3#2722
sauwming merged 20 commits intomasterfrom
webrtc-aec3

Conversation

@sauwming
Copy link
Copy Markdown
Member

@sauwming sauwming commented Jun 1, 2021

The current WebRTC source included in PJSIP is already quite old (from Oct 2015) and only supports a clock rate of 16 KHz (see #2404). So in this PR, we add the latest WebRTC AEC3 into PJSIP.

Requirement: C++17
Due to this requirement, and the complexity needed to build the AEC3 component (in my local Mac machine, PJSIP build time nearly doubles from ~35 sec to ~65 sec if AEC3 is included), by default AEC3 will be disabled and the old WebRTC AEC is still made available.

Licenses: check third_party/webrtc_aec3/PJSIP_NOTES about the licenses of WebRTC itself and external third party components required, such as abseil, rnnoise, and pffft.

Features:

  • AEC3
  • Noise Suppressor
    Pass the option PJMEDIA_ECHO_USE_NOISE_SUPPRESSOR to enable it.
  • AGC2
    The next generation AGC functionality. AGC2 aims to automatically adjust levels by acting on the microphone gain and/or applying digital gain.
    Pass the option PJMEDIA_ECHO_USE_GAIN_CONTROLLER to enable it.

To support WebRTC AEC3, enable it when configuring PJSIP, i.e.:
./configure --enable-libwebrtc-aec3
And check if it can be built:
checking if WebRtc AEC3 can be compiled with C++17... yes

To use it, specify PJMEDIA_ECHO_WEBRTC_AEC3 in pjsua_media_config.ec_options or MediaConfig::ecOptions.
You can test with our sample app pjsua, by pass the number 4 as the EC option desired, i.e..:
./pjsua --ec-opt=4
You can check the EC statistics using the API pjsua_get_ec_stat() or from pjsua_call_dump(). It will output information like this:
EC stat: WebRTC AEC3 metrics: delay=12 ms, return loss=-7.30, return loss enh=1.09

Copy link
Copy Markdown
Member

@ismangil ismangil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also update detailed Licensing wiki

Copy link
Copy Markdown
Member

@nanangizz nanangizz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As briefly discussed before, there seem to be no microphone gain adjustment? So perhaps we should remove or add some notes about "acting on the microphone gain" in the PR desc?

@sauwming
Copy link
Copy Markdown
Member Author

sauwming commented Jun 2, 2021

As briefly discussed before, there seem to be no microphone gain adjustment? So perhaps we should remove or add some notes about "acting on the microphone gain" in the PR desc?

It's the original wording in their documentation, taken from:
https://github.com/pjsip/pjproject/blob/webrtc-aec3/third_party/webrtc_aec3/src/modules/audio_processing/gain_controller2.h#L28

And the dictionary says that "acting on" means "to use (something, such as a feeling or suggestion) as a reason or basis for doing something", so what the doc says is that it uses microphone gain information and then apply digital gain based on that info.

@sauwming sauwming merged commit 0046373 into master Jun 3, 2021
trengginas added a commit that referenced this pull request Apr 19, 2022
sauwming pushed a commit that referenced this pull request Sep 29, 2022
wosrediinanatour pushed a commit to wosrediinanatour/pjproject that referenced this pull request Jan 16, 2023
wosrediinanatour pushed a commit to wosrediinanatour/pjproject that referenced this pull request Jan 16, 2023
wosrediinanatour pushed a commit to wosrediinanatour/pjproject that referenced this pull request Jan 16, 2023
@maneeshj
Copy link
Copy Markdown

I did the above steps to build AEC3, but my logs output AEC3 stats as all 0 numbers. I am not sure if AEC is actually kicked in or not. Does O in return loss, delay indicate it is not being used ?

@monocyte
Copy link
Copy Markdown

monocyte commented Mar 14, 2023

Having the same issue: followed build instructions on macOS and Windows, but every call stats show zeroes in AEC3 stats on both OS:
EC stat: WebRTC AEC3 metrics: delay=0 ms, return loss=0.00, return loss enh=0.00
I used opus codec and ec_options == PJMEDIA_ECHO_WEBRTC_AEC3 | PJMEDIA_ECHO_USE_NOISE_SUPPRESSOR.

After some research I discovered that echo cancellation is working (at least it's created and called in echo_webrtc_aec3.cpp), but stats (using pjsua_call_dump) are printed before webrtc_aec3_cancel_echo is called with echo->get_metrics == PJ_TRUE, so they are empty.

@sauwming sauwming deleted the webrtc-aec3 branch June 5, 2023 16:01
@fbreton06
Copy link
Copy Markdown

Hi guys, sorry it's probably not the better location to post that.
I've write a python program to establish a SIP audio communication on my Raspberry4.
It's based on pjsua2 module from PJSIP V1.13.1 release.
I'm trying to suppress echo with activating the PJMEDIA_ECHO_WEBRTC_AEC3, but result is disappointing.
Has anyone advices to improve that?
cheers,

BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
BarryYin pushed a commit to BarryYin/pjproject that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants