From ce3725c41eea1b60e9e13a39ceecc724f7170777 Mon Sep 17 00:00:00 2001
From: Simon Morlat <simon.morlat@linphone.org>
Date: Wed, 20 Sep 2023 14:38:26 +0200
Subject: [PATCH] Adapt video call quality tests to take into account changes
 in network simulator and available bandwidth estimator. Fix initialization of
 NatPolicy that could be left orphaned in case of remote provisionning with
 default_values.

---
 coreapi/proxy.c               |  5 ++---
 src/alert/alert.h             |  4 ++--
 src/nat/nat-policy.cpp        | 14 +++++++-------
 tester/video_quality_tester.c | 30 +++++++++---------------------
 4 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/coreapi/proxy.c b/coreapi/proxy.c
index 9b5ac723a2..f5acc0d842 100644
--- a/coreapi/proxy.c
+++ b/coreapi/proxy.c
@@ -172,10 +172,9 @@ LinphoneStatus linphone_proxy_config_set_route(LinphoneProxyConfig *cfg, const c
 		}
 		tmp.append(route);
 
-		SalAddress *addr = sal_address_new(tmp.c_str());
+		auto *addr = linphone_address_new(tmp.c_str());
 		if (addr != NULL) {
-			sal_address_unref(addr);
-			list = bctbx_list_append(list, linphone_address_new(tmp.c_str()));
+			list = bctbx_list_append(list, addr);
 		}
 	}
 
diff --git a/src/alert/alert.h b/src/alert/alert.h
index a634161b43..00d7afafd0 100644
--- a/src/alert/alert.h
+++ b/src/alert/alert.h
@@ -75,8 +75,8 @@ private:
 	uint64_t mDelay;
 	uint64_t mLastCheck;
 };
-class AlertMonitor : public CoreAccessor {
 
+class AlertMonitor : public CoreAccessor {
 public:
 	AlertMonitor(const std::shared_ptr<Core> &core);
 	void notify(const std::shared_ptr<Dictionary> &properties, LinphoneAlertType);
@@ -89,9 +89,9 @@ public:
 	bool getAlertsEnabled();
 
 protected:
-	bool mAlertsEnabled;
 	std::unordered_map<LinphoneAlertType, AlertTimer> mTimers;
 	std::unordered_map<LinphoneAlertType, std::shared_ptr<Alert>> mRunningAlerts;
+	bool mAlertsEnabled;
 };
 
 class VideoQualityAlertMonitor : public AlertMonitor {
diff --git a/src/nat/nat-policy.cpp b/src/nat/nat-policy.cpp
index cd169a944e..9d397c7bc7 100644
--- a/src/nat/nat-policy.cpp
+++ b/src/nat/nat-policy.cpp
@@ -30,13 +30,12 @@ LINPHONE_BEGIN_NAMESPACE
 NatPolicy::NatPolicy(const std::shared_ptr<Core> &core, NatPolicy::ConstructionMethod method, const std::string &value)
     : CoreAccessor(core) {
 	LpConfig *config = linphone_core_get_config(core->getCCore());
+	char ref[17] = {0};
+	belle_sip_random_token(ref, 16);
+	mRef = ref;
+
 	if (method == ConstructionMethod::Default) {
-		mRef = value;
-		if (mRef.empty()) {
-			char ref[17] = {0};
-			belle_sip_random_token(ref, 16);
-			mRef = ref;
-		}
+
 	} else if (method == ConstructionMethod::FromSectionName) {
 		initFromSection(config, value.c_str());
 	} else if (method == ConstructionMethod::FromRefName) {
@@ -265,7 +264,8 @@ const struct addrinfo *NatPolicy::getStunServerAddrinfo() {
 }
 
 void NatPolicy::initFromSection(const LinphoneConfig *config, const char *section) {
-	mRef = linphone_config_get_string(config, section, "ref", "");
+	const char *ref = linphone_config_get_string(config, section, "ref", nullptr);
+	if (ref != nullptr) mRef = ref;
 	mStunServer = linphone_config_get_string(config, section, "stun_server", "");
 	mStunServerUsername = linphone_config_get_string(config, section, "stun_server_username", "");
 	mTurnUdpEnabled = !!linphone_config_get_bool(config, section, "turn_enable_udp", TRUE);
diff --git a/tester/video_quality_tester.c b/tester/video_quality_tester.c
index f17ef2e096..1faff5a19a 100644
--- a/tester/video_quality_tester.c
+++ b/tester/video_quality_tester.c
@@ -217,7 +217,7 @@ static void video_call_with_high_bandwidth_available(void) {
 	pol.automatically_initiate = TRUE;
 	linphone_core_set_video_policy(marie->lc, &pol);
 	linphone_core_set_video_policy(pauline->lc, &pol);
-
+	linphone_core_set_preferred_video_definition_by_name(marie->lc, "QVGA");
 	simparams.mode = OrtpNetworkSimulatorOutbound;
 	simparams.enabled = TRUE;
 	simparams.max_bandwidth = 1000000;
@@ -232,8 +232,8 @@ static void video_call_with_high_bandwidth_available(void) {
 		/*wait a little in order to have traffic*/
 		BC_ASSERT_TRUE(wait_for_until(marie->lc, pauline->lc, NULL, 5, 50000));
 
-		BC_ASSERT_GREATER((float)marie->stat.last_tmmbr_value_received, 810000.f, float, "%f");
-		BC_ASSERT_LOWER((float)marie->stat.last_tmmbr_value_received, 1150000.f, float, "%f");
+		BC_ASSERT_GREATER((float)marie->stat.last_tmmbr_value_received, 750000.f, float, "%f");
+		BC_ASSERT_LOWER((float)marie->stat.last_tmmbr_value_received, 1000000.f, float, "%f");
 
 		end_call(marie, pauline);
 	}
@@ -242,7 +242,7 @@ static void video_call_with_high_bandwidth_available(void) {
 	linphone_core_manager_destroy(pauline);
 }
 
-static void video_call_expected_fps_for_specified_bandwidth(int bandwidth, int fps, const char *resolution) {
+static void video_call_expected_fps_for_specified_bandwidth(int bandwidth, int expected_fps, const char *resolution) {
 	LinphoneCoreManager *marie = linphone_core_manager_new("marie_rc");
 	LinphoneCoreManager *pauline = linphone_core_manager_new("pauline_rc");
 	LinphoneVideoPolicy pol = {0};
@@ -284,14 +284,14 @@ static void video_call_expected_fps_for_specified_bandwidth(int bandwidth, int f
 				BC_ASSERT_TRUE(
 				    wait_for_until(marie->lc, pauline->lc, &marie->stat.last_tmmbr_value_received, 1, 10000));
 
-				if ((int)vstream->configured_fps == fps) {
+				if ((int)vstream->configured_fps == expected_fps) {
 					break;
 				} else {
 					/*target fps not reached yet, wait more time*/
 					wait_for_until(marie->lc, pauline->lc, NULL, 0, 2000);
 				}
 			}
-			BC_ASSERT_EQUAL((int)vstream->configured_fps, fps, int, "%d");
+			BC_ASSERT_EQUAL((int)vstream->configured_fps, expected_fps, int, "%d");
 			end_call(marie, pauline);
 		}
 	} else {
@@ -310,11 +310,7 @@ static void video_call_expected_fps_for_specified_bandwidth(int bandwidth, int f
  *
  **/
 static void video_call_expected_fps_for_low_bandwidth(void) {
-#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
-	video_call_expected_fps_for_specified_bandwidth(100000, 10, "qvga");
-#else
-	video_call_expected_fps_for_specified_bandwidth(350000, 15, "vga");
-#endif
+	video_call_expected_fps_for_specified_bandwidth(350000, 18, "vga");
 }
 
 /*
@@ -325,11 +321,7 @@ static void video_call_expected_fps_for_low_bandwidth(void) {
  *
  **/
 static void video_call_expected_fps_for_regular_bandwidth(void) {
-#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
-	video_call_expected_fps_for_specified_bandwidth(500000, 12, "vga");
-#else
-	video_call_expected_fps_for_specified_bandwidth(450000, 25, "vga");
-#endif
+	video_call_expected_fps_for_specified_bandwidth(500000, 25, "vga");
 }
 
 /*
@@ -340,11 +332,7 @@ static void video_call_expected_fps_for_regular_bandwidth(void) {
  *
  **/
 static void video_call_expected_fps_for_high_bandwidth(void) {
-#if defined(__ANDROID__) || (TARGET_OS_IPHONE == 1) || defined(__arm__) || defined(_M_ARM)
-	video_call_expected_fps_for_specified_bandwidth(400000, 12, "qcif");
-#else
 	video_call_expected_fps_for_specified_bandwidth(5000000, 30, "vga");
-#endif
 }
 
 static void video_call_expected_size_for_specified_bandwidth_with_congestion(
@@ -564,7 +552,7 @@ static void on_nack_alert(LinphoneCore *core, LinphoneAlert *alert) {
 	if (type == LinphoneAlertQoSRetransmissionFailures) {
 		(*count)++;
 		const LinphoneDictionary *props = linphone_alert_get_informations(alert);
-		float indicator = linphone_dictionary_get_float(props, "nack indicator");
+		float indicator = linphone_dictionary_get_float(props, "nack-performance");
 		BC_ASSERT_TRUE(indicator > 0.0f);
 	}
 }
-- 
GitLab