Changeset 5597 for pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
- Timestamp:
- Jun 3, 2017 9:22:34 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r5534 r5597 47 47 }; 48 48 49 /* ICE listener */ 50 typedef 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 49 57 struct transport_ice 50 58 { … … 57 65 58 66 pjmedia_ice_cb cb; 67 ice_listener listener; 68 ice_listener listener_empty; 59 69 unsigned media_option; 60 70 … … 67 77 pj_sockaddr remote_rtcp; 68 78 unsigned addr_len; /**< Length of addresses. */ 79 unsigned rem_rtp_cnt; /**< How many pkt from this addr. */ 69 80 70 81 pj_bool_t use_ice; … … 244 255 tp_ice->oa_role = ROLE_NONE; 245 256 tp_ice->use_ice = PJ_FALSE; 257 pj_list_init(&tp_ice->listener); 258 pj_list_init(&tp_ice->listener_empty); 246 259 247 260 pj_memcpy(&ice_st_cfg, cfg, sizeof(pj_ice_strans_cfg)); … … 286 299 PJ_ASSERT_RETURN(tp, NULL); 287 300 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 */ 308 PJ_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 */ 346 PJ_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); 288 372 } 289 373 … … 1620 1704 pj_memcpy(&tp_ice->remote_rtcp, rem_rtcp, addr_len); 1621 1705 tp_ice->addr_len = addr_len; 1706 tp_ice->rem_rtp_cnt = 0; 1622 1707 1623 1708 /* Init source RTP & RTCP addresses and counter */ … … 1731 1816 /* Don't switch while we're receiving from remote_rtp */ 1732 1817 tp_ice->rtp_src_cnt = 0; 1818 tp_ice->rem_rtp_cnt++; 1733 1819 } else { 1734 1820 … … 1745 1831 1746 1832 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); 1748 1837 } else { 1749 1838 char addr_text[80]; … … 1834 1923 { 1835 1924 struct transport_ice *tp_ice; 1925 ice_listener *il; 1836 1926 1837 1927 tp_ice = (struct transport_ice*) pj_ice_strans_get_user_data(ice_st); … … 1845 1935 if (tp_ice->cb.on_ice_complete) 1846 1936 (*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 } 1847 1946 } 1848 1947
Note: See TracChangeset
for help on using the changeset viewer.