From 016a4eae3331e0fe7db428ab7381b0fbc93a7267 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Wed, 25 Jun 2008 21:16:46 +0000 Subject: 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 --- pjnath/include/pjnath/config.h | 35 +++++++++++++++++++++++++++--- pjnath/src/pjnath/ice_session.c | 48 ++++++++++++++++++++++++++++++++++++++--- pjnath/src/pjnath/ice_strans.c | 26 ++++++++++++++++------ 3 files changed, 96 insertions(+), 13 deletions(-) (limited to 'pjnath') 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 @@ -243,13 +243,42 @@ #endif +/** + * 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<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<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; icomp_cnt; ++i) { -- cgit v1.2.3