Ticket #479: ticket479.patch
File ticket479.patch, 16.9 KB (added by nanang, 17 years ago) |
---|
-
pjmedia/include/pjmedia/transport.h
207 207 208 208 #include <pjmedia/sdp.h> 209 209 210 210 211 /** 212 * Transport info contains general socket info and list of transport specific 213 * info, since transports can be stacked (e.g: SRTP stacked on top of UDP). 214 * This constant specifies max number of transport specific info can be 215 * hold in a single instance of transport info. 216 */ 217 #define PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXCNT 4 218 219 /** 220 * Max size in bytes of storage buffer of a transport specific info. 221 */ 222 #define PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE 128 223 224 225 /** 211 226 * Forward declaration for media transport. 212 227 */ 213 228 typedef struct pjmedia_transport pjmedia_transport; 214 229 215 230 /** 231 * Forward declaration for media transport info. 232 */ 233 typedef struct pjmedia_transport_info pjmedia_transport_info; 234 235 /** 216 236 * This enumeration specifies the general behaviour of media processing 217 237 */ 218 238 typedef enum pjmedia_tranport_media_option … … 228 248 229 249 } pjmedia_tranport_media_option; 230 250 251 231 252 /** 232 253 * This structure describes the operations for the stream transport. 233 254 */ … … 239 260 * Application should call #pjmedia_transport_get_info() instead 240 261 */ 241 262 pj_status_t (*get_info)(pjmedia_transport *tp, 242 pjmedia_ sock_info *info);263 pjmedia_transport_info *info); 243 264 244 265 /** 245 266 * This function is called by the stream when the transport is about … … 368 389 PJMEDIA_TRANSPORT_TYPE_UDP, 369 390 370 391 /** Media transport using ICE */ 371 PJMEDIA_TRANSPORT_TYPE_ICE 392 PJMEDIA_TRANSPORT_TYPE_ICE, 372 393 394 /** 395 * Media transport SRTP, this transport is actually security adapter to be 396 * stacked with other transport to enable encryption on the underlying 397 * transport. 398 */ 399 PJMEDIA_TRANSPORT_TYPE_SRTP 400 373 401 } pjmedia_transport_type; 374 402 375 403 … … 390 418 pjmedia_transport_op *op; 391 419 }; 392 420 421 /** 422 * This structure describes buffer storage of transport specific info. 423 * The actual transport specific info contents will be defined by transport 424 * implementation. Note that some transport implementations do not need to 425 * provide specific info, since the general socket info is enough. 426 */ 427 typedef struct pjmedia_transport_specific_info 428 { 429 /** 430 * Specify media transport type. 431 */ 432 pjmedia_transport_type type; 393 433 434 /** 435 * Specify storage buffer size of transport specific info. 436 */ 437 int cbsize; 438 439 /** 440 * Storage buffer of transport specific info. 441 */ 442 char buffer[PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE]; 443 444 } pjmedia_transport_specific_info; 445 446 394 447 /** 448 * This structure describes transport informations, including general 449 * socket information and specific information of single transport or 450 * stacked transports (e.g: SRTP stacked on top of UDP) 451 */ 452 struct pjmedia_transport_info 453 { 454 /** 455 * General socket info. 456 */ 457 pjmedia_sock_info sock_info; 458 459 /** 460 * Specifies number of transport specific info included. 461 */ 462 int specific_info_cnt; 463 464 /** 465 * Buffer storage of transport specific info. 466 */ 467 pjmedia_transport_specific_info spc_info[PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXCNT]; 468 469 }; 470 471 472 /** 395 473 * Get media socket info from the specified transport. The socket info 396 474 * contains information about the local address of this transport, and 397 475 * would be needed for example to fill in the "c=" and "m=" line of local … … 403 481 * @return PJ_SUCCESS on success. 404 482 */ 405 483 PJ_INLINE(pj_status_t) pjmedia_transport_get_info(pjmedia_transport *tp, 406 pjmedia_ sock_info *info)484 pjmedia_transport_info *info) 407 485 { 408 486 if (tp->op->get_info) 409 487 return (*tp->op->get_info)(tp, info); -
pjmedia/include/pjmedia/transport_srtp.h
160 160 161 161 162 162 /** 163 * This structure specifies SRTP transport specific info. 164 */ 165 typedef struct pjmedia_srtp_info 166 { 167 /** 168 * Specify whether the SRTP transport is active for SRTP session. 169 */ 170 pj_bool_t active; 171 172 /** 173 * Specify the policy used by the SRTP session for receive direction. 174 */ 175 pjmedia_srtp_crypto rx_policy; 176 177 /** 178 * Specify the policy used by the SRTP session for transmit direction. 179 */ 180 pjmedia_srtp_crypto tx_policy; 181 182 } pjmedia_srtp_info; 183 184 185 /** 163 186 * Initialize SRTP setting with its default values. 164 187 * 165 188 * @param opt SRTP setting to be initialized. -
pjmedia/src/pjmedia/transport_srtp.c
125 125 * These are media transport operations. 126 126 */ 127 127 static pj_status_t transport_get_info (pjmedia_transport *tp, 128 pjmedia_ sock_info *info);128 pjmedia_transport_info *info); 129 129 static pj_status_t transport_attach (pjmedia_transport *tp, 130 130 void *user_data, 131 131 const pj_sockaddr_t *rem_addr, … … 551 551 552 552 553 553 static pj_status_t transport_get_info(pjmedia_transport *tp, 554 pjmedia_ sock_info *info)554 pjmedia_transport_info *info) 555 555 { 556 556 transport_srtp *srtp = (transport_srtp*) tp; 557 pjmedia_srtp_info srtp_info; 558 int spc_info_idx; 559 pj_status_t status; 557 560 558 /* put SRTP info as well? */ 559 return pjmedia_transport_get_info(srtp->real_tp, info); 561 PJ_ASSERT_RETURN(tp && info, PJ_EINVAL); 562 PJ_ASSERT_RETURN(info->specific_info_cnt < 563 PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXCNT, PJ_ETOOMANY); 564 PJ_ASSERT_RETURN(sizeof(pjmedia_srtp_info) <= 565 PJMEDIA_TRANSPORT_SPECIFIC_INFO_MAXSIZE, PJ_ENOMEM); 566 567 status = pjmedia_transport_get_info(srtp->real_tp, info); 568 if (status != PJ_SUCCESS) 569 return status; 570 571 srtp_info.active = srtp->session_inited; 572 srtp_info.rx_policy = srtp->rx_policy; 573 srtp_info.tx_policy = srtp->tx_policy; 574 575 spc_info_idx = info->specific_info_cnt++; 576 info->spc_info[spc_info_idx].type = PJMEDIA_TRANSPORT_TYPE_SRTP; 577 info->spc_info[spc_info_idx].cbsize = sizeof(srtp_info); 578 pj_memcpy(&info->spc_info[spc_info_idx].buffer, &srtp_info, 579 sizeof(srtp_info)); 580 581 return PJ_SUCCESS; 560 582 } 561 583 562 584 static pj_status_t transport_attach(pjmedia_transport *tp, -
pjmedia/src/pjmedia/transport_udp.c
101 101 * These are media transport operations. 102 102 */ 103 103 static pj_status_t transport_get_info (pjmedia_transport *tp, 104 pjmedia_ sock_info *info);104 pjmedia_transport_info *info); 105 105 static pj_status_t transport_attach (pjmedia_transport *tp, 106 106 void *user_data, 107 107 const pj_sockaddr_t *rem_addr, … … 584 584 585 585 /* Called to get the transport info */ 586 586 static pj_status_t transport_get_info(pjmedia_transport *tp, 587 pjmedia_ sock_info *info)587 pjmedia_transport_info *info) 588 588 { 589 589 struct transport_udp *udp = (struct transport_udp*)tp; 590 590 PJ_ASSERT_RETURN(tp && info, PJ_EINVAL); 591 591 592 info->rtp_sock = udp->rtp_sock; 593 info->rtp_addr_name = udp->rtp_addr_name; 594 info->rtcp_sock = udp->rtcp_sock; 595 info->rtcp_addr_name = udp->rtcp_addr_name; 592 info->sock_info.rtp_sock = udp->rtp_sock; 593 info->sock_info.rtp_addr_name = udp->rtp_addr_name; 594 info->sock_info.rtcp_sock = udp->rtcp_sock; 595 info->sock_info.rtcp_addr_name = udp->rtcp_addr_name; 596 info->specific_info_cnt = 0; 596 597 597 598 return PJ_SUCCESS; 598 599 } -
pjmedia/src/pjmedia/transport_ice.c
55 55 * These are media transport operations. 56 56 */ 57 57 static pj_status_t transport_get_info (pjmedia_transport *tp, 58 pjmedia_ sock_info *info);58 pjmedia_transport_info *info); 59 59 static pj_status_t transport_attach (pjmedia_transport *tp, 60 60 void *user_data, 61 61 const pj_sockaddr_t *rem_addr, … … 673 673 674 674 675 675 static pj_status_t transport_get_info(pjmedia_transport *tp, 676 pjmedia_ sock_info *info)676 pjmedia_transport_info *info) 677 677 { 678 678 struct transport_ice *tp_ice = (struct transport_ice*)tp; 679 679 pj_ice_strans *ice_st = tp_ice->ice_st; 680 680 pj_ice_strans_comp *comp; 681 681 682 pj_bzero( info, sizeof(*info));683 info-> rtp_sock = info->rtcp_sock = PJ_INVALID_SOCKET;682 pj_bzero(&info->sock_info, sizeof(info->sock_info)); 683 info->sock_info.rtp_sock = info->sock_info.rtcp_sock = PJ_INVALID_SOCKET; 684 684 685 685 /* Retrieve address of default candidate for component 1 (RTP) */ 686 686 comp = ice_st->comp[0]; 687 687 pj_assert(comp->default_cand >= 0); 688 info-> rtp_sock = comp->sock;689 pj_memcpy(&info-> rtp_addr_name,688 info->sock_info.rtp_sock = comp->sock; 689 pj_memcpy(&info->sock_info.rtp_addr_name, 690 690 &comp->cand_list[comp->default_cand].addr, 691 691 sizeof(pj_sockaddr_in)); 692 692 … … 694 694 if (ice_st->comp_cnt > 1) { 695 695 comp = ice_st->comp[1]; 696 696 pj_assert(comp->default_cand >= 0); 697 info-> rtp_sock = comp->sock;698 pj_memcpy(&info-> rtcp_addr_name,697 info->sock_info.rtp_sock = comp->sock; 698 pj_memcpy(&info->sock_info.rtcp_addr_name, 699 699 &comp->cand_list[comp->default_cand].addr, 700 700 sizeof(pj_sockaddr_in)); 701 701 } 702 702 703 info->specific_info_cnt = 0; 703 704 704 705 return PJ_SUCCESS; 705 706 } -
pjsip/src/pjsua-lib/pjsua_media.c
814 814 { 815 815 enum { MAX_MEDIA = 1, MEDIA_IDX = 0 }; 816 816 pjmedia_sdp_session *sdp; 817 pjmedia_ sock_info skinfo;817 pjmedia_transport_info tpinfo; 818 818 pjsua_call *call = &pjsua_var.calls[call_id]; 819 819 pj_status_t status; 820 820 … … 826 826 } 827 827 828 828 /* Get media socket info */ 829 pjmedia_transport_get_info(call->med_tp, & skinfo);829 pjmedia_transport_get_info(call->med_tp, &tpinfo); 830 830 831 831 /* Create SDP */ 832 832 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pool, MAX_MEDIA, 833 & skinfo, &sdp);833 &tpinfo.sock_info, &sdp); 834 834 if (status != PJ_SUCCESS) { 835 835 if (sip_status_code) *sip_status_code = 500; 836 836 goto on_error; -
pjsip/src/pjsua-lib/pjsua_core.c
260 260 { 261 261 pjsip_tx_data *tdata; 262 262 pjsip_response_addr res_addr; 263 pjmedia_ sock_info skinfo;263 pjmedia_transport_info tpinfo; 264 264 pjmedia_sdp_session *sdp; 265 265 const pjsip_hdr *cap_hdr; 266 266 pj_status_t status; … … 320 320 } 321 321 322 322 /* Get media socket info */ 323 pjmedia_transport_get_info(pjsua_var.calls[0].med_tp, & skinfo);323 pjmedia_transport_get_info(pjsua_var.calls[0].med_tp, &tpinfo); 324 324 325 325 /* Add SDP body, using call0's RTP address */ 326 326 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, tdata->pool, 1, 327 & skinfo, &sdp);327 &tpinfo.sock_info, &sdp); 328 328 if (status == PJ_SUCCESS) { 329 329 pjsip_create_sdp_body(tdata->pool, sdp, &tdata->msg->body); 330 330 } … … 2060 2060 PJ_LOG(3,(THIS_FILE, "Dumping media transports:")); 2061 2061 for (i=0; i<pjsua_var.ua_cfg.max_calls; ++i) { 2062 2062 pjsua_call *call = &pjsua_var.calls[i]; 2063 pjmedia_ sock_info skinfo;2063 pjmedia_transport_info tpinfo; 2064 2064 char addr_buf[80]; 2065 2065 2066 /* MSVC complains about skinfo not being initialized */2067 pj_bzero(& skinfo, sizeof(skinfo));2066 /* MSVC complains about tpinfo not being initialized */ 2067 pj_bzero(&tpinfo, sizeof(tpinfo)); 2068 2068 2069 pjmedia_transport_get_info(call->med_tp, & skinfo);2069 pjmedia_transport_get_info(call->med_tp, &tpinfo); 2070 2070 2071 2071 PJ_LOG(3,(THIS_FILE, " %s: %s", 2072 2072 (pjsua_var.media_cfg.enable_ice ? "ICE" : "UDP"), 2073 pj_sockaddr_print(& skinfo.rtp_addr_name, addr_buf,2073 pj_sockaddr_print(&tpinfo.sock_info.rtp_addr_name, addr_buf, 2074 2074 sizeof(addr_buf), 3))); 2075 2075 } 2076 2076 -
pjsip/src/pjsua-lib/pjsua_call.c
2200 2200 char *p, *end; 2201 2201 pj_status_t status; 2202 2202 int len; 2203 pjmedia_transport_info tp_info; 2203 2204 2204 2205 PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 2205 2206 PJ_EINVAL); … … 2258 2259 *p = '\0'; 2259 2260 } 2260 2261 2262 /* Get SRTP status */ 2263 pjmedia_transport_get_info(call->med_tp, &tp_info); 2264 if (tp_info.specific_info_cnt > 0) { 2265 int i; 2266 for (i = 0; i < tp_info.specific_info_cnt; ++i) { 2267 if (tp_info.spc_info[i].type == PJMEDIA_TRANSPORT_TYPE_SRTP) 2268 { 2269 pjmedia_srtp_info *srtp_info = 2270 (pjmedia_srtp_info*) tp_info.spc_info[i].buffer; 2271 2272 len = pj_ansi_snprintf(p, end-p, 2273 "%s SRTP status: %s Crypto-suite: %s", 2274 indent, 2275 (srtp_info->active?"Active":"Not active"), 2276 srtp_info->tx_policy.name.ptr); 2277 if (len > 0 && len < end-p) { 2278 p += len; 2279 *p++ = '\n'; 2280 *p = '\0'; 2281 } 2282 break; 2283 } 2284 } 2285 } 2286 2261 2287 /* Dump session statistics */ 2262 2288 if (with_media && call->session) 2263 2289 dump_media_session(indent, p, end-p, call->session); … … 2442 2468 code==PJSIP_SC_NOT_ACCEPTABLE_HERE) 2443 2469 { 2444 2470 pjmedia_sdp_session *local_sdp; 2445 pjmedia_ sock_info si;2471 pjmedia_transport_info ti; 2446 2472 2447 call->med_tp->op->get_info(call->med_tp, &si);2473 pjmedia_transport_get_info(call->med_tp, &ti); 2448 2474 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, tdata->pool, 2449 1, & si, &local_sdp);2475 1, &ti.sock_info, &local_sdp); 2450 2476 if (status == PJ_SUCCESS) { 2451 2477 pjsip_create_sdp_body(tdata->pool, local_sdp, 2452 2478 &tdata->msg->body); … … 2551 2577 pj_status_t status; 2552 2578 pjmedia_sdp_conn *conn; 2553 2579 pjmedia_sdp_attr *attr; 2554 pjmedia_ sock_info skinfo;2580 pjmedia_transport_info tp_info; 2555 2581 pjmedia_sdp_session *sdp; 2556 2582 2557 2583 /* Get media socket info */ 2558 pjmedia_transport_get_info(call->med_tp, & skinfo);2584 pjmedia_transport_get_info(call->med_tp, &tp_info); 2559 2585 2560 2586 /* Create new offer */ 2561 2587 status = pjmedia_endpt_create_sdp(pjsua_var.med_endpt, pjsua_var.pool, 1, 2562 & skinfo, &sdp);2588 &tp_info.sock_info, &sdp); 2563 2589 if (status != PJ_SUCCESS) { 2564 2590 pjsua_perror(THIS_FILE, "Unable to create local SDP", status); 2565 2591 return status; -
pjsip-apps/src/samples/simpleua.c
81 81 static pj_caching_pool cp; /* Global pool factory. */ 82 82 83 83 static pjmedia_endpt *g_med_endpt; /* Media endpoint. */ 84 static pjmedia_ sock_info g_med_skinfo;/* Socket info for media */84 static pjmedia_transport_info g_med_tpinfo; /* Socket info for media */ 85 85 static pjmedia_transport *g_med_transport;/* Media stream transport */ 86 86 87 87 /* Call variables: */ … … 301 301 * need this info to create SDP (i.e. the address and port info in 302 302 * the SDP). 303 303 */ 304 pjmedia_transport_get_info(g_med_transport, &g_med_ skinfo);304 pjmedia_transport_get_info(g_med_transport, &g_med_tpinfo); 305 305 306 306 307 307 /* … … 364 364 status = pjmedia_endpt_create_sdp( g_med_endpt, /* the media endpt */ 365 365 dlg->pool, /* pool. */ 366 366 1, /* # of streams */ 367 &g_med_skinfo, /* RTP sock info */ 367 &g_med_tpinfo.sock_info, 368 /* RTP sock info */ 368 369 &local_sdp); /* the SDP result */ 369 370 PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); 370 371 … … 571 572 */ 572 573 573 574 status = pjmedia_endpt_create_sdp( g_med_endpt, rdata->tp_info.pool, 1, 574 &g_med_ skinfo,575 &g_med_tpinfo.sock_info, 575 576 &local_sdp); 576 577 PJ_ASSERT_RETURN(status == PJ_SUCCESS, PJ_TRUE); 577 578 -
pjsip-apps/src/samples/siprtp.c
1005 1005 pjmedia_sdp_session *sdp; 1006 1006 pjmedia_sdp_media *m; 1007 1007 pjmedia_sdp_attr *attr; 1008 pjmedia_ sock_info tpinfo;1008 pjmedia_transport_info tpinfo; 1009 1009 struct media_stream *audio = &call->media[0]; 1010 1010 1011 1011 PJ_ASSERT_RETURN(pool && p_sdp, PJ_EINVAL); … … 1047 1047 1048 1048 /* Standard media info: */ 1049 1049 m->desc.media = pj_str("audio"); 1050 m->desc.port = pj_ntohs(tpinfo. rtp_addr_name.ipv4.sin_port);1050 m->desc.port = pj_ntohs(tpinfo.sock_info.rtp_addr_name.ipv4.sin_port); 1051 1051 m->desc.port_count = 1; 1052 1052 m->desc.transport = pj_str("RTP/AVP"); 1053 1053