summaryrefslogtreecommitdiff
path: root/pjsip/src/pjsua-lib
diff options
context:
space:
mode:
Diffstat (limited to 'pjsip/src/pjsua-lib')
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c11
-rw-r--r--pjsip/src/pjsua-lib/pjsua_media.c32
2 files changed, 39 insertions, 4 deletions
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 45918bd7..847fab51 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -1205,6 +1205,7 @@ static void stun_resolve_complete(pjsua_stun_resolve *sess)
result.token = sess->token;
result.status = sess->status;
result.name = sess->srv[sess->idx];
+ result.index = sess->idx;
pj_memcpy(&result.addr, &sess->addr, sizeof(result.addr));
sess->has_result = PJ_TRUE;
@@ -1508,6 +1509,7 @@ static void internal_stun_resolve_cb(const pj_stun_resolve_result *result)
pjsua_var.stun_status = result->status;
if ((result->status == PJ_SUCCESS) && (pjsua_var.ua_cfg.stun_srv_cnt>0)) {
pj_memcpy(&pjsua_var.stun_srv, &result->addr, sizeof(result->addr));
+ pjsua_var.stun_srv_idx = result->index;
/* Perform NAT type detection if not yet */
if (pjsua_var.nat_type == PJ_STUN_NAT_TYPE_UNKNOWN &&
@@ -1554,7 +1556,12 @@ pj_status_t resolve_stun_server(pj_bool_t wait)
* result.
*/
if (wait) {
- while (pjsua_var.stun_status == PJ_EPENDING) {
+ pj_bool_t has_pjsua_lock = PJSUA_LOCK_IS_LOCKED();
+
+ if (has_pjsua_lock)
+ PJSUA_UNLOCK();
+
+ while (pjsua_var.stun_status == PJ_EPENDING) {
/* If there is no worker thread or
* the function is called from the only worker thread,
* we have to handle the events here.
@@ -1568,6 +1575,8 @@ pj_status_t resolve_stun_server(pj_bool_t wait)
pj_thread_sleep(10);
}
}
+ if (has_pjsua_lock)
+ PJSUA_LOCK();
}
}
diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c
index 7a8404c8..524915c7 100644
--- a/pjsip/src/pjsua-lib/pjsua_media.c
+++ b/pjsip/src/pjsua-lib/pjsua_media.c
@@ -393,11 +393,37 @@ static pj_status_t create_rtp_rtcp_sock(pjsua_call_media *call_med,
if (status != PJ_SUCCESS && pjsua_var.ua_cfg.stun_srv_cnt > 1 &&
((acc->cfg.media_stun_use & PJSUA_STUN_RETRY_ON_FAILURE)!=0))
{
- PJ_LOG(4,(THIS_FILE, "Failed to get STUN mapped address, "
- "retrying other STUN servers"));
+ pj_str_t srv =
+ pjsua_var.ua_cfg.stun_srv[pjsua_var.stun_srv_idx];
+
+ PJ_LOG(4,(THIS_FILE, "Failed to get STUN mapped address, "
+ "retrying other STUN servers"));
+
+ if (pjsua_var.stun_srv_idx < pjsua_var.ua_cfg.stun_srv_cnt-1) {
+ PJSUA_LOCK();
+ /* Move the unusable STUN server to the last position
+ * as the least prioritize.
+ */
+ pj_array_erase(pjsua_var.ua_cfg.stun_srv,
+ sizeof(pj_str_t),
+ pjsua_var.ua_cfg.stun_srv_cnt,
+ pjsua_var.stun_srv_idx);
+
+ pj_array_insert(pjsua_var.ua_cfg.stun_srv,
+ sizeof(pj_str_t),
+ pjsua_var.ua_cfg.stun_srv_cnt-1,
+ pjsua_var.ua_cfg.stun_srv_cnt-1,
+ &srv);
+
+ PJSUA_UNLOCK();
+ }
status=pjsua_update_stun_servers(pjsua_var.ua_cfg.stun_srv_cnt,
pjsua_var.ua_cfg.stun_srv,
- PJ_TRUE);
+ PJ_FALSE);
+
+ if (status == PJ_SUCCESS)
+ status = resolve_stun_server(PJ_TRUE);
+
if (status == PJ_SUCCESS) {
if (pjsua_var.stun_srv.addr.sa_family != 0) {
pj_ansi_strcpy(ip_addr,