Changeset 2945 for pjproject


Ignore:
Timestamp:
Oct 14, 2009 1:13:18 PM (14 years ago)
Author:
bennylp
Message:

Ticket #881: send UPDATE or re-INVITE after ICE negotiation, if the default candidate has changed

  • done
  • added pj_ice_strans_state (to be used for informational purposes for now)
  • added pjmedia ICE transport specific info, and display it in call dump output
  • misc fixes (changed pjmedia_transport_info.spec_info_cnt from int to unsigned)
Location:
pjproject/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/include/pjmedia/transport.h

    r2394 r2945  
    504504     * Specifies number of transport specific info included. 
    505505     */ 
    506     int specific_info_cnt; 
     506    unsigned specific_info_cnt; 
    507507 
    508508    /** 
  • pjproject/trunk/pjmedia/include/pjmedia/transport_ice.h

    r2394 r2945  
    6161 
    6262} pjmedia_ice_cb; 
     63 
     64 
     65/** 
     66 * This structure specifies ICE transport specific info. This structure 
     67 * will be filled in media transport specific info. 
     68 */ 
     69typedef struct pjmedia_ice_transport_info 
     70{ 
     71    /** 
     72     * ICE sesion state. 
     73     */ 
     74    pj_ice_strans_state sess_state; 
     75 
     76    /** 
     77     * Session role. 
     78     */ 
     79    pj_ice_sess_role role; 
     80 
     81    /** 
     82     * Number of components in the component array. Before ICE negotiation 
     83     * is complete, the number represents the number of components of the 
     84     * local agent. After ICE negotiation has been completed successfully, 
     85     * the number represents the number of common components between local 
     86     * and remote agents. 
     87     */ 
     88    unsigned comp_cnt; 
     89 
     90    /** 
     91     * Array of ICE components. Typically the first element denotes RTP and 
     92     * second element denotes RTCP. 
     93     */ 
     94    struct 
     95    { 
     96        /** 
     97         * Local candidate type. 
     98         */ 
     99        pj_ice_cand_type    lcand_type; 
     100 
     101        /** 
     102         * Remote candidate type. 
     103         */ 
     104        pj_ice_cand_type    rcand_type; 
     105 
     106    } comp[2]; 
     107 
     108} pjmedia_ice_transport_info; 
    63109 
    64110 
  • pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c

    r2896 r2945  
    14741474    } 
    14751475 
     1476    /* Fill up transport specific info */ 
     1477    if (info->specific_info_cnt < PJ_ARRAY_SIZE(info->spc_info)) { 
     1478        pjmedia_transport_specific_info *tsi; 
     1479        pjmedia_ice_transport_info *ii; 
     1480        unsigned i; 
     1481 
     1482        pj_assert(sizeof(*ii) <= sizeof(tsi->buffer)); 
     1483        tsi = &info->spc_info[info->specific_info_cnt++]; 
     1484        tsi->type = PJMEDIA_TRANSPORT_TYPE_ICE; 
     1485        tsi->cbsize = sizeof(*ii); 
     1486 
     1487        ii = (pjmedia_ice_transport_info*) tsi->buffer; 
     1488        pj_bzero(ii, sizeof(*ii)); 
     1489 
     1490        if (pj_ice_strans_has_sess(tp_ice->ice_st)) 
     1491            ii->role = pj_ice_strans_get_role(tp_ice->ice_st); 
     1492        else 
     1493            ii->role = PJ_ICE_SESS_ROLE_UNKNOWN; 
     1494        ii->sess_state = pj_ice_strans_get_state(tp_ice->ice_st); 
     1495        ii->comp_cnt = pj_ice_strans_get_running_comp_cnt(tp_ice->ice_st); 
     1496         
     1497        for (i=1; i<=ii->comp_cnt && i<=PJ_ARRAY_SIZE(ii->comp); ++i) { 
     1498            const pj_ice_sess_check *chk; 
     1499 
     1500            chk = pj_ice_strans_get_valid_pair(tp_ice->ice_st, i); 
     1501            if (chk) { 
     1502                ii->comp[i-1].lcand_type = chk->lcand->type; 
     1503                ii->comp[i-1].rcand_type = chk->rcand->type; 
     1504            } 
     1505        } 
     1506    } 
     1507 
    14761508    return PJ_SUCCESS; 
    14771509} 
  • pjproject/trunk/pjnath/include/pjnath/ice_strans.h

    r2724 r2945  
    328328 
    329329 
     330/** 
     331 * ICE stream transport's state. 
     332 */ 
     333typedef enum pj_ice_strans_state 
     334{ 
     335    /** 
     336     * ICE stream transport is not created. 
     337     */ 
     338    PJ_ICE_STRANS_STATE_NULL, 
     339 
     340    /** 
     341     * ICE candidate gathering process is in progress. 
     342     */ 
     343    PJ_ICE_STRANS_STATE_INIT, 
     344 
     345    /** 
     346     * ICE stream transport initialization/candidate gathering process is 
     347     * complete, ICE session may be created on this stream transport. 
     348     */ 
     349    PJ_ICE_STRANS_STATE_READY, 
     350 
     351    /** 
     352     * New session has been created and the session is ready. 
     353     */ 
     354    PJ_ICE_STRANS_STATE_SESS_READY, 
     355 
     356    /** 
     357     * ICE negotiation is in progress. 
     358     */ 
     359    PJ_ICE_STRANS_STATE_NEGO, 
     360 
     361    /** 
     362     * ICE negotiation has completed successfully and media is ready 
     363     * to be used. 
     364     */ 
     365    PJ_ICE_STRANS_STATE_RUNNING, 
     366 
     367    /** 
     368     * ICE negotiation has completed with failure. 
     369     */ 
     370    PJ_ICE_STRANS_STATE_FAILED 
     371 
     372} pj_ice_strans_state; 
     373 
     374 
    330375/**  
    331376 * Initialize ICE transport configuration with default values. 
     
    370415                                          const pj_ice_strans_cb *cb, 
    371416                                          pj_ice_strans **p_ice_st); 
     417 
     418/** 
     419 * Get ICE session state. 
     420 * 
     421 * @param ice_st        The ICE stream transport. 
     422 * 
     423 * @return              ICE session state. 
     424 */ 
     425PJ_DECL(pj_ice_strans_state) pj_ice_strans_get_state(pj_ice_strans *ice_st); 
     426 
     427 
     428/** 
     429 * Get string representation of ICE state. 
     430 * 
     431 * @param state         ICE stream transport state. 
     432 * 
     433 * @return              String. 
     434 */ 
     435PJ_DECL(const char*) pj_ice_strans_state_name(pj_ice_strans_state state); 
     436 
    372437 
    373438/** 
  • pjproject/trunk/pjnath/src/pjnath/ice_strans.c

    r2724 r2945  
    174174    pj_lock_t               *init_lock; /**< Initialization mutex.      */ 
    175175 
     176    pj_ice_strans_state      state;     /**< Session state.             */ 
    176177    pj_ice_sess             *ice;       /**< ICE session.               */ 
    177178    pj_time_val              start_time;/**< Time when ICE was started  */ 
     
    488489    ice_st->comp = (pj_ice_strans_comp**)  
    489490                   pj_pool_calloc(pool, comp_cnt, sizeof(pj_ice_strans_comp*)); 
     491 
     492    /* Move state to candidate gathering */ 
     493    ice_st->state = PJ_ICE_STRANS_STATE_INIT; 
    490494 
    491495    /* Acquire initialization mutex to prevent callback to be  
     
    562566} 
    563567 
     568/* Get ICE session state. */ 
     569PJ_DEF(pj_ice_strans_state) pj_ice_strans_get_state(pj_ice_strans *ice_st) 
     570{ 
     571    return ice_st->state; 
     572} 
     573 
     574/* State string */ 
     575PJ_DEF(const char*) pj_ice_strans_state_name(pj_ice_strans_state state) 
     576{ 
     577    const char *names[] = { 
     578        "Null", 
     579        "Candidate Gathering", 
     580        "Candidate Gathering Complete", 
     581        "Session Initialized", 
     582        "Negotiation In Progress", 
     583        "Negotiation Success", 
     584        "Negotiation Failed" 
     585    }; 
     586 
     587    PJ_ASSERT_RETURN(state <= PJ_ICE_STRANS_STATE_FAILED, "???"); 
     588    return names[state]; 
     589} 
     590 
    564591/* Notification about failure */ 
    565592static void sess_fail(pj_ice_strans *ice_st, pj_ice_strans_op op, 
     
    604631    /* All candidates have been gathered */ 
    605632    ice_st->cb_called = PJ_TRUE; 
     633    ice_st->state = PJ_ICE_STRANS_STATE_READY; 
    606634    if (ice_st->cb.on_ice_complete) 
    607635        (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_INIT,  
     
    783811    } 
    784812 
     813    /* ICE session is ready for negotiation */ 
     814    ice_st->state = PJ_ICE_STRANS_STATE_SESS_READY; 
     815 
    785816    return PJ_SUCCESS; 
    786817 
     
    9831014    } 
    9841015 
     1016    ice_st->state = PJ_ICE_STRANS_STATE_NEGO; 
    9851017    return status; 
    9861018} 
     
    10121044    } 
    10131045 
     1046    ice_st->state = PJ_ICE_STRANS_STATE_INIT; 
    10141047    return PJ_SUCCESS; 
    10151048} 
     
    11701203        } 
    11711204 
     1205        ice_st->state = (status==PJ_SUCCESS) ? PJ_ICE_STRANS_STATE_RUNNING : 
     1206                                               PJ_ICE_STRANS_STATE_FAILED; 
     1207 
    11721208        (*ice_st->cb.on_ice_complete)(ice_st, PJ_ICE_STRANS_OP_NEGOTIATION,  
    11731209                                      status); 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r2874 r2945  
    8383    pj_bool_t            med_tp_auto_del; /**< May delete media transport   */ 
    8484    pjsua_med_tp_st      med_tp_st; /**< Media transport state              */ 
     85    pj_sockaddr          med_rtp_addr; /**< Current RTP source address 
     86                                            (used to update ICE default 
     87                                            address)                        */ 
    8588    pj_stun_nat_type     rem_nat_type; /**< NAT type of remote endpoint.    */ 
    8689    pjmedia_srtp_use     rem_srtp_use; /**< Remote's SRTP usage policy.     */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r2943 r2945  
    28302830    } 
    28312831 
    2832     /* Get SRTP status */ 
     2832    /* Get and ICE SRTP status */ 
    28332833    pjmedia_transport_info_init(&tp_info); 
    28342834    pjmedia_transport_get_info(call->med_tp, &tp_info); 
    28352835    if (tp_info.specific_info_cnt > 0) { 
    2836         int i; 
     2836        unsigned i; 
    28372837        for (i = 0; i < tp_info.specific_info_cnt; ++i) { 
    28382838            if (tp_info.spc_info[i].type == PJMEDIA_TRANSPORT_TYPE_SRTP)  
     
    28512851                    *p = '\0'; 
    28522852                } 
    2853                 break; 
     2853            } else if (tp_info.spc_info[i].type==PJMEDIA_TRANSPORT_TYPE_ICE) { 
     2854                const pjmedia_ice_transport_info *ii; 
     2855 
     2856                ii = (const pjmedia_ice_transport_info*)  
     2857                     tp_info.spc_info[i].buffer; 
     2858 
     2859                len = pj_ansi_snprintf(p, end-p,  
     2860                                       "%s  ICE role: %s, state: %s, comp_cnt: %u", 
     2861                                       indent, 
     2862                                       pj_ice_sess_role_name(ii->role), 
     2863                                       pj_ice_strans_state_name(ii->sess_state), 
     2864                                       ii->comp_cnt); 
     2865                if (len > 0 && len < end-p) { 
     2866                    p += len; 
     2867                    *p++ = '\n'; 
     2868                    *p = '\0'; 
     2869                } 
    28542870            } 
    28552871        } 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c

    r2943 r2945  
    822822                pjsua_var.ua_cfg.cb.on_call_media_state(id); 
    823823            } 
     824        } else { 
     825            /* Send UPDATE if default transport address is different than 
     826             * what was advertised (ticket #881) 
     827             */ 
     828            pjmedia_transport_info tpinfo; 
     829            pjmedia_ice_transport_info *ii = NULL; 
     830            unsigned i; 
     831 
     832            pjmedia_transport_info_init(&tpinfo); 
     833            pjmedia_transport_get_info(tp, &tpinfo); 
     834            for (i=0; i<tpinfo.specific_info_cnt; ++i) { 
     835                if (tpinfo.spc_info[i].type==PJMEDIA_TRANSPORT_TYPE_ICE) { 
     836                    ii = (pjmedia_ice_transport_info*) 
     837                         tpinfo.spc_info[i].buffer; 
     838                    break; 
     839                } 
     840            } 
     841 
     842            if (ii && ii->role==PJ_ICE_SESS_ROLE_CONTROLLING && 
     843                pj_sockaddr_cmp(&tpinfo.sock_info.rtp_addr_name, 
     844                                &pjsua_var.calls[id].med_rtp_addr)) 
     845            { 
     846                PJ_LOG(4,(THIS_FILE,  
     847                          "ICE default transport address has changed for " 
     848                          "call %d, sending UPDATE", id)); 
     849                pjsua_call_update(id, 0, NULL); 
     850            } 
    824851        } 
    825852        break; 
     
    13211348    } 
    13221349 
     1350    /* Update currently advertised RTP source address */ 
     1351    pj_memcpy(&call->med_rtp_addr, &tpinfo.sock_info.rtp_addr_name,  
     1352              sizeof(pj_sockaddr)); 
     1353 
    13231354    *p_sdp = sdp; 
    13241355    return PJ_SUCCESS; 
     
    14831514        pjmedia_transport_get_info(call->med_tp, &tp_info); 
    14841515        if (tp_info.specific_info_cnt > 0) { 
    1485             int i; 
     1516            unsigned i; 
    14861517            for (i = 0; i < tp_info.specific_info_cnt; ++i) { 
    14871518                if (tp_info.spc_info[i].type == PJMEDIA_TRANSPORT_TYPE_SRTP)  
Note: See TracChangeset for help on using the changeset viewer.