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

Optimize the number of characters written to SDP by ICE

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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,  
Note: See TracChangeset for help on using the changeset viewer.