- Timestamp:
- Dec 28, 2016 3:40:07 AM (8 years ago)
- Location:
- pjproject/branches/projects/uwp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/uwp
- Property svn:mergeinfo changed
/pjproject/trunk (added) merged: 5209,5212-5234,5237-5253,5255,5257-5292,5294-5297,5299-5332,5334-5394,5396-5438,5440-5469,5471-5496,5498-5510
- Property svn:mergeinfo changed
-
pjproject/branches/projects/uwp/pjsip/src/pjsua-lib/pjsua_media.c
r5205 r5513 254 254 255 255 /* Make sure STUN server resolution has completed */ 256 if (!use_ipv6 && pjsua_sip_acc_is_using_stun(call_med->call->acc_id)) { 257 status = resolve_stun_server(PJ_TRUE); 256 if (!use_ipv6 && pjsua_media_acc_is_using_stun(call_med->call->acc_id)) { 257 pj_bool_t retry_stun = (acc->cfg.media_stun_use & 258 PJSUA_STUN_RETRY_ON_FAILURE) == 259 PJSUA_STUN_RETRY_ON_FAILURE; 260 status = resolve_stun_server(PJ_TRUE, retry_stun); 258 261 if (status != PJ_SUCCESS) { 259 262 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); … … 351 354 * and make sure that the mapped RTCP port is adjacent with the RTP. 352 355 */ 353 if (!use_ipv6 && pjsua_sip_acc_is_using_stun(call_med->call->acc_id) && 356 if (!use_ipv6 && 357 pjsua_media_acc_is_using_stun(call_med->call->acc_id) && 354 358 pjsua_var.stun_srv.addr.sa_family != 0) 355 359 { … … 359 363 pjstun_setting stun_opt; 360 364 361 pj_ansi_strcpy(ip_addr, 362 pj_inet_ntoa(pjsua_var.stun_srv.ipv4.sin_addr)); 365 pj_sockaddr_print(&pjsua_var.stun_srv, ip_addr,sizeof(ip_addr),0); 363 366 stun_srv = pj_str(ip_addr); 364 367 … … 389 392 else 390 393 #endif 394 395 if (status != PJ_SUCCESS && pjsua_var.ua_cfg.stun_srv_cnt > 1 && 396 ((acc->cfg.media_stun_use & PJSUA_STUN_RETRY_ON_FAILURE)== 397 PJSUA_STUN_RETRY_ON_FAILURE)) 398 { 399 pj_str_t srv = 400 pjsua_var.ua_cfg.stun_srv[pjsua_var.stun_srv_idx]; 401 402 PJ_LOG(4,(THIS_FILE, "Failed to get STUN mapped address, " 403 "retrying other STUN servers")); 404 405 if (pjsua_var.stun_srv_idx < pjsua_var.ua_cfg.stun_srv_cnt-1) { 406 PJSUA_LOCK(); 407 /* Move the unusable STUN server to the last position 408 * as the least prioritize. 409 */ 410 pj_array_erase(pjsua_var.ua_cfg.stun_srv, 411 sizeof(pj_str_t), 412 pjsua_var.ua_cfg.stun_srv_cnt, 413 pjsua_var.stun_srv_idx); 414 415 pj_array_insert(pjsua_var.ua_cfg.stun_srv, 416 sizeof(pj_str_t), 417 pjsua_var.ua_cfg.stun_srv_cnt-1, 418 pjsua_var.ua_cfg.stun_srv_cnt-1, 419 &srv); 420 421 PJSUA_UNLOCK(); 422 } 423 status=pjsua_update_stun_servers(pjsua_var.ua_cfg.stun_srv_cnt, 424 pjsua_var.ua_cfg.stun_srv, 425 PJ_TRUE); 426 if (status == PJ_SUCCESS) { 427 if (pjsua_var.stun_srv.addr.sa_family != 0) { 428 pj_sockaddr_print(&pjsua_var.stun_srv, 429 ip_addr, sizeof(ip_addr), 0); 430 stun_srv = pj_str(ip_addr); 431 } else { 432 stun_srv.slen = 0; 433 } 434 435 stun_opt.srv1 = stun_opt.srv2 = stun_srv; 436 stun_opt.port1 = stun_opt.port2 = 437 pj_ntohs(pjsua_var.stun_srv.ipv4.sin_port); 438 status = pjstun_get_mapped_addr2(&pjsua_var.cp.factory, 439 &stun_opt, 2, sock, 440 resolved_addr); 441 } 442 } 443 391 444 if (status != PJ_SUCCESS) { 392 pjsua_perror(THIS_FILE, "STUN resolve error", status); 393 goto on_error; 445 if (!pjsua_var.ua_cfg.stun_ignore_failure) { 446 pjsua_perror(THIS_FILE, "STUN resolve error", status); 447 goto on_error; 448 } 449 450 PJ_LOG(4,(THIS_FILE, "Ignoring STUN resolve error %d", 451 status)); 452 453 if (!pj_sockaddr_has_addr(&bound_addr)) { 454 pj_sockaddr addr; 455 456 /* Get local IP address. */ 457 status = pj_gethostip(af, &addr); 458 if (status != PJ_SUCCESS) 459 goto on_error; 460 461 pj_sockaddr_copy_addr(&bound_addr, &addr); 462 } 463 464 for (i=0; i<2; ++i) { 465 pj_sockaddr_init(af, &mapped_addr[i], NULL, 0); 466 pj_sockaddr_copy_addr(&mapped_addr[i], &bound_addr); 467 pj_sockaddr_set_port(&mapped_addr[i], 468 (pj_uint16_t)(acc->next_rtp_port+i)); 469 } 470 break; 394 471 } 395 472 … … 679 756 break; 680 757 case PJ_ICE_STRANS_OP_KEEP_ALIVE: 758 case PJ_ICE_STRANS_OP_ADDR_CHANGE: 681 759 if (result != PJ_SUCCESS) { 682 760 PJ_PERROR(4,(THIS_FILE, result, … … 695 773 call->index, &info); 696 774 } 697 if (pjsua_var.ua_cfg.cb.on_ice_transport_error) { 775 if (pjsua_var.ua_cfg.cb.on_ice_transport_error && 776 op == PJ_ICE_STRANS_OP_KEEP_ALIVE) 777 { 698 778 pjsua_call_id id = call->index; 699 779 (*pjsua_var.ua_cfg.cb.on_ice_transport_error)(id, op, result, … … 744 824 unsigned comp_cnt; 745 825 pj_status_t status; 826 pj_bool_t use_ipv6; 746 827 747 828 acc_cfg = &pjsua_var.acc[call_med->call->acc_id].cfg; 829 use_ipv6 = (acc_cfg->ipv6_media_use != PJSUA_IPV6_DISABLED); 748 830 749 831 /* Make sure STUN server resolution has completed */ 750 status = resolve_stun_server(PJ_TRUE); 751 if (status != PJ_SUCCESS) { 752 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 753 return status; 832 if (pjsua_media_acc_is_using_stun(call_med->call->acc_id)) { 833 pj_bool_t retry_stun = (acc_cfg->media_stun_use & 834 PJSUA_STUN_RETRY_ON_FAILURE) == 835 PJSUA_STUN_RETRY_ON_FAILURE; 836 status = resolve_stun_server(PJ_TRUE, retry_stun); 837 if (status != PJ_SUCCESS) { 838 pjsua_perror(THIS_FILE, "Error resolving STUN server", status); 839 return status; 840 } 754 841 } 755 842 756 843 /* Create ICE stream transport configuration */ 757 844 pj_ice_strans_cfg_default(&ice_cfg); 845 pj_bzero(&ice_cfg.stun, sizeof(ice_cfg.stun)); 846 pj_bzero(&ice_cfg.turn, sizeof(ice_cfg.turn)); 758 847 pj_stun_config_init(&ice_cfg.stun_cfg, &pjsua_var.cp.factory, 0, 759 848 pjsip_endpt_get_ioqueue(pjsua_var.endpt), 760 849 pjsip_endpt_get_timer_heap(pjsua_var.endpt)); 761 850 762 ice_cfg.af = pj_AF_INET();763 851 ice_cfg.resolver = pjsua_var.resolver; 764 852 765 853 ice_cfg.opt = acc_cfg->ice_cfg.ice_opt; 766 854 767 /* Configure STUN settings */ 768 if (pj_sockaddr_has_addr(&pjsua_var.stun_srv)) { 769 pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0); 770 ice_cfg.stun.server = pj_str(stunip); 771 ice_cfg.stun.port = pj_sockaddr_get_port(&pjsua_var.stun_srv); 772 } 773 if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) 774 ice_cfg.stun.max_host_cands = acc_cfg->ice_cfg.ice_max_host_cands; 775 776 /* Copy binding port setting to STUN setting */ 777 pj_sockaddr_init(ice_cfg.af, &ice_cfg.stun.cfg.bound_addr, 778 &cfg->bound_addr, (pj_uint16_t)cfg->port); 779 ice_cfg.stun.cfg.port_range = (pj_uint16_t)cfg->port_range; 780 if (cfg->port != 0 && ice_cfg.stun.cfg.port_range == 0) 781 ice_cfg.stun.cfg.port_range = 782 (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); 783 784 /* Copy QoS setting to STUN setting */ 785 ice_cfg.stun.cfg.qos_type = cfg->qos_type; 786 pj_memcpy(&ice_cfg.stun.cfg.qos_params, &cfg->qos_params, 787 sizeof(cfg->qos_params)); 855 /* If STUN transport is configured, initialize STUN transport settings */ 856 if ((pj_sockaddr_has_addr(&pjsua_var.stun_srv) && 857 pjsua_media_acc_is_using_stun(call_med->call->acc_id)) || 858 acc_cfg->ice_cfg.ice_max_host_cands != 0) 859 { 860 ice_cfg.stun_tp_cnt = 1; 861 pj_ice_strans_stun_cfg_default(&ice_cfg.stun_tp[0]); 862 if (use_ipv6 && PJ_ICE_MAX_STUN >= 2) { 863 ice_cfg.stun_tp_cnt = 2; 864 pj_ice_strans_stun_cfg_default(&ice_cfg.stun_tp[1]); 865 ice_cfg.stun_tp[1].af = pj_AF_INET6(); 866 } 867 } 868 869 /* Configure STUN transport settings */ 870 if (ice_cfg.stun_tp_cnt) { 871 unsigned i; 872 873 /* Configure STUN server (currently only for IPv4) */ 874 if (pj_sockaddr_has_addr(&pjsua_var.stun_srv) && 875 pjsua_media_acc_is_using_stun(call_med->call->acc_id)) 876 { 877 pj_sockaddr_print(&pjsua_var.stun_srv, stunip, sizeof(stunip), 0); 878 ice_cfg.stun_tp[0].server = pj_str(stunip); 879 ice_cfg.stun_tp[0].port = 880 pj_sockaddr_get_port(&pjsua_var.stun_srv); 881 } 882 883 /* Configure max host candidates */ 884 if (acc_cfg->ice_cfg.ice_max_host_cands >= 0) { 885 for (i = 0; i < ice_cfg.stun_tp_cnt; ++i) 886 ice_cfg.stun_tp[i].max_host_cands = 887 acc_cfg->ice_cfg.ice_max_host_cands; 888 } 889 890 /* Configure binding address */ 891 pj_sockaddr_init(ice_cfg.stun_tp[0].af, 892 &ice_cfg.stun_tp[0].cfg.bound_addr, 893 &cfg->bound_addr, (pj_uint16_t)cfg->port); 894 ice_cfg.stun_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range; 895 if (cfg->port != 0 && ice_cfg.stun_tp[0].cfg.port_range == 0) { 896 ice_cfg.stun_tp[0].cfg.port_range = 897 (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); 898 } 899 if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) { 900 pj_str_t IN6_ADDR_ANY = {"0", 1}; 901 pj_sockaddr_init(pj_AF_INET6(), 902 &ice_cfg.stun_tp[1].cfg.bound_addr, 903 &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); 904 ice_cfg.stun_tp[1].cfg.port_range = 905 ice_cfg.stun_tp[0].cfg.port_range; 906 } 907 908 /* Configure QoS setting */ 909 ice_cfg.stun_tp[0].cfg.qos_type = cfg->qos_type; 910 pj_memcpy(&ice_cfg.stun_tp[0].cfg.qos_params, &cfg->qos_params, 911 sizeof(cfg->qos_params)); 912 if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) { 913 ice_cfg.stun_tp[1].cfg.qos_type = cfg->qos_type; 914 pj_memcpy(&ice_cfg.stun_tp[1].cfg.qos_params, &cfg->qos_params, 915 sizeof(cfg->qos_params)); 916 } 917 918 /* Configure max packet size */ 919 ice_cfg.stun_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 920 if (use_ipv6 && ice_cfg.stun_tp_cnt > 1) 921 ice_cfg.stun_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 922 923 } 788 924 789 925 /* Configure TURN settings */ 790 926 if (acc_cfg->turn_cfg.enable_turn) { 927 ice_cfg.turn_tp_cnt = 1; 928 pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[0]); 929 if (use_ipv6 && PJ_ICE_MAX_TURN >= 3) { 930 ice_cfg.turn_tp_cnt = 3; 931 932 pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[1]); 933 ice_cfg.turn_tp[1].af = pj_AF_INET6(); 934 935 /* Additional candidate: IPv4 relay via IPv6 TURN server */ 936 pj_ice_strans_turn_cfg_default(&ice_cfg.turn_tp[2]); 937 ice_cfg.turn_tp[2].af = pj_AF_INET6(); 938 ice_cfg.turn_tp[2].alloc_param.af = pj_AF_INET(); 939 } 940 941 /* Configure TURN server */ 791 942 status = parse_host_port(&acc_cfg->turn_cfg.turn_server, 792 &ice_cfg.turn .server,793 &ice_cfg.turn .port);794 if (status != PJ_SUCCESS || ice_cfg.turn .server.slen == 0) {943 &ice_cfg.turn_tp[0].server, 944 &ice_cfg.turn_tp[0].port); 945 if (status != PJ_SUCCESS || ice_cfg.turn_tp[0].server.slen == 0) { 795 946 PJ_LOG(1,(THIS_FILE, "Invalid TURN server setting")); 796 947 return PJ_EINVAL; 797 948 } 798 if (ice_cfg.turn.port == 0) 799 ice_cfg.turn.port = 3479; 800 ice_cfg.turn.conn_type = acc_cfg->turn_cfg.turn_conn_type; 801 pj_memcpy(&ice_cfg.turn.auth_cred, 949 950 /* Configure TURN connection settings and credential */ 951 if (ice_cfg.turn_tp[0].port == 0) 952 ice_cfg.turn_tp[0].port = 3479; 953 ice_cfg.turn_tp[0].conn_type = acc_cfg->turn_cfg.turn_conn_type; 954 pj_memcpy(&ice_cfg.turn_tp[0].auth_cred, 802 955 &acc_cfg->turn_cfg.turn_auth_cred, 803 sizeof(ice_cfg.turn.auth_cred)); 804 805 /* Copy QoS setting to TURN setting */ 806 ice_cfg.turn.cfg.qos_type = cfg->qos_type; 807 pj_memcpy(&ice_cfg.turn.cfg.qos_params, &cfg->qos_params, 956 sizeof(ice_cfg.turn_tp[0].auth_cred)); 957 958 if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) { 959 ice_cfg.turn_tp[1].server = ice_cfg.turn_tp[0].server; 960 ice_cfg.turn_tp[1].port = ice_cfg.turn_tp[0].port; 961 ice_cfg.turn_tp[1].conn_type = ice_cfg.turn_tp[0].conn_type; 962 pj_memcpy(&ice_cfg.turn_tp[1].auth_cred, 963 &acc_cfg->turn_cfg.turn_auth_cred, 964 sizeof(ice_cfg.turn_tp[1].auth_cred)); 965 966 ice_cfg.turn_tp[2].server = ice_cfg.turn_tp[0].server; 967 ice_cfg.turn_tp[2].port = ice_cfg.turn_tp[0].port; 968 ice_cfg.turn_tp[2].conn_type = ice_cfg.turn_tp[0].conn_type; 969 pj_memcpy(&ice_cfg.turn_tp[2].auth_cred, 970 &acc_cfg->turn_cfg.turn_auth_cred, 971 sizeof(ice_cfg.turn_tp[2].auth_cred)); 972 } 973 974 /* Configure QoS setting */ 975 ice_cfg.turn_tp[0].cfg.qos_type = cfg->qos_type; 976 pj_memcpy(&ice_cfg.turn_tp[0].cfg.qos_params, &cfg->qos_params, 808 977 sizeof(cfg->qos_params)); 809 810 /* Copy binding port setting to TURN setting */ 811 pj_sockaddr_init(ice_cfg.af, &ice_cfg.turn.cfg.bound_addr, 978 if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) { 979 ice_cfg.turn_tp[1].cfg.qos_type = cfg->qos_type; 980 pj_memcpy(&ice_cfg.turn_tp[1].cfg.qos_params, &cfg->qos_params, 981 sizeof(cfg->qos_params)); 982 983 ice_cfg.turn_tp[2].cfg.qos_type = cfg->qos_type; 984 pj_memcpy(&ice_cfg.turn_tp[2].cfg.qos_params, &cfg->qos_params, 985 sizeof(cfg->qos_params)); 986 } 987 988 /* Configure binding address */ 989 pj_sockaddr_init(ice_cfg.turn_tp[0].af, &ice_cfg.turn_tp[0].cfg.bound_addr, 812 990 &cfg->bound_addr, (pj_uint16_t)cfg->port); 813 ice_cfg.turn .cfg.port_range = (pj_uint16_t)cfg->port_range;814 if (cfg->port != 0 && ice_cfg.turn .cfg.port_range == 0)815 ice_cfg.turn .cfg.port_range =991 ice_cfg.turn_tp[0].cfg.port_range = (pj_uint16_t)cfg->port_range; 992 if (cfg->port != 0 && ice_cfg.turn_tp[0].cfg.port_range == 0) 993 ice_cfg.turn_tp[0].cfg.port_range = 816 994 (pj_uint16_t)(pjsua_var.ua_cfg.max_calls * 10); 817 } 818 819 /* Configure packet size for STUN and TURN sockets */ 820 ice_cfg.stun.cfg.max_pkt_size = PJMEDIA_MAX_MRU; 821 ice_cfg.turn.cfg.max_pkt_size = PJMEDIA_MAX_MRU; 995 996 if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) { 997 pj_str_t IN6_ADDR_ANY = {"0", 1}; 998 pj_sockaddr_init(pj_AF_INET6(), 999 &ice_cfg.turn_tp[1].cfg.bound_addr, 1000 &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); 1001 ice_cfg.turn_tp[1].cfg.port_range = 1002 ice_cfg.turn_tp[0].cfg.port_range; 1003 1004 pj_sockaddr_init(pj_AF_INET6(), 1005 &ice_cfg.turn_tp[2].cfg.bound_addr, 1006 &IN6_ADDR_ANY, (pj_uint16_t)cfg->port); 1007 ice_cfg.turn_tp[2].cfg.port_range = 1008 ice_cfg.turn_tp[0].cfg.port_range; 1009 } 1010 1011 /* Configure max packet size */ 1012 ice_cfg.turn_tp[0].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 1013 if (use_ipv6 && ice_cfg.turn_tp_cnt > 1) { 1014 ice_cfg.turn_tp[1].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 1015 ice_cfg.turn_tp[2].cfg.max_pkt_size = PJMEDIA_MAX_MRU; 1016 } 1017 } 822 1018 823 1019 pj_bzero(&ice_cb, sizeof(pjmedia_ice_cb)); … … 1344 1540 else 1345 1541 srtp_opt.use = acc->cfg.use_srtp; 1542 1543 if (pjsua_var.ua_cfg.cb.on_create_media_transport_srtp) { 1544 pjsua_call *call = call_med->call; 1545 pjmedia_srtp_use srtp_use = srtp_opt.use; 1546 1547 (*pjsua_var.ua_cfg.cb.on_create_media_transport_srtp) 1548 (call->index, call_med->idx, &srtp_opt); 1549 1550 /* Close_member_tp must not be overwritten by app */ 1551 srtp_opt.close_member_tp = PJ_TRUE; 1552 1553 /* Revert SRTP usage policy if media is reinitialized */ 1554 if (call->inv && call->inv->state == PJSIP_INV_STATE_CONFIRMED) { 1555 srtp_opt.use = srtp_use; 1556 } 1557 } 1346 1558 1347 1559 status = pjmedia_transport_srtp_create(pjsua_var.med_endpt, … … 1764 1976 * Otherwise, apply media count from the call setting directly. 1765 1977 */ 1766 if (reinit ) {1978 if (reinit && (call->opt.flag & PJSUA_CALL_REINIT_MEDIA) == 0) { 1767 1979 1768 1980 /* We are sending reoffer, check media count for each media type … … 1828 2040 } 1829 2041 #endif 2042 } 2043 2044 /* In case of media reinit, 'med_prov_cnt' may be decreased 2045 * because the new call->opt says so. As media count should 2046 * never decrease, we should verify 'med_prov_cnt' to be 2047 * at least equal to 'med_cnt' (see also #1987). 2048 */ 2049 if (reinit && (call->opt.flag & PJSUA_CALL_REINIT_MEDIA) && 2050 call->med_prov_cnt < call->med_cnt) 2051 { 2052 call->med_prov_cnt = call->med_cnt; 1830 2053 } 1831 2054 } … … 2100 2323 pjmedia_sdp_neg_get_active_local(call->inv->neg, &s_); 2101 2324 2102 pj_assert(mi < s_->media_count); 2103 m = pjmedia_sdp_media_clone(pool, s_->media[mi]); 2104 m->desc.port = 0; 2325 if (mi < s_->media_count) { 2326 m = pjmedia_sdp_media_clone(pool, s_->media[mi]); 2327 m->desc.port = 0; 2328 } else { 2329 /* Remote may have removed some media lines in 2330 * previous negotiations. However, since our 2331 * media count may never decrease (as per 2332 * the RFC), we'll just offer unknown media here. 2333 */ 2334 m->desc.media = pj_str("unknown"); 2335 m->desc.fmt[0] = pj_str("0"); 2336 } 2105 2337 } 2106 2338 break; … … 3012 3244 #endif 3013 3245 } else { 3014 status = PJMEDIA_E INVALIMEDIATYPE;3246 status = PJMEDIA_EUNSUPMEDIATYPE; 3015 3247 } 3016 3248 … … 3041 3273 call_med->dir = PJMEDIA_DIR_NONE; 3042 3274 3043 PJ_PERROR(1,(THIS_FILE, status, "Error updating media call%02d:%d", 3044 call_id, mi)); 3275 if (status != PJMEDIA_EUNSUPMEDIATYPE) { 3276 PJ_PERROR(1, (THIS_FILE, status, "Error updating media " 3277 "call%02d:%d", call_id, mi)); 3278 } else { 3279 PJ_PERROR(3, (THIS_FILE, status, "Skipped updating media " 3280 "call%02d:%d (media type=%s)", call_id, mi, 3281 pjmedia_type_name(call_med->type))); 3282 } 3283 3045 3284 } else { 3046 3285 /* Only set 'got_media' flag if this media is not disabled */
Note: See TracChangeset
for help on using the changeset viewer.