前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >PJSIP支持webrtc回声消除处理

PJSIP支持webrtc回声消除处理

作者头像
呱牛笔记
发布2023-10-16 19:15:26
4470
发布2023-10-16 19:15:26
举报
文章被收录于专栏:呱牛笔记呱牛笔记

1、编译

支持webrtc-aec

./configure --host=arm-openwrt-linux-muslgnueabi ?--prefix=$PWD/install ?--disable-libwebrtc --disable-libyuv --disable-v4l2 ? --disable-opencore-amrnb --disable-speex-codec --disable-speex-aec --with-openh264=/home/lyz/work/broadcast_app/app/thirds_libs_src/pjproject-2.12.1/third_party/openh264-2.3.1 ?--enable-libwebrtc-aec3 --with-opus=/home/lyz/work/broadcast_app/app/thirds_libs_src/pjproject-2.12.1/third_party/opus/

支持外部webrtc

./configure --host=arm-openwrt-linux-muslgnueabi ?--prefix=$PWD/install --enable-libwebrtc --disable-libyuv --disable-v4l2 ? --disable-opencore-amrnb --disable-speex-codec --disable-speex-aec --with-openh264=/home/lyz/work/broadcast_app/app/thirds_libs_src/pjproject-2.12.1/third_party/openh264-2.3.1 ?--disable-libwebrtc-aec3 --with-opus=/home/lyz/work/broadcast_app/app/thirds_libs_src/pjproject-2.12.1/third_party/opus/

2、代码修改:增加两个方法处理播放和录制;

代码语言:javascript
复制
PJ_DEF(pj_status_t)?webrtc_aec_cancel_echo_playback(void?*state,
?????????????????????????pj_int16_t?*play_frm?){
????webrtc_ec?*echo?=?(webrtc_ec*)?state;
????unsigned?i,?j,?frm_idx?=?0;
????int?status;
????const?sample?*?buf_ptr;
?????????????????????????
????for(i?=?echo->samples_per_frame?/?echo->subframe_len;?i?>?0;?i--)?{
#if?PJMEDIA_WEBRTC_AEC_USE_MOBILE
	????????buf_ptr?=?&play_frm[frm_idx];
#else
	????????for?(j?=?0;?j?<?echo->subframe_len;?j++)?{
	????????????echo->tmp_buf2[j]?=?play_frm[frm_idx+j];
	????????}
	????????buf_ptr?=?echo->tmp_buf2;
#endif
????????
	????/*?Feed?farend?buffer?*/
	????status?=?WebRtcAec_BufferFarend(echo->AEC_inst,?buf_ptr,
	????????????????????????????????????????echo->subframe_len);
???????????frm_idx+=?echo->subframe_len;
????}
????return?PJ_SUCCESS;
}
PJ_DEF(pj_status_t)?webrtc_aec_cancel_echo_capture(void?*state,
?????????????????????????pj_int16_t?*rec_frm,
?????????????????????????unsigned?options?){
????webrtc_ec?*echo?=?(webrtc_ec*)?state;
????int?status;
????unsigned?i,?j,?frm_idx?=?0;
????const?sample?*?buf_ptr;
????sample?*?out_buf_ptr;
?????????????????
????for(i?=?echo->samples_per_frame?/?echo->subframe_len;?i?>?0;?i--)?{
#if?PJMEDIA_WEBRTC_AEC_USE_MOBILE
	????????buf_ptr?=?&rec_frm[frm_idx];
#else
	????????for?(j?=?0;?j?<?echo->subframe_len;?j++)?{
???????????		?echo->tmp_buf[j]?=?rec_frm[frm_idx+j];
	????????????echo->tmp_buf2[j]?=?NULL;
	????????}
???????	?buf_ptr?=?echo->tmp_buf2;
#endif
????????buf_ptr?=?echo->tmp_buf;
????????out_buf_ptr?=?echo->tmp_buf2;
#if?PJMEDIA_WEBRTC_AEC_USE_MOBILE
????????status?=?WebRtcAecm_Process(echo->AEC_inst,?&rec_frm[frm_idx],
????????????????????????????????????(echo->NS_inst??buf_ptr:?NULL),
????????????????????????????????????out_buf_ptr,?echo->subframe_len,
????????????????????????????????????echo->tail);
#else
????????status?=?WebRtcAec_Process(echo->AEC_inst,?&buf_ptr,
???????????????????????????????????echo->channel_count,?&out_buf_ptr,
???????????????????????????????????echo->subframe_len,?(int16_t)echo->tail,?0);
#endif
????????if?(status?!=?0)?{
????????????print_webrtc_aec_error("Process?echo",?echo->AEC_inst);
????????????return?PJ_EUNKNOWN;
????????}
?????????for?(j?=?0;?j?<?echo->subframe_len;?j++)?{
????????????rec_frm[frm_idx++]?=?(pj_int16_t)out_buf_ptr[j];
????????}
????}
????return?PJ_SUCCESS;
}
????

/*
?*?WebRTC?AEC?prototypes
?*/
#if?defined(PJMEDIA_HAS_WEBRTC_AEC)?&&?PJMEDIA_HAS_WEBRTC_AEC!=0
static?struct?ec_operations?webrtc_aec_op?=
{
????"WebRTC?AEC",
????&webrtc_aec_create,
????&webrtc_aec_destroy,
????&webrtc_aec_reset,
????&webrtc_aec_cancel_echo,
????&webrtc_aec_cancel_echo_playback,
????&webrtc_aec_cancel_echo_capture,
????&webrtc_aec_get_stat
};
#endif

"pjlib/include/pj/config_site.h"

3、支持外部webrtc

#define PJMEDIA_HAS_WEBRTC_AEC 1 # ? define PJMEDIA_WEBRTC_AEC_USE_MOBILE ? ? ? ?1

4、修改default.conf文件配置pjsua_app的启动配置文件支持回声消除:

代码语言:javascript
复制
#webrtc echo--ec-opt=3#webrtc-aec3 echo
#--ec-opt=4#--stereo--ec-tail=75

5、webrtc-aec3如何开启

代码语言:javascript
复制
./configure?--host=arm-openwrt-linux-muslgnueabi??--prefix=$PWD/install??
--disable-libwebrtc?--disable-libyuv?--disable-v4l2???--disable-opencore-amrnb?
--disable-speex-codec?--disable-speex-aec?
--with-openh264=/home/app/thirds_libs_src/pjproject-2.12.1/third_party/openh264-2.3.1??
--enable-libwebrtc-aec3?--with-opus=/home/ap/thirds_libs_src/pjproject-2.12.1/third_party/opus/?


修改third_party\build\os-auto.mak
ifneq?(,1)
ifeq?(0,1)
#?External?webrtc?AEC3
else
DIRS?+=?webrtc_aec3
WEBRTC_AEC3_OTHER_CFLAGS?=?-fexceptions?-mfpu=neon?-mfloat-abi=hard?-DWEBRTC_LINUX=1??-DWEBRTC_APM_DEBUG_DUMP=0?-DWEBRTC_POSIX=1
ifneq?($(findstring?sse2,sse2),)
#????export?WEBRTC_AEC3_SRC?=?\
#	common_audio/resampler/sinc_resampler_sse.o?\
#	common_audio/third_party/ooura/fft_size_128/ooura_fft_sse2.o
#????export?WEBRTC_AEC3_SRC?+=?\
#	common_audio/resampler/sinc_resampler_avx2.o?\
#	modules/audio_processing/aec3/adaptive_fir_filter_erl_avx2.o?\
#	modules/audio_processing/aec3/adaptive_fir_filter_avx2.o?\
#	modules/audio_processing/aec3/fft_data_avx2.o?\
#	modules/audio_processing/aec3/matched_filter_avx2.o?\
#	modules/audio_processing/aec3/vector_math_avx2.o?\
#	modules/audio_processing/agc2/rnn_vad/rnn_vector_math_avx2.o
#????WEBRTC_AEC3_OTHER_CFLAGS?+=?-mfma
else?ifneq?($(findstring?neon,sse2),)
????export?WEBRTC_AEC3_SRC?=?\
	common_audio/resampler/sinc_resampler_neon.o?\
	common_audio/third_party/ooura/fft_size_128/ooura_fft_neon.o
????WEBRTC_AEC3_OTHER_CFLAGS?+=?-DWEBRTC_HAS_NEON
endif
endif
endif


配置aec-3参数,启动配置文件中增加webrtc?echo的配置

#webrtc?echo
--ec-opt=4

本文为呱牛笔记原创文章,转载无需和我联系,但请注明来自呱牛笔记 ,it3q.com

本文参与?腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-31 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体同步曝光计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com