summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-06-25 21:16:46 +0000
committerBenny Prijono <bennylp@teluu.com>2008-06-25 21:16:46 +0000
commit016a4eae3331e0fe7db428ab7381b0fbc93a7267 (patch)
treebfb7bda2734b23901507e403d8661e43cd266572
parentbeffb154962293bb6a355a8f734e7f2ab1379718 (diff)
Optimize the number of characters written to SDP by ICE
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2054 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjnath/include/pjnath/config.h35
-rw-r--r--pjnath/src/pjnath/ice_session.c48
-rw-r--r--pjnath/src/pjnath/ice_strans.c26
3 files changed, 96 insertions, 13 deletions
diff --git a/pjnath/include/pjnath/config.h b/pjnath/include/pjnath/config.h
index e002a105..c29de63f 100644
--- a/pjnath/include/pjnath/config.h
+++ b/pjnath/include/pjnath/config.h
@@ -244,12 +244,41 @@
/**
+ * The number of bits to represent component IDs. This will affect
+ * the maximum number of components (PJ_ICE_MAX_COMP) value.
+ */
+#ifndef PJ_ICE_COMP_BITS
+# define PJ_ICE_COMP_BITS 3
+#endif
+
+
+/**
* Maximum number of ICE components.
+ */
+#define PJ_ICE_MAX_COMP (2<<PJ_ICE_COMP_BITS)
+
+
+/**
+ * The number of bits to represent candidate type preference.
+ */
+#ifndef PJ_ICE_CAND_TYPE_PREF_BITS
+# define PJ_ICE_CAND_TYPE_PREF_BITS 2
+#endif
+
+
+/**
+ * The number of bits to represent ICE candidate's local preference. The
+ * local preference is used to specify preference among candidates with
+ * the same type, and ICE draft suggests 65535 as the default local
+ * preference, which means we need 16 bits to represent the value. But
+ * since we don't have the facility to specify local preference, we'll
+ * just disable this feature and let the preference sorted by the
+ * type only.
*
- * Default: 8
+ * Default: 0
*/
-#ifndef PJ_ICE_MAX_COMP
-# define PJ_ICE_MAX_COMP 8
+#ifndef PJ_ICE_LOCAL_PREF_BITS
+# define PJ_ICE_LOCAL_PREF_BITS 0
#endif
diff --git a/pjnath/src/pjnath/ice_session.c b/pjnath/src/pjnath/ice_session.c
index 1ca17150..36fb59e5 100644
--- a/pjnath/src/pjnath/ice_session.c
+++ b/pjnath/src/pjnath/ice_session.c
@@ -65,13 +65,22 @@ static const char *role_names[] =
"Controlling"
};
-/* Default ICE session preferences, according to draft-ice */
+/* Candidate type preference */
static pj_uint8_t cand_type_prefs[4] =
{
+#if PJ_ICE_CAND_TYPE_PREF_BITS < 8
+ /* Keep it to 2 bits */
+ 3, /**< PJ_ICE_HOST_PREF */
+ 1, /**< PJ_ICE_SRFLX_PREF. */
+ 2, /**< PJ_ICE_PRFLX_PREF */
+ 0 /**< PJ_ICE_RELAYED_PREF */
+#else
+ /* Default ICE session preferences, according to draft-ice */
126, /**< PJ_ICE_HOST_PREF */
100, /**< PJ_ICE_SRFLX_PREF. */
110, /**< PJ_ICE_PRFLX_PREF */
0 /**< PJ_ICE_RELAYED_PREF */
+#endif
};
#define CHECK_NAME_LEN 128
@@ -215,6 +224,7 @@ PJ_DEF(void) pj_ice_calc_foundation(pj_pool_t *pool,
pj_ice_cand_type type,
const pj_sockaddr *base_addr)
{
+#if 0
char buf[64];
pj_uint32_t val;
@@ -227,6 +237,16 @@ PJ_DEF(void) pj_ice_calc_foundation(pj_pool_t *pool,
pj_ansi_snprintf(buf, sizeof(buf), "%c%x",
get_type_prefix(type), val);
pj_strdup2(pool, foundation, buf);
+#else
+ /* Much shorter version, valid for candidates added by
+ * pj_ice_strans.
+ */
+ foundation->ptr = (char*) pj_pool_alloc(pool, 1);
+ *foundation->ptr = (char)get_type_prefix(type);
+ foundation->slen = 1;
+
+ PJ_UNUSED_ARG(base_addr);
+#endif
}
@@ -450,10 +470,14 @@ PJ_DEF(pj_status_t) pj_ice_sess_change_role(pj_ice_sess *ice,
PJ_DEF(pj_status_t) pj_ice_sess_set_prefs(pj_ice_sess *ice,
const pj_uint8_t prefs[4])
{
+ unsigned i;
PJ_ASSERT_RETURN(ice && prefs, PJ_EINVAL);
ice->prefs = (pj_uint8_t*) pj_pool_calloc(ice->pool, PJ_ARRAY_SIZE(prefs),
sizeof(pj_uint8_t));
- pj_memcpy(ice->prefs, prefs, sizeof(prefs));
+ for (i=0; i<4; ++i) {
+ pj_assert(prefs[i] < (2 << PJ_ICE_CAND_TYPE_PREF_BITS));
+ ice->prefs[i] = prefs[i];
+ }
return PJ_SUCCESS;
}
@@ -578,9 +602,27 @@ static pj_uint32_t CALC_CAND_PRIO(pj_ice_sess *ice,
pj_uint32_t local_pref,
pj_uint32_t comp_id)
{
+#if 0
return ((ice->prefs[type] & 0xFF) << 24) +
((local_pref & 0xFFFF) << 8) +
(((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),
+
+ comp_shift = 0,
+ local_shift = (PJ_ICE_COMP_BITS),
+ type_shift = (comp_shift + local_shift),
+
+ max_comp = (2<<PJ_ICE_COMP_BITS),
+ };
+
+ return ((ice->prefs[type] & type_mask) << type_shift) +
+ ((local_pref & local_mask) << local_shift) +
+ (((max_comp - comp_id) & comp_mask) << comp_shift);
+#endif
}
@@ -1429,7 +1471,7 @@ static pj_status_t perform_check(pj_ice_sess *ice,
msg_data->data.req.ckid = check_id;
/* Add PRIORITY */
- prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535,
+ prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 0,
lcand->comp_id);
pj_stun_msg_add_uint_attr(check->tdata->pool, check->tdata->msg,
PJ_STUN_ATTR_PRIORITY, prio);
diff --git a/pjnath/src/pjnath/ice_strans.c b/pjnath/src/pjnath/ice_strans.c
index 44442951..ee72aee9 100644
--- a/pjnath/src/pjnath/ice_strans.c
+++ b/pjnath/src/pjnath/ice_strans.c
@@ -45,10 +45,24 @@ enum tp_type
TP_TURN
};
-/* Candidate preference default values */
-#define SRFLX_PREF 65535
-#define HOST_PREF 65530
-#define RELAY_PREF 65525
+/* Candidate's local preference values. This is mostly used to
+ * specify preference among candidates with the same type. Since
+ * we don't have the facility to specify that, we'll just set it
+ * all to zero.
+ */
+#define SRFLX_PREF 0
+#define HOST_PREF 0
+#define RELAY_PREF 0
+
+/* The candidate type preference when STUN candidate is used */
+static pj_uint8_t srflx_pref_table[4] =
+{
+ /* Keep it to 2 bits */
+ 1, /**< PJ_ICE_HOST_PREF */
+ 2, /**< PJ_ICE_SRFLX_PREF */
+ 3, /**< PJ_ICE_PRFLX_PREF */
+ 0 /**< PJ_ICE_RELAYED_PREF */
+};
/* ICE callbacks */
@@ -639,7 +653,6 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
/* Associate user data */
ice_st->ice->user_data = (void*)ice_st;
-#if 0
/* If default candidate for components are SRFLX one, upload a custom
* type priority to ICE session so that SRFLX candidates will get
* checked first.
@@ -648,9 +661,8 @@ PJ_DEF(pj_status_t) pj_ice_strans_init_ice(pj_ice_strans *ice_st,
ice_st->comp[0]->cand_list[ice_st->comp[0]->default_cand].type
== PJ_ICE_CAND_TYPE_SRFLX)
{
- pj_ice_sess_set_prefs(ice_st->ice, srflx_prio);
+ pj_ice_sess_set_prefs(ice_st->ice, srflx_pref_table);
}
-#endif
/* Add components/candidates */
for (i=0; i<ice_st->comp_cnt; ++i) {