From 173c7f3d9faec203b25ef13c031f219213dd095b Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Mon, 13 Dec 2010 10:53:42 +0100 Subject: [PATCH 1/3] Removed unused function. --- coreapi/linphonecore.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 7c5ee9071..05f03315d 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -3967,14 +3967,6 @@ static PayloadType* find_payload_type_from_list(const char* type, int rate,const return NULL; } -static void printCodecs(const MSList* from) { - const MSList *elem; - for(elem=from;elem!=NULL;elem=elem->next){ - PayloadType *pt=(PayloadType*)elem->data; - ms_message(payload_type_get_mime(pt)); - } -} - /** * Get payload type from mime type and clock rate * @ingroup media_parameters From 16972baf9c9d34b27afff54779029a0d47680b3d Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Mon, 13 Dec 2010 10:57:41 +0100 Subject: [PATCH 2/3] rework bandwidth management --- coreapi/linphonecall.c | 22 ++++++++++------------ coreapi/linphonecore.c | 14 -------------- coreapi/misc.c | 42 ++++++++++++++---------------------------- coreapi/private.h | 7 ++----- 4 files changed, 26 insertions(+), 59 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index e85fc8492..63d881bba 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -65,11 +65,12 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCa LinphoneAddress *addr=linphone_address_new(me); const char *username=linphone_address_get_username (addr); SalMediaDescription *md=sal_media_description_new(); - + md->nstreams=1; strncpy(md->addr,call->localip,sizeof(md->addr)); strncpy(md->username,username,sizeof(md->username)); md->bandwidth=linphone_core_get_download_bandwidth(lc); + /*set audio capabilities */ strncpy(md->streams[0].addr,call->localip,sizeof(md->streams[0].addr)); md->streams[0].port=call->audio_port; @@ -81,8 +82,6 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCa l=ms_list_append(l,pt); md->streams[0].payloads=l; - if (lc->dw_audio_bw>0) - md->streams[0].bandwidth=lc->dw_audio_bw; if (call->params.has_video){ md->nstreams++; @@ -91,8 +90,6 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCa md->streams[1].type=SalVideo; l=make_codec_list(lc,lc->codecs_conf.video_codecs,0); md->streams[1].payloads=l; - if (lc->dw_video_bw) - md->streams[1].bandwidth=lc->dw_video_bw; } linphone_address_destroy(addr); return md; @@ -716,12 +713,13 @@ static void post_configure_audio_streams(LinphoneCall*call){ -static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){ +static RtpProfile *make_profile(LinphoneCall *call, const SalMediaDescription *md, const SalStreamDescription *desc, int *used_pt){ int bw; const MSList *elem; RtpProfile *prof=rtp_profile_new("Call profile"); bool_t first=TRUE; int remote_bw=0; + LinphoneCore *lc=call->core; *used_pt=-1; for(elem=desc->payloads;elem!=NULL;elem=elem->next){ @@ -730,7 +728,7 @@ static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, if (first) { if (desc->type==SalAudio){ - linphone_core_update_allocated_audio_bandwidth_in_call(lc,pt); + linphone_core_update_allocated_audio_bandwidth_in_call(call,pt); } *used_pt=payload_type_get_number(pt); first=FALSE; @@ -740,13 +738,13 @@ static RtpProfile *make_profile(LinphoneCore *lc, const SalMediaDescription *md, /*case where b=AS is given globally, not per stream*/ remote_bw=md->bandwidth; if (desc->type==SalVideo){ - remote_bw-=lc->audio_bw; + remote_bw-=call->audio_bw-10; } } if (desc->type==SalAudio){ - bw=get_min_bandwidth(lc->up_audio_bw,remote_bw); - }else bw=get_min_bandwidth(lc->up_video_bw,remote_bw); + bw=get_min_bandwidth(call->audio_bw,remote_bw); + }else bw=get_min_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){ pt->normal_bitrate=-1; @@ -801,7 +799,7 @@ void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_mut MSSndCard *captcard=lc->sound_conf.capt_sndcard; const char *playfile=lc->play_file; const char *recfile=lc->rec_file; - call->audio_profile=make_profile(lc,call->resultdesc,stream,&used_pt); + call->audio_profile=make_profile(call,call->resultdesc,stream,&used_pt); if (used_pt!=-1){ if (playcard==NULL) { ms_warning("No card defined for playback !"); @@ -866,7 +864,7 @@ void linphone_call_start_media_streams(LinphoneCall *call, bool_t all_inputs_mut call->current_params.has_video=FALSE; if (stream && stream->dir!=SalStreamInactive) { const char *addr=stream->addr[0]!='\0' ? stream->addr : call->resultdesc->addr; - call->video_profile=make_profile(lc,call->resultdesc,stream,&used_pt); + call->video_profile=make_profile(call,call->resultdesc,stream,&used_pt); if (used_pt!=-1){ VideoStreamDir dir=VideoStreamSendRecv; MSWebCam *cam=lc->video_conf.device; diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 7c5ee9071..d6c25252d 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -816,13 +816,6 @@ static void autoreplier_config_init(LinphoneCore *lc) */ void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){ lc->net_conf.download_bw=bw; - if (bw==0){ /*infinite*/ - lc->dw_audio_bw=-1; - lc->dw_video_bw=-1; - }else { - lc->dw_audio_bw=MIN(lc->audio_bw,bw); - lc->dw_video_bw=MAX(bw-lc->dw_audio_bw-10,0);/*-10: security margin*/ - } } /** @@ -840,13 +833,6 @@ void linphone_core_set_download_bandwidth(LinphoneCore *lc, int bw){ */ void linphone_core_set_upload_bandwidth(LinphoneCore *lc, int bw){ lc->net_conf.upload_bw=bw; - if (bw==0){ /*infinite*/ - lc->up_audio_bw=-1; - lc->up_video_bw=-1; - }else{ - lc->up_audio_bw=MIN(lc->audio_bw,bw); - lc->up_video_bw=MAX(bw-lc->up_audio_bw-10,0);/*-10: security margin*/ - } } /** diff --git a/coreapi/misc.c b/coreapi/misc.c index a83cd8394..44d058a86 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -233,11 +233,8 @@ static double get_audio_payload_bandwidth(LinphoneCore *lc, const PayloadType *p return packet_size*8.0*npacket; } -void linphone_core_update_allocated_audio_bandwidth_in_call(LinphoneCore *lc, const PayloadType *pt){ - lc->audio_bw=(int)(get_audio_payload_bandwidth(lc,pt)/1000.0); - /*update*/ - linphone_core_set_download_bandwidth(lc,lc->net_conf.download_bw); - linphone_core_set_upload_bandwidth(lc,lc->net_conf.upload_bw); +void linphone_core_update_allocated_audio_bandwidth_in_call(LinphoneCall *call, const PayloadType *pt){ + call->audio_bw=(int)(get_audio_payload_bandwidth(call->core,pt)/1000.0); } void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc){ @@ -254,7 +251,7 @@ void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc){ } } if (max) { - linphone_core_update_allocated_audio_bandwidth_in_call(lc,max); + lc->audio_bw=(int)(get_audio_payload_bandwidth(lc,max)/1000.0); } } @@ -278,11 +275,6 @@ bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, Payl break; case PAYLOAD_VIDEO: if (bandwidth_limit!=0) {/* infinite (-1) or strictly positive*/ - /*let the video use all the bandwidth minus the maximum bandwidth used by audio */ - if (bandwidth_limit>0) - pt->normal_bitrate=bandwidth_limit*1000; - else - pt->normal_bitrate=1500000; /*around 1.5 Mbit/s*/ ret=TRUE; } else ret=FALSE; @@ -295,8 +287,7 @@ bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, Payl bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType *pt) { double codec_band; - int min_audio_bw; - int min_video_bw; + int allowed_bw,video_bw; bool_t ret=FALSE; /* update allocated audio bandwidth to allocate the remaining to video. @@ -304,18 +295,21 @@ bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType the audio bandwidth is refined to the selected codec */ if (!linphone_core_in_call(lc)) linphone_core_update_allocated_audio_bandwidth(lc); - min_audio_bw=get_min_bandwidth(linphone_core_get_download_bandwidth(lc), + allowed_bw=get_min_bandwidth(linphone_core_get_download_bandwidth(lc), linphone_core_get_upload_bandwidth(lc)); - if (min_audio_bw==0) min_audio_bw=-1; - min_video_bw=get_min_bandwidth(lc->dw_video_bw,lc->up_video_bw); + if (allowed_bw==0) { + allowed_bw=-1; + video_bw=1500; /*around 1.5 Mbit/s*/ + }else + video_bw=allowed_bw-lc->audio_bw-10; switch (pt->type){ case PAYLOAD_AUDIO_CONTINUOUS: case PAYLOAD_AUDIO_PACKETIZED: codec_band=get_audio_payload_bandwidth(lc,pt); - ret=bandwidth_is_greater(min_audio_bw*1000,codec_band); + ret=bandwidth_is_greater(allowed_bw*1000,codec_band); /*hack to avoid using uwb codecs when having low bitrate and video*/ - if (bandwidth_is_greater(199,min_audio_bw)){ + if (bandwidth_is_greater(199,allowed_bw)){ if (linphone_core_video_enabled(lc) && pt->clock_rate>16000){ ret=FALSE; } @@ -323,19 +317,11 @@ bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType //ms_message("Payload %s: %g",pt->mime_type,codec_band); break; case PAYLOAD_VIDEO: - if (min_video_bw!=0) {/* infinite (-1) or strictly positive*/ - /*let the video use all the bandwidth minus the maximum bandwidth used by audio */ - if (min_video_bw>0) - pt->normal_bitrate=min_video_bw*1000; - else - pt->normal_bitrate=1500000; /*around 1.5 Mbit/s*/ - ret=TRUE; - } + if (video_bw>0) + pt->normal_bitrate=video_bw*1000; else ret=FALSE; break; } - /*if (!ret) ms_warning("Payload %s is not usable with your internet connection.",pt->mime_type);*/ - return ret; } diff --git a/coreapi/private.h b/coreapi/private.h index 3a5e3483c..ca9b46fda 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -90,6 +90,7 @@ struct _LinphoneCall LinphoneCallParams params; LinphoneCallParams current_params; int up_bw; /*upload bandwidth setting at the time the call is started. Used to detect if it changes during a call */ + int audio_bw; /*upload bandwidth used by audio */ bool_t refer_pending; bool_t media_pending; bool_t audio_muted; @@ -171,7 +172,7 @@ void linphone_subscription_closed(LinphoneCore *lc, SalOp *op); MSList *linphone_find_friend(MSList *fl, const LinphoneAddress *fri, LinphoneFriend **lf); void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc); -void linphone_core_update_allocated_audio_bandwidth_in_call(LinphoneCore *lc, const PayloadType *pt); +void linphone_core_update_allocated_audio_bandwidth_in_call(LinphoneCall *call, const PayloadType *pt); void linphone_core_run_stun_tests(LinphoneCore *lc, LinphoneCall *call); void linphone_core_send_initial_subscribes(LinphoneCore *lc); @@ -412,10 +413,6 @@ struct _LinphoneCore char *play_file; char *rec_file; time_t prevtime; - int dw_audio_bw; - int up_audio_bw; - int dw_video_bw; - int up_video_bw; int audio_bw; LinphoneWaitingCallback wait_cb; void *wait_ctx; From ff08abbb6a39b59d18789d29113bf53a3164ab86 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Mon, 13 Dec 2010 13:42:39 +0100 Subject: [PATCH 3/3] improvements in bandwidth management --- coreapi/linphonecore.c | 11 +++++++++-- coreapi/misc.c | 12 +++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/coreapi/linphonecore.c b/coreapi/linphonecore.c index 512aea752..7eb2850bf 100644 --- a/coreapi/linphonecore.c +++ b/coreapi/linphonecore.c @@ -2198,7 +2198,7 @@ int linphone_core_update_call(LinphoneCore *lc, LinphoneCall *call, const Linpho **/ int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call) { - LinphoneProxyConfig *cfg=NULL; + LinphoneProxyConfig *cfg=NULL,*dest_proxy=NULL; const char *contact=NULL; SalOp *replaced; SalMediaDescription *new_md; @@ -2253,8 +2253,15 @@ int linphone_core_accept_call(LinphoneCore *lc, LinphoneCall *call) } linphone_core_get_default_proxy(lc,&cfg); + dest_proxy=cfg; + dest_proxy=linphone_core_lookup_known_proxy(lc,call->log->to); + + if (cfg!=dest_proxy && dest_proxy!=NULL) { + ms_message("Overriding default proxy setting for this call:"); + ms_message("The used identity will be %s",linphone_proxy_config_get_identity(dest_proxy)); + } /*try to be best-effort in giving real local or routable contact address*/ - contact=get_fixed_contact(lc,call,cfg); + contact=get_fixed_contact(lc,call,dest_proxy); if (contact) sal_op_set_contact(call->op,contact); diff --git a/coreapi/misc.c b/coreapi/misc.c index 44d058a86..c2e1ae211 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -289,12 +289,8 @@ bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType double codec_band; int allowed_bw,video_bw; bool_t ret=FALSE; - /* - update allocated audio bandwidth to allocate the remaining to video. - This must be done outside calls, because after sdp negociation - the audio bandwidth is refined to the selected codec - */ - if (!linphone_core_in_call(lc)) linphone_core_update_allocated_audio_bandwidth(lc); + + linphone_core_update_allocated_audio_bandwidth(lc); allowed_bw=get_min_bandwidth(linphone_core_get_download_bandwidth(lc), linphone_core_get_upload_bandwidth(lc)); if (allowed_bw==0) { @@ -317,8 +313,10 @@ bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, PayloadType //ms_message("Payload %s: %g",pt->mime_type,codec_band); break; case PAYLOAD_VIDEO: - if (video_bw>0) + if (video_bw>0){ pt->normal_bitrate=video_bw*1000; + ret=TRUE; + } else ret=FALSE; break; }