Ignore:
Timestamp:
Mar 22, 2007 9:00:53 PM (17 years ago)
Author:
bennylp
Message:

Final ICE stream transport

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath-test/ice_test.c

    r1095 r1096  
    3838static pj_stun_config stun_cfg; 
    3939 
    40 static void on_ice_complete(pj_icemt *icemt,  
     40static void on_ice_complete(pj_ice_st *icest,  
    4141                            pj_status_t status) 
    4242{ 
    43     struct ice_data *id = (struct ice_data*) icemt->user_data; 
     43    struct ice_data *id = (struct ice_data*) icest->user_data; 
    4444    id->complete = PJ_TRUE; 
    4545    id->err_code = status; 
     
    4949 
    5050 
    51 static void on_rx_rtp(pj_icemt *icemt, 
    52                       void *pkt, pj_size_t size, 
    53                       const pj_sockaddr_t *src_addr, 
    54                       unsigned src_addr_len) 
    55 { 
    56     struct ice_data *id = (struct ice_data*) icemt->user_data; 
    57  
    58     id->rx_rtp_cnt++; 
    59     pj_memcpy(id->last_rx_rtp_data, pkt, size); 
    60     id->last_rx_rtp_data[size] = '\0'; 
    61  
    62     PJ_UNUSED_ARG(src_addr); 
    63     PJ_UNUSED_ARG(src_addr_len); 
    64 } 
    65  
    66  
    67 static void on_rx_rtcp(pj_icemt *icemt, 
     51static void on_rx_data(pj_ice_st *icest, 
     52                       unsigned comp_id, unsigned cand_id, 
    6853                       void *pkt, pj_size_t size, 
    6954                       const pj_sockaddr_t *src_addr, 
    7055                       unsigned src_addr_len) 
    7156{ 
    72     struct ice_data *id = (struct ice_data*) icemt->user_data; 
    73  
    74     id->rx_rtcp_cnt++; 
    75     pj_memcpy(id->last_rx_rtcp_data, pkt, size); 
    76     id->last_rx_rtcp_data[size] = '\0'; 
    77  
     57    struct ice_data *id = (struct ice_data*) icest->user_data; 
     58 
     59    if (comp_id == 1) { 
     60        id->rx_rtp_cnt++; 
     61        pj_memcpy(id->last_rx_rtp_data, pkt, size); 
     62        id->last_rx_rtp_data[size] = '\0'; 
     63    } else if (comp_id == 2) { 
     64        id->rx_rtcp_cnt++; 
     65        pj_memcpy(id->last_rx_rtcp_data, pkt, size); 
     66        id->last_rx_rtcp_data[size] = '\0'; 
     67    } else { 
     68        pj_assert(!"Invalid component ID"); 
     69    } 
     70 
     71    PJ_UNUSED_ARG(cand_id); 
    7872    PJ_UNUSED_ARG(src_addr); 
    7973    PJ_UNUSED_ARG(src_addr_len); 
     
    9892static int ice_basic_create_destroy_test() 
    9993{ 
    100     pj_icemt *im; 
    101     pj_ice *ice; 
    102     pj_icemt_cb icemt_cb; 
     94    pj_ice_st *im; 
     95    pj_ice_st_cb icest_cb; 
    10396    pj_status_t status; 
    10497 
    10598    PJ_LOG(3,(THIS_FILE, "...basic create/destroy")); 
    10699 
    107     pj_bzero(&icemt_cb, sizeof(icemt_cb)); 
    108     icemt_cb.on_ice_complete = &on_ice_complete; 
    109     icemt_cb.on_rx_rtp = &on_rx_rtp; 
    110     icemt_cb.on_rx_rtcp = &on_rx_rtcp; 
    111  
    112     status = pj_icemt_create(&stun_cfg, NULL, PJ_ICE_ROLE_CONTROLLING, 
    113                              &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im); 
     100    pj_bzero(&icest_cb, sizeof(icest_cb)); 
     101    icest_cb.on_ice_complete = &on_ice_complete; 
     102    icest_cb.on_rx_data = &on_rx_data; 
     103 
     104    status = pj_ice_st_create(&stun_cfg, NULL, NULL, &icest_cb, &im); 
    114105    if (status != PJ_SUCCESS) 
    115106        return -10; 
    116107 
    117     ice = im->ice; 
    118  
    119     pj_icemt_destroy(im); 
     108    pj_ice_st_destroy(im); 
    120109 
    121110    return 0; 
     
    123112 
    124113 
    125 static pj_status_t set_remote_list(pj_icemt *src, pj_icemt *dst) 
    126 { 
    127     unsigned i, count; 
    128     unsigned cand_id[PJ_ICE_MAX_CAND]; 
     114static pj_status_t start_ice(pj_ice_st *ist, pj_ice_st *remote) 
     115{ 
     116    unsigned count; 
    129117    pj_ice_cand cand[PJ_ICE_MAX_CAND]; 
    130118    pj_status_t status; 
    131119 
    132     count = PJ_ARRAY_SIZE(cand_id); 
    133     status = pj_ice_enum_cands(src->ice, &count, cand_id); 
     120    count = PJ_ARRAY_SIZE(cand); 
     121    status = pj_ice_st_enum_cands(remote, &count, cand); 
    134122    if (status != PJ_SUCCESS) 
    135123        return status; 
    136124 
    137     for (i=0; i<count; ++i) { 
    138         pj_ice_cand *p_cand; 
    139         status = pj_ice_get_cand(src->ice, cand_id[i], &p_cand); 
    140         if (status != PJ_SUCCESS) 
    141             return status; 
    142  
    143         pj_memcpy(&cand[i], p_cand, sizeof(pj_ice_cand)); 
    144     } 
    145  
    146     status = pj_ice_create_check_list(dst->ice, count, cand); 
    147     return status; 
    148 } 
     125    return pj_ice_st_start_ice(ist, &remote->ice->rx_ufrag, &remote->ice->rx_pass, 
     126                               count, cand); 
     127} 
     128 
    149129 
    150130 
     
    163143static int perform_ice_test(const char *title, 
    164144                            unsigned wait_before_send, 
    165                             unsigned max_total_time, 
    166                             unsigned ocand_cnt, 
    167                             const pj_ice_cand ocand[], 
    168                             unsigned acand_cnt, 
    169                             const pj_ice_cand acand[]) 
    170 { 
    171     pj_icemt *im1, *im2; 
    172     pj_icemt_cb icemt_cb; 
     145                            unsigned max_total_time) 
     146{ 
     147    pj_ice_st *im1, *im2; 
     148    pj_ice_st_cb icest_cb; 
    173149    struct ice_data *id1, *id2; 
    174150    pj_timestamp t_start, t_end; 
    175151    pj_ice_cand *rcand; 
    176152    pj_str_t data_from_offerer, data_from_answerer; 
    177     unsigned i; 
    178153    pj_status_t status; 
    179154 
    180155    PJ_LOG(3,(THIS_FILE, "...%s", title)); 
    181156 
    182     pj_bzero(&icemt_cb, sizeof(icemt_cb)); 
    183     icemt_cb.on_ice_complete = &on_ice_complete; 
    184     icemt_cb.on_rx_rtp = &on_rx_rtp; 
    185     icemt_cb.on_rx_rtcp = &on_rx_rtcp; 
     157    pj_bzero(&icest_cb, sizeof(icest_cb)); 
     158    icest_cb.on_ice_complete = &on_ice_complete; 
     159    icest_cb.on_rx_data = &on_rx_data; 
    186160 
    187161    /* Create first ICE */ 
    188     status = pj_icemt_create(&stun_cfg, "offerer", PJ_ICE_ROLE_CONTROLLING, 
    189                              &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im1); 
     162    status = pj_ice_st_create(&stun_cfg, "offerer", NULL, &icest_cb, &im1); 
    190163    if (status != PJ_SUCCESS) 
    191164        return -20; 
     
    195168    im1->user_data = id1; 
    196169 
    197     /* Add additional candidates */ 
    198     for (i=0; i<ocand_cnt; ++i) { 
    199         status = pj_ice_add_cand(im1->ice, 1, ocand[i].type, 65535, 
    200                                  &ocand[i].foundation, &ocand[i].addr, 
    201                                  &ocand[i].base_addr, &ocand[i].srv_addr, 
    202                                  sizeof(pj_sockaddr_in), NULL); 
    203         if (status != PJ_SUCCESS) 
    204             return -22; 
    205     } 
     170    /* Add first component */ 
     171    status = pj_ice_st_add_comp(im1, 1); 
     172    if (status != PJ_SUCCESS) 
     173        return -21; 
     174 
     175    /* Add host candidate */ 
     176    status = pj_ice_st_add_host_interface(im1, 1, 65535, NULL, NULL, PJ_FALSE, NULL); 
     177    if (status != PJ_SUCCESS) 
     178        return -21; 
    206179 
    207180    /* Create second ICE */ 
    208     status = pj_icemt_create(&stun_cfg, "answerer", PJ_ICE_ROLE_CONTROLLED, 
    209                              &icemt_cb, 0, PJ_FALSE, PJ_FALSE, NULL, &im2); 
     181    status = pj_ice_st_create(&stun_cfg, "answerer", NULL, &icest_cb, &im2); 
    210182    if (status != PJ_SUCCESS) 
    211183        return -25; 
     
    215187    im2->user_data = id2; 
    216188 
    217     /* Add additional candidates */ 
    218     for (i=0; i<acand_cnt; ++i) { 
    219         status = pj_ice_add_cand(im1->ice, 1, acand[i].type, 65535, 
    220                                  &acand[i].foundation, &acand[i].addr, 
    221                                  &acand[i].base_addr, &acand[i].srv_addr, 
    222                                  sizeof(pj_sockaddr_in), NULL); 
    223         if (status != PJ_SUCCESS) 
    224             return -22; 
    225     } 
    226  
    227     /* Set credentials */ 
    228     { 
    229         pj_str_t u1 = pj_str("offerer"); 
    230         pj_str_t p1 = pj_str("pass1"); 
    231         pj_str_t u2 = pj_str("answerer"); 
    232         pj_str_t p2 = pj_str("pass2"); 
    233  
    234         pj_ice_set_credentials(im1->ice, &u1, &p1, &u2, &p2); 
    235         pj_ice_set_credentials(im2->ice, &u2, &p2, &u1, &p1); 
    236     } 
    237  
    238     /* Send offer to im2 */ 
    239     status = set_remote_list(im1, im2); 
     189    /* Add first component */ 
     190    status = pj_ice_st_add_comp(im2, 1); 
     191    if (status != PJ_SUCCESS) 
     192        return -26; 
     193 
     194    /* Add host candidate */ 
     195    status = pj_ice_st_add_host_interface(im2, 1, 65535, NULL, NULL, PJ_FALSE, NULL); 
     196    if (status != PJ_SUCCESS) 
     197        return -27; 
     198 
     199    /* Init ICE on im1 */ 
     200    status = pj_ice_st_init_ice(im1, PJ_ICE_ROLE_CONTROLLING, NULL, NULL); 
     201    if (status != PJ_SUCCESS) 
     202        return -29; 
     203 
     204    /* Init ICE on im2 */ 
     205    status = pj_ice_st_init_ice(im2, PJ_ICE_ROLE_CONTROLLED, NULL, NULL); 
     206    if (status != PJ_SUCCESS) 
     207        return -29; 
     208 
     209    /* Start ICE on im2 */ 
     210    status = start_ice(im2, im1); 
    240211    if (status != PJ_SUCCESS) 
    241212        return -30; 
    242213 
    243     /* Send answer to im1 */ 
    244     status = set_remote_list(im2, im1); 
     214    /* Start ICE on im1 */ 
     215    status = start_ice(im1, im2); 
    245216    if (status != PJ_SUCCESS) 
    246217        return -35; 
     
    248219    /* Mark start time */ 
    249220    pj_get_timestamp(&t_start); 
    250  
    251     /* Both can start now */ 
    252     status = pj_ice_start_check(im1->ice); 
    253     if (status != PJ_SUCCESS) 
    254         return -40; 
    255  
    256 #if 1 
    257     status = pj_ice_start_check(im2->ice); 
    258     if (status != PJ_SUCCESS) 
    259         return -45; 
    260 #endif 
    261221 
    262222    /* Poll for wait_before_send msecs before we send the first data */ 
     
    366326 
    367327 
    368     pj_icemt_destroy(im1); 
    369     pj_icemt_destroy(im2); 
     328    pj_ice_st_destroy(im1); 
     329    pj_ice_st_destroy(im2); 
    370330    return 0; 
    371331} 
     
    378338    pj_ioqueue_t *ioqueue; 
    379339    pj_timer_heap_t *timer_heap; 
    380     pj_ice_cand ocand[PJ_ICE_MAX_CAND]; 
    381     pj_ice_cand acand[PJ_ICE_MAX_CAND]; 
    382     pj_str_t s; 
    383340 
    384341    pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); 
     
    396353 
    397354    /* Direct communication */ 
    398     rc = perform_ice_test("Direct connection", 500, 1000, 0, NULL, 0, NULL); 
     355    rc = perform_ice_test("Direct connection", 500, 1000); 
    399356    if (rc != 0) 
    400357        goto on_return; 
    401358 
    402359    /* Direct communication with invalid address */ 
    403     pj_bzero(ocand, sizeof(ocand)); 
    404     pj_sockaddr_in_init(&ocand[0].addr.ipv4, pj_cstr(&s, "127.0.0.127"), 1234); 
    405     pj_sockaddr_in_init(&ocand[0].base_addr.ipv4, pj_cstr(&s, "127.0.0.128"), 1234); 
    406     ocand[0].comp_id = 1; 
    407     ocand[0].foundation = pj_str("H2"); 
    408     ocand[0].type = PJ_ICE_CAND_TYPE_HOST; 
    409  
    410     rc = perform_ice_test("Direct connection with 1 invalid address", 500, 1000, 1, ocand, 0, NULL); 
     360    rc = perform_ice_test("Direct connection with 1 invalid address", 500, 1000); 
    411361    if (rc != 0) 
    412362        goto on_return; 
    413363 
    414364    /* Direct communication with two components */ 
    415     rc = perform_ice_test("Direct connection with two components", 500, 1000, 0, NULL, 0, NULL); 
     365    rc = perform_ice_test("Direct connection with two components", 500, 1000); 
    416366    if (rc != 0) 
    417367        goto on_return; 
Note: See TracChangeset for help on using the changeset viewer.