Changeset 715
- Timestamp:
- Sep 14, 2006 11:17:48 AM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r695 r715 21 21 22 22 #define THIS_FILE "pjsua.c" 23 #define NO_LIMIT (int)0x7FFFFFFF 23 24 24 25 //#define STEREO_DEMO 26 27 /* Call specific data */ 28 struct call_data 29 { 30 pj_timer_entry timer; 31 }; 25 32 26 33 … … 41 48 unsigned buddy_cnt; 42 49 pjsua_buddy_config buddy_cfg[PJSUA_MAX_BUDDIES]; 50 51 struct call_data call_data[PJSUA_MAX_CALLS]; 43 52 44 53 pj_pool_t *pool; … … 83 92 puts (""); 84 93 puts ("General options:"); 94 puts (" --config-file=file Read the config/arguments from file."); 85 95 puts (" --help Display this help screen"); 86 96 puts (" --version Display version info"); 87 97 puts (""); 88 98 puts ("Logging options:"); 89 puts (" --config-file=file Read the config/arguments from file.");90 99 puts (" --log-file=fname Log to filename (default stderr)"); 91 100 puts (" --log-level=N Set log max level to N (0(none) to 6(trace)) (default=5)"); … … 145 154 puts (" --max-calls=N Maximum number of concurrent calls (default:4, max:255)"); 146 155 puts (" --thread-cnt=N Number of worker threads (default:1)"); 147 /*148 156 puts (" --duration=SEC Set maximum call duration (default:no limit)"); 149 */ 157 150 158 puts (""); 151 159 fflush(stdout); … … 168 176 pjsua_transport_config_default(&cfg->rtp_cfg); 169 177 cfg->rtp_cfg.port = 4000; 170 cfg->duration = (unsigned)-1;178 cfg->duration = NO_LIMIT; 171 179 cfg->wav_id = PJSUA_INVALID_ID; 172 180 cfg->wav_port = PJSUA_INVALID_ID; … … 622 630 } 623 631 break; 632 */ 624 633 625 634 case OPT_DURATION: 626 635 cfg->duration = my_atoi(pj_optarg); 627 636 break; 628 */629 637 630 638 case OPT_THREAD_CNT: … … 708 716 cfg->cfg.max_calls = my_atoi(pj_optarg); 709 717 if (cfg->cfg.max_calls < 1 || cfg->cfg.max_calls > PJSUA_MAX_CALLS) { 710 PJ_LOG(1,(THIS_FILE,"Too many calls for max-calls (1-%d)", 718 PJ_LOG(1,(THIS_FILE,"Error: maximum call setting exceeds " 719 "compile time limit (PJSUA_MAX_CALLS=%d)", 711 720 PJSUA_MAX_CALLS)); 712 721 return -1; … … 1043 1052 1044 1053 /* Uas-duration. */ 1045 if (config->duration != (unsigned)-1) {1054 if (config->duration != NO_LIMIT) { 1046 1055 pj_ansi_sprintf(line, "--duration %d\n", 1047 1056 config->duration); … … 1172 1181 1173 1182 1183 /* Callback from timer when the maximum call duration has been 1184 * exceeded. 1185 */ 1186 static void call_timeout_callback(pj_timer_heap_t *timer_heap, 1187 struct pj_timer_entry *entry) 1188 { 1189 pjsua_call_id call_id = entry->id; 1190 pjsua_msg_data msg_data; 1191 pjsip_generic_string_hdr warn; 1192 pj_str_t hname = pj_str("Warning"); 1193 pj_str_t hvalue = pj_str("399 pjsua \"Call duration exceeded\""); 1194 1195 PJ_UNUSED_ARG(timer_heap); 1196 1197 /* Add warning header */ 1198 pjsua_msg_data_init(&msg_data); 1199 pjsip_generic_string_hdr_init2(&warn, &hname, &hvalue); 1200 pj_list_push_back(&msg_data.hdr_list, &warn); 1201 1202 /* Call duration has been exceeded; disconnect the call */ 1203 PJ_LOG(3,(THIS_FILE, "Duration (%d seconds) has been exceeded " 1204 "for call %d, disconnecting the call", 1205 app_config.duration, call_id)); 1206 entry->id = PJSUA_INVALID_ID; 1207 pjsua_call_hangup(call_id, 200, NULL, &msg_data); 1208 } 1209 1174 1210 1175 1211 /* … … 1186 1222 if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) { 1187 1223 1224 /* Cancel duration timer, if any */ 1225 if (app_config.call_data[call_id].timer.id != PJSUA_INVALID_ID) { 1226 struct call_data *cd = &app_config.call_data[call_id]; 1227 pjsip_endpoint *endpt = pjsua_get_pjsip_endpt(); 1228 1229 cd->timer.id = PJSUA_INVALID_ID; 1230 pjsip_endpt_cancel_timer(endpt, &cd->timer); 1231 } 1232 1188 1233 PJ_LOG(3,(THIS_FILE, "Call %d is DISCONNECTED [reason=%d (%s)]", 1189 1234 call_id, … … 1196 1241 1197 1242 } else { 1243 1244 if (app_config.duration!=NO_LIMIT && 1245 call_info.state == PJSIP_INV_STATE_CONFIRMED) 1246 { 1247 /* Schedule timer to hangup call after the specified duration */ 1248 struct call_data *cd = &app_config.call_data[call_id]; 1249 pjsip_endpoint *endpt = pjsua_get_pjsip_endpt(); 1250 pj_time_val delay; 1251 1252 cd->timer.id = call_id; 1253 delay.sec = app_config.duration; 1254 delay.msec = 0; 1255 pjsip_endpt_schedule_timer(endpt, &cd->timer, &delay); 1256 } 1198 1257 1199 1258 PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s", … … 2365 2424 #endif 2366 2425 2426 /* Initialize calls data */ 2427 for (i=0; i<PJ_ARRAY_SIZE(app_config.call_data); ++i) { 2428 app_config.call_data[i].timer.id = PJSUA_INVALID_ID; 2429 app_config.call_data[i].timer.cb = &call_timeout_callback; 2430 } 2431 2367 2432 /* Optionally registers WAV file */ 2368 2433 if (app_config.wav_file.slen) { -
pjproject/trunk/pjsip/include/pjsip/sip_msg.h
r622 r715 880 880 const pj_str_t *hvalue); 881 881 882 882 883 /** 883 884 * Initialize a preallocated memory with the header structure. This function … … 903 904 const pj_str_t *hvalue); 904 905 906 907 /** 908 * Construct a generic string header without allocating memory from the pool. 909 * This function is useful to create a temporary header which life-time is 910 * very short (for example, creating the header in the stack to be passed 911 * as argument to a function which will copy the header). 912 * 913 * @param pool The pool. 914 * @param hname The header name to be assigned to the header, or NULL to 915 * assign the header name with some string. 916 * @param hvalue Optional string to be assigned as the value. 917 * 918 * @return The header, or THROW exception. 919 */ 920 PJ_DECL(void) pjsip_generic_string_hdr_init2(pjsip_generic_string_hdr *h, 921 pj_str_t *hname, 922 pj_str_t *hvalue); 905 923 906 924 -
pjproject/trunk/pjsip/src/pjsip/sip_msg.c
r713 r715 506 506 }; 507 507 508 509 PJ_DEF(void) pjsip_generic_string_hdr_init2(pjsip_generic_string_hdr *hdr, 510 pj_str_t *hname, 511 pj_str_t *hvalue) 512 { 513 init_hdr(hdr, PJSIP_H_OTHER, &generic_hdr_vptr); 514 if (hname) { 515 hdr->name = *hname; 516 hdr->sname = *hname; 517 } 518 if (hvalue) { 519 hdr->hvalue = *hvalue; 520 } else { 521 hdr->hvalue.ptr = NULL; 522 hdr->hvalue.slen = 0; 523 } 524 } 525 526 508 527 PJ_DEF(pjsip_generic_string_hdr*) 509 528 pjsip_generic_string_hdr_init( pj_pool_t *pool, … … 513 532 { 514 533 pjsip_generic_string_hdr *hdr = mem; 515 516 init_hdr(hdr, PJSIP_H_OTHER, &generic_hdr_vptr); 534 pj_str_t dup_hname, dup_hval; 535 517 536 if (hnames) { 518 pj_strdup(pool, &hdr->name, hnames); 519 hdr->sname = hdr->name; 520 } 537 pj_strdup(pool, &dup_hname, hnames); 538 } else { 539 dup_hname.slen = 0; 540 } 541 521 542 if (hvalue) { 522 pj_strdup(pool, & hdr->hvalue, hvalue);543 pj_strdup(pool, &dup_hval, hvalue); 523 544 } else { 524 hdr->hvalue.ptr = NULL;525 hdr->hvalue.slen = 0; 526 } 527 545 dup_hval.slen = 0; 546 } 547 548 pjsip_generic_string_hdr_init2(hdr, &dup_hname, &dup_hval); 528 549 return hdr; 529 550 }
Note: See TracChangeset
for help on using the changeset viewer.