From 3c94dd0b9ecd786af2aa1caa1beb5815ed396257 Mon Sep 17 00:00:00 2001 From: Simon Morlat Date: Wed, 24 Jun 2015 17:45:57 +0200 Subject: [PATCH] repair linphone_core_check_payload_type_usability() and add non regression test. --- coreapi/misc.c | 10 ++++++---- coreapi/private.h | 9 +++++---- tester/setup_tester.c | 27 ++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/coreapi/misc.c b/coreapi/misc.c index 83a732365..8d7d8939e 100644 --- a/coreapi/misc.c +++ b/coreapi/misc.c @@ -224,7 +224,7 @@ void linphone_core_update_allocated_audio_bandwidth(LinphoneCore *lc){ } } -bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, const PayloadType *pt, int bandwidth_limit) +bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, const PayloadType *pt, int bandwidth_limit) { double codec_band; bool_t ret=FALSE; @@ -233,8 +233,8 @@ bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, cons case PAYLOAD_AUDIO_CONTINUOUS: case PAYLOAD_AUDIO_PACKETIZED: codec_band=get_audio_payload_bandwidth(lc,pt,bandwidth_limit); - ret=bandwidth_is_greater(bandwidth_limit*1000,codec_band); - //ms_message("Payload %s: %g",pt->mime_type,codec_band); + ret=bandwidth_is_greater(bandwidth_limit,codec_band); + /*ms_message("Payload %s: codec_bandwidth=%g, bandwidth_limit=%i",pt->mime_type,codec_band,bandwidth_limit);*/ break; case PAYLOAD_VIDEO: if (bandwidth_limit!=0) {/* infinite (-1) or strictly positive*/ @@ -248,7 +248,9 @@ bool_t linphone_core_is_payload_type_usable_for_bandwidth(LinphoneCore *lc, cons /* return TRUE if codec can be used with bandwidth, FALSE else*/ bool_t linphone_core_check_payload_type_usability(LinphoneCore *lc, const PayloadType *pt){ - bool_t ret=linphone_core_is_payload_type_usable_for_bandwidth(lc, pt, linphone_core_get_payload_type_bitrate(lc,pt)); + int maxbw=get_min_bandwidth(linphone_core_get_download_bandwidth(lc), + linphone_core_get_upload_bandwidth(lc)); + bool_t ret=linphone_core_is_payload_type_usable_for_bandwidth(lc, pt, maxbw); if ((pt->type==PAYLOAD_AUDIO_CONTINUOUS || pt->type==PAYLOAD_AUDIO_PACKETIZED) && lc->sound_conf.capt_sndcard && !(ms_snd_card_get_capabilities(lc->sound_conf.capt_sndcard) & MS_SND_CARD_CAP_BUILTIN_ECHO_CANCELLER) diff --git a/coreapi/private.h b/coreapi/private.h index deae8cac2..69aab7412 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -349,14 +349,15 @@ static MS2_INLINE int get_min_bandwidth(int dbw, int ubw){ } static MS2_INLINE bool_t bandwidth_is_greater(int bw1, int bw2){ - if (bw1<0) return TRUE; - else if (bw2<0) return FALSE; + if (bw1<=0) return TRUE; + else if (bw2<=0) return FALSE; else return bw1>=bw2; } static MS2_INLINE int get_remaining_bandwidth_for_video(int total, int audio){ - if (total<=0) return 0; - return total-audio-10; + int ret = total-audio-10; + if (ret < 0) ret = 0; + return ret; } static MS2_INLINE void set_string(char **dest, const char *src){ diff --git a/tester/setup_tester.c b/tester/setup_tester.c index cb1bcb883..444dc773d 100644 --- a/tester/setup_tester.c +++ b/tester/setup_tester.c @@ -265,6 +265,30 @@ static void devices_reload_test(void) { linphone_core_manager_destroy(mgr); } +static void codec_usability_test(void) { + LinphoneCoreManager *mgr = linphone_core_manager_new2("empty_rc", FALSE); + PayloadType *pt = linphone_core_find_payload_type(mgr->lc, "PCMU", 8000, -1); + + BC_ASSERT_TRUE(pt!=NULL); + if (!pt) goto end; + /*no limit*/ + linphone_core_set_upload_bandwidth(mgr->lc, 0); + linphone_core_set_download_bandwidth(mgr->lc, 0); + BC_ASSERT_TRUE(linphone_core_check_payload_type_usability(mgr->lc, pt)); + /*low limit*/ + linphone_core_set_upload_bandwidth(mgr->lc, 50); + linphone_core_set_download_bandwidth(mgr->lc, 50); + BC_ASSERT_FALSE(linphone_core_check_payload_type_usability(mgr->lc, pt)); + + /*reasonable limit*/ + linphone_core_set_upload_bandwidth(mgr->lc, 200); + linphone_core_set_download_bandwidth(mgr->lc, 200); + BC_ASSERT_TRUE(linphone_core_check_payload_type_usability(mgr->lc, pt)); + +end: + linphone_core_manager_destroy(mgr); +} + test_t setup_tests[] = { { "Version check", linphone_version_test }, { "Linphone Address", linphone_address_test }, @@ -278,7 +302,8 @@ test_t setup_tests[] = { { "LPConfig zero_len value from file", linphone_lpconfig_from_file_zerolen_value }, { "LPConfig zero_len value from XML", linphone_lpconfig_from_xml_zerolen_value }, { "Chat room", chat_root_test }, - { "Devices reload", devices_reload_test } + { "Devices reload", devices_reload_test }, + { "Codec usability", codec_usability_test } }; test_suite_t setup_test_suite = {