- Timestamp:
- May 3, 2006 6:16:06 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r412 r430 35 35 " Program options:\n" 36 36 " --count=N, -c Set number of calls to create (default:1) \n" 37 " --duration=SEC, -d Set maximum call duration (default:unlimited) \n" 38 " --auto-quit, -q Quit when calls have been completed (default:no)\n" 37 39 "\n" 38 40 " Address and ports options:\n" … … 129 131 pj_time_val response_time; 130 132 pj_time_val connect_time; 133 134 pj_timer_entry d_timer; /**< Disconnect timer. */ 131 135 }; 132 136 … … 135 139 { 136 140 unsigned max_calls; 141 unsigned uac_calls; 142 unsigned duration; 143 pj_bool_t auto_quit; 137 144 unsigned thread_count; 138 145 int sip_port; … … 188 195 struct call *call, 189 196 pjmedia_sdp_session **p_sdp); 197 198 /* Hangup call */ 199 static void hangup_call(unsigned index); 190 200 191 201 /* Destroy the call's media */ … … 524 534 dst_uri, /* remote target */ 525 535 &dlg); /* dialog */ 526 if (status != PJ_SUCCESS) 536 if (status != PJ_SUCCESS) { 537 ++app.uac_calls; 527 538 return status; 539 } 528 540 529 541 /* Create SDP */ … … 534 546 if (status != PJ_SUCCESS) { 535 547 pjsip_dlg_terminate(dlg); 548 ++app.uac_calls; 536 549 return status; 537 550 } … … 682 695 683 696 697 /* Callback timer to disconnect call (limiting call duration) */ 698 static void timer_disconnect_call( pj_timer_heap_t *timer_heap, 699 struct pj_timer_entry *entry) 700 { 701 struct call *call = entry->user_data; 702 703 PJ_UNUSED_ARG(timer_heap); 704 705 entry->id = 0; 706 hangup_call(call->index); 707 } 708 709 684 710 /* Callback to be called when invite session's state has changed: */ 685 711 static void call_on_state_changed( pjsip_inv_session *inv, … … 696 722 697 723 pj_time_val null_time = {0, 0}; 724 725 if (call->d_timer.id != 0) { 726 pjsip_endpt_cancel_timer(app.sip_endpt, &call->d_timer); 727 call->d_timer.id = 0; 728 } 698 729 699 730 PJ_LOG(3,(THIS_FILE, "Call #%d disconnected. Reason=%s", … … 713 744 call->connect_time = null_time; 714 745 746 ++app.uac_calls; 715 747 716 748 } else if (inv->state == PJSIP_INV_STATE_CONFIRMED) { … … 728 760 PJ_TIME_VAL_MSEC(t))); 729 761 762 if (app.duration != 0) { 763 call->d_timer.id = 1; 764 call->d_timer.user_data = call; 765 call->d_timer.cb = &timer_disconnect_call; 766 767 t.sec = app.duration; 768 t.msec = 0; 769 770 pjsip_endpt_schedule_timer(app.sip_endpt, &call->d_timer, &t); 771 } 772 730 773 } else if ( inv->state == PJSIP_INV_STATE_EARLY || 731 774 inv->state == PJSIP_INV_STATE_CONNECTING) { … … 775 818 struct pj_getopt_option long_options[] = { 776 819 { "count", 1, 0, 'c' }, 820 { "duration", 1, 0, 'd' }, 821 { "auto-quit", 0, 0, 'q' }, 777 822 { "local-port", 1, 0, 'p' }, 778 823 { "rtp-port", 1, 0, 'r' }, … … 820 865 /* Parse options */ 821 866 pj_optind = 0; 822 while((c=pj_getopt_long(argc,argv, "c: p:r:i:l:",867 while((c=pj_getopt_long(argc,argv, "c:d:p:r:i:l:q", 823 868 long_options, &option_index))!=-1) 824 869 { … … 831 876 } 832 877 break; 878 case 'd': 879 app.duration = atoi(pj_optarg); 880 break; 881 case 'q': 882 app.auto_quit = 1; 883 break; 884 833 885 case 'p': 834 886 app.sip_port = atoi(pj_optarg); … … 1760 1812 return 1; 1761 1813 1814 /* Verify options: */ 1815 1816 /* Auto-quit can not be specified for UAS */ 1817 if (app.auto_quit && app.uri_to_call.slen == 0) { 1818 printf("Error: --auto-quit option only valid for outgoing " 1819 "mode (UAC) only\n"); 1820 return 1; 1821 } 1822 1762 1823 /* Init logging */ 1763 1824 status = app_logging_init(); … … 1805 1866 } 1806 1867 1868 if (app.auto_quit) { 1869 /* Wait for calls to complete */ 1870 while (app.uac_calls < app.max_calls) 1871 pj_thread_sleep(100); 1872 pj_thread_sleep(200); 1873 } else { 1874 /* Start user interface loop */ 1875 console_main(); 1876 } 1877 1807 1878 } else { 1808 1879 1809 1880 PJ_LOG(3,(THIS_FILE, "Ready for incoming calls (max=%d)", 1810 1881 app.max_calls)); 1811 } 1812 1813 /* Start user interface loop */ 1814 console_main(); 1882 1883 /* Start user interface loop */ 1884 console_main(); 1885 1886 } 1815 1887 1816 1888
Note: See TracChangeset
for help on using the changeset viewer.