forked from mirrors/linphone-iphone
edge optimization in progress
This commit is contained in:
parent
487b375da9
commit
cfb3b3dfd5
3 changed files with 71 additions and 18 deletions
|
|
@ -333,9 +333,17 @@ static void discover_mtu(LinphoneCore *lc, const char *remote){
|
|||
}
|
||||
}
|
||||
|
||||
static void update_sal_media_description_from_params(SalMediaDescription *md, const LinphoneCallParams *params){
|
||||
if (params->down_bw)
|
||||
md->bandwidth=params->down_bw;
|
||||
if (params->down_ptime)
|
||||
md->streams[0].ptime=params->down_ptime;
|
||||
}
|
||||
|
||||
LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, const LinphoneCallParams *params)
|
||||
{
|
||||
LinphoneCall *call=ms_new0(LinphoneCall,1);
|
||||
int ping_time=-1;
|
||||
call->dir=LinphoneCallOutgoing;
|
||||
call->op=sal_op_new(lc->sal);
|
||||
sal_op_set_user_pointer(call->op,call);
|
||||
|
|
@ -350,7 +358,11 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr
|
|||
call->localdesc=create_local_media_description (lc,call);
|
||||
call->camera_active=params->has_video;
|
||||
if (linphone_core_get_firewall_policy(call->core) == LinphonePolicyUseStun) {
|
||||
linphone_core_run_stun_tests(call->core,call);
|
||||
ping_time=linphone_core_run_stun_tests(call->core,call);
|
||||
}
|
||||
if (ping_time>=0) {
|
||||
linphone_core_adapt_to_network(lc,ping_time,&call->params);
|
||||
update_sal_media_description_from_params(call->localdesc,&call->params);
|
||||
}
|
||||
discover_mtu(lc,linphone_address_get_domain (to));
|
||||
if (params->referer){
|
||||
|
|
@ -363,6 +375,7 @@ LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, LinphoneAddr
|
|||
LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *from, LinphoneAddress *to, SalOp *op){
|
||||
LinphoneCall *call=ms_new0(LinphoneCall,1);
|
||||
char *from_str;
|
||||
int ping_time=-1;
|
||||
|
||||
call->dir=LinphoneCallIncoming;
|
||||
sal_op_set_user_pointer(op,call);
|
||||
|
|
@ -385,7 +398,7 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
|
|||
linphone_call_init_common(call, from, to);
|
||||
linphone_core_init_default_params(lc, &call->params);
|
||||
call->params.has_video &= !!lc->video_policy.automatically_accept;
|
||||
call->localdesc=create_local_media_description (lc,call);
|
||||
call->localdesc=create_local_media_description(lc,call);
|
||||
call->camera_active=call->params.has_video;
|
||||
switch (linphone_core_get_firewall_policy(call->core)) {
|
||||
case LinphonePolicyUseIce:
|
||||
|
|
@ -403,11 +416,15 @@ LinphoneCall * linphone_call_new_incoming(LinphoneCore *lc, LinphoneAddress *fro
|
|||
}
|
||||
break;
|
||||
case LinphonePolicyUseStun:
|
||||
linphone_core_run_stun_tests(call->core,call);
|
||||
ping_time=linphone_core_run_stun_tests(call->core,call);
|
||||
/* No break to also destroy ice session in this case. */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (ping_time>=0) {
|
||||
linphone_core_adapt_to_network(lc,ping_time,&call->params);
|
||||
update_sal_media_description_from_params(call->localdesc,&call->params);
|
||||
};
|
||||
discover_mtu(lc,linphone_address_get_domain(from));
|
||||
return call;
|
||||
}
|
||||
|
|
@ -1137,6 +1154,7 @@ static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *m
|
|||
int remote_bw=0;
|
||||
LinphoneCore *lc=call->core;
|
||||
int up_ptime=0;
|
||||
const LinphoneCallParams *params=&call->params;
|
||||
*used_pt=-1;
|
||||
|
||||
for(elem=desc->payloads;elem!=NULL;elem=elem->next){
|
||||
|
|
@ -1146,7 +1164,9 @@ static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *m
|
|||
if ((pt->flags & PAYLOAD_TYPE_FLAG_CAN_SEND) && first) {
|
||||
if (desc->type==SalAudio){
|
||||
linphone_core_update_allocated_audio_bandwidth_in_call(call,pt);
|
||||
up_ptime=linphone_core_get_upload_ptime(lc);
|
||||
if (params->up_ptime)
|
||||
up_ptime=params->up_ptime;
|
||||
else up_ptime=linphone_core_get_upload_ptime(lc);
|
||||
}
|
||||
*used_pt=payload_type_get_number(pt);
|
||||
first=FALSE;
|
||||
|
|
@ -1161,7 +1181,12 @@ static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *m
|
|||
}
|
||||
|
||||
if (desc->type==SalAudio){
|
||||
bw=get_min_bandwidth(call->audio_bw,remote_bw);
|
||||
int audio_bw=call->audio_bw;
|
||||
if (params->up_bw){
|
||||
if (params->up_bw< audio_bw)
|
||||
audio_bw=params->up_bw;
|
||||
}
|
||||
bw=get_min_bandwidth(audio_bw,remote_bw);
|
||||
}else bw=get_min_bandwidth(get_video_bandwidth(linphone_core_get_upload_bandwidth (lc),call->audio_bw),remote_bw);
|
||||
if (bw>0) pt->normal_bitrate=bw*1000;
|
||||
else if (desc->type==SalAudio){
|
||||
|
|
|
|||
|
|
@ -466,12 +466,13 @@ static int recvStunResponse(ortp_socket_t sock, char *ipaddr, int *port, int *id
|
|||
return len;
|
||||
}
|
||||
|
||||
void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){
|
||||
/* this functions runs a simple stun test and return the number of milliseconds to complete the tests, or -1 if the test were failed.*/
|
||||
int linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){
|
||||
const char *server=linphone_core_get_stun_server(lc);
|
||||
|
||||
|
||||
if (lc->sip_conf.ipv6_enabled){
|
||||
ms_warning("stun support is not implemented for ipv6");
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
if (server!=NULL){
|
||||
struct sockaddr_storage ss;
|
||||
|
|
@ -483,29 +484,31 @@ void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){
|
|||
bool_t cone_audio=FALSE,cone_video=FALSE;
|
||||
struct timeval init,cur;
|
||||
SalEndpointCandidate *ac,*vc;
|
||||
double elapsed;
|
||||
int ret=0;
|
||||
|
||||
ac=&call->localdesc->streams[0].candidates[0];
|
||||
vc=&call->localdesc->streams[1].candidates[0];
|
||||
|
||||
if (parse_hostname_to_addr(server,&ss,&ss_len)<0){
|
||||
ms_error("Fail to parser stun server address: %s",server);
|
||||
return;
|
||||
return -1;
|
||||
}
|
||||
if (lc->vtable.display_status!=NULL)
|
||||
lc->vtable.display_status(lc,_("Stun lookup in progress..."));
|
||||
|
||||
/*create the two audio and video RTP sockets, and send STUN message to our stun server */
|
||||
sock1=create_socket(call->audio_port);
|
||||
if (sock1==-1) return;
|
||||
if (sock1==-1) return -1;
|
||||
if (video_enabled){
|
||||
sock2=create_socket(call->video_port);
|
||||
if (sock2==-1) return ;
|
||||
if (sock2==-1) return -1;
|
||||
}
|
||||
got_audio=FALSE;
|
||||
got_video=FALSE;
|
||||
gettimeofday(&init,NULL);
|
||||
do{
|
||||
double elapsed;
|
||||
|
||||
int id;
|
||||
if (loops%20==0){
|
||||
ms_message("Sending stun requests...");
|
||||
|
|
@ -544,10 +547,12 @@ void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){
|
|||
elapsed=((cur.tv_sec-init.tv_sec)*1000.0) + ((cur.tv_usec-init.tv_usec)/1000.0);
|
||||
if (elapsed>2000) {
|
||||
ms_message("Stun responses timeout, going ahead.");
|
||||
ret=-1;
|
||||
break;
|
||||
}
|
||||
loops++;
|
||||
}while(!(got_audio && (got_video||sock2==-1) ) );
|
||||
if (ret==0) ret=(int)elapsed;
|
||||
if (!got_audio){
|
||||
ms_error("No stun server response for audio port.");
|
||||
}else{
|
||||
|
|
@ -570,9 +575,29 @@ void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call){
|
|||
}
|
||||
close_socket(sock1);
|
||||
if (sock2!=-1) close_socket(sock2);
|
||||
return ret;
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
void linphone_core_adapt_to_network(LinphoneCore *lc, int ping_time_ms, LinphoneCallParams *params){
|
||||
if (lp_config_get_int(lc->config,"net","activate_edge_workarounds",0)==1){
|
||||
int threshold=lp_config_get_int(lc->config,"net","edge_ping_time",500);
|
||||
|
||||
if (ping_time_ms>threshold){
|
||||
int edge_ptime=lp_config_get_int(lc->config,"net","edge_ptime",100);
|
||||
int edge_bw=lp_config_get_int(lc->config,"net","edge_bw",30);
|
||||
/* we are in a 2G network*/
|
||||
params->up_bw=params->down_bw=edge_bw;
|
||||
params->up_ptime=params->down_ptime=edge_ptime;
|
||||
|
||||
}/*else use default settings */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call)
|
||||
{
|
||||
char local_addr[64];
|
||||
|
|
|
|||
|
|
@ -69,8 +69,12 @@ struct _LinphoneCallParams{
|
|||
LinphoneCall *referer; /*in case this call creation is consecutive to an incoming transfer, this points to the original call */
|
||||
int audio_bw; /* bandwidth limit for audio stream */
|
||||
LinphoneMediaEncryption media_encryption;
|
||||
PayloadType *audio_codec;
|
||||
PayloadType *video_codec;
|
||||
PayloadType *audio_codec; /*audio codec currently in use */
|
||||
PayloadType *video_codec; /*video codec currently in use */
|
||||
int down_bw;
|
||||
int up_bw;
|
||||
int down_ptime;
|
||||
int up_ptime;
|
||||
bool_t has_video;
|
||||
bool_t real_early_media; /*send real media even during early media (for outgoing calls)*/
|
||||
bool_t in_conference; /*in conference mode */
|
||||
|
|
@ -179,10 +183,7 @@ int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, sock
|
|||
int set_lock_file();
|
||||
int get_lock_file();
|
||||
int remove_lock_file();
|
||||
int do_registration(LinphoneCore *lc, bool_t doit);
|
||||
void check_for_registration(LinphoneCore *lc);
|
||||
void check_sound_device(LinphoneCore *lc);
|
||||
void linphone_core_verify_codecs(LinphoneCore *lc);
|
||||
void linphone_core_get_local_ip(LinphoneCore *lc, const char *to, char *result);
|
||||
bool_t host_has_ipv6_network();
|
||||
bool_t lp_spawn_command_line_sync(const char *command, char **result,int *command_ret);
|
||||
|
|
@ -229,7 +230,8 @@ MSList *linphone_find_friend(MSList *fl, const LinphoneAddress *fri, LinphoneFri
|
|||
|
||||
void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc);
|
||||
void linphone_core_update_allocated_audio_bandwidth_in_call(LinphoneCall *call, const PayloadType *pt);
|
||||
void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call);
|
||||
int linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call);
|
||||
void linphone_core_adapt_to_network(LinphoneCore *lc, int ping_time_ms, LinphoneCallParams *params);
|
||||
int linphone_core_gather_ice_candidates(LinphoneCore *lc, LinphoneCall *call);
|
||||
void linphone_core_update_local_media_description_from_ice(SalMediaDescription *desc, IceSession *session);
|
||||
void linphone_core_update_ice_from_remote_media_description(LinphoneCall *call, const SalMediaDescription *md);
|
||||
|
|
@ -386,6 +388,7 @@ typedef struct rtp_config
|
|||
/* stop rtp xmit when audio muted */
|
||||
bool_t audio_adaptive_jitt_comp_enabled;
|
||||
bool_t video_adaptive_jitt_comp_enabled;
|
||||
bool_t pad;
|
||||
}rtp_config_t;
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue