Ignore:
Timestamp:
Jun 3, 2017 9:22:34 AM (7 years ago)
Author:
nanang
Message:

Re #2018: Initial version of DTLS-SRTP implementation.

File:
1 edited

Legend:

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

    r5534 r5597  
    4747}; 
    4848 
     49/* ICE listener */ 
     50typedef struct ice_listener 
     51{ 
     52    PJ_DECL_LIST_MEMBER(struct ice_listener); 
     53    pjmedia_ice_cb       cb; 
     54    void                *user_data; 
     55} ice_listener; 
     56 
    4957struct transport_ice 
    5058{ 
     
    5765 
    5866    pjmedia_ice_cb       cb; 
     67    ice_listener         listener; 
     68    ice_listener         listener_empty; 
    5969    unsigned             media_option; 
    6070 
     
    6777    pj_sockaddr          remote_rtcp; 
    6878    unsigned             addr_len;      /**< Length of addresses.           */ 
     79    unsigned             rem_rtp_cnt;   /**< How many pkt from this addr.   */ 
    6980 
    7081    pj_bool_t            use_ice; 
     
    244255    tp_ice->oa_role = ROLE_NONE; 
    245256    tp_ice->use_ice = PJ_FALSE; 
     257    pj_list_init(&tp_ice->listener); 
     258    pj_list_init(&tp_ice->listener_empty); 
    246259 
    247260    pj_memcpy(&ice_st_cfg, cfg, sizeof(pj_ice_strans_cfg)); 
     
    286299    PJ_ASSERT_RETURN(tp, NULL); 
    287300    return pj_ice_strans_get_grp_lock(((struct transport_ice *)tp)->ice_st); 
     301} 
     302 
     303 
     304/* 
     305 * Add application to receive ICE notifications from the specified ICE media 
     306 * transport. 
     307 */ 
     308PJ_DEF(pj_status_t) pjmedia_ice_add_ice_cb( pjmedia_transport *tp, 
     309                                            const pjmedia_ice_cb *cb, 
     310                                            void *user_data) 
     311{ 
     312    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     313    ice_listener *il; 
     314    pj_grp_lock_t *grp_lock; 
     315 
     316    PJ_ASSERT_RETURN(tp && cb, PJ_EINVAL); 
     317    grp_lock = pjmedia_ice_get_grp_lock(tp); 
     318    PJ_ASSERT_RETURN(grp_lock, PJ_EINVAL); 
     319 
     320    pj_grp_lock_acquire(grp_lock); 
     321 
     322    if (!pj_list_empty(&tp_ice->listener_empty)) { 
     323        il = tp_ice->listener_empty.next; 
     324        pj_list_erase(il); 
     325        il->cb = *cb; 
     326        il->user_data = user_data; 
     327        pj_list_push_back(&tp_ice->listener, il); 
     328    } else { 
     329        il = PJ_POOL_ZALLOC_T(tp_ice->pool, ice_listener); 
     330        pj_list_init(il); 
     331        il->cb = *cb; 
     332        il->user_data = user_data; 
     333        pj_list_push_back(&tp_ice->listener, il); 
     334    } 
     335 
     336    pj_grp_lock_release(grp_lock); 
     337 
     338    return PJ_SUCCESS; 
     339} 
     340 
     341 
     342/* 
     343 * Remove application to stop receiving ICE notifications the specified 
     344 * ICE media transport. 
     345 */ 
     346PJ_DEF(pj_status_t) pjmedia_ice_remove_ice_cb( pjmedia_transport *tp, 
     347                                               const pjmedia_ice_cb *cb, 
     348                                               void *user_data) 
     349{ 
     350    struct transport_ice *tp_ice = (struct transport_ice*)tp; 
     351    ice_listener *il; 
     352    pj_grp_lock_t *grp_lock; 
     353 
     354    PJ_ASSERT_RETURN(tp && cb, PJ_EINVAL); 
     355    grp_lock = pjmedia_ice_get_grp_lock(tp); 
     356    PJ_ASSERT_RETURN(grp_lock, PJ_EINVAL); 
     357 
     358    pj_grp_lock_acquire(grp_lock); 
     359 
     360    for (il=tp_ice->listener.next; il!=&tp_ice->listener; il=il->next) { 
     361        if (pj_memcmp(&il->cb, cb, sizeof(cb))==0 && il->user_data==user_data) 
     362            break; 
     363    } 
     364    if (il != &tp_ice->listener) { 
     365        pj_list_erase(il); 
     366        pj_list_push_back(&tp_ice->listener_empty, il); 
     367    } 
     368 
     369    pj_grp_lock_release(grp_lock); 
     370 
     371    return (il != &tp_ice->listener? PJ_SUCCESS : PJ_ENOTFOUND); 
    288372} 
    289373 
     
    16201704    pj_memcpy(&tp_ice->remote_rtcp, rem_rtcp, addr_len); 
    16211705    tp_ice->addr_len = addr_len; 
     1706    tp_ice->rem_rtp_cnt = 0; 
    16221707 
    16231708    /* Init source RTP & RTCP addresses and counter */ 
     
    17311816                /* Don't switch while we're receiving from remote_rtp */ 
    17321817                tp_ice->rtp_src_cnt = 0; 
     1818                tp_ice->rem_rtp_cnt++; 
    17331819            } else { 
    17341820 
     
    17451831 
    17461832                if (tp_ice->rtp_src_cnt < PJMEDIA_RTP_NAT_PROBATION_CNT) { 
    1747                     discard = PJ_TRUE; 
     1833                    /* Only discard if we have ever received packet from 
     1834                     * remote address (remote_rtp). 
     1835                     */ 
     1836                    discard = (tp_ice->rem_rtp_cnt != 0); 
    17481837                } else { 
    17491838                    char addr_text[80]; 
     
    18341923{ 
    18351924    struct transport_ice *tp_ice; 
     1925    ice_listener *il; 
    18361926 
    18371927    tp_ice = (struct transport_ice*) pj_ice_strans_get_user_data(ice_st); 
     
    18451935    if (tp_ice->cb.on_ice_complete) 
    18461936        (*tp_ice->cb.on_ice_complete)(&tp_ice->base, op, result); 
     1937 
     1938    for (il=tp_ice->listener.next; il!=&tp_ice->listener; il=il->next) { 
     1939        if (il->cb.on_ice_complete2) { 
     1940            (*il->cb.on_ice_complete2)(&tp_ice->base, op, result, 
     1941                                       il->user_data); 
     1942        } else if (il->cb.on_ice_complete) { 
     1943            (*il->cb.on_ice_complete)(&tp_ice->base, op, result); 
     1944        } 
     1945    } 
    18471946} 
    18481947 
Note: See TracChangeset for help on using the changeset viewer.