Changeset 1735 for pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
- Timestamp:
- Jan 23, 2008 8:39:07 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r1656 r1735 52 52 * These are media transport operations. 53 53 */ 54 static pj_status_t tp_get_info(pjmedia_transport *tp, 55 pjmedia_sock_info *info); 56 static pj_status_t tp_attach( pjmedia_transport *tp, 57 void *stream, 58 const pj_sockaddr_t *rem_addr, 59 const pj_sockaddr_t *rem_rtcp, 60 unsigned addr_len, 61 void (*rtp_cb)(void*, 62 const void*, 63 pj_ssize_t), 64 void (*rtcp_cb)(void*, 65 const void*, 66 pj_ssize_t)); 67 static void tp_detach( pjmedia_transport *tp, 68 void *strm); 69 static pj_status_t tp_send_rtp( pjmedia_transport *tp, 70 const void *pkt, 71 pj_size_t size); 72 static pj_status_t tp_send_rtcp( pjmedia_transport *tp, 73 const void *pkt, 74 pj_size_t size); 54 static pj_status_t transport_get_info (pjmedia_transport *tp, 55 pjmedia_sock_info *info); 56 static pj_status_t transport_attach (pjmedia_transport *tp, 57 void *user_data, 58 const pj_sockaddr_t *rem_addr, 59 const pj_sockaddr_t *rem_rtcp, 60 unsigned addr_len, 61 void (*rtp_cb)(void*, 62 const void*, 63 pj_ssize_t), 64 void (*rtcp_cb)(void*, 65 const void*, 66 pj_ssize_t)); 67 static void transport_detach (pjmedia_transport *tp, 68 void *strm); 69 static pj_status_t transport_send_rtp( pjmedia_transport *tp, 70 const void *pkt, 71 pj_size_t size); 72 static pj_status_t transport_send_rtcp(pjmedia_transport *tp, 73 const void *pkt, 74 pj_size_t size); 75 static pj_status_t transport_media_create(pjmedia_transport *tp, 76 pj_pool_t *pool, 77 pjmedia_sdp_session *sdp_local, 78 const pjmedia_sdp_session *sdp_remote, 79 unsigned media_index); 80 static pj_status_t transport_media_start (pjmedia_transport *tp, 81 pj_pool_t *pool, 82 pjmedia_sdp_session *sdp_local, 83 const pjmedia_sdp_session *sdp_remote, 84 unsigned media_index); 85 static pj_status_t transport_media_stop(pjmedia_transport *tp); 86 static pj_status_t transport_simulate_lost(pjmedia_transport *tp, 87 pjmedia_dir dir, 88 unsigned pct_lost); 89 static pj_status_t transport_destroy (pjmedia_transport *tp); 75 90 76 91 /* … … 85 100 86 101 87 static pjmedia_transport_op tp_ice_op = 88 { 89 &tp_get_info, 90 &tp_attach, 91 &tp_detach, 92 &tp_send_rtp, 93 &tp_send_rtcp, 94 &pjmedia_ice_destroy 102 static pjmedia_transport_op transport_ice_op = 103 { 104 &transport_get_info, 105 &transport_attach, 106 &transport_detach, 107 &transport_send_rtp, 108 &transport_send_rtcp, 109 &transport_media_create, 110 &transport_media_start, 111 &transport_media_stop, 112 &transport_simulate_lost, 113 &transport_destroy 95 114 }; 96 115 … … 133 152 tp_ice->ice_st = ice_st; 134 153 pj_ansi_strcpy(tp_ice->base.name, ice_st->obj_name); 135 tp_ice->base.op = &t p_ice_op;154 tp_ice->base.op = &transport_ice_op; 136 155 tp_ice->base.type = PJMEDIA_TRANSPORT_TYPE_ICE; 137 156 … … 144 163 if (p_tp) 145 164 *p_tp = &tp_ice->base; 146 147 return PJ_SUCCESS;148 }149 150 151 /*152 * Destroy ICE media transport.153 */154 PJ_DEF(pj_status_t) pjmedia_ice_destroy(pjmedia_transport *tp)155 {156 struct transport_ice *tp_ice = (struct transport_ice*)tp;157 158 if (tp_ice->ice_st) {159 pj_ice_strans_destroy(tp_ice->ice_st);160 /*Must not touch tp_ice after ice_st is destroyed!161 (it has the pool)162 tp_ice->ice_st = NULL;163 */164 }165 165 166 166 return PJ_SUCCESS; … … 231 231 comp, PJ_EINVAL); 232 232 233 pj_memcpy(comp, tp_ice->ice_st->comp[comp_id-1], sizeof(pj_ice_strans_comp)); 233 pj_memcpy(comp, tp_ice->ice_st->comp[comp_id-1], 234 sizeof(pj_ice_strans_comp)); 234 235 return PJ_SUCCESS; 235 236 } … … 247 248 { 248 249 struct transport_ice *tp_ice = (struct transport_ice*)tp; 249 return pj_ice_strans_init_ice(tp_ice->ice_st, role, local_ufrag, local_passwd); 250 return pj_ice_strans_init_ice(tp_ice->ice_st, role, local_ufrag, 251 local_passwd); 250 252 } 251 253 … … 255 257 * This will add ICE attributes to the SDP. 256 258 */ 257 PJ_DEF(pj_status_t) pjmedia_ice_modify_sdp(pjmedia_transport *tp, 258 pj_pool_t *pool, 259 pjmedia_sdp_session *sdp) 260 { 261 struct transport_ice *tp_ice = (struct transport_ice*)tp; 259 static pj_status_t transport_media_create(pjmedia_transport *tp, 260 pj_pool_t *pool, 261 pjmedia_sdp_session *sdp_local, 262 const pjmedia_sdp_session *sdp_remote, 263 unsigned media_index) 264 { 265 struct transport_ice *tp_ice = (struct transport_ice*)tp; 266 pj_ice_sess_role ice_role; 262 267 enum { MAXLEN = 256 }; 263 268 char *buffer; 264 269 pjmedia_sdp_attr *attr; 265 270 unsigned i, cand_cnt; 271 pj_status_t status; 272 273 /* Init ICE */ 274 ice_role = (sdp_remote==NULL ? PJ_ICE_SESS_ROLE_CONTROLLING : 275 PJ_ICE_SESS_ROLE_CONTROLLED); 276 277 status = pjmedia_ice_init_ice(tp, ice_role, NULL, NULL); 278 if (status != PJ_SUCCESS) 279 return status; 280 266 281 267 282 buffer = (char*) pj_pool_alloc(pool, MAXLEN); … … 270 285 attr = pjmedia_sdp_attr_create(pool, "ice-ufrag", 271 286 &tp_ice->ice_st->ice->rx_ufrag); 272 sdp ->attr[sdp->attr_count++] = attr;287 sdp_local->attr[sdp_local->attr_count++] = attr; 273 288 274 289 /* Create ice-pwd attribute */ 275 290 attr = pjmedia_sdp_attr_create(pool, "ice-pwd", 276 291 &tp_ice->ice_st->ice->rx_pass); 277 sdp ->attr[sdp->attr_count++] = attr;292 sdp_local->attr[sdp_local->attr_count++] = attr; 278 293 279 294 /* Add all candidates (to media level) */ … … 281 296 for (i=0; i<cand_cnt; ++i) { 282 297 pj_ice_sess_cand *cand; 298 pjmedia_sdp_media *m; 283 299 pj_str_t value; 284 300 int len; … … 330 346 value = pj_str(buffer); 331 347 attr = pjmedia_sdp_attr_create(pool, "candidate", &value); 332 sdp->media[0]->attr[sdp->media[0]->attr_count++] = attr; 348 m = sdp_local->media[media_index]; 349 m->attr[m->attr_count++] = attr; 333 350 } 334 351 … … 457 474 PJ_LOG(4,(tp_ice->ice_st->obj_name, 458 475 "Disabling local ICE, reason=%s", reason)); 459 pjmedia_ice_stop_ice(&tp_ice->base);476 transport_media_stop(&tp_ice->base); 460 477 } 461 478 … … 464 481 * Start ICE checks when both offer and answer are available. 465 482 */ 466 PJ_DEF(pj_status_t) pjmedia_ice_start_ice(pjmedia_transport *tp, 467 pj_pool_t *pool, 468 const pjmedia_sdp_session *rem_sdp, 469 unsigned media_index) 483 static pj_status_t transport_media_start(pjmedia_transport *tp, 484 pj_pool_t *pool, 485 pjmedia_sdp_session *sdp_local, 486 const pjmedia_sdp_session *sdp_remote, 487 unsigned media_index) 470 488 { 471 489 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 482 500 pj_status_t status; 483 501 484 PJ_ASSERT_RETURN(tp && pool && rem_sdp, PJ_EINVAL); 485 PJ_ASSERT_RETURN(media_index < rem_sdp->media_count, PJ_EINVAL); 486 487 sdp_med = rem_sdp->media[media_index]; 502 PJ_UNUSED_ARG(sdp_local); 503 504 PJ_ASSERT_RETURN(tp && pool && sdp_remote, PJ_EINVAL); 505 PJ_ASSERT_RETURN(media_index < sdp_remote->media_count, PJ_EINVAL); 506 507 sdp_med = sdp_remote->media[media_index]; 488 508 489 509 /* Get the SDP connection for the media stream. … … 493 513 conn = sdp_med->conn; 494 514 if (conn == NULL) 495 conn = rem_sdp->conn;515 conn = sdp_remote->conn; 496 516 497 517 if (conn == NULL) { … … 508 528 if (attr == NULL) { 509 529 /* Find ice-ufrag attribute in session descriptor */ 510 attr = pjmedia_sdp_attr_find2( rem_sdp->attr_count, rem_sdp->attr,530 attr = pjmedia_sdp_attr_find2(sdp_remote->attr_count, sdp_remote->attr, 511 531 "ice-ufrag", NULL); 512 532 if (attr == NULL) { … … 522 542 if (attr == NULL) { 523 543 /* Find ice-pwd attribute in session descriptor */ 524 attr = pjmedia_sdp_attr_find2( rem_sdp->attr_count, rem_sdp->attr,544 attr = pjmedia_sdp_attr_find2(sdp_remote->attr_count, sdp_remote->attr, 525 545 "ice-pwd", NULL); 526 546 if (attr == NULL) { … … 609 629 610 630 611 PJ_DEF(pj_status_t) pjmedia_ice_stop_ice(pjmedia_transport *tp)631 static pj_status_t transport_media_stop(pjmedia_transport *tp) 612 632 { 613 633 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 616 636 617 637 618 static pj_status_t t p_get_info(pjmedia_transport *tp,619 638 static pj_status_t transport_get_info(pjmedia_transport *tp, 639 pjmedia_sock_info *info) 620 640 { 621 641 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 649 669 650 670 651 static pj_status_t t p_attach(pjmedia_transport *tp,652 void *stream,653 const pj_sockaddr_t *rem_addr,654 const pj_sockaddr_t *rem_rtcp,655 unsigned addr_len,656 void (*rtp_cb)(void*,657 const void*,658 pj_ssize_t),659 void (*rtcp_cb)(void*,660 const void*,661 pj_ssize_t))671 static pj_status_t transport_attach (pjmedia_transport *tp, 672 void *stream, 673 const pj_sockaddr_t *rem_addr, 674 const pj_sockaddr_t *rem_rtcp, 675 unsigned addr_len, 676 void (*rtp_cb)(void*, 677 const void*, 678 pj_ssize_t), 679 void (*rtcp_cb)(void*, 680 const void*, 681 pj_ssize_t)) 662 682 { 663 683 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 674 694 675 695 676 static void t p_detach(pjmedia_transport *tp,677 696 static void transport_detach(pjmedia_transport *tp, 697 void *strm) 678 698 { 679 699 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 687 707 688 708 689 static pj_status_t t p_send_rtp(pjmedia_transport *tp,690 691 709 static pj_status_t transport_send_rtp(pjmedia_transport *tp, 710 const void *pkt, 711 pj_size_t size) 692 712 { 693 713 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 709 729 710 730 711 static pj_status_t t p_send_rtcp(pjmedia_transport *tp,712 713 731 static pj_status_t transport_send_rtcp(pjmedia_transport *tp, 732 const void *pkt, 733 pj_size_t size) 714 734 { 715 735 struct transport_ice *tp_ice = (struct transport_ice*)tp; … … 799 819 800 820 /* Simulate lost */ 801 PJ_DEF(pj_status_t) pjmedia_ice_simulate_lost(pjmedia_transport *tp,802 803 821 static pj_status_t transport_simulate_lost(pjmedia_transport *tp, 822 pjmedia_dir dir, 823 unsigned pct_lost) 804 824 { 805 825 struct transport_ice *ice = (struct transport_ice*) tp; … … 816 836 } 817 837 838 839 /* 840 * Destroy ICE media transport. 841 */ 842 static pj_status_t transport_destroy(pjmedia_transport *tp) 843 { 844 struct transport_ice *tp_ice = (struct transport_ice*)tp; 845 846 if (tp_ice->ice_st) { 847 pj_ice_strans_destroy(tp_ice->ice_st); 848 /*Must not touch tp_ice after ice_st is destroyed! 849 (it has the pool) 850 tp_ice->ice_st = NULL; 851 */ 852 } 853 854 return PJ_SUCCESS; 855 } 856
Note: See TracChangeset
for help on using the changeset viewer.