Commit 79df3f43 authored by Mohamed Chibani's avatar Mohamed Chibani Committed by Adrien Béraud

ice-turn: Fix audio loss after 5mn

Add PJNATH patch that modifies the following behaviors:

 - "Local preference" used to compute the candidate priority is
 now unique to each candidate (i.e., two candidates of the same
 type will never have the same priority.)

 - The "nominated pair" selected by the controlling agent will be
 the active pair, regardless of the computed priority.

 - The permissions, given to peer candidates on TURN server when
 ICE negotiation starts, are now set permanent (periodically
 renewed) to allow a peer to send on any valid pairs (pairs that
 have successfully passed the connectivity checks.)

IMPORTANT: The patches are a back-port from PJSIP/PJNATH project,
these patches must be disabled when PSIP/PJNATH is upgraded.

Gitlab: #223
Change-Id: I82482d7da0b51f6e557fb6a5e98631f8b8a54db1
parent fd4fb6d2
......@@ -11,10 +11,10 @@ Subject: [PATCH] android
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/aconfigure b/aconfigure
index 7fcb12ec4..066a1d0f4 100755
index 51b01a2..2d606ba 100755
--- a/aconfigure
+++ b/aconfigure
@@ -5954,9 +5954,6 @@ case $target in
@@ -5958,9 +5958,6 @@ case $target in
esac
# UUID
case $target in
......@@ -25,10 +25,10 @@ index 7fcb12ec4..066a1d0f4 100755
if test "$ac_has_uuid_lib" = "1" -a "$ac_has_uuid_h" = "1"; then
ac_os_objs="$ac_os_objs guid_uuid.o"
diff --git a/aconfigure.ac b/aconfigure.ac
index 0367679e2..0280f6894 100644
index 954b815..f254a30 100644
--- a/aconfigure.ac
+++ b/aconfigure.ac
@@ -489,9 +489,6 @@ case $target in
@@ -492,9 +492,6 @@ case $target in
esac
# UUID
case $target in
......@@ -39,13 +39,13 @@ index 0367679e2..0280f6894 100644
if test "$ac_has_uuid_lib" = "1" -a "$ac_has_uuid_h" = "1"; then
ac_os_objs="$ac_os_objs guid_uuid.o"
diff --git a/pjlib/include/pj/config_site.h b/pjlib/include/pj/config_site.h
index 47dd40ad5..f8cf75f80 100644
index 7b8ea25..333dfc2 100644
--- a/pjlib/include/pj/config_site.h
+++ b/pjlib/include/pj/config_site.h
@@ -21,3 +21,14 @@
#define PJ_ICE_MAX_TURN 4
#define PJ_ICE_COMP_BITS 2
#define PJ_ICE_MAX_CHECKS 1024
@@ -24,3 +24,14 @@
/* Set permanent permissions on the TURN
server for all peer candidates */
#define PJ_ICE_ST_USE_TURN_PERMANENT_PERM PJ_TRUE
+
+/*
+ * ANDROID settings.
......@@ -57,8 +57,9 @@ index 47dd40ad5..f8cf75f80 100644
+#undef PJMEDIA_HAS_G722_CODEC
+#define PJMEDIA_HAS_G722_CODEC 1
+#define PJMEDIA_VID_DEV_INFO_FMT_CNT 128
\ No newline at end of file
diff --git a/pjlib/src/pj/os_timestamp_posix.c b/pjlib/src/pj/os_timestamp_posix.c
index 0aed8c470..1ec156b0d 100644
index 0aed8c4..1ec156b 100644
--- a/pjlib/src/pj/os_timestamp_posix.c
+++ b/pjlib/src/pj/os_timestamp_posix.c
@@ -203,7 +203,7 @@ PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
......@@ -70,6 +71,3 @@ index 0aed8c470..1ec156b0d 100644
#include <errno.h>
#include <time.h>
--
2.24.1
......@@ -8,18 +8,17 @@ Subject: [PATCH 1/3] win config
1 file changed, 5 insertions(+)
diff --git a/pjlib/include/pj/config_site.h b/pjlib/include/pj/config_site.h
index 47dd40ad5..5d4e3d10d 100644
index 7b8ea25..85cf2ed 100644
--- a/pjlib/include/pj/config_site.h
+++ b/pjlib/include/pj/config_site.h
@@ -21,3 +21,8 @@
#define PJ_ICE_MAX_TURN 4
#define PJ_ICE_COMP_BITS 2
#define PJ_ICE_MAX_CHECKS 1024
@@ -24,3 +24,8 @@
/* Set permanent permissions on the TURN
server for all peer candidates */
#define PJ_ICE_ST_USE_TURN_PERMANENT_PERM PJ_TRUE
+
+/*
+ * WINDOWS settings.
+ */
+#define THIRD_PARTY_MEDIA 0
--
2.24.1
2.25.4
......@@ -10,7 +10,7 @@ Subject: [PATCH 2/3] win vs gnutls
3 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/pjlib/build/pjlib.vcxproj b/pjlib/build/pjlib.vcxproj
index f2d6fb42c..dee805a7c 100644
index f2d6fb4..dee805a 100644
--- a/pjlib/build/pjlib.vcxproj
+++ b/pjlib/build/pjlib.vcxproj
@@ -309,14 +309,17 @@
......@@ -49,10 +49,10 @@ index f2d6fb42c..dee805a7c 100644
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-Static|Win32'">
<ClCompile>
diff --git a/pjlib/include/pj/config_site.h b/pjlib/include/pj/config_site.h
index 5d4e3d10d..a37d6d88c 100644
index 85cf2ed..fe65725 100644
--- a/pjlib/include/pj/config_site.h
+++ b/pjlib/include/pj/config_site.h
@@ -26,3 +26,6 @@
@@ -29,3 +29,6 @@
* WINDOWS settings.
*/
#define THIRD_PARTY_MEDIA 0
......@@ -60,7 +60,7 @@ index 5d4e3d10d..a37d6d88c 100644
+#define PJ_HAS_SSL_SOCK 1
+#define PJ_SSL_SOCK_IMP PJ_SSL_SOCK_IMP_GNUTLS
diff --git a/pjmedia/build/pjmedia.vcxproj b/pjmedia/build/pjmedia.vcxproj
index e596939d0..0c7108b83 100644
index e596939..0c7108b 100644
--- a/pjmedia/build/pjmedia.vcxproj
+++ b/pjmedia/build/pjmedia.vcxproj
@@ -307,14 +307,17 @@
......@@ -99,5 +99,5 @@ index e596939d0..0c7108b83 100644
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
--
2.24.1
2.25.4
......@@ -5,11 +5,11 @@ Subject: [PATCH 3/3] win vs2017 props
---
build/vs/pjproject-vs14-common-config.props | 8 ++++----
build/vs/pjproject-vs14-common-defaults.props | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)
build/vs/pjproject-vs14-common-defaults.props | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/build/vs/pjproject-vs14-common-config.props b/build/vs/pjproject-vs14-common-config.props
index de8848ff5..6aa0276ba 100644
index de8848f..6aa0276 100644
--- a/build/vs/pjproject-vs14-common-config.props
+++ b/build/vs/pjproject-vs14-common-config.props
@@ -18,22 +18,22 @@
......@@ -40,7 +40,7 @@ index de8848ff5..6aa0276ba 100644
<AppTypeRev>10.0</AppTypeRev>
diff --git a/build/vs/pjproject-vs14-common-defaults.props b/build/vs/pjproject-vs14-common-defaults.props
index 526f6c925..198282b90 100644
index 526f6c9..974447f 100644
--- a/build/vs/pjproject-vs14-common-defaults.props
+++ b/build/vs/pjproject-vs14-common-defaults.props
@@ -3,7 +3,7 @@
......@@ -52,13 +52,5 @@ index 526f6c925..198282b90 100644
</PropertyGroup>
<PropertyGroup>
<_ProjectFileVersion>14.0.22823.1</_ProjectFileVersion>
@@ -35,4 +35,4 @@
<Value>$(VSVer)</Value>
</BuildMacro>
</ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
--
2.24.1
2.25.4
......@@ -13,7 +13,7 @@ new file mode 100644
index 000000000..47dd40ad5
--- /dev/null
+++ b/pjlib/include/pj/config_site.h
@@ -0,0 +1,23 @@
@@ -0,0 +1,26 @@
+#include "config_site_sample.h"
+
+/*
......@@ -37,6 +37,9 @@ index 000000000..47dd40ad5
+#define PJ_ICE_MAX_TURN 4
+#define PJ_ICE_COMP_BITS 2
+#define PJ_ICE_MAX_CHECKS 1024
+/* Set permanent permissions on the TURN
+ server for all peer candidates */
+#define PJ_ICE_ST_USE_TURN_PERMANENT_PERM PJ_TRUE
--
2.24.1
From 0a13964065c2e4592eff07ec0880cb2af0a86ff9 Mon Sep 17 00:00:00 2001
From: Nanang Izzuddin <nanang@teluu.com>
Date: Fri, 7 Aug 2020 16:03:43 +0700
Subject: [PATCH 1/3] - Assign unique local preferences for candidates with the
same type. - Update component's valid pair condition, instead of just higher
priority, also consider 'nominated' flag.
---
pjnath/src/pjnath/ice_session.c | 18 +++++++++++++++++-
pjnath/src/pjnath/ice_strans.c | 9 +++++----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index 2a4125bc5..4eb5adea9 100644
--- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c
@@ -1297,7 +1297,23 @@ static void update_comp_check(pj_ice_sess *ice, unsigned comp_id,
if (comp->valid_check == NULL) {
comp->valid_check = check;
} else {
- if (CMP_CHECK_PRIO(comp->valid_check, check) < 0)
+ pj_bool_t update = PJ_FALSE;
+
+ /* Update component's valid check with conditions:
+ * - it is the first nominated check, or
+ * - it has higher prio, as long as nomination status is NOT degraded
+ * (existing is nominated -> new is not-nominated).
+ */
+ if (!comp->nominated_check && check->nominated)
+ {
+ update = PJ_TRUE;
+ } else if (CMP_CHECK_PRIO(comp->valid_check, check) < 0 &&
+ (!comp->nominated_check || check->nominated))
+ {
+ update = PJ_TRUE;
+ }
+
+ if (update)
comp->valid_check = check;
}
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 5481c59e1..54ae9f769 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -418,7 +418,7 @@ static pj_status_t add_update_turn(pj_ice_strans *ice_st,
cand = &comp->cand_list[comp->cand_cnt];
cand->type = PJ_ICE_CAND_TYPE_RELAYED;
cand->status = PJ_EPENDING;
- cand->local_pref = RELAY_PREF;
+ cand->local_pref = (pj_uint16_t)(RELAY_PREF - idx);
cand->transport_id = tp_id;
cand->comp_id = (pj_uint8_t) comp->comp_id;
new_cand = PJ_TRUE;
@@ -480,7 +480,8 @@ static pj_bool_t ice_cand_equals(pj_ice_sess_cand *lcand,
|| lcand->status != rcand->status
|| lcand->comp_id != rcand->comp_id
|| lcand->transport_id != rcand->transport_id
- || lcand->local_pref != rcand->local_pref
+ // local pref is no longer a constant, so it may be different
+ //|| lcand->local_pref != rcand->local_pref
|| lcand->prio != rcand->prio
|| pj_sockaddr_cmp(&lcand->addr, &rcand->addr) != 0
|| pj_sockaddr_cmp(&lcand->base_addr, &rcand->base_addr) != 0)
@@ -539,7 +540,7 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
cand = &comp->cand_list[comp->cand_cnt];
cand->type = PJ_ICE_CAND_TYPE_SRFLX;
cand->status = PJ_EPENDING;
- cand->local_pref = SRFLX_PREF;
+ cand->local_pref = (pj_uint16_t)(SRFLX_PREF - idx);
cand->transport_id = CREATE_TP_ID(TP_STUN, idx);
cand->comp_id = (pj_uint8_t) comp->comp_id;
@@ -679,7 +680,7 @@ static pj_status_t add_stun_and_host(pj_ice_strans *ice_st,
cand->type = PJ_ICE_CAND_TYPE_HOST;
cand->status = PJ_SUCCESS;
- cand->local_pref = HOST_PREF;
+ cand->local_pref = (pj_uint16_t)(HOST_PREF - *cand_cnt);
cand->transport_id = CREATE_TP_ID(TP_STUN, idx);
cand->comp_id = (pj_uint8_t) comp->comp_id;
pj_sockaddr_cp(&cand->addr, addr);
--
2.25.1
From afb1e188a9b1ee532634cabdd41937d0f21d97db Mon Sep 17 00:00:00 2001
From: Nanang Izzuddin <nanang@teluu.com>
Date: Fri, 7 Aug 2020 16:23:09 +0700
Subject: [PATCH 2/3] Add new compile-time setting
PJ_ICE_ST_USE_TURN_PERMANENT_PERM, if set, TURN client session will
automatically renew permission for all remote candidates.
---
pjnath/include/pjnath/config.h | 11 +++++++++++
pjnath/src/pjnath/ice_strans.c | 5 +++--
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h
index fc1e27550..bc2f4b158 100644
--- a/pjnath/include/pjnath/config.h
+++ b/pjnath/include/pjnath/config.h
@@ -457,6 +457,17 @@
#endif
+/**
+ * This constant specifies whether ICE stream transport should allow TURN
+ * client session to automatically renew permission for all remote candidates.
+ *
+ * Default: PJ_FALSE
+ */
+#ifndef PJ_ICE_ST_USE_TURN_PERMANENT_PERM
+# define PJ_ICE_ST_USE_TURN_PERMANENT_PERM PJ_FALSE
+#endif
+
+
/** ICE session pool initial size. */
#ifndef PJNATH_POOL_LEN_ICE_SESS
# define PJNATH_POOL_LEN_ICE_SESS 512
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 54ae9f769..5630b69e5 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -1504,8 +1504,9 @@ PJ_DEF(pj_status_t) pj_ice_strans_start_ice( pj_ice_strans *ice_st,
}
if (count && !comp->turn[n].err_cnt && comp->turn[n].sock) {
- status = pj_turn_sock_set_perm(comp->turn[n].sock, count,
- addrs, 0);
+ status = pj_turn_sock_set_perm(
+ comp->turn[n].sock, count,
+ addrs, PJ_ICE_ST_USE_TURN_PERMANENT_PERM);
if (status != PJ_SUCCESS) {
pj_ice_strans_stop_ice(ice_st);
return status;
--
2.25.1
From 9150099c0b45345cde9d738d7f0f344ade4788cc Mon Sep 17 00:00:00 2001
From: nanangizz <nanang@teluu.com>
Date: Tue, 11 Aug 2020 11:36:08 +0700
Subject: [PATCH 3/3] - update local preference for peer reflexive candidate -
also update PRIORITY field value in performing connectivity check (must use
peer reflexive type and local pref must be unique, is this necessary?) - fix
local preference mask for non-standard ICE prio calculation
---
pjnath/include/pjnath/ice_session.h | 5 +++++
pjnath/src/pjnath/ice_session.c | 27 ++++++++++++++++++---------
pjnath/src/pjnath/ice_strans.c | 6 +++---
3 files changed, 26 insertions(+), 12 deletions(-)
diff --git a/pjnath/include/pjnath/ice_session.h b/pjnath/include/pjnath/ice_session.h
index 8971220f0..a889020f9 100644
--- a/pjnath/include/pjnath/ice_session.h
+++ b/pjnath/include/pjnath/ice_session.h
@@ -237,6 +237,11 @@ typedef struct pj_ice_msg_data
*/
typedef struct pj_ice_sess_cand
{
+ /**
+ * The candidate ID.
+ */
+ unsigned id;
+
/**
* The candidate type, as described in #pj_ice_cand_type enumeration.
*/
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index 4eb5adea9..b2cfc3ec2 100644
--- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c
@@ -686,9 +686,9 @@ static pj_uint32_t CALC_CAND_PRIO(pj_ice_sess *ice,
(((256 - comp_id) & 0xFF) << 0);
#else
enum {
- type_mask = ((2 << PJ_ICE_CAND_TYPE_PREF_BITS) - 1),
- local_mask = ((2 << PJ_ICE_LOCAL_PREF_BITS) - 1),
- comp_mask = ((2 << PJ_ICE_COMP_BITS) - 1),
+ type_mask = ((1 << PJ_ICE_CAND_TYPE_PREF_BITS) - 1),
+ local_mask = ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1),
+ comp_mask = ((1 << PJ_ICE_COMP_BITS) - 1),
comp_shift = 0,
local_shift = (PJ_ICE_COMP_BITS),
@@ -918,11 +918,13 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
}
lcand = &ice->lcand[ice->lcand_cnt];
+ lcand->id = ice->lcand_cnt;
lcand->comp_id = (pj_uint8_t)comp_id;
lcand->transport_id = (pj_uint8_t)transport_id;
lcand->type = type;
lcand->transport = transport;
pj_strdup(ice->pool, &lcand->foundation, foundation);
+ lcand->local_pref = local_pref;
lcand->prio = CALC_CAND_PRIO(ice, type, local_pref, lcand->comp_id);
pj_sockaddr_cp(&lcand->addr, addr);
pj_sockaddr_cp(&lcand->base_addr, base_addr);
@@ -950,7 +952,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
LOG4((ice->obj_name,
"Candidate %d added: comp_id=%d, type=%s, foundation=%.*s, "
"addr=%s:%d, base=%s:%d, prio=0x%x (%u)",
- ice->lcand_cnt,
+ lcand->id,
lcand->comp_id,
cand_type_names[lcand->type],
(int)lcand->foundation.slen,
@@ -962,7 +964,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_add_cand(pj_ice_sess *ice,
lcand->prio, lcand->prio));
if (p_cand_id)
- *p_cand_id = ice->lcand_cnt;
+ *p_cand_id = lcand->id;
++ice->lcand_cnt;
@@ -1692,7 +1694,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
pj_memcpy(cn, &rem_cand[i], sizeof(pj_ice_sess_cand));
pj_strdup(ice->pool, &cn->foundation, &rem_cand[i].foundation);
- ice->rcand_cnt++;
+ cn->id = ice->rcand_cnt++;
}
/* Generate checklist */
@@ -1823,10 +1825,11 @@ static pj_status_t perform_check(pj_ice_sess *ice,
/* Add PRIORITY */
#if PJNATH_ICE_PRIO_STD
- prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535,
+ prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535 - lcand->id,
lcand->comp_id);
#else
- prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 0,
+ prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX,
+ ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1) - lcand->id,
lcand->comp_id);
#endif
pj_stun_msg_add_uint_attr(check->tdata->pool, check->tdata->msg,
@@ -2422,7 +2425,13 @@ static void on_stun_request_complete(pj_stun_session *stun_sess,
status = pj_ice_sess_add_cand(ice, check->lcand->comp_id,
msg_data->transport_id,
PJ_ICE_CAND_TYPE_PRFLX,
- 65535, &foundation,
+#if PJNATH_ICE_PRIO_STD
+ 65535 - ice->lcand_cnt,
+#else
+ ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1) -
+ ice->lcand_cnt,
+#endif
+ &foundation,
&xaddr->sockaddr,
&check->lcand->base_addr,
&check->lcand->base_addr,
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 5630b69e5..2fc3c6c0c 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -64,9 +64,9 @@ enum tp_type
# define HOST_PREF 65535
# define RELAY_PREF 65535
#else
-# define SRFLX_PREF 0
-# define HOST_PREF 0
-# define RELAY_PREF 0
+# define SRFLX_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
+# define HOST_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
+# define RELAY_PREF ((1 << PJ_ICE_LOCAL_PREF_BITS) - 1)
#endif
--
2.25.1
......@@ -13,11 +13,14 @@
"0007-pj_ice_sess.patch",
"0008-fix_ioqueue_ipv6_sendto.patch",
"0009-add-config-site.patch",
"0011-fix-tcp-death-detection.patch",
"0012-fix-turn-shutdown-crash.patch",
"0013-Assign-unique-local-preferences-for-candidates-with-.patch",
"0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch",
"0015-update-local-preference-for-peer-reflexive-candidate.patch",
"0001-win-config.patch",
"0002-win-vs-gnutls.patch",
"0003-win-vs2017-props.patch",
"0011-fix-tcp-death-detection.patch",
"0012-fix-turn-shutdown-crash.patch"
"0003-win-vs2017-props.patch"
],
"project_paths": [
"pjlib-util/build/pjlib_util.vcxproj",
......
......@@ -57,6 +57,9 @@ pjproject: pjproject-$(PJPROJECT_VERSION).tar.gz .sum-pjproject
$(APPLY) $(SRC)/pjproject/0010-fix-pkgconfig.patch
$(APPLY) $(SRC)/pjproject/0011-fix-tcp-death-detection.patch
$(APPLY) $(SRC)/pjproject/0012-fix-turn-shutdown-crash.patch
$(APPLY) $(SRC)/pjproject/0013-Assign-unique-local-preferences-for-candidates-with-.patch
$(APPLY) $(SRC)/pjproject/0014-Add-new-compile-time-setting-PJ_ICE_ST_USE_TURN_PERM.patch
$(APPLY) $(SRC)/pjproject/0015-update-local-preference-for-peer-reflexive-candidate.patch
ifdef HAVE_ANDROID
$(APPLY) $(SRC)/pjproject/0001-android.patch
endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment