twoconk 发布的文章

主站的逻辑:

决定标签测距的时间槽位信息;
决定多个站测距过程中回复A包的时序;
从站的逻辑:

根据从站的内部序号,决定测距过程中回复A包的时序;

方案:

一、开机上电同步主站tick,并收集基站列表:

1. 开机上电后,即发上线通知, 只有主站回复自己的tick;

2. 如果超时20ms 没有收到主站回复的SYNC,则决定自己就是主站;

3. 收到主站回复的SYNC ,以及包括主站的tick,则同步tick,计算主站到从站的距离,如果超过400m(避免超过区域的主站交叉覆盖的情况发生),则设置自己为主,否则设置为从站;


二、定时周期同步tick:

每个站都是2s定期广播发送tick同步包,根据tick时间戳大小决定谁是主站;

如果超过3次没有收到任何同步tick的数据包,则自动决定自己为主站,能解决比方主站下电了的情况,将备站自动升级为主站!

修改选主策略:选主策略调整为根据ID号大小决定谁是主,这样,每次选主都能稳定的选出固定的主站,而不是来回切换主站!

缺点是:主站一直是主站,可能在相同区域的超过测距要求的基站就得不到工作的机会!

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