From d9f3e1c8cf07b39303c24035c426ba07d8138fef Mon Sep 17 00:00:00 2001 From: smorlat Date: Mon, 23 Mar 2009 14:09:10 +0000 Subject: [PATCH] tuning of echo limiter git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@358 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/coreapi/exevents.c | 5 ++++ linphone/coreapi/linphonecore.c | 14 ++++++++++- linphone/coreapi/lpconfig.c | 2 +- linphone/coreapi/proxy.c | 34 ++++++++++++++++++-------- linphone/mediastreamer2/src/ice.c | 6 ++--- linphone/mediastreamer2/src/msvolume.c | 27 ++++++++++++++++---- 6 files changed, 68 insertions(+), 20 deletions(-) diff --git a/linphone/coreapi/exevents.c b/linphone/coreapi/exevents.c index 907830b42..95057eca4 100644 --- a/linphone/coreapi/exevents.c +++ b/linphone/coreapi/exevents.c @@ -704,6 +704,11 @@ int linphone_accept_video_offer(sdp_context_t *ctx,sdp_payload_t *payload) if (!linphone_core_video_enabled(lc)) return -1; + if (payload->remoteport==0) { + ms_message("Video stream refused by remote."); + return 0; + } + params=&call->video_params; remote_profile=call->profile; /* see if this codec is supported in our local rtp profile*/ diff --git a/linphone/coreapi/linphonecore.c b/linphone/coreapi/linphonecore.c index c55f1dbaf..225f063f1 100644 --- a/linphone/coreapi/linphonecore.c +++ b/linphone/coreapi/linphonecore.c @@ -1436,7 +1436,7 @@ static void post_configure_audio_streams(LinphoneCore *lc){ float speed=lp_config_get_float(lc->config,"sound","el_speed",-1); float thres=lp_config_get_float(lc->config,"sound","el_thres",-1); if (speed!=-1) - ms_filter_call_method(st->volsend,MS_VOLUME_SET_EA_SPEED,&speed); + ms_filter_call_method(st->volrecv,MS_VOLUME_SET_EA_SPEED,&speed); if (thres!=-1) ms_filter_call_method(st->volrecv,MS_VOLUME_SET_EA_THRESHOLD,&thres); } @@ -2406,6 +2406,18 @@ LpConfig *linphone_core_get_config(LinphoneCore *lc){ void linphone_core_uninit(LinphoneCore *lc) { + if (lc->call){ + int i; + linphone_core_terminate_call(lc,NULL); + for(i=0;i<10;++i){ +#ifndef WIN32 + usleep(50000); +#else + Sleep(50); +#endif + linphone_core_iterate(lc); + } + } gstate_new_state(lc, GSTATE_POWER_SHUTDOWN, NULL); #ifdef VIDEO_ENABLED if (lc->previewstream!=NULL){ diff --git a/linphone/coreapi/lpconfig.c b/linphone/coreapi/lpconfig.c index 4d3ba5660..f513ad9df 100644 --- a/linphone/coreapi/lpconfig.c +++ b/linphone/coreapi/lpconfig.c @@ -292,7 +292,7 @@ int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, i float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *key, float default_value){ const char *str=lp_config_get_string(lpconfig,section,key,NULL); - float ret; + float ret=default_value; if (str==NULL) return default_value; sscanf(str,"%f",&ret); return ret; diff --git a/linphone/coreapi/proxy.c b/linphone/coreapi/proxy.c index eb1016b7d..d4d3b2b95 100644 --- a/linphone/coreapi/proxy.c +++ b/linphone/coreapi/proxy.c @@ -25,6 +25,14 @@ Copyright (C) 2000 Simon MORLAT (simon.morlat@linphone.org) #include "lpconfig.h" #include "private.h" +void linphone_proxy_config_write_all_to_config_file(LinphoneCore *lc){ + MSList *elem; + int i; + for(elem=lc->sip_conf.proxies,i=0;elem!=NULL;elem=ms_list_next(elem),i++){ + LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)elem->data; + linphone_proxy_config_write_to_config_file(lc->config,cfg,i); + } +} void linphone_proxy_config_init(LinphoneProxyConfig *obj){ memset(obj,0,sizeof(LinphoneProxyConfig)); @@ -231,13 +239,10 @@ void linphone_proxy_config_apply(LinphoneProxyConfig *obj,LinphoneCore *lc) linphone_proxy_config_done(obj); } -int linphone_proxy_config_done(LinphoneProxyConfig *obj) -{ +static void linphone_proxy_config_register(LinphoneProxyConfig *obj){ const char *id_str; - if (!linphone_proxy_config_check(obj->lc,obj)) return -1; if (obj->reg_identity!=NULL) id_str=obj->reg_identity; else id_str=linphone_core_get_primary_contact(obj->lc); - obj->frozen=FALSE; if (obj->reg_sendregister){ char *ct=NULL; osip_message_t *msg=NULL; @@ -245,6 +250,14 @@ int linphone_proxy_config_done(LinphoneProxyConfig *obj) eXosip_register_send_register(obj->rid,msg); if (ct!=NULL) osip_free(ct); } +} + +int linphone_proxy_config_done(LinphoneProxyConfig *obj) +{ + if (!linphone_proxy_config_check(obj->lc,obj)) return -1; + obj->frozen=FALSE; + linphone_proxy_config_register(obj); + linphone_proxy_config_write_all_to_config_file(obj->lc); return 0; } @@ -502,15 +515,14 @@ const MSList *linphone_core_get_proxy_config_list(const LinphoneCore *lc){ void linphone_proxy_config_process_authentication_failure(LinphoneCore *lc, eXosip_event_t *ev){ LinphoneProxyConfig *cfg=linphone_core_get_proxy_config_from_rid(lc, ev->rid); if (cfg){ - cfg->auth_failures++; - /*restart a new register */ - if (cfg->auth_failures==1){ - linphone_proxy_config_done(cfg); - } + cfg->auth_failures++; + /*restart a new register */ + if (cfg->auth_failures==1){ + linphone_proxy_config_register(cfg); + } } } - void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyConfig *obj, int index) { char key[50]; @@ -537,6 +549,8 @@ void linphone_proxy_config_write_to_config_file(LpConfig *config, LinphoneProxyC lp_config_set_int(config,key,"publish",obj->publish); } + + LinphoneProxyConfig *linphone_proxy_config_new_from_config_file(LpConfig *config, int index) { const char *tmp; diff --git a/linphone/mediastreamer2/src/ice.c b/linphone/mediastreamer2/src/ice.c index 27da8a6cf..1b76cdad6 100644 --- a/linphone/mediastreamer2/src/ice.c +++ b/linphone/mediastreamer2/src/ice.c @@ -165,7 +165,7 @@ static int ice_sound_send_stun_request(RtpSession *session, struct IceCheckList /* prepare ONCE tie-break value */ if (checklist->tiebreak_value==0) { - checklist->tiebreak_value = random() * (0x7fffffffffffffff/0x7fff); + checklist->tiebreak_value = random() * (0x7fffffffffffffffLL /0x7fff); } cand_pair=NULL; @@ -513,7 +513,7 @@ static int ice_process_stun_message(RtpSession *session, struct IceCheckList *ch /* prepare ONCE tie-break value */ if (checklist->tiebreak_value==0) { - checklist->tiebreak_value = random() * (0x7fffffffffffffff/0x7fff); + checklist->tiebreak_value = random() * (0x7fffffffffffffffLL/0x7fff); } memset (src6host, 0, sizeof (src6host)); @@ -947,7 +947,7 @@ static int ice_process_stun_message(RtpSession *session, struct IceCheckList *ch { struct in_addr inaddr; char mapped_addr[64]; - struct CandidatePair *cand_pair; + struct CandidatePair *cand_pair=NULL; int pos; inaddr.s_addr = htonl (mappedAddr.addr); snprintf(mapped_addr, sizeof(mapped_addr), diff --git a/linphone/mediastreamer2/src/msvolume.c b/linphone/mediastreamer2/src/msvolume.c index 7c7f8a85e..036bcf72a 100644 --- a/linphone/mediastreamer2/src/msvolume.c +++ b/linphone/mediastreamer2/src/msvolume.c @@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static const float max_e=32767*32767; static const float coef=0.1; -static const float gain_k=0.2; - +static const float gain_k=0.03; +static const float en_weight=4.0; static const float noise_thres=0.1; @@ -46,6 +46,7 @@ static void volume_init(MSFilter *f){ v->ea_active=FALSE; v->gain_k=gain_k; v->thres=noise_thres; + v->peer=NULL; f->data=v; } @@ -67,14 +68,22 @@ static int volume_get_linear(MSFilter *f, void *arg){ return 0; } +static inline float compute_gain(float static_gain, float energy, float weight){ + float ret=static_gain*(1 - (energy*weight)); + if (ret<0) ret=0; + return ret; +} + static void volume_echo_avoider_process(Volume *v){ float peer_e; float gain; + float gain_k2; ms_filter_call_method(v->peer,MS_VOLUME_GET_LINEAR,&peer_e); + peer_e=sqrt(peer_e); if (v->ea_active){ if (peer_e>v->thres){ /*lower our output*/ - gain=v->static_gain*(1-peer_e); + gain=compute_gain(v->static_gain,peer_e,en_weight); }else { gain=v->static_gain; v->ea_active=FALSE; @@ -84,11 +93,15 @@ static void volume_echo_avoider_process(Volume *v){ ms_filter_call_method(v->peer,MS_VOLUME_GET_EA_STATE,&peer_active); if (peer_e>v->thres && ! peer_active){ /*lower our output*/ - gain=v->static_gain*(1-peer_e); + gain=compute_gain(v->static_gain,peer_e,en_weight); v->ea_active=TRUE; }else gain=v->static_gain; } - v->gain=(v->gain*(1-v->gain_k)) + (v->gain_k*v->gain); + if (v->ea_active){ + gain_k2=5*v->gain_k; + }else gain_k2=v->gain_k; + v->gain=(v->gain*(1-gain_k2)) + (gain_k2*gain); + ms_message("ea_active=%i, peer_e=%f gain=%f gain_k=%f",v->ea_active,peer_e,v->gain, v->gain_k); } static int volume_set_gain(MSFilter *f, void *arg){ @@ -208,3 +221,7 @@ MSFilterDesc ms_volume_desc={ methods }; #endif + +MS_FILTER_DESC_EXPORT(ms_volume_desc) + +