修改PJSIP支持webrtc回声消除处理

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/

增加两个方法处理播放和录制;


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"

支持外部webrtc


#define PJMEDIA_HAS_WEBRTC_AEC 1
#   define PJMEDIA_WEBRTC_AEC_USE_MOBILE        1

 

支持webrtc_aec3


#ifdef PJMEDIA_HAS_WEBRTC_AEC3
#undef  PJMEDIA_HAS_WEBRTC_AEC3
#define PJMEDIA_HAS_WEBRTC_AEC3 1
#endif

 

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


#webrtc echo
--ec-opt=3
#webrtc-aec3 echo
#--ec-opt=4
#--stereo
--ec-tail=75
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值