From 7d90f44faebe2552a838e61f2973318175b4e586 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Fri, 26 Nov 2010 18:20:52 +0100 Subject: [PATCH] implement linphone_call_params_set_audio_bandwidth_limit() --- coreapi/linphonecall.c | 24 +++++++++++++++++++----- coreapi/linphonecore.h | 1 + coreapi/misc.c | 4 +--- coreapi/private.h | 4 ++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/coreapi/linphonecall.c b/coreapi/linphonecall.c index 15ffa24d1..11b46c89e 100644 --- a/coreapi/linphonecall.c +++ b/coreapi/linphonecall.c @@ -40,13 +40,19 @@ static MSWebCam *get_nowebcam_device(){ #endif -static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs){ +static MSList *make_codec_list(LinphoneCore *lc, const MSList *codecs, int bandwidth_limit){ MSList *l=NULL; const MSList *it; for(it=codecs;it!=NULL;it=it->next){ PayloadType *pt=(PayloadType*)it->data; - if ((pt->flags & PAYLOAD_TYPE_ENABLED) && linphone_core_check_payload_type_usability(lc,pt)){ - l=ms_list_append(l,payload_type_clone(pt)); + if (pt->flags & PAYLOAD_TYPE_ENABLED){ + if (bandwidth_limit>0 && !linphone_core_is_payload_type_usable_for_bandwidth(lc,pt,bandwidth_limit)){ + ms_message("Codec %s/%i eliminated because of audio bandwidth constraint.",pt->mime_type,pt->clock_rate); + continue; + } + if (linphone_core_check_payload_type_usability(lc,pt)){ + l=ms_list_append(l,payload_type_clone(pt)); + } } } return l; @@ -70,7 +76,7 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCa md->streams[0].proto=SalProtoRtpAvp; md->streams[0].type=SalAudio; md->streams[0].ptime=lc->net_conf.down_ptime; - l=make_codec_list(lc,lc->codecs_conf.audio_codecs); + l=make_codec_list(lc,lc->codecs_conf.audio_codecs,call->params.audio_bw); pt=payload_type_clone(rtp_profile_get_payload_from_mime(&av_profile,"telephone-event")); l=ms_list_append(l,pt); md->streams[0].payloads=l; @@ -83,7 +89,7 @@ SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCa md->streams[1].port=call->video_port; md->streams[1].proto=SalProtoRtpAvp; md->streams[1].type=SalVideo; - l=make_codec_list(lc,lc->codecs_conf.video_codecs); + 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; @@ -533,6 +539,14 @@ bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams return cp->real_early_media; } +/** + * Refine bandwidth settings for this call by setting a bandwidth limit for audio streams. + * As a consequence, codecs whose bitrates are not compatible with this limit won't be used. +**/ +void linphone_call_params_set_audio_bandwidth_limit(LinphoneCallParams *cp, int bandwidth){ + cp->audio_bw=bandwidth; +} + /** * **/ diff --git a/coreapi/linphonecore.h b/coreapi/linphonecore.h index a6ab6a12f..219b13a7e 100644 --- a/coreapi/linphonecore.h +++ b/coreapi/linphonecore.h @@ -180,6 +180,7 @@ void linphone_call_params_enable_video(LinphoneCallParams *cp, bool_t enabled); bool_t linphone_call_params_video_enabled(const LinphoneCallParams *cp); void linphone_call_params_enable_early_media_sending(LinphoneCallParams *cp, bool_t enabled); bool_t linphone_call_params_early_media_sending_enabled(const LinphoneCallParams *cp); +void linphone_call_params_set_audio_bandwidth_limit(LinphoneCallParams *cp, int bw); void linphone_call_params_destroy(LinphoneCallParams *cp); /** diff --git a/coreapi/misc.c b/coreapi/misc.c index 00b4d2895..a83cd8394 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -258,7 +258,7 @@ void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc){ } } -bool_t linphone_core_is_payload_type_usable(LinphoneCore *lc, PayloadType *pt, int bandwidth_limit) +bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, PayloadType *pt, int bandwidth_limit) { double codec_band; bool_t ret=FALSE; @@ -288,8 +288,6 @@ bool_t linphone_core_is_payload_type_usable(LinphoneCore *lc, PayloadType *pt, 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 6ee0071a2..1203fe0fa 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -58,6 +58,7 @@ 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 */ bool_t has_video; bool_t real_early_media; /*send real media even during early media (for outgoing calls)*/ bool_t pad[2]; @@ -441,6 +442,9 @@ void linphone_core_set_state(LinphoneCore *lc, LinphoneGlobalState gstate, const SalMediaDescription *create_local_media_description(LinphoneCore *lc, LinphoneCall *call); void linphone_core_update_streams(LinphoneCore *lc, LinphoneCall *call, SalMediaDescription *new_md); + +bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, PayloadType *pt, int bandwidth_limit); + #define linphone_core_ready(lc) ((lc)->state!=LinphoneGlobalStartup) void _linphone_core_configure_resolver();