Changeset 2054


Ignore:
Timestamp:
Jun 25, 2008 9:16:46 PM (11 years ago)
Author:
bennylp
Message:

Optimize the number of characters written to SDP by ICE

Location:
pjproject/trunk/pjnath
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/include/pjnath/config.h

    r1988 r2054  
    245245 
    246246/** 
     247 * The number of bits to represent component IDs. This will affect 
     248 * the maximum number of components (PJ_ICE_MAX_COMP) value. 
     249 */ 
     250#ifndef PJ_ICE_COMP_BITS 
     251#   define PJ_ICE_COMP_BITS                         3 
     252#endif 
     253 
     254 
     255/** 
    247256 * Maximum number of ICE components. 
    248  * 
    249  * Default: 8 
    250  */ 
    251 #ifndef PJ_ICE_MAX_COMP 
    252 #   define PJ_ICE_MAX_COMP                          8 
     257 */ 
     258#define PJ_ICE_MAX_COMP             (2<<PJ_ICE_COMP_BITS) 
     259 
     260 
     261/** 
     262 * The number of bits to represent candidate type preference. 
     263 */ 
     264#ifndef PJ_ICE_CAND_TYPE_PREF_BITS 
     265#   define PJ_ICE_CAND_TYPE_PREF_BITS               2 
     266#endif 
     267 
     268 
     269/** 
     270 * The number of bits to represent ICE candidate's local preference. The 
     271 * local preference is used to specify preference among candidates with 
     272 * the same type, and ICE draft suggests 65535 as the default local  
     273 * preference, which means we need 16 bits to represent the value. But  
     274 * since we don't have the facility to specify local preference, we'll 
     275 * just disable this feature and let the preference sorted by the  
     276 * type only. 
     277 * 
     278 * Default: 0 
     279 */ 
     280#ifndef PJ_ICE_LOCAL_PREF_BITS 
     281#   define PJ_ICE_LOCAL_PREF_BITS                   0 
    253282#endif 
    254283 
  • pjproject/trunk/pjnath/src/pjnath/ice_session.c

    r2047 r2054  
    6666}; 
    6767 
    68 /* Default ICE session preferences, according to draft-ice */ 
     68/* Candidate type preference */ 
    6969static pj_uint8_t cand_type_prefs[4] = 
    7070{ 
     71#if PJ_ICE_CAND_TYPE_PREF_BITS < 8 
     72    /* Keep it to 2 bits */ 
     73    3,      /**< PJ_ICE_HOST_PREF       */ 
     74    1,      /**< PJ_ICE_SRFLX_PREF.     */ 
     75    2,      /**< PJ_ICE_PRFLX_PREF      */ 
     76    0       /**< PJ_ICE_RELAYED_PREF    */ 
     77#else 
     78    /* Default ICE session preferences, according to draft-ice */ 
    7179    126,    /**< PJ_ICE_HOST_PREF       */ 
    7280    100,    /**< PJ_ICE_SRFLX_PREF.     */ 
    7381    110,    /**< PJ_ICE_PRFLX_PREF      */ 
    7482    0       /**< PJ_ICE_RELAYED_PREF    */ 
     83#endif 
    7584}; 
    7685 
     
    216225                                    const pj_sockaddr *base_addr) 
    217226{ 
     227#if 0 
    218228    char buf[64]; 
    219229    pj_uint32_t val; 
     
    228238                     get_type_prefix(type), val); 
    229239    pj_strdup2(pool, foundation, buf); 
     240#else 
     241    /* Much shorter version, valid for candidates added by 
     242     * pj_ice_strans. 
     243     */ 
     244    foundation->ptr = (char*) pj_pool_alloc(pool, 1); 
     245    *foundation->ptr = (char)get_type_prefix(type); 
     246    foundation->slen = 1; 
     247 
     248    PJ_UNUSED_ARG(base_addr); 
     249#endif 
    230250} 
    231251 
     
    451471                                          const pj_uint8_t prefs[4]) 
    452472{ 
     473    unsigned i; 
    453474    PJ_ASSERT_RETURN(ice && prefs, PJ_EINVAL); 
    454475    ice->prefs = (pj_uint8_t*) pj_pool_calloc(ice->pool, PJ_ARRAY_SIZE(prefs), 
    455476                                              sizeof(pj_uint8_t)); 
    456     pj_memcpy(ice->prefs, prefs, sizeof(prefs)); 
     477    for (i=0; i<4; ++i) { 
     478        pj_assert(prefs[i] < (2 << PJ_ICE_CAND_TYPE_PREF_BITS)); 
     479        ice->prefs[i] = prefs[i]; 
     480    } 
    457481    return PJ_SUCCESS; 
    458482} 
     
    579603                                  pj_uint32_t comp_id) 
    580604{ 
     605#if 0 
    581606    return ((ice->prefs[type] & 0xFF) << 24) +  
    582607           ((local_pref & 0xFFFF)    << 8) + 
    583608           (((256 - comp_id) & 0xFF) << 0); 
     609#else 
     610    enum { 
     611        type_mask   = ((2 << PJ_ICE_CAND_TYPE_PREF_BITS) - 1), 
     612        local_mask  = ((2 << PJ_ICE_LOCAL_PREF_BITS) - 1), 
     613        comp_mask   = ((2 << PJ_ICE_COMP_BITS) - 1), 
     614 
     615        comp_shift  = 0, 
     616        local_shift = (PJ_ICE_COMP_BITS), 
     617        type_shift  = (comp_shift + local_shift), 
     618 
     619        max_comp    = (2<<PJ_ICE_COMP_BITS), 
     620    }; 
     621 
     622    return ((ice->prefs[type] & type_mask) << type_shift) +  
     623           ((local_pref & local_mask) << local_shift) + 
     624           (((max_comp - comp_id) & comp_mask) << comp_shift); 
     625#endif 
    584626} 
    585627 
     
    14301472 
    14311473    /* Add PRIORITY */ 
    1432     prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 65535,  
     1474    prio = CALC_CAND_PRIO(ice, PJ_ICE_CAND_TYPE_PRFLX, 0,  
    14331475                          lcand->comp_id); 
    14341476    pj_stun_msg_add_uint_attr(check->tdata->pool, check->tdata->msg,  
  • pjproject/trunk/pjnath/src/pjnath/ice_strans.c

    r2043 r2054  
    4646}; 
    4747 
    48 /* Candidate preference default values */ 
    49 #define SRFLX_PREF  65535 
    50 #define HOST_PREF   65530 
    51 #define RELAY_PREF  65525 
     48/* Candidate's local preference values. This is mostly used to 
     49 * specify preference among candidates with the same type. Since 
     50 * we don't have the facility to specify that, we'll just set it 
     51 * all to zero. 
     52 */ 
     53#define SRFLX_PREF  0 
     54#define HOST_PREF   0 
     55#define RELAY_PREF  0 
     56 
     57/* The candidate type preference when STUN candidate is used */ 
     58static pj_uint8_t srflx_pref_table[4] =  
     59{ 
     60    /* Keep it to 2 bits */ 
     61    1,  /**< PJ_ICE_HOST_PREF       */ 
     62    2,  /**< PJ_ICE_SRFLX_PREF      */ 
     63    3,  /**< PJ_ICE_PRFLX_PREF      */ 
     64    0   /**< PJ_ICE_RELAYED_PREF    */ 
     65}; 
    5266 
    5367 
     
    640654    ice_st->ice->user_data = (void*)ice_st; 
    641655 
    642 #if 0 
    643656    /* If default candidate for components are SRFLX one, upload a custom 
    644657     * type priority to ICE session so that SRFLX candidates will get 
     
    649662            == PJ_ICE_CAND_TYPE_SRFLX) 
    650663    { 
    651         pj_ice_sess_set_prefs(ice_st->ice, srflx_prio); 
    652     } 
    653 #endif 
     664        pj_ice_sess_set_prefs(ice_st->ice, srflx_pref_table); 
     665    } 
    654666 
    655667    /* Add components/candidates */ 
Note: See TracChangeset for help on using the changeset viewer.