Skip to content

Instantly share code, notes, and snippets.

@xytis
Created December 6, 2013 08:38
Show Gist options
  • Save xytis/7820491 to your computer and use it in GitHub Desktop.
Save xytis/7820491 to your computer and use it in GitHub Desktop.
diff --git channels/chan_sip.c channels/chan_sip.c
index 04c4638..59031fe 100644
--- channels/chan_sip.c
+++ channels/chan_sip.c
@@ -5884,6 +5884,12 @@ static int dialog_initialize_rtp(struct sip_pvt *dialog)
return -1;
}
+ //Set ice role depending on call direction
+ //Later may do the same to other channels too.
+ if ((ice = ast_rtp_instance_get_ice((dialog->rtp)))) {
+ ice->set_role(dialog->rtp, dialog->outgoing_call);
+ }
+
if (!ast_test_flag(&dialog->flags[2], SIP_PAGE3_ICE_SUPPORT) && (ice = ast_rtp_instance_get_ice(dialog->rtp))) {
ice->stop(dialog->rtp);
}
diff --git channels/sip/sdp_crypto.c channels/sip/sdp_crypto.c
index cacdcbe..2cb162b 100644
--- channels/sip/sdp_crypto.c
+++ channels/sip/sdp_crypto.c
@@ -231,11 +231,11 @@ int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_in
suite_val = AST_AES_CM_128_HMAC_SHA1_80;
ast_set_flag(srtp, SRTP_CRYPTO_TAG_80);
taglen = 80;
- } else if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_32")) {
+ }/* else if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_32")) {
suite_val = AST_AES_CM_128_HMAC_SHA1_32;
ast_set_flag(srtp, SRTP_CRYPTO_TAG_32);
taglen = 32;
- } else {
+ }*/ else {
ast_log(LOG_WARNING, "Unsupported crypto suite: %s\n", suite);
return -1;
}
diff --git include/asterisk/rtp_engine.h include/asterisk/rtp_engine.h
index 51455e9..89cd865 100644
--- include/asterisk/rtp_engine.h
+++ include/asterisk/rtp_engine.h
@@ -351,6 +351,8 @@ struct ast_rtp_engine_ice {
struct ao2_container *(*get_local_candidates)(struct ast_rtp_instance *instance);
/*! Callback for telling the ICE support that it is talking to an ice-lite implementation */
void (*ice_lite)(struct ast_rtp_instance *instance);
+ /*! Callback to set ICE role */
+ void (*set_role)(struct ast_rtp_instance *instance, unsigned int is_controlling);
};
/*! \brief DTLS setup types */
diff --git res/pjproject/pjnath/src/pjnath/ice_session.c res/pjproject/pjnath/src/pjnath/ice_session.c
index 6bcf1e3..1d5436e 100644
--- res/pjproject/pjnath/src/pjnath/ice_session.c
+++ res/pjproject/pjnath/src/pjnath/ice_session.c
@@ -1614,7 +1614,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
PJ_ASSERT_RETURN(ice && rem_ufrag && rem_passwd && rcand_cnt && rcand,
PJ_EINVAL);
- PJ_ASSERT_RETURN(rcand_cnt + ice->rcand_cnt <= PJ_ICE_MAX_CAND,
+ PJ_ASSERT_RETURN(rcand_cnt <= PJ_ICE_MAX_CAND,
PJ_ETOOMANY);
pj_mutex_lock(ice->mutex);
@@ -1657,6 +1657,7 @@ PJ_DEF(pj_status_t) pj_ice_sess_create_check_list(
/* Generate checklist */
clist = &ice->clist;
+ clist->count = 0; //Forget all previous checks.
for (i=0; i<ice->lcand_cnt; ++i) {
for (j=0; j<ice->rcand_cnt; ++j) {
diff --git res/res_rtp_asterisk.c res/res_rtp_asterisk.c
index a90cc46..4bbc129 100644
--- res/res_rtp_asterisk.c
+++ res/res_rtp_asterisk.c
@@ -426,6 +426,18 @@ static void ast_rtp_ice_set_authentication(struct ast_rtp_instance *instance, co
}
}
+static void ast_rtp_ice_clean_remote_candidates(struct ast_rtp_instance *instance)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+
+ if (!rtp->remote_candidates) {
+ return;
+ }
+
+ ao2_ref(rtp->remote_candidates, -1);
+ rtp->remote_candidates = NULL;
+}
+
static void ast_rtp_ice_add_remote_candidate(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
{
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
@@ -503,7 +515,7 @@ static void ast_rtp_ice_start(struct ast_rtp_instance *instance)
struct ast_rtp_engine_ice_candidate *candidate;
int cand_cnt = 0;
- if (!rtp->ice || !rtp->remote_candidates || rtp->ice_started) {
+ if (!rtp->ice || !rtp->remote_candidates /* || rtp->ice_started*/) {
return;
}
@@ -549,6 +561,7 @@ static void ast_rtp_ice_start(struct ast_rtp_instance *instance)
rtp->ice_started = 1;
rtp->strict_rtp_state = STRICT_RTP_OPEN;
}
+ ast_rtp_ice_clean_remote_candidates(instance);
}
static void ast_rtp_ice_stop(struct ast_rtp_instance *instance)
@@ -603,6 +616,20 @@ static void ast_rtp_ice_lite(struct ast_rtp_instance *instance)
pj_ice_sess_change_role(rtp->ice, PJ_ICE_SESS_ROLE_CONTROLLING);
}
+static void ast_rtp_set_role(struct ast_rtp_instance *instance, unsigned int is_controlling)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+
+ if (!rtp->ice) {
+ return;
+ }
+
+ pj_thread_register_check();
+
+ pj_ice_sess_change_role(rtp->ice, is_controlling ? PJ_ICE_SESS_ROLE_CONTROLLING : PJ_ICE_SESS_ROLE_CONTROLLED);
+
+}
+
static int ice_candidate_cmp(void *obj, void *arg, int flags)
{
struct ast_rtp_engine_ice_candidate *candidate1 = obj, *candidate2 = arg;
@@ -696,6 +723,7 @@ static struct ast_rtp_engine_ice ast_rtp_ice = {
.get_password = ast_rtp_ice_get_password,
.get_local_candidates = ast_rtp_ice_get_local_candidates,
.ice_lite = ast_rtp_ice_lite,
+ .set_role = ast_rtp_set_role,
};
#ifdef HAVE_OPENSSL_SRTP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment