Ignore:
Timestamp:
Mar 25, 2007 6:44:51 PM (17 years ago)
Author:
bennylp
Message:

ICE (work in progress): use single socket for all candidates in component, and implemented IP interface enumeration on Win32

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c

    r1101 r1104  
    7070 * And these are ICE callbacks. 
    7171 */ 
    72 static void ice_on_rx_data(pj_ice_st *ice_st, 
    73                            unsigned comp_id, unsigned cand_id, 
     72static void ice_on_rx_data(pj_ice_st *ice_st, unsigned comp_id,  
    7473                           void *pkt, pj_size_t size, 
    7574                           const pj_sockaddr_t *src_addr, 
     
    10099    pj_ice_st_cb ice_st_cb; 
    101100    struct transport_ice *tp_ice; 
    102     unsigned i; 
    103101    pj_status_t status; 
    104102 
     
    111109 
    112110    /* Create ICE */ 
    113     status = pj_ice_st_create(stun_cfg, name, NULL, &ice_st_cb, &ice_st); 
     111    status = pj_ice_st_create(stun_cfg, name, comp_cnt, NULL,  
     112                              &ice_st_cb, &ice_st); 
    114113    if (status != PJ_SUCCESS) 
    115114        return status; 
    116115 
    117     /* Add components */ 
    118     for (i=0; i<comp_cnt; ++i) { 
    119         status = pj_ice_st_add_comp(ice_st, i+1); 
    120         if (status != PJ_SUCCESS)  
    121             goto on_error; 
    122     } 
    123116 
    124117    /* Create transport instance and attach to ICE */ 
     
    136129 
    137130    return PJ_SUCCESS; 
    138  
    139 on_error: 
    140     pj_ice_st_destroy(ice_st); 
    141     return status; 
    142131} 
    143132 
     
    158147 
    159148 
    160 PJ_DECL(pj_ice_st*) pjmedia_ice_get_ice_st(pjmedia_transport *tp) 
     149PJ_DEF(pj_status_t) pjmedia_ice_start_init( pjmedia_transport *tp, 
     150                                            unsigned options, 
     151                                            const pj_sockaddr_in *start_addr, 
     152                                            const pj_sockaddr_in *stun_srv, 
     153                                            const pj_sockaddr_in *turn_srv) 
     154{ 
     155    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     156    unsigned comp_id; 
     157    pj_status_t status; 
     158 
     159    status = pj_ice_st_set_stun_srv(tp_ice->ice_st, stun_srv, turn_srv); 
     160    if (status != PJ_SUCCESS) 
     161        return status; 
     162 
     163    status = pj_ice_st_create_comp(tp_ice->ice_st, 1, options, start_addr,  
     164                                   &comp_id); 
     165    if (status != PJ_SUCCESS) 
     166        return status; 
     167 
     168    if (tp_ice->ice_st->comp_cnt > 1) { 
     169        pj_sockaddr_in addr; 
     170 
     171        pj_memcpy(&addr, &tp_ice->ice_st->comp[0]->local_addr.ipv4, 
     172                  sizeof(pj_sockaddr_in)); 
     173        if (start_addr) 
     174            addr.sin_addr.s_addr = start_addr->sin_addr.s_addr; 
     175        else 
     176            addr.sin_addr.s_addr = 0; 
     177 
     178        addr.sin_port = (pj_uint16_t)(pj_ntohs(addr.sin_port)+1); 
     179        status = pj_ice_st_create_comp(tp_ice->ice_st, 2, options,  
     180                                       &addr, &comp_id); 
     181        if (status != PJ_SUCCESS) 
     182            return status; 
     183    } 
     184    return status; 
     185} 
     186 
     187 
     188PJ_DEF(pj_status_t) pjmedia_ice_get_init_status(pjmedia_transport *tp) 
     189{ 
     190    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     191    return pj_ice_st_get_comps_status(tp_ice->ice_st); 
     192} 
     193 
     194 
     195PJ_DEF(pj_status_t) pjmedia_ice_get_comp( pjmedia_transport *tp, 
     196                                          unsigned comp_id, 
     197                                          pj_ice_st_comp *comp) 
     198{ 
     199    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     200    PJ_ASSERT_RETURN(tp && comp_id && comp_id <= tp_ice->ice_st->comp_cnt && 
     201                     comp, PJ_EINVAL); 
     202 
     203    pj_memcpy(comp, tp_ice->ice_st->comp[comp_id-1], sizeof(pj_ice_st_comp)); 
     204    return PJ_SUCCESS;               
     205} 
     206 
     207PJ_DEF(pj_ice_st*) pjmedia_ice_get_ice_st(pjmedia_transport *tp) 
    161208{ 
    162209    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     
    416463{ 
    417464    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
    418     int rel_idx = -1, srflx_idx = -1, host_idx = -1, idx = -1; 
    419     unsigned i; 
     465    pj_ice_st *ice_st = tp_ice->ice_st; 
     466    pj_ice_st_comp *comp; 
    420467 
    421468    pj_bzero(info, sizeof(*info)); 
    422469    info->rtp_sock = info->rtcp_sock = PJ_INVALID_SOCKET; 
    423470 
    424     for (i=0; i<tp_ice->ice_st->itf_cnt; ++i) { 
    425         pj_ice_st_interface *itf = tp_ice->ice_st->itfs[i]; 
    426  
    427         if (itf->type == PJ_ICE_CAND_TYPE_HOST && host_idx == -1) 
    428             host_idx = i; 
    429         else if (itf->type == PJ_ICE_CAND_TYPE_RELAYED && rel_idx == -1) 
    430             rel_idx = i; 
    431         else if (itf->type == PJ_ICE_CAND_TYPE_SRFLX && srflx_idx == -1) 
    432             srflx_idx = i; 
    433     } 
    434  
    435     if (idx == -1 && srflx_idx != -1) 
    436         idx = srflx_idx; 
    437     else if (idx == -1 && rel_idx != -1) 
    438         idx = rel_idx; 
    439     else if (idx == -1 && host_idx != -1) 
    440         idx = host_idx; 
    441  
    442     PJ_ASSERT_RETURN(idx != -1, PJ_EBUG); 
    443  
    444     pj_memcpy(&info->rtp_addr_name, &tp_ice->ice_st->itfs[idx]->addr, 
     471    /* Retrieve address of default candidate for component 1 (RTP) */ 
     472    comp = ice_st->comp[0]; 
     473    pj_assert(comp->default_cand >= 0); 
     474    info->rtp_sock = comp->sock; 
     475    pj_memcpy(&info->rtp_addr_name,  
     476              &comp->cand_list[comp->default_cand].addr, 
    445477              sizeof(pj_sockaddr_in)); 
     478 
     479    /* Retrieve address of default candidate for component 12(RTCP) */ 
     480    if (ice_st->comp_cnt > 1) { 
     481        comp = ice_st->comp[1]; 
     482        pj_assert(comp->default_cand >= 0); 
     483        info->rtp_sock = comp->sock; 
     484        pj_memcpy(&info->rtp_addr_name,  
     485                  &comp->cand_list[comp->default_cand].addr, 
     486                  sizeof(pj_sockaddr_in)); 
     487    } 
     488 
    446489 
    447490    return PJ_SUCCESS; 
     
    492535{ 
    493536    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
    494     if (tp_ice->ice_st->ice) { 
    495         return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size); 
    496     } else { 
    497         return pj_ice_st_sendto(tp_ice->ice_st, 1, 0, 
    498                                 pkt, size, &tp_ice->remote_rtp, 
    499                                 sizeof(pj_sockaddr_in)); 
    500     } 
     537    return pj_ice_st_sendto(tp_ice->ice_st, 1,  
     538                            pkt, size, &tp_ice->remote_rtp, 
     539                            sizeof(pj_sockaddr_in)); 
    501540} 
    502541 
     
    506545                                pj_size_t size) 
    507546{ 
    508 #if 0 
    509     struct transport_ice *tp_ice = (struct transport_ice*)tp; 
    510     return pj_ice_st_send_data(tp_ice->ice_st, 1, pkt, size); 
    511 #else 
    512     PJ_TODO(SUPPORT_RTCP); 
    513     PJ_UNUSED_ARG(tp); 
    514     PJ_UNUSED_ARG(pkt); 
    515     PJ_UNUSED_ARG(size); 
    516     return PJ_SUCCESS; 
    517 #endif 
    518 } 
    519  
    520  
    521 static void ice_on_rx_data(pj_ice_st *ice_st, 
    522                            unsigned comp_id, unsigned cand_id, 
     547    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     548    if (tp_ice->ice_st->comp_cnt > 1) { 
     549        return pj_ice_st_sendto(tp_ice->ice_st, 2,  
     550                                pkt, size, &tp_ice->remote_rtp, 
     551                                sizeof(pj_sockaddr_in)); 
     552    } else { 
     553        return PJ_SUCCESS; 
     554    } 
     555} 
     556 
     557 
     558static void ice_on_rx_data(pj_ice_st *ice_st, unsigned comp_id,  
    523559                           void *pkt, pj_size_t size, 
    524560                           const pj_sockaddr_t *src_addr, 
     
    532568        (*tp_ice->rtcp_cb)(tp_ice->stream, pkt, size); 
    533569 
    534     PJ_UNUSED_ARG(cand_id); 
    535570    PJ_UNUSED_ARG(src_addr); 
    536571    PJ_UNUSED_ARG(src_addr_len); 
     572 
     573    PJ_TODO(SWITCH_SOURCE_ADDRESS); 
    537574} 
    538575 
Note: See TracChangeset for help on using the changeset viewer.