Changeset 5788 for pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
- Timestamp:
- May 9, 2018 6:58:48 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r5752 r5788 82 82 pj_sockaddr rtcp_src_addr; /**< Actual source RTCP address. */ 83 83 unsigned rtcp_src_cnt; /**< How many pkt from this addr. */ 84 pj_bool_t enable_rtcp_mux;/**< Enable RTP& RTCP multiplexing?*/ 85 pj_bool_t use_rtcp_mux; /**< Use RTP & RTCP multiplexing? */ 84 86 85 87 unsigned tx_drop_pct; /**< Percent of tx pkts to drop. */ … … 194 196 static const pj_str_t STR_IP6 = { "IP6", 3 }; 195 197 static const pj_str_t STR_RTCP = { "rtcp", 4 }; 198 static const pj_str_t STR_RTCP_MUX = { "rtcp-mux", 8 }; 196 199 static const pj_str_t STR_BANDW_RR = { "RR", 2 }; 197 200 static const pj_str_t STR_BANDW_RS = { "RS", 2 }; … … 505 508 unsigned media_index, 506 509 unsigned comp_cnt, 507 pj_bool_t restart_session) 510 pj_bool_t restart_session, 511 pj_bool_t rtcp_mux) 508 512 { 509 513 enum { … … 759 763 } 760 764 } 761 765 766 /* Add a=rtcp-mux attribute */ 767 if (rtcp_mux) { 768 pjmedia_sdp_attr *attr; 769 770 attr = PJ_POOL_ZALLOC_T(sdp_pool, pjmedia_sdp_attr); 771 attr->name = STR_RTCP_MUX; 772 m->attr[m->attr_count++] = attr; 773 } 762 774 763 775 return PJ_SUCCESS; … … 895 907 /* Encode ICE in SDP */ 896 908 status = encode_session_in_sdp(tp_ice, sdp_pool, loc_sdp, media_index, 897 tp_ice->comp_cnt, PJ_FALSE); 909 tp_ice->comp_cnt, PJ_FALSE, 910 tp_ice->enable_rtcp_mux); 898 911 if (status != PJ_SUCCESS) { 899 912 set_no_ice(tp_ice, "Error encoding SDP answer", status); … … 923 936 924 937 rem_m = rem_sdp->media[media_index]; 938 939 /* Check if remote wants RTCP mux */ 940 if (tp_ice->enable_rtcp_mux) { 941 pjmedia_sdp_attr *attr; 942 943 attr = pjmedia_sdp_attr_find(rem_m->attr_count, rem_m->attr, 944 &STR_RTCP_MUX, NULL); 945 tp_ice->use_rtcp_mux = (attr? PJ_TRUE: PJ_FALSE); 946 } 925 947 926 948 /* Get the "ice-ufrag" and "ice-pwd" attributes */ … … 1064 1086 1065 1087 /* Check matched component count and ice_mismatch */ 1066 if (comp1_found && (tp_ice->comp_cnt==1 || !has_rtcp)) { 1088 if (comp1_found && 1089 (tp_ice->comp_cnt==1 || !has_rtcp || tp_ice->use_rtcp_mux)) 1090 { 1067 1091 sdp_state->match_comp_cnt = 1; 1068 1092 sdp_state->ice_mismatch = PJ_FALSE; … … 1123 1147 } 1124 1148 1149 /* Encode information in SDP if ICE is not used */ 1150 static pj_status_t encode_no_ice_in_sdp( struct transport_ice *tp_ice, 1151 pj_pool_t *pool, 1152 pjmedia_sdp_session *sdp_local, 1153 const pjmedia_sdp_session *rem_sdp, 1154 unsigned media_index) 1155 { 1156 if (tp_ice->enable_rtcp_mux) { 1157 pjmedia_sdp_media *m = sdp_local->media[media_index]; 1158 pjmedia_sdp_attr *attr; 1159 pj_bool_t add_rtcp_mux = PJ_TRUE; 1160 1161 if (rem_sdp) 1162 add_rtcp_mux = tp_ice->use_rtcp_mux; 1163 else { 1164 /* For subsequent offer, set it to false first since 1165 * we are still waiting for remote answer. 1166 */ 1167 tp_ice->use_rtcp_mux = PJ_FALSE; 1168 } 1169 1170 /* Remove RTCP attribute because for subsequent offers/answers, 1171 * the address (obtained from transport_get_info() ) may be 1172 * incorrect if we are not yet confirmed to use RTCP mux 1173 * (because we are still waiting for remote answer) or 1174 * if remote rejects it. 1175 */ 1176 pjmedia_sdp_attr_remove_all(&m->attr_count, m->attr, "rtcp"); 1177 1178 if (!tp_ice->use_rtcp_mux && tp_ice->comp_cnt > 1) { 1179 pj_ice_sess_cand cand; 1180 pj_status_t status; 1181 1182 status = pj_ice_strans_get_def_cand(tp_ice->ice_st, 2, &cand); 1183 if (status == PJ_SUCCESS) { 1184 /* Add RTCP attribute if the remote doesn't offer or 1185 * rejects it. 1186 */ 1187 attr = pjmedia_sdp_attr_create_rtcp(pool, &cand.addr); 1188 if (attr) 1189 pjmedia_sdp_attr_add(&m->attr_count, m->attr, attr); 1190 } 1191 } 1192 1193 /* Add a=rtcp-mux attribute. */ 1194 if (add_rtcp_mux) { 1195 attr = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_attr); 1196 attr->name = STR_RTCP_MUX; 1197 m->attr[m->attr_count++] = attr; 1198 } 1199 } 1200 return PJ_SUCCESS; 1201 } 1202 1125 1203 1126 1204 /* Verify incoming offer and create initial answer */ … … 1151 1229 if (tp_ice->rem_offer_state.match_comp_cnt==0) { 1152 1230 set_no_ice(tp_ice, "No ICE found in SDP offer", PJ_SUCCESS); 1231 encode_no_ice_in_sdp(tp_ice, sdp_pool, loc_sdp, rem_sdp, 1232 media_index); 1153 1233 return PJ_SUCCESS; 1154 1234 } … … 1164 1244 status = encode_session_in_sdp(tp_ice, sdp_pool, loc_sdp, media_index, 1165 1245 tp_ice->rem_offer_state.match_comp_cnt, 1166 PJ_FALSE );1246 PJ_FALSE, tp_ice->use_rtcp_mux); 1167 1247 if (status != PJ_SUCCESS) { 1168 1248 set_no_ice(tp_ice, "Error encoding SDP answer", status); … … 1184 1264 if (pj_ice_strans_has_sess(tp_ice->ice_st) == PJ_FALSE) { 1185 1265 /* We don't have ICE */ 1266 encode_no_ice_in_sdp(tp_ice, sdp_pool, loc_sdp, NULL, media_index); 1186 1267 return PJ_SUCCESS; 1187 1268 } … … 1189 1270 comp_cnt = pj_ice_strans_get_running_comp_cnt(tp_ice->ice_st); 1190 1271 return encode_session_in_sdp(tp_ice, sdp_pool, loc_sdp, media_index, 1191 comp_cnt, PJ_FALSE );1272 comp_cnt, PJ_FALSE, tp_ice->enable_rtcp_mux); 1192 1273 } 1193 1274 … … 1218 1299 if (tp_ice->rem_offer_state.match_comp_cnt == 0) { 1219 1300 /* Remote no longer offers ICE */ 1301 encode_no_ice_in_sdp(tp_ice, sdp_pool, loc_sdp, rem_sdp, 1302 media_index); 1220 1303 return PJ_SUCCESS; 1221 1304 } … … 1228 1311 status = encode_session_in_sdp(tp_ice, sdp_pool, loc_sdp, media_index, 1229 1312 tp_ice->rem_offer_state.match_comp_cnt, 1230 tp_ice->rem_offer_state.ice_restart); 1313 tp_ice->rem_offer_state.ice_restart, 1314 tp_ice->use_rtcp_mux); 1231 1315 if (status != PJ_SUCCESS) 1232 1316 return status; … … 1241 1325 if (tp_ice->rem_offer_state.match_comp_cnt == 0) { 1242 1326 /* Remote does not support ICE */ 1327 encode_no_ice_in_sdp(tp_ice, sdp_pool, loc_sdp, rem_sdp, 1328 media_index); 1243 1329 return PJ_SUCCESS; 1244 1330 } … … 1262 1348 status = encode_session_in_sdp(tp_ice, sdp_pool, loc_sdp, media_index, 1263 1349 tp_ice->rem_offer_state.match_comp_cnt, 1264 tp_ice->rem_offer_state.ice_restart); 1350 tp_ice->rem_offer_state.ice_restart, 1351 tp_ice->use_rtcp_mux); 1265 1352 if (status != PJ_SUCCESS) 1266 1353 return status; … … 1291 1378 1292 1379 tp_ice->media_option = options; 1380 tp_ice->enable_rtcp_mux = ((options & PJMEDIA_TPMED_RTCP_MUX) != 0); 1293 1381 tp_ice->oa_role = ROLE_NONE; 1294 1382 tp_ice->initial_sdp = PJ_TRUE; … … 1402 1490 } 1403 1491 1404 cand_cnt++; 1492 if (!tp_ice->use_rtcp_mux || cand[cand_cnt].comp_id < 2) 1493 cand_cnt++; 1405 1494 } 1406 1495 … … 1655 1744 1656 1745 /* Get RTCP default address */ 1657 if (tp_ice->comp_cnt > 1) { 1746 if (tp_ice->use_rtcp_mux) { 1747 pj_sockaddr_cp(&info->sock_info.rtcp_addr_name, &cand.addr); 1748 } else if (tp_ice->comp_cnt > 1) { 1658 1749 status = pj_ice_strans_get_def_cand(tp_ice->ice_st, 2, &cand); 1659 1750 if (status != PJ_SUCCESS) … … 1750 1841 tp_ice->rtcp_cb = att_param->rtcp_cb; 1751 1842 1843 /* Check again if we are multiplexing RTP & RTCP. */ 1844 tp_ice->use_rtcp_mux = (pj_sockaddr_has_addr(&att_param->rem_addr) && 1845 pj_sockaddr_cmp(&att_param->rem_addr, 1846 &att_param->rem_rtcp) == 0); 1847 1752 1848 pj_memcpy(&tp_ice->remote_rtp, &att_param->rem_addr, att_param->addr_len); 1753 1849 pj_memcpy(&tp_ice->remote_rtcp, &att_param->rem_rtcp, att_param->addr_len); … … 1815 1911 { 1816 1912 struct transport_ice *tp_ice = (struct transport_ice*)tp; 1817 if (tp_ice->comp_cnt > 1) { 1913 1914 if (tp_ice->comp_cnt > 1 || tp_ice->use_rtcp_mux) { 1915 unsigned comp_id = (tp_ice->use_rtcp_mux? 1: 2); 1818 1916 if (addr == NULL) { 1819 1917 addr = &tp_ice->remote_rtcp; 1820 1918 addr_len = pj_sockaddr_get_len(addr); 1821 } 1822 return pj_ice_strans_sendto(tp_ice->ice_st, 2, pkt, size,1919 } 1920 return pj_ice_strans_sendto(tp_ice->ice_st, comp_id, pkt, size, 1823 1921 addr, addr_len); 1824 1922 } else { … … 1889 1987 sizeof(addr_text), 3))); 1890 1988 1891 /* Also update remote RTCP address if actual RTCP source 1892 * address is not heard yet. 1893 */ 1894 if (!pj_sockaddr_has_addr(&tp_ice->rtcp_src_addr)) { 1989 if (tp_ice->use_rtcp_mux) { 1990 pj_sockaddr_cp(&tp_ice->remote_rtcp, &tp_ice->remote_rtp); 1991 } else if (!pj_sockaddr_has_addr(&tp_ice->rtcp_src_addr)) { 1992 /* Also update remote RTCP address if actual RTCP source 1993 * address is not heard yet. 1994 */ 1895 1995 pj_uint16_t port; 1896 1996
Note: See TracChangeset
for help on using the changeset viewer.