Changeset 4538 for pjproject/trunk
- Timestamp:
- Jun 19, 2013 9:06:55 AM (11 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/include/pj/sock.h
r4343 r4538 1308 1308 1309 1309 /** 1310 * Helper function to set socket buffer size using #pj_sock_setsockopt() 1311 * with capability to auto retry with lower buffer setting value until 1312 * the highest possible value is successfully set. 1313 * 1314 * @param sockfd The socket descriptor. 1315 * @param optname The option name, valid values are pj_SO_RCVBUF() 1316 * and pj_SO_SNDBUF(). 1317 * @param auto_retry Option whether auto retry with lower value is 1318 * enabled. 1319 * @param buf_size On input, specify the prefered buffer size setting, 1320 * on output, the buffer size setting applied. 1321 * 1322 * @return PJ_SUCCESS or the status code. 1323 */ 1324 PJ_DECL(pj_status_t) pj_sock_setsockopt_sobuf( pj_sock_t sockfd, 1325 pj_uint16_t optname, 1326 pj_bool_t auto_retry, 1327 unsigned *buf_size); 1328 1329 1330 /** 1310 1331 * Receives data stream or message coming to the specified socket. 1311 1332 * -
pjproject/trunk/pjlib/src/pj/sock_common.c
r4343 r4538 1080 1080 1081 1081 1082 /* 1083 * Adjust socket send/receive buffer size. 1084 */ 1085 PJ_DEF(pj_status_t) pj_sock_setsockopt_sobuf( pj_sock_t sockfd, 1086 pj_uint16_t optname, 1087 pj_bool_t auto_retry, 1088 unsigned *buf_size) 1089 { 1090 pj_status_t status; 1091 int try_size, cur_size, i, step, size_len; 1092 enum { MAX_TRY = 20 }; 1093 1094 PJ_CHECK_STACK(); 1095 1096 PJ_ASSERT_RETURN(sockfd != PJ_INVALID_SOCKET && 1097 buf_size && 1098 *buf_size > 0 && 1099 (optname == pj_SO_RCVBUF() || 1100 optname == pj_SO_SNDBUF()), 1101 PJ_EINVAL); 1102 1103 size_len = sizeof(cur_size); 1104 status = pj_sock_getsockopt(sockfd, pj_SOL_SOCKET(), optname, 1105 &cur_size, &size_len); 1106 if (status != PJ_SUCCESS) 1107 return status; 1108 1109 try_size = *buf_size; 1110 step = (try_size - cur_size) / MAX_TRY; 1111 if (step < 4096) 1112 step = 4096; 1113 1114 for (i = 0; i < (MAX_TRY-1); ++i) { 1115 if (try_size <= cur_size) { 1116 /* Done, return current size */ 1117 *buf_size = cur_size; 1118 break; 1119 } 1120 1121 status = pj_sock_setsockopt(sockfd, pj_SOL_SOCKET(), optname, 1122 &try_size, sizeof(try_size)); 1123 if (status == PJ_SUCCESS) { 1124 status = pj_sock_getsockopt(sockfd, pj_SOL_SOCKET(), optname, 1125 &cur_size, &size_len); 1126 if (status != PJ_SUCCESS) { 1127 /* Ops! No info about current size, just return last try size 1128 * and quit. 1129 */ 1130 *buf_size = try_size; 1131 break; 1132 } 1133 } 1134 1135 if (!auto_retry) 1136 break; 1137 1138 try_size -= step; 1139 } 1140 1141 return status; 1142 } 1143 1144 1082 1145 /* Only need to implement these in DLL build */ 1083 1146 #if defined(PJ_DLL) -
pjproject/trunk/pjmedia/include/pjmedia/config.h
r4443 r4538 1218 1218 1219 1219 /** 1220 * Specify target value for socket receive buffer size. It will be 1221 * applied to RTP socket of media transport using setsockopt(). When 1222 * transport failed to set the specified size, it will try with lower 1223 * value until the highest possible is successfully set. 1224 * 1225 * Setting this to zero will leave the socket receive buffer size to 1226 * OS default (e.g: usually 8 KB on desktop platforms). 1227 * 1228 * Default: 64 KB when video is enabled, otherwise zero (OS default) 1229 */ 1230 #ifndef PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE 1231 # if PJMEDIA_HAS_VIDEO 1232 # define PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE (64*1024) 1233 # else 1234 # define PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE 0 1235 # endif 1236 #endif 1237 1238 1239 /** 1240 * Specify target value for socket send buffer size. It will be 1241 * applied to RTP socket of media transport using setsockopt(). When 1242 * transport failed to set the specified size, it will try with lower 1243 * value until the highest possible is successfully set. 1244 * 1245 * Setting this to zero will leave the socket send buffer size to 1246 * OS default (e.g: usually 8 KB on desktop platforms). 1247 * 1248 * Default: 64 KB when video is enabled, otherwise zero (OS default) 1249 */ 1250 #ifndef PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE 1251 # if PJMEDIA_HAS_VIDEO 1252 # define PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE (64*1024) 1253 # else 1254 # define PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE 0 1255 # endif 1256 #endif 1257 1258 1259 /** 1220 1260 * @} 1221 1261 */ -
pjproject/trunk/pjmedia/src/pjmedia/transport_ice.c
r4350 r4538 226 226 pj_pool_t *pool; 227 227 pj_ice_strans_cb ice_st_cb; 228 pj_ice_strans_cfg ice_st_cfg; 228 229 struct transport_ice *tp_ice; 229 230 pj_status_t status; … … 246 247 tp_ice->use_ice = PJ_FALSE; 247 248 249 pj_memcpy(&ice_st_cfg, cfg, sizeof(pj_ice_strans_cfg)); 248 250 if (cb) 249 251 pj_memcpy(&tp_ice->cb, cb, sizeof(pjmedia_ice_cb)); … … 259 261 ice_st_cb.on_rx_data = &ice_on_rx_data; 260 262 263 /* Configure RTP socket buffer settings, if not set */ 264 if (ice_st_cfg.comp[COMP_RTP-1].so_rcvbuf_size == 0) { 265 ice_st_cfg.comp[COMP_RTP-1].so_rcvbuf_size = 266 PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE; 267 } 268 if (ice_st_cfg.comp[COMP_RTP-1].so_sndbuf_size == 0) { 269 ice_st_cfg.comp[COMP_RTP-1].so_sndbuf_size = 270 PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE; 271 } 272 261 273 /* Create ICE */ 262 status = pj_ice_strans_create(name, cfg, comp_cnt, tp_ice,274 status = pj_ice_strans_create(name, &ice_st_cfg, comp_cnt, tp_ice, 263 275 &ice_st_cb, &tp_ice->ice_st); 264 276 if (status != PJ_SUCCESS) { -
pjproject/trunk/pjmedia/src/pjmedia/transport_udp.c
r4197 r4538 694 694 udp->rtcp_src_cnt = 0; 695 695 696 /* Set buffer size for RTP socket */ 697 #if PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE 698 { 699 unsigned sobuf_size = PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE; 700 pj_status_t status; 701 status = pj_sock_setsockopt_sobuf(udp->rtp_sock, pj_SO_RCVBUF(), 702 PJ_TRUE, &sobuf_size); 703 if (status != PJ_SUCCESS) { 704 pj_perror(3, tp->name, status, "Failed setting SO_RCVBUF"); 705 } else { 706 if (sobuf_size < PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE) { 707 PJ_LOG(4, (tp->name, 708 "Warning! Cannot set SO_RCVBUF as configured, " 709 "now=%d, configured=%d", 710 sobuf_size, PJMEDIA_TRANSPORT_SO_RCVBUF_SIZE)); 711 } else { 712 PJ_LOG(5, (tp->name, "SO_RCVBUF set to %d", sobuf_size)); 713 } 714 } 715 } 716 #endif 717 #if PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE 718 { 719 unsigned sobuf_size = PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE; 720 pj_status_t status; 721 status = pj_sock_setsockopt_sobuf(udp->rtp_sock, pj_SO_SNDBUF(), 722 PJ_TRUE, &sobuf_size); 723 if (status != PJ_SUCCESS) { 724 pj_perror(3, tp->name, status, "Failed setting SO_SNDBUF"); 725 } else { 726 if (sobuf_size < PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE) { 727 PJ_LOG(4, (tp->name, 728 "Warning! Cannot set SO_SNDBUF as configured, " 729 "now=%d, configured=%d", 730 sobuf_size, PJMEDIA_TRANSPORT_SO_SNDBUF_SIZE)); 731 } else { 732 PJ_LOG(5, (tp->name, "SO_SNDBUF set to %d", sobuf_size)); 733 } 734 } 735 } 736 #endif 737 696 738 /* Unlock keys */ 697 739 pj_ioqueue_unlock_key(udp->rtcp_key); -
pjproject/trunk/pjnath/include/pjnath/ice_strans.h
r4133 r4538 371 371 pj_qos_params qos_params; 372 372 373 /** 374 * Specify target value for socket receive buffer size. It will be 375 * applied using setsockopt(). When it fails to set the specified 376 * size, it will try with lower value until the highest possible is 377 * successfully set. 378 * 379 * When this is set to zero, this component will apply socket receive 380 * buffer size settings specified in STUN and TURN socket config 381 * above, i.e: \a stun::cfg::so_rcvbuf_size and 382 * \a turn::cfg::so_rcvbuf_size. Otherwise, this setting will be 383 * applied to STUN and TURN sockets for this component, overriding 384 * the setting specified in STUN/TURN socket config. 385 * 386 * Default: 0 387 */ 388 unsigned so_rcvbuf_size; 389 390 /** 391 * Specify target value for socket send buffer size. It will be 392 * applied using setsockopt(). When it fails to set the specified 393 * size, it will try with lower value until the highest possible is 394 * successfully set. 395 * 396 * When this is set to zero, this component will apply socket send 397 * buffer size settings specified in STUN and TURN socket config 398 * above, i.e: \a stun::cfg::so_sndbuf_size and 399 * \a turn::cfg::so_sndbuf_size. Otherwise, this setting will be 400 * applied to STUN and TURN sockets for this component, overriding 401 * the setting specified in STUN/TURN socket config. 402 * 403 * Default: 0 404 */ 405 unsigned so_sndbuf_size; 406 373 407 } comp[PJ_ICE_MAX_COMP]; 374 408 -
pjproject/trunk/pjnath/include/pjnath/stun_sock.h
r4360 r4538 295 295 */ 296 296 pj_bool_t qos_ignore_error; 297 298 /** 299 * Specify target value for socket receive buffer size. It will be 300 * applied using setsockopt(). When it fails to set the specified size, 301 * it will try with lower value until the highest possible is 302 * successfully set. 303 * 304 * Default: 0 (OS default) 305 */ 306 unsigned so_rcvbuf_size; 307 308 /** 309 * Specify target value for socket send buffer size. It will be 310 * applied using setsockopt(). When it fails to set the specified size, 311 * it will try with lower value until the highest possible is 312 * successfully set. 313 * 314 * Default: 0 (OS default) 315 */ 316 unsigned so_sndbuf_size; 297 317 298 318 } pj_stun_sock_cfg; -
pjproject/trunk/pjnath/include/pjnath/turn_sock.h
r4360 r4538 166 166 */ 167 167 pj_uint16_t port_range; 168 169 /** 170 * Specify target value for socket receive buffer size. It will be 171 * applied using setsockopt(). When it fails to set the specified size, 172 * it will try with lower value until the highest possible has been 173 * successfully set. 174 * 175 * Default: 0 (OS default) 176 */ 177 unsigned so_rcvbuf_size; 178 179 /** 180 * Specify target value for socket send buffer size. It will be 181 * applied using setsockopt(). When it fails to set the specified size, 182 * it will try with lower value until the highest possible has been 183 * successfully set. 184 * 185 * Default: 0 (OS default) 186 */ 187 unsigned so_sndbuf_size; 168 188 169 189 } pj_turn_sock_cfg; -
pjproject/trunk/pjnath/src/pjnath/ice_strans.c
r4537 r4538 297 297 } 298 298 299 /* Override with component specific socket buffer size settings, if any */ 300 if (ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size > 0) { 301 ice_st->cfg.turn.cfg.so_rcvbuf_size = 302 ice_st->cfg.comp[comp->comp_id-1].so_rcvbuf_size; 303 } 304 if (ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size > 0) { 305 ice_st->cfg.turn.cfg.so_sndbuf_size = 306 ice_st->cfg.comp[comp->comp_id-1].so_sndbuf_size; 307 } 308 299 309 /* Create the TURN transport */ 300 310 status = pj_turn_sock_create(&ice_st->cfg.stun_cfg, ice_st->cfg.af, … … 382 392 &ice_st->cfg.comp[comp_id-1].qos_params, 383 393 sizeof(ice_st->cfg.stun.cfg.qos_params)); 394 } 395 396 /* Override component specific socket buffer size settings, if any */ 397 if (ice_st->cfg.comp[comp_id-1].so_rcvbuf_size > 0) { 398 ice_st->cfg.stun.cfg.so_rcvbuf_size = 399 ice_st->cfg.comp[comp_id-1].so_rcvbuf_size; 400 } 401 if (ice_st->cfg.comp[comp_id-1].so_sndbuf_size > 0) { 402 ice_st->cfg.stun.cfg.so_sndbuf_size = 403 ice_st->cfg.comp[comp_id-1].so_sndbuf_size; 384 404 } 385 405 -
pjproject/trunk/pjnath/src/pjnath/stun_sock.c
r4537 r4538 238 238 goto on_error; 239 239 240 /* Apply socket buffer size */ 241 if (cfg->so_rcvbuf_size > 0) { 242 unsigned sobuf_size = cfg->so_rcvbuf_size; 243 status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_RCVBUF(), 244 PJ_TRUE, &sobuf_size); 245 if (status != PJ_SUCCESS) { 246 pj_perror(3, stun_sock->obj_name, status, 247 "Failed setting SO_RCVBUF"); 248 } else { 249 if (sobuf_size < cfg->so_rcvbuf_size) { 250 PJ_LOG(4, (stun_sock->obj_name, 251 "Warning! Cannot set SO_RCVBUF as configured, " 252 "now=%d, configured=%d", 253 sobuf_size, cfg->so_rcvbuf_size)); 254 } else { 255 PJ_LOG(5, (stun_sock->obj_name, "SO_RCVBUF set to %d", 256 sobuf_size)); 257 } 258 } 259 } 260 if (cfg->so_sndbuf_size > 0) { 261 unsigned sobuf_size = cfg->so_sndbuf_size; 262 status = pj_sock_setsockopt_sobuf(stun_sock->sock_fd, pj_SO_SNDBUF(), 263 PJ_TRUE, &sobuf_size); 264 if (status != PJ_SUCCESS) { 265 pj_perror(3, stun_sock->obj_name, status, 266 "Failed setting SO_SNDBUF"); 267 } else { 268 if (sobuf_size < cfg->so_sndbuf_size) { 269 PJ_LOG(4, (stun_sock->obj_name, 270 "Warning! Cannot set SO_SNDBUF as configured, " 271 "now=%d, configured=%d", 272 sobuf_size, cfg->so_sndbuf_size)); 273 } else { 274 PJ_LOG(5, (stun_sock->obj_name, "SO_SNDBUF set to %d", 275 sobuf_size)); 276 } 277 } 278 } 279 240 280 /* Bind socket */ 241 281 max_bind_retry = MAX_BIND_RETRY; -
pjproject/trunk/pjnath/src/pjnath/turn_sock.c
r4537 r4538 811 811 } 812 812 813 /* Apply socket buffer size */ 814 if (turn_sock->setting.so_rcvbuf_size > 0) { 815 unsigned sobuf_size = turn_sock->setting.so_rcvbuf_size; 816 status = pj_sock_setsockopt_sobuf(sock, pj_SO_RCVBUF(), 817 PJ_TRUE, &sobuf_size); 818 if (status != PJ_SUCCESS) { 819 pj_perror(3, turn_sock->obj_name, status, 820 "Failed setting SO_RCVBUF"); 821 } else { 822 if (sobuf_size < turn_sock->setting.so_rcvbuf_size) { 823 PJ_LOG(4, (turn_sock->obj_name, 824 "Warning! Cannot set SO_RCVBUF as configured," 825 " now=%d, configured=%d", sobuf_size, 826 turn_sock->setting.so_rcvbuf_size)); 827 } else { 828 PJ_LOG(5, (turn_sock->obj_name, "SO_RCVBUF set to %d", 829 sobuf_size)); 830 } 831 } 832 } 833 if (turn_sock->setting.so_sndbuf_size > 0) { 834 unsigned sobuf_size = turn_sock->setting.so_sndbuf_size; 835 status = pj_sock_setsockopt_sobuf(sock, pj_SO_SNDBUF(), 836 PJ_TRUE, &sobuf_size); 837 if (status != PJ_SUCCESS) { 838 pj_perror(3, turn_sock->obj_name, status, 839 "Failed setting SO_SNDBUF"); 840 } else { 841 if (sobuf_size < turn_sock->setting.so_sndbuf_size) { 842 PJ_LOG(4, (turn_sock->obj_name, 843 "Warning! Cannot set SO_SNDBUF as configured," 844 " now=%d, configured=%d", sobuf_size, 845 turn_sock->setting.so_sndbuf_size)); 846 } else { 847 PJ_LOG(5, (turn_sock->obj_name, "SO_SNDBUF set to %d", 848 sobuf_size)); 849 } 850 } 851 } 852 813 853 /* Create active socket */ 814 854 pj_activesock_cfg_default(&asock_cfg);
Note: See TracChangeset
for help on using the changeset viewer.