Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1 | /* $Id$ */ |
| 2 | /* |
Benny Prijono | 844653c | 2008-12-23 17:27:53 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008-2009 Teluu Inc. (http://www.teluu.com) |
Benny Prijono | 32177c0 | 2008-06-20 22:44:47 +0000 | [diff] [blame] | 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | #include <pjsua-lib/pjsua.h> |
| 21 | |
| 22 | |
Benny Prijono | 4ab9fbb | 2007-10-12 12:14:27 +0000 | [diff] [blame] | 23 | #define THIS_FILE "pjsua_app.c" |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 24 | #define NO_LIMIT (int)0x7FFFFFFF |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 25 | |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 26 | //#define STEREO_DEMO |
Benny Prijono | 40860c3 | 2008-09-04 13:55:33 +0000 | [diff] [blame] | 27 | //#define TRANSPORT_ADAPTER_SAMPLE |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 28 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 29 | /* Ringtones US UK */ |
| 30 | #define RINGBACK_FREQ1 440 /* 400 */ |
| 31 | #define RINGBACK_FREQ2 480 /* 450 */ |
| 32 | #define RINGBACK_ON 2000 /* 400 */ |
| 33 | #define RINGBACK_OFF 4000 /* 200 */ |
| 34 | #define RINGBACK_CNT 1 /* 2 */ |
| 35 | #define RINGBACK_INTERVAL 4000 /* 2000 */ |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 36 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 37 | #define RING_FREQ1 800 |
| 38 | #define RING_FREQ2 640 |
| 39 | #define RING_ON 200 |
| 40 | #define RING_OFF 100 |
| 41 | #define RING_CNT 3 |
| 42 | #define RING_INTERVAL 3000 |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 43 | |
| 44 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 45 | /* Call specific data */ |
| 46 | struct call_data |
| 47 | { |
| 48 | pj_timer_entry timer; |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 49 | pj_bool_t ringback_on; |
| 50 | pj_bool_t ring_on; |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 53 | |
| 54 | /* Pjsua application data */ |
| 55 | static struct app_config |
| 56 | { |
| 57 | pjsua_config cfg; |
| 58 | pjsua_logging_config log_cfg; |
| 59 | pjsua_media_config media_cfg; |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 60 | pj_bool_t no_refersub; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 61 | pj_bool_t no_tcp; |
| 62 | pj_bool_t no_udp; |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 63 | pj_bool_t use_tls; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 64 | pjsua_transport_config udp_cfg; |
| 65 | pjsua_transport_config rtp_cfg; |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 66 | pjsip_redirect_op redir_op; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 67 | |
| 68 | unsigned acc_cnt; |
| 69 | pjsua_acc_config acc_cfg[PJSUA_MAX_ACC]; |
| 70 | |
| 71 | unsigned buddy_cnt; |
| 72 | pjsua_buddy_config buddy_cfg[PJSUA_MAX_BUDDIES]; |
| 73 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 74 | struct call_data call_data[PJSUA_MAX_CALLS]; |
| 75 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 76 | pj_pool_t *pool; |
| 77 | /* Compatibility with older pjsua */ |
| 78 | |
| 79 | unsigned codec_cnt; |
| 80 | pj_str_t codec_arg[32]; |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 81 | unsigned codec_dis_cnt; |
| 82 | pj_str_t codec_dis[32]; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 83 | pj_bool_t null_audio; |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 84 | unsigned wav_count; |
| 85 | pj_str_t wav_files[32]; |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 86 | unsigned tone_count; |
| 87 | pjmedia_tone_desc tones[32]; |
| 88 | pjsua_conf_port_id tone_slots[32]; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 89 | pjsua_player_id wav_id; |
| 90 | pjsua_conf_port_id wav_port; |
| 91 | pj_bool_t auto_play; |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 92 | pj_bool_t auto_play_hangup; |
| 93 | pj_timer_entry auto_hangup_timer; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 94 | pj_bool_t auto_loop; |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 95 | pj_bool_t auto_conf; |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 96 | pj_str_t rec_file; |
| 97 | pj_bool_t auto_rec; |
| 98 | pjsua_recorder_id rec_id; |
| 99 | pjsua_conf_port_id rec_port; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 100 | unsigned auto_answer; |
| 101 | unsigned duration; |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 102 | |
| 103 | #ifdef STEREO_DEMO |
| 104 | pjmedia_snd_port *snd; |
| 105 | #endif |
| 106 | |
Benny Prijono | 6dd967c | 2006-12-26 02:27:14 +0000 | [diff] [blame] | 107 | float mic_level, |
| 108 | speaker_level; |
| 109 | |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 110 | int capture_dev, playback_dev; |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 111 | unsigned capture_lat, playback_lat; |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 112 | |
| 113 | pj_bool_t no_tones; |
| 114 | int ringback_slot; |
| 115 | int ringback_cnt; |
| 116 | pjmedia_port *ringback_port; |
| 117 | int ring_slot; |
| 118 | int ring_cnt; |
| 119 | pjmedia_port *ring_port; |
| 120 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 121 | } app_config; |
| 122 | |
| 123 | |
Benny Prijono | 21b9ad9 | 2006-08-15 13:11:22 +0000 | [diff] [blame] | 124 | //static pjsua_acc_id current_acc; |
| 125 | #define current_acc pjsua_acc_get_default() |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 126 | static pjsua_call_id current_call = PJSUA_INVALID_ID; |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 127 | static pj_bool_t cmd_echo; |
| 128 | static int stdout_refresh = -1; |
| 129 | static const char *stdout_refresh_text = "STDOUT_REFRESH"; |
| 130 | static pj_bool_t stdout_refresh_quit = PJ_FALSE; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 131 | static pj_str_t uri_arg; |
| 132 | |
Nanang Izzuddin | 660eee8 | 2008-07-17 14:54:03 +0000 | [diff] [blame] | 133 | static char some_buf[1024 * 3]; |
Benny Prijono | 6eddd87 | 2008-03-21 13:46:08 +0000 | [diff] [blame] | 134 | |
Benny Prijono | 594e4c5 | 2006-09-14 18:51:01 +0000 | [diff] [blame] | 135 | #ifdef STEREO_DEMO |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 136 | static void stereo_demo(); |
Benny Prijono | 594e4c5 | 2006-09-14 18:51:01 +0000 | [diff] [blame] | 137 | #endif |
Benny Prijono | 40860c3 | 2008-09-04 13:55:33 +0000 | [diff] [blame] | 138 | #ifdef TRANSPORT_ADAPTER_SAMPLE |
| 139 | static pj_status_t transport_adapter_sample(void); |
| 140 | #endif |
Benny Prijono | ad2e0ca | 2007-04-29 12:31:51 +0000 | [diff] [blame] | 141 | pj_status_t app_destroy(void); |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 142 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 143 | static void ringback_start(pjsua_call_id call_id); |
| 144 | static void ring_start(pjsua_call_id call_id); |
| 145 | static void ring_stop(pjsua_call_id call_id); |
| 146 | |
| 147 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 148 | /***************************************************************************** |
| 149 | * Configuration manipulation |
| 150 | */ |
| 151 | |
| 152 | /* Show usage */ |
| 153 | static void usage(void) |
| 154 | { |
| 155 | puts ("Usage:"); |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 156 | puts (" pjsua [options] [SIP URL to call]"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 157 | puts (""); |
| 158 | puts ("General options:"); |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 159 | puts (" --config-file=file Read the config/arguments from file."); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 160 | puts (" --help Display this help screen"); |
| 161 | puts (" --version Display version info"); |
| 162 | puts (""); |
| 163 | puts ("Logging options:"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 164 | puts (" --log-file=fname Log to filename (default stderr)"); |
| 165 | puts (" --log-level=N Set log max level to N (0(none) to 6(trace)) (default=5)"); |
| 166 | puts (" --app-log-level=N Set log max level for stdout display (default=4)"); |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 167 | puts (" --color Use colorful logging (default yes on Win32)"); |
| 168 | puts (" --no-color Disable colorful logging"); |
Benny Prijono | b794486 | 2008-07-19 20:53:49 +0000 | [diff] [blame] | 169 | puts (" --light-bg Use dark colors for light background (default is dark bg)"); |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 170 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 171 | puts (""); |
| 172 | puts ("SIP Account options:"); |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 173 | puts (" --use-ims Enable 3GPP/IMS related settings on this account"); |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 174 | #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 175 | puts (" --use-srtp=N Use SRTP? 0:disabled, 1:optional, 2:mandatory (def:0)"); |
| 176 | puts (" --srtp-secure=N SRTP require secure SIP? 0:no, 1:tls, 1:sips (def:1)"); |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 177 | #endif |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 178 | puts (" --registrar=url Set the URL of registrar server"); |
| 179 | puts (" --id=url Set the URL of local ID (used in From header)"); |
| 180 | puts (" --contact=url Optionally override the Contact information"); |
Benny Prijono | 30fe485 | 2008-12-10 16:54:16 +0000 | [diff] [blame] | 181 | puts (" --contact-params=S Append the specified parameters S in Contact URI"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 182 | puts (" --proxy=url Optional URL of proxy server to visit"); |
| 183 | puts (" May be specified multiple times"); |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 184 | puts (" --reg-timeout=SEC Optional registration interval (default 55)"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 185 | puts (" --realm=string Set realm"); |
| 186 | puts (" --username=string Set authentication username"); |
| 187 | puts (" --password=string Set authentication password"); |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 188 | puts (" --publish Send presence PUBLISH for this account"); |
Benny Prijono | dcfc0ba | 2007-09-30 16:50:27 +0000 | [diff] [blame] | 189 | puts (" --use-100rel Require reliable provisional response (100rel)"); |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 190 | puts (" --auto-update-nat=N Where N is 0 or 1 to enable/disable SIP traversal behind"); |
| 191 | puts (" symmetric NAT (default 1)"); |
Benny Prijono | b67eaac | 2007-02-18 20:56:00 +0000 | [diff] [blame] | 192 | puts (" --next-cred Add another credentials"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 193 | puts (""); |
| 194 | puts ("SIP Account Control:"); |
| 195 | puts (" --next-account Add more account"); |
| 196 | puts (""); |
| 197 | puts ("Transport Options:"); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 198 | puts (" --local-port=port Set TCP/UDP port. This implicitly enables both "); |
| 199 | puts (" TCP and UDP transports on the specified port, unless"); |
| 200 | puts (" if TCP or UDP is disabled."); |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 201 | puts (" --ip-addr=IP Use the specifed address as SIP and RTP addresses."); |
| 202 | puts (" (Hint: the IP may be the public IP of the NAT/router)"); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 203 | puts (" --no-tcp Disable TCP transport."); |
| 204 | puts (" --no-udp Disable UDP transport."); |
Benny Prijono | fa9e5b1 | 2006-10-08 12:39:34 +0000 | [diff] [blame] | 205 | puts (" --nameserver=NS Add the specified nameserver to enable SRV resolution"); |
| 206 | puts (" This option can be specified multiple times."); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 207 | puts (" --outbound=url Set the URL of global outbound proxy server"); |
| 208 | puts (" May be specified multiple times"); |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 209 | puts (" --stun-srv=name Set STUN server host or domain"); |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 210 | puts (""); |
| 211 | puts ("TLS Options:"); |
Benny Prijono | b67eaac | 2007-02-18 20:56:00 +0000 | [diff] [blame] | 212 | puts (" --use-tls Enable TLS transport (default=no)"); |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 213 | puts (" --tls-ca-file Specify TLS CA file (default=none)"); |
| 214 | puts (" --tls-cert-file Specify TLS certificate file (default=none)"); |
| 215 | puts (" --tls-privkey-file Specify TLS private key file (default=none)"); |
| 216 | puts (" --tls-password Specify TLS password to private key file (default=none)"); |
| 217 | puts (" --tls-verify-server Verify server's certificate (default=no)"); |
| 218 | puts (" --tls-verify-client Verify client's certificate (default=no)"); |
| 219 | puts (" --tls-neg-timeout Specify TLS negotiation timeout (default=no)"); |
Benny Prijono | e10db84 | 2008-07-01 15:31:59 +0000 | [diff] [blame] | 220 | puts (" --tls-srv-name Specify TLS server name for multi-hosting server (optional)"); |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 221 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 222 | puts (""); |
| 223 | puts ("Media Options:"); |
| 224 | puts (" --add-codec=name Manually add codec (default is to enable all)"); |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 225 | puts (" --dis-codec=name Disable codec (can be specified multiple times)"); |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 226 | puts (" --clock-rate=N Override conference bridge clock rate"); |
| 227 | puts (" --snd-clock-rate=N Override sound device clock rate"); |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 228 | puts (" --stereo Audio device and conference bridge opened in stereo mode"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 229 | puts (" --null-audio Use NULL audio device"); |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 230 | puts (" --play-file=file Register WAV file in conference bridge."); |
| 231 | puts (" This can be specified multiple times."); |
Benny Prijono | b67eaac | 2007-02-18 20:56:00 +0000 | [diff] [blame] | 232 | puts (" --play-tone=FORMAT Register tone to the conference bridge."); |
| 233 | puts (" FORMAT is 'F1,F2,ON,OFF', where F1,F2 are"); |
| 234 | puts (" frequencies, and ON,OFF=on/off duration in msec."); |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 235 | puts (" This can be specified multiple times."); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 236 | puts (" --auto-play Automatically play the file (to incoming calls only)"); |
| 237 | puts (" --auto-loop Automatically loop incoming RTP to outgoing RTP"); |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 238 | puts (" --auto-conf Automatically put calls in conference with others"); |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 239 | puts (" --rec-file=file Open file recorder (extension can be .wav or .mp3"); |
| 240 | puts (" --auto-rec Automatically record conversation"); |
Benny Prijono | 00cae61 | 2006-07-31 15:19:36 +0000 | [diff] [blame] | 241 | puts (" --quality=N Specify media quality (0-10, default=6)"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 242 | puts (" --ptime=MSEC Override codec ptime to MSEC (default=specific)"); |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 243 | puts (" --no-vad Disable VAD/silence detector (default=vad enabled)"); |
Benny Prijono | d79f25c | 2006-08-02 19:41:37 +0000 | [diff] [blame] | 244 | puts (" --ec-tail=MSEC Set echo canceller tail length (default=256)"); |
Benny Prijono | 59b3ffe | 2008-08-11 18:10:42 +0000 | [diff] [blame] | 245 | puts (" --ec-opt=OPT Select echo canceller algorithm (0=default, "); |
| 246 | puts (" 1=speex, 2=suppressor)"); |
Benny Prijono | 00cae61 | 2006-07-31 15:19:36 +0000 | [diff] [blame] | 247 | puts (" --ilbc-mode=MODE Set iLBC codec mode (20 or 30, default is 20)"); |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 248 | puts (" --capture-dev=id Audio capture device ID (default=-1)"); |
| 249 | puts (" --playback-dev=id Audio playback device ID (default=-1)"); |
Nanang Izzuddin | 81e9bd5 | 2008-06-27 12:52:51 +0000 | [diff] [blame] | 250 | puts (" --capture-lat=N Audio capture latency, in ms (default=100)"); |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 251 | puts (" --playback-lat=N Audio playback latency, in ms (default=100)"); |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 252 | puts (" --snd-auto-close=N Auto close audio device when it is idle for N seconds."); |
| 253 | puts (" Specify N=-1 (default) to disable this feature."); |
| 254 | puts (" Specify N=0 for instant close when unused."); |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 255 | puts (" --no-tones Disable audible tones"); |
Nanang Izzuddin | c985354 | 2008-07-17 16:59:07 +0000 | [diff] [blame] | 256 | puts (" --jb-max-size Specify jitter buffer maximum size, in frames (default=-1)"); |
Benny Prijono | 00cae61 | 2006-07-31 15:19:36 +0000 | [diff] [blame] | 257 | |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 258 | puts (""); |
| 259 | puts ("Media Transport Options:"); |
| 260 | puts (" --use-ice Enable ICE (default:no)"); |
Benny Prijono | 551af42 | 2008-08-07 09:55:52 +0000 | [diff] [blame] | 261 | puts (" --ice-no-host Disable ICE host candidates (default: no)"); |
| 262 | puts (" --ice-no-rtcp Disable RTCP component in ICE (default: no)"); |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 263 | puts (" --rtp-port=N Base port to try for RTP (default=4000)"); |
| 264 | puts (" --rx-drop-pct=PCT Drop PCT percent of RX RTP (for pkt lost sim, default: 0)"); |
| 265 | puts (" --tx-drop-pct=PCT Drop PCT percent of TX RTP (for pkt lost sim, default: 0)"); |
| 266 | puts (" --use-turn Enable TURN relay with ICE (default:no)"); |
| 267 | puts (" --turn-srv Domain or host name of TURN server (\"NAME:PORT\" format)"); |
| 268 | puts (" --turn-tcp Use TCP connection to TURN server (default no)"); |
| 269 | puts (" --turn-user TURN username"); |
| 270 | puts (" --turn-passwd TURN password"); |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 271 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 272 | puts (""); |
| 273 | puts ("Buddy List (can be more than one):"); |
| 274 | puts (" --add-buddy url Add the specified URL to the buddy list."); |
| 275 | puts (""); |
| 276 | puts ("User Agent options:"); |
| 277 | puts (" --auto-answer=code Automatically answer incoming calls with code (e.g. 200)"); |
| 278 | puts (" --max-calls=N Maximum number of concurrent calls (default:4, max:255)"); |
Benny Prijono | f521eb0 | 2006-08-06 23:07:25 +0000 | [diff] [blame] | 279 | puts (" --thread-cnt=N Number of worker threads (default:1)"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 280 | puts (" --duration=SEC Set maximum call duration (default:no limit)"); |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 281 | puts (" --norefersub Suppress event subscription when transfering calls"); |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 282 | puts (" --use-compact-form Minimize SIP message size"); |
Benny Prijono | 91d06b6 | 2008-09-20 12:16:56 +0000 | [diff] [blame] | 283 | puts (" --no-force-lr Allow strict-route to be used (i.e. do not force lr)"); |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 284 | puts (" --accept-redirect=N Specify how to handle call redirect (3xx) response."); |
| 285 | puts (" 0: reject, 1: follow automatically (default), 2: ask"); |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 286 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 287 | puts (""); |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 288 | puts ("When URL is specified, pjsua will immediately initiate call to that URL"); |
| 289 | puts (""); |
| 290 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 291 | fflush(stdout); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | /* Set default config. */ |
| 296 | static void default_config(struct app_config *cfg) |
| 297 | { |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 298 | char tmp[80]; |
Benny Prijono | 1febfdf | 2007-02-18 01:35:04 +0000 | [diff] [blame] | 299 | unsigned i; |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 300 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 301 | pjsua_config_default(&cfg->cfg); |
Benny Prijono | 106f5b7 | 2007-08-30 13:49:33 +0000 | [diff] [blame] | 302 | pj_ansi_sprintf(tmp, "PJSUA v%s/%s", pj_get_version(), PJ_OS_NAME); |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 303 | pj_strdup2_with_null(app_config.pool, &cfg->cfg.user_agent, tmp); |
| 304 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 305 | pjsua_logging_config_default(&cfg->log_cfg); |
| 306 | pjsua_media_config_default(&cfg->media_cfg); |
| 307 | pjsua_transport_config_default(&cfg->udp_cfg); |
| 308 | cfg->udp_cfg.port = 5060; |
| 309 | pjsua_transport_config_default(&cfg->rtp_cfg); |
| 310 | cfg->rtp_cfg.port = 4000; |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 311 | cfg->redir_op = PJSIP_REDIRECT_ACCEPT; |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 312 | cfg->duration = NO_LIMIT; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 313 | cfg->wav_id = PJSUA_INVALID_ID; |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 314 | cfg->rec_id = PJSUA_INVALID_ID; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 315 | cfg->wav_port = PJSUA_INVALID_ID; |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 316 | cfg->rec_port = PJSUA_INVALID_ID; |
Benny Prijono | 6dd967c | 2006-12-26 02:27:14 +0000 | [diff] [blame] | 317 | cfg->mic_level = cfg->speaker_level = 1.0; |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 318 | cfg->capture_dev = PJSUA_INVALID_ID; |
| 319 | cfg->playback_dev = PJSUA_INVALID_ID; |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 320 | cfg->capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY; |
| 321 | cfg->playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 322 | cfg->ringback_slot = PJSUA_INVALID_ID; |
| 323 | cfg->ring_slot = PJSUA_INVALID_ID; |
Benny Prijono | 1febfdf | 2007-02-18 01:35:04 +0000 | [diff] [blame] | 324 | |
| 325 | for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i) |
| 326 | pjsua_acc_config_default(&cfg->acc_cfg[i]); |
| 327 | |
| 328 | for (i=0; i<PJ_ARRAY_SIZE(cfg->buddy_cfg); ++i) |
| 329 | pjsua_buddy_config_default(&cfg->buddy_cfg[i]); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
| 333 | /* |
| 334 | * Read command arguments from config file. |
| 335 | */ |
| 336 | static int read_config_file(pj_pool_t *pool, const char *filename, |
| 337 | int *app_argc, char ***app_argv) |
| 338 | { |
| 339 | int i; |
| 340 | FILE *fhnd; |
| 341 | char line[200]; |
| 342 | int argc = 0; |
| 343 | char **argv; |
| 344 | enum { MAX_ARGS = 64 }; |
| 345 | |
| 346 | /* Allocate MAX_ARGS+1 (argv needs to be terminated with NULL argument) */ |
| 347 | argv = pj_pool_calloc(pool, MAX_ARGS+1, sizeof(char*)); |
| 348 | argv[argc++] = *app_argv[0]; |
| 349 | |
| 350 | /* Open config file. */ |
| 351 | fhnd = fopen(filename, "rt"); |
| 352 | if (!fhnd) { |
| 353 | PJ_LOG(1,(THIS_FILE, "Unable to open config file %s", filename)); |
| 354 | fflush(stdout); |
| 355 | return -1; |
| 356 | } |
| 357 | |
| 358 | /* Scan tokens in the file. */ |
| 359 | while (argc < MAX_ARGS && !feof(fhnd)) { |
Benny Prijono | bf5b469 | 2007-06-28 03:20:17 +0000 | [diff] [blame] | 360 | char *token; |
| 361 | char *p; |
| 362 | const char *whitespace = " \t\r\n"; |
| 363 | char cDelimiter; |
| 364 | int len, token_len; |
| 365 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 366 | if (fgets(line, sizeof(line), fhnd) == NULL) break; |
Benny Prijono | bf5b469 | 2007-06-28 03:20:17 +0000 | [diff] [blame] | 367 | |
| 368 | // Trim ending newlines |
| 369 | len = strlen(line); |
| 370 | if (line[len-1]=='\n') |
| 371 | line[--len] = '\0'; |
| 372 | if (line[len-1]=='\r') |
| 373 | line[--len] = '\0'; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 374 | |
Benny Prijono | bf5b469 | 2007-06-28 03:20:17 +0000 | [diff] [blame] | 375 | if (len==0) continue; |
| 376 | |
| 377 | for (p = line; *p != '\0' && argc < MAX_ARGS; p++) { |
| 378 | // first, scan whitespaces |
| 379 | while (*p != '\0' && strchr(whitespace, *p) != NULL) p++; |
| 380 | |
| 381 | if (*p == '\0') // are we done yet? |
| 382 | break; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 383 | |
Benny Prijono | bf5b469 | 2007-06-28 03:20:17 +0000 | [diff] [blame] | 384 | if (*p == '"' || *p == '\'') { // is token a quoted string |
| 385 | cDelimiter = *p++; // save quote delimiter |
| 386 | token = p; |
| 387 | |
| 388 | while (*p != '\0' && *p != cDelimiter) p++; |
| 389 | |
| 390 | if (*p == '\0') // found end of the line, but, |
| 391 | cDelimiter = '\0'; // didn't find a matching quote |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 392 | |
Benny Prijono | bf5b469 | 2007-06-28 03:20:17 +0000 | [diff] [blame] | 393 | } else { // token's not a quoted string |
| 394 | token = p; |
| 395 | |
| 396 | while (*p != '\0' && strchr(whitespace, *p) == NULL) p++; |
| 397 | |
| 398 | cDelimiter = *p; |
| 399 | } |
| 400 | |
| 401 | *p = '\0'; |
| 402 | token_len = p-token; |
| 403 | |
| 404 | if (token_len > 0) { |
| 405 | if (*token == '#') |
| 406 | break; // ignore remainder of line |
| 407 | |
| 408 | argv[argc] = pj_pool_alloc(pool, token_len + 1); |
| 409 | pj_memcpy(argv[argc], token, token_len + 1); |
| 410 | ++argc; |
| 411 | } |
| 412 | |
| 413 | *p = cDelimiter; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
| 417 | /* Copy arguments from command line */ |
| 418 | for (i=1; i<*app_argc && argc < MAX_ARGS; ++i) |
| 419 | argv[argc++] = (*app_argv)[i]; |
| 420 | |
| 421 | if (argc == MAX_ARGS && (i!=*app_argc || !feof(fhnd))) { |
| 422 | PJ_LOG(1,(THIS_FILE, |
| 423 | "Too many arguments specified in cmd line/config file")); |
| 424 | fflush(stdout); |
| 425 | fclose(fhnd); |
| 426 | return -1; |
| 427 | } |
| 428 | |
| 429 | fclose(fhnd); |
| 430 | |
| 431 | /* Assign the new command line back to the original command line. */ |
| 432 | *app_argc = argc; |
| 433 | *app_argv = argv; |
| 434 | return 0; |
| 435 | |
| 436 | } |
| 437 | |
| 438 | static int my_atoi(const char *cs) |
| 439 | { |
| 440 | pj_str_t s; |
Benny Prijono | 1e2dbe6 | 2007-06-15 04:15:16 +0000 | [diff] [blame] | 441 | |
| 442 | pj_cstr(&s, cs); |
| 443 | if (cs[0] == '-') { |
| 444 | s.ptr++, s.slen--; |
| 445 | return 0 - (int)pj_strtoul(&s); |
| 446 | } else if (cs[0] == '+') { |
| 447 | s.ptr++, s.slen--; |
| 448 | return pj_strtoul(&s); |
| 449 | } else { |
| 450 | return pj_strtoul(&s); |
| 451 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
| 455 | /* Parse arguments. */ |
| 456 | static pj_status_t parse_args(int argc, char *argv[], |
| 457 | struct app_config *cfg, |
| 458 | pj_str_t *uri_to_call) |
| 459 | { |
| 460 | int c; |
| 461 | int option_index; |
Benny Prijono | af09dc3 | 2007-04-22 12:48:30 +0000 | [diff] [blame] | 462 | enum { OPT_CONFIG_FILE=127, OPT_LOG_FILE, OPT_LOG_LEVEL, OPT_APP_LOG_LEVEL, |
Benny Prijono | b794486 | 2008-07-19 20:53:49 +0000 | [diff] [blame] | 463 | OPT_COLOR, OPT_NO_COLOR, OPT_LIGHT_BG, |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 464 | OPT_HELP, OPT_VERSION, OPT_NULL_AUDIO, OPT_SND_AUTO_CLOSE, |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 465 | OPT_LOCAL_PORT, OPT_IP_ADDR, OPT_PROXY, OPT_OUTBOUND_PROXY, |
| 466 | OPT_REGISTRAR, OPT_REG_TIMEOUT, OPT_PUBLISH, OPT_ID, OPT_CONTACT, |
Benny Prijono | 30fe485 | 2008-12-10 16:54:16 +0000 | [diff] [blame] | 467 | OPT_CONTACT_PARAMS, |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 468 | OPT_100REL, OPT_USE_IMS, OPT_REALM, OPT_USERNAME, OPT_PASSWORD, |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 469 | OPT_NAMESERVER, OPT_STUN_DOMAIN, OPT_STUN_SRV, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 470 | OPT_ADD_BUDDY, OPT_OFFER_X_MS_MSG, OPT_NO_PRESENCE, |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 471 | OPT_AUTO_ANSWER, OPT_AUTO_PLAY, OPT_AUTO_PLAY_HANGUP, OPT_AUTO_LOOP, |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 472 | OPT_AUTO_CONF, OPT_CLOCK_RATE, OPT_SND_CLOCK_RATE, OPT_STEREO, |
| 473 | OPT_USE_ICE, OPT_USE_SRTP, OPT_SRTP_SECURE, |
Benny Prijono | 551af42 | 2008-08-07 09:55:52 +0000 | [diff] [blame] | 474 | OPT_USE_TURN, OPT_ICE_NO_HOST, OPT_ICE_NO_RTCP, OPT_TURN_SRV, |
| 475 | OPT_TURN_TCP, OPT_TURN_USER, OPT_TURN_PASSWD, |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 476 | OPT_PLAY_FILE, OPT_PLAY_TONE, OPT_RTP_PORT, OPT_ADD_CODEC, |
| 477 | OPT_ILBC_MODE, OPT_REC_FILE, OPT_AUTO_REC, |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 478 | OPT_COMPLEXITY, OPT_QUALITY, OPT_PTIME, OPT_NO_VAD, |
Benny Prijono | 59b3ffe | 2008-08-11 18:10:42 +0000 | [diff] [blame] | 479 | OPT_RX_DROP_PCT, OPT_TX_DROP_PCT, OPT_EC_TAIL, OPT_EC_OPT, |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 480 | OPT_NEXT_ACCOUNT, OPT_NEXT_CRED, OPT_MAX_CALLS, |
Benny Prijono | f521eb0 | 2006-08-06 23:07:25 +0000 | [diff] [blame] | 481 | OPT_DURATION, OPT_NO_TCP, OPT_NO_UDP, OPT_THREAD_CNT, |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 482 | OPT_NOREFERSUB, OPT_ACCEPT_REDIRECT, |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 483 | OPT_USE_TLS, OPT_TLS_CA_FILE, OPT_TLS_CERT_FILE, OPT_TLS_PRIV_FILE, |
| 484 | OPT_TLS_PASSWORD, OPT_TLS_VERIFY_SERVER, OPT_TLS_VERIFY_CLIENT, |
Benny Prijono | e10db84 | 2008-07-01 15:31:59 +0000 | [diff] [blame] | 485 | OPT_TLS_NEG_TIMEOUT, OPT_TLS_SRV_NAME, |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 486 | OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV, |
Nanang Izzuddin | c985354 | 2008-07-17 16:59:07 +0000 | [diff] [blame] | 487 | OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, OPT_NO_TONES, OPT_JB_MAX_SIZE, |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 488 | OPT_STDOUT_REFRESH, OPT_STDOUT_REFRESH_TEXT, |
Benny Prijono | 4d0da3a | 2008-06-26 20:23:47 +0000 | [diff] [blame] | 489 | #ifdef _IONBF |
| 490 | OPT_STDOUT_NO_BUF, |
| 491 | #endif |
Benny Prijono | 91d06b6 | 2008-09-20 12:16:56 +0000 | [diff] [blame] | 492 | OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC, |
| 493 | OPT_NO_FORCE_LR |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 494 | }; |
| 495 | struct pj_getopt_option long_options[] = { |
| 496 | { "config-file",1, 0, OPT_CONFIG_FILE}, |
| 497 | { "log-file", 1, 0, OPT_LOG_FILE}, |
| 498 | { "log-level", 1, 0, OPT_LOG_LEVEL}, |
| 499 | { "app-log-level",1,0,OPT_APP_LOG_LEVEL}, |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 500 | { "color", 0, 0, OPT_COLOR}, |
| 501 | { "no-color", 0, 0, OPT_NO_COLOR}, |
Benny Prijono | b794486 | 2008-07-19 20:53:49 +0000 | [diff] [blame] | 502 | { "light-bg", 0, 0, OPT_LIGHT_BG}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 503 | { "help", 0, 0, OPT_HELP}, |
| 504 | { "version", 0, 0, OPT_VERSION}, |
| 505 | { "clock-rate", 1, 0, OPT_CLOCK_RATE}, |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 506 | { "snd-clock-rate", 1, 0, OPT_SND_CLOCK_RATE}, |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 507 | { "stereo", 0, 0, OPT_STEREO}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 508 | { "null-audio", 0, 0, OPT_NULL_AUDIO}, |
| 509 | { "local-port", 1, 0, OPT_LOCAL_PORT}, |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 510 | { "ip-addr", 1, 0, OPT_IP_ADDR}, |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 511 | { "no-tcp", 0, 0, OPT_NO_TCP}, |
| 512 | { "no-udp", 0, 0, OPT_NO_UDP}, |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 513 | { "norefersub", 0, 0, OPT_NOREFERSUB}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 514 | { "proxy", 1, 0, OPT_PROXY}, |
| 515 | { "outbound", 1, 0, OPT_OUTBOUND_PROXY}, |
| 516 | { "registrar", 1, 0, OPT_REGISTRAR}, |
| 517 | { "reg-timeout",1, 0, OPT_REG_TIMEOUT}, |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 518 | { "publish", 0, 0, OPT_PUBLISH}, |
Benny Prijono | dcfc0ba | 2007-09-30 16:50:27 +0000 | [diff] [blame] | 519 | { "use-100rel", 0, 0, OPT_100REL}, |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 520 | { "use-ims", 0, 0, OPT_USE_IMS}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 521 | { "id", 1, 0, OPT_ID}, |
| 522 | { "contact", 1, 0, OPT_CONTACT}, |
Benny Prijono | 30fe485 | 2008-12-10 16:54:16 +0000 | [diff] [blame] | 523 | { "contact-params",1,0, OPT_CONTACT_PARAMS}, |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 524 | { "auto-update-nat", 1, 0, OPT_AUTO_UPDATE_NAT}, |
| 525 | { "use-compact-form", 0, 0, OPT_USE_COMPACT_FORM}, |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 526 | { "accept-redirect", 1, 0, OPT_ACCEPT_REDIRECT}, |
Benny Prijono | 91d06b6 | 2008-09-20 12:16:56 +0000 | [diff] [blame] | 527 | { "no-force-lr",0, 0, OPT_NO_FORCE_LR}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 528 | { "realm", 1, 0, OPT_REALM}, |
| 529 | { "username", 1, 0, OPT_USERNAME}, |
| 530 | { "password", 1, 0, OPT_PASSWORD}, |
Benny Prijono | fa9e5b1 | 2006-10-08 12:39:34 +0000 | [diff] [blame] | 531 | { "nameserver", 1, 0, OPT_NAMESERVER}, |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 532 | { "stun-domain",1, 0, OPT_STUN_DOMAIN}, |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 533 | { "stun-srv", 1, 0, OPT_STUN_SRV}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 534 | { "add-buddy", 1, 0, OPT_ADD_BUDDY}, |
| 535 | { "offer-x-ms-msg",0,0,OPT_OFFER_X_MS_MSG}, |
| 536 | { "no-presence", 0, 0, OPT_NO_PRESENCE}, |
| 537 | { "auto-answer",1, 0, OPT_AUTO_ANSWER}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 538 | { "auto-play", 0, 0, OPT_AUTO_PLAY}, |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 539 | { "auto-play-hangup",0, 0, OPT_AUTO_PLAY_HANGUP}, |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 540 | { "auto-rec", 0, 0, OPT_AUTO_REC}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 541 | { "auto-loop", 0, 0, OPT_AUTO_LOOP}, |
| 542 | { "auto-conf", 0, 0, OPT_AUTO_CONF}, |
| 543 | { "play-file", 1, 0, OPT_PLAY_FILE}, |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 544 | { "play-tone", 1, 0, OPT_PLAY_TONE}, |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 545 | { "rec-file", 1, 0, OPT_REC_FILE}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 546 | { "rtp-port", 1, 0, OPT_RTP_PORT}, |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 547 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 548 | { "use-ice", 0, 0, OPT_USE_ICE}, |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 549 | { "use-turn", 0, 0, OPT_USE_TURN}, |
| 550 | { "ice-no-host",0, 0, OPT_ICE_NO_HOST}, |
Benny Prijono | 551af42 | 2008-08-07 09:55:52 +0000 | [diff] [blame] | 551 | { "ice-no-rtcp",0, 0, OPT_ICE_NO_RTCP}, |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 552 | { "turn-srv", 1, 0, OPT_TURN_SRV}, |
| 553 | { "turn-tcp", 0, 0, OPT_TURN_TCP}, |
| 554 | { "turn-user", 1, 0, OPT_TURN_USER}, |
| 555 | { "turn-passwd",1, 0, OPT_TURN_PASSWD}, |
| 556 | |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 557 | #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) |
| 558 | { "use-srtp", 1, 0, OPT_USE_SRTP}, |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 559 | { "srtp-secure",1, 0, OPT_SRTP_SECURE}, |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 560 | #endif |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 561 | { "add-codec", 1, 0, OPT_ADD_CODEC}, |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 562 | { "dis-codec", 1, 0, OPT_DIS_CODEC}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 563 | { "complexity", 1, 0, OPT_COMPLEXITY}, |
| 564 | { "quality", 1, 0, OPT_QUALITY}, |
| 565 | { "ptime", 1, 0, OPT_PTIME}, |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 566 | { "no-vad", 0, 0, OPT_NO_VAD}, |
Benny Prijono | d79f25c | 2006-08-02 19:41:37 +0000 | [diff] [blame] | 567 | { "ec-tail", 1, 0, OPT_EC_TAIL}, |
Benny Prijono | 59b3ffe | 2008-08-11 18:10:42 +0000 | [diff] [blame] | 568 | { "ec-opt", 1, 0, OPT_EC_OPT}, |
Benny Prijono | 00cae61 | 2006-07-31 15:19:36 +0000 | [diff] [blame] | 569 | { "ilbc-mode", 1, 0, OPT_ILBC_MODE}, |
| 570 | { "rx-drop-pct",1, 0, OPT_RX_DROP_PCT}, |
| 571 | { "tx-drop-pct",1, 0, OPT_TX_DROP_PCT}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 572 | { "next-account",0,0, OPT_NEXT_ACCOUNT}, |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 573 | { "next-cred", 0, 0, OPT_NEXT_CRED}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 574 | { "max-calls", 1, 0, OPT_MAX_CALLS}, |
Benny Prijono | f521eb0 | 2006-08-06 23:07:25 +0000 | [diff] [blame] | 575 | { "duration", 1, 0, OPT_DURATION}, |
| 576 | { "thread-cnt", 1, 0, OPT_THREAD_CNT}, |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 577 | { "use-tls", 0, 0, OPT_USE_TLS}, |
| 578 | { "tls-ca-file",1, 0, OPT_TLS_CA_FILE}, |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 579 | { "tls-cert-file",1,0, OPT_TLS_CERT_FILE}, |
| 580 | { "tls-privkey-file",1,0, OPT_TLS_PRIV_FILE}, |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 581 | { "tls-password",1,0, OPT_TLS_PASSWORD}, |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 582 | { "tls-verify-server", 0, 0, OPT_TLS_VERIFY_SERVER}, |
| 583 | { "tls-verify-client", 0, 0, OPT_TLS_VERIFY_CLIENT}, |
| 584 | { "tls-neg-timeout", 1, 0, OPT_TLS_NEG_TIMEOUT}, |
Benny Prijono | e10db84 | 2008-07-01 15:31:59 +0000 | [diff] [blame] | 585 | { "tls-srv-name", 1, 0, OPT_TLS_SRV_NAME}, |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 586 | { "capture-dev", 1, 0, OPT_CAPTURE_DEV}, |
| 587 | { "playback-dev", 1, 0, OPT_PLAYBACK_DEV}, |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 588 | { "capture-lat", 1, 0, OPT_CAPTURE_LAT}, |
| 589 | { "playback-lat", 1, 0, OPT_PLAYBACK_LAT}, |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 590 | { "stdout-refresh", 1, 0, OPT_STDOUT_REFRESH}, |
| 591 | { "stdout-refresh-text", 1, 0, OPT_STDOUT_REFRESH_TEXT}, |
Benny Prijono | 4d0da3a | 2008-06-26 20:23:47 +0000 | [diff] [blame] | 592 | #ifdef _IONBF |
| 593 | { "stdout-no-buf", 0, 0, OPT_STDOUT_NO_BUF }, |
| 594 | #endif |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 595 | { "snd-auto-close", 1, 0, OPT_SND_AUTO_CLOSE}, |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 596 | { "no-tones", 0, 0, OPT_NO_TONES}, |
Nanang Izzuddin | c985354 | 2008-07-17 16:59:07 +0000 | [diff] [blame] | 597 | { "jb-max-size", 1, 0, OPT_JB_MAX_SIZE}, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 598 | { NULL, 0, 0, 0} |
| 599 | }; |
| 600 | pj_status_t status; |
| 601 | pjsua_acc_config *cur_acc; |
| 602 | char *config_file = NULL; |
| 603 | unsigned i; |
| 604 | |
| 605 | /* Run pj_getopt once to see if user specifies config file to read. */ |
Benny Prijono | f762ee7 | 2006-12-01 11:14:37 +0000 | [diff] [blame] | 606 | pj_optind = 0; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 607 | while ((c=pj_getopt_long(argc, argv, "", long_options, |
| 608 | &option_index)) != -1) |
| 609 | { |
| 610 | switch (c) { |
| 611 | case OPT_CONFIG_FILE: |
| 612 | config_file = pj_optarg; |
| 613 | break; |
| 614 | } |
| 615 | if (config_file) |
| 616 | break; |
| 617 | } |
| 618 | |
| 619 | if (config_file) { |
| 620 | status = read_config_file(app_config.pool, config_file, &argc, &argv); |
| 621 | if (status != 0) |
| 622 | return status; |
| 623 | } |
| 624 | |
| 625 | cfg->acc_cnt = 0; |
| 626 | cur_acc = &cfg->acc_cfg[0]; |
| 627 | |
| 628 | |
| 629 | /* Reinitialize and re-run pj_getopt again, possibly with new arguments |
| 630 | * read from config file. |
| 631 | */ |
| 632 | pj_optind = 0; |
| 633 | while((c=pj_getopt_long(argc,argv, "", long_options,&option_index))!=-1) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 634 | pj_str_t tmp; |
| 635 | long lval; |
| 636 | |
| 637 | switch (c) { |
| 638 | |
Benny Prijono | 6f13748 | 2006-06-15 11:31:36 +0000 | [diff] [blame] | 639 | case OPT_CONFIG_FILE: |
| 640 | /* Ignore as this has been processed before */ |
| 641 | break; |
| 642 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 643 | case OPT_LOG_FILE: |
| 644 | cfg->log_cfg.log_filename = pj_str(pj_optarg); |
| 645 | break; |
| 646 | |
| 647 | case OPT_LOG_LEVEL: |
| 648 | c = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
| 649 | if (c < 0 || c > 6) { |
| 650 | PJ_LOG(1,(THIS_FILE, |
| 651 | "Error: expecting integer value 0-6 " |
| 652 | "for --log-level")); |
| 653 | return PJ_EINVAL; |
| 654 | } |
| 655 | cfg->log_cfg.level = c; |
| 656 | pj_log_set_level( c ); |
| 657 | break; |
| 658 | |
| 659 | case OPT_APP_LOG_LEVEL: |
| 660 | cfg->log_cfg.console_level = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
| 661 | if (cfg->log_cfg.console_level < 0 || cfg->log_cfg.console_level > 6) { |
| 662 | PJ_LOG(1,(THIS_FILE, |
| 663 | "Error: expecting integer value 0-6 " |
| 664 | "for --app-log-level")); |
| 665 | return PJ_EINVAL; |
| 666 | } |
| 667 | break; |
| 668 | |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 669 | case OPT_COLOR: |
| 670 | cfg->log_cfg.decor |= PJ_LOG_HAS_COLOR; |
| 671 | break; |
| 672 | |
| 673 | case OPT_NO_COLOR: |
| 674 | cfg->log_cfg.decor &= ~PJ_LOG_HAS_COLOR; |
| 675 | break; |
| 676 | |
Benny Prijono | b794486 | 2008-07-19 20:53:49 +0000 | [diff] [blame] | 677 | case OPT_LIGHT_BG: |
| 678 | pj_log_set_color(1, PJ_TERM_COLOR_R); |
| 679 | pj_log_set_color(2, PJ_TERM_COLOR_R | PJ_TERM_COLOR_G); |
| 680 | pj_log_set_color(3, PJ_TERM_COLOR_B | PJ_TERM_COLOR_G); |
| 681 | pj_log_set_color(4, 0); |
| 682 | pj_log_set_color(5, 0); |
| 683 | pj_log_set_color(77, 0); |
| 684 | break; |
| 685 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 686 | case OPT_HELP: |
| 687 | usage(); |
| 688 | return PJ_EINVAL; |
| 689 | |
| 690 | case OPT_VERSION: /* version */ |
| 691 | pj_dump_config(); |
| 692 | return PJ_EINVAL; |
| 693 | |
| 694 | case OPT_NULL_AUDIO: |
| 695 | cfg->null_audio = PJ_TRUE; |
| 696 | break; |
| 697 | |
| 698 | case OPT_CLOCK_RATE: |
| 699 | lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
Benny Prijono | 5dfac8f | 2008-06-02 14:06:19 +0000 | [diff] [blame] | 700 | if (lval < 8000 || lval > 192000) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 701 | PJ_LOG(1,(THIS_FILE, "Error: expecting value between " |
Benny Prijono | 5dfac8f | 2008-06-02 14:06:19 +0000 | [diff] [blame] | 702 | "8000-192000 for conference clock rate")); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 703 | return PJ_EINVAL; |
| 704 | } |
| 705 | cfg->media_cfg.clock_rate = lval; |
| 706 | break; |
| 707 | |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 708 | case OPT_SND_CLOCK_RATE: |
| 709 | lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
Benny Prijono | 5dfac8f | 2008-06-02 14:06:19 +0000 | [diff] [blame] | 710 | if (lval < 8000 || lval > 192000) { |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 711 | PJ_LOG(1,(THIS_FILE, "Error: expecting value between " |
Benny Prijono | 5dfac8f | 2008-06-02 14:06:19 +0000 | [diff] [blame] | 712 | "8000-192000 for sound device clock rate")); |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 713 | return PJ_EINVAL; |
| 714 | } |
| 715 | cfg->media_cfg.snd_clock_rate = lval; |
| 716 | break; |
| 717 | |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 718 | case OPT_STEREO: |
| 719 | cfg->media_cfg.channel_count = 2; |
| 720 | break; |
| 721 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 722 | case OPT_LOCAL_PORT: /* local-port */ |
| 723 | lval = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
Benny Prijono | e347cb0 | 2007-02-14 14:36:13 +0000 | [diff] [blame] | 724 | if (lval < 0 || lval > 65535) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 725 | PJ_LOG(1,(THIS_FILE, |
| 726 | "Error: expecting integer value for " |
| 727 | "--local-port")); |
| 728 | return PJ_EINVAL; |
| 729 | } |
| 730 | cfg->udp_cfg.port = (pj_uint16_t)lval; |
| 731 | break; |
| 732 | |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 733 | case OPT_IP_ADDR: /* ip-addr */ |
| 734 | cfg->udp_cfg.public_addr = pj_str(pj_optarg); |
| 735 | cfg->rtp_cfg.public_addr = pj_str(pj_optarg); |
| 736 | break; |
| 737 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 738 | case OPT_NO_UDP: /* no-udp */ |
| 739 | if (cfg->no_tcp) { |
Benny Prijono | b988d76 | 2007-12-05 04:30:04 +0000 | [diff] [blame] | 740 | PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); |
| 741 | return PJ_EINVAL; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | cfg->no_udp = PJ_TRUE; |
| 745 | break; |
| 746 | |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 747 | case OPT_NOREFERSUB: /* norefersub */ |
| 748 | cfg->no_refersub = PJ_TRUE; |
| 749 | break; |
| 750 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 751 | case OPT_NO_TCP: /* no-tcp */ |
| 752 | if (cfg->no_udp) { |
Benny Prijono | b988d76 | 2007-12-05 04:30:04 +0000 | [diff] [blame] | 753 | PJ_LOG(1,(THIS_FILE,"Error: can not disable both TCP and UDP")); |
| 754 | return PJ_EINVAL; |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | cfg->no_tcp = PJ_TRUE; |
| 758 | break; |
| 759 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 760 | case OPT_PROXY: /* proxy */ |
| 761 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 762 | PJ_LOG(1,(THIS_FILE, |
| 763 | "Error: invalid SIP URL '%s' " |
| 764 | "in proxy argument", pj_optarg)); |
| 765 | return PJ_EINVAL; |
| 766 | } |
| 767 | cur_acc->proxy[cur_acc->proxy_cnt++] = pj_str(pj_optarg); |
| 768 | break; |
| 769 | |
| 770 | case OPT_OUTBOUND_PROXY: /* outbound proxy */ |
| 771 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 772 | PJ_LOG(1,(THIS_FILE, |
| 773 | "Error: invalid SIP URL '%s' " |
| 774 | "in outbound proxy argument", pj_optarg)); |
| 775 | return PJ_EINVAL; |
| 776 | } |
| 777 | cfg->cfg.outbound_proxy[cfg->cfg.outbound_proxy_cnt++] = pj_str(pj_optarg); |
| 778 | break; |
| 779 | |
| 780 | case OPT_REGISTRAR: /* registrar */ |
| 781 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 782 | PJ_LOG(1,(THIS_FILE, |
| 783 | "Error: invalid SIP URL '%s' in " |
| 784 | "registrar argument", pj_optarg)); |
| 785 | return PJ_EINVAL; |
| 786 | } |
| 787 | cur_acc->reg_uri = pj_str(pj_optarg); |
| 788 | break; |
| 789 | |
| 790 | case OPT_REG_TIMEOUT: /* reg-timeout */ |
| 791 | cur_acc->reg_timeout = pj_strtoul(pj_cstr(&tmp,pj_optarg)); |
| 792 | if (cur_acc->reg_timeout < 1 || cur_acc->reg_timeout > 3600) { |
| 793 | PJ_LOG(1,(THIS_FILE, |
| 794 | "Error: invalid value for --reg-timeout " |
| 795 | "(expecting 1-3600)")); |
| 796 | return PJ_EINVAL; |
| 797 | } |
| 798 | break; |
| 799 | |
Benny Prijono | 3a5e1ab | 2006-08-15 20:26:34 +0000 | [diff] [blame] | 800 | case OPT_PUBLISH: /* publish */ |
| 801 | cur_acc->publish_enabled = PJ_TRUE; |
| 802 | break; |
| 803 | |
Benny Prijono | dcfc0ba | 2007-09-30 16:50:27 +0000 | [diff] [blame] | 804 | case OPT_100REL: /** 100rel */ |
| 805 | cur_acc->require_100rel = PJ_TRUE; |
| 806 | cfg->cfg.require_100rel = PJ_TRUE; |
| 807 | break; |
| 808 | |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 809 | case OPT_USE_IMS: /* Activate IMS settings */ |
| 810 | cur_acc->auth_pref.initial_auth = PJ_TRUE; |
Benny Prijono | 2a67ea4 | 2007-10-25 02:51:33 +0000 | [diff] [blame] | 811 | break; |
| 812 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 813 | case OPT_ID: /* id */ |
| 814 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 815 | PJ_LOG(1,(THIS_FILE, |
| 816 | "Error: invalid SIP URL '%s' " |
| 817 | "in local id argument", pj_optarg)); |
| 818 | return PJ_EINVAL; |
| 819 | } |
| 820 | cur_acc->id = pj_str(pj_optarg); |
| 821 | break; |
| 822 | |
| 823 | case OPT_CONTACT: /* contact */ |
| 824 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 825 | PJ_LOG(1,(THIS_FILE, |
| 826 | "Error: invalid SIP URL '%s' " |
| 827 | "in contact argument", pj_optarg)); |
| 828 | return PJ_EINVAL; |
| 829 | } |
Benny Prijono | b4a17c9 | 2006-07-10 14:40:21 +0000 | [diff] [blame] | 830 | cur_acc->force_contact = pj_str(pj_optarg); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 831 | break; |
| 832 | |
Benny Prijono | 30fe485 | 2008-12-10 16:54:16 +0000 | [diff] [blame] | 833 | case OPT_CONTACT_PARAMS: |
| 834 | cur_acc->contact_params = pj_str(pj_optarg); |
| 835 | break; |
| 836 | |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 837 | case OPT_AUTO_UPDATE_NAT: /* OPT_AUTO_UPDATE_NAT */ |
Benny Prijono | e8554ef | 2008-03-22 09:33:52 +0000 | [diff] [blame] | 838 | cur_acc->allow_contact_rewrite = pj_strtoul(pj_cstr(&tmp, pj_optarg)); |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 839 | break; |
| 840 | |
| 841 | case OPT_USE_COMPACT_FORM: |
| 842 | /* enable compact form - from Ticket #342 */ |
| 843 | { |
| 844 | extern pj_bool_t pjsip_use_compact_form; |
| 845 | extern pj_bool_t pjsip_include_allow_hdr_in_dlg; |
| 846 | extern pj_bool_t pjmedia_add_rtpmap_for_static_pt; |
| 847 | |
| 848 | pjsip_use_compact_form = PJ_TRUE; |
| 849 | /* do not transmit Allow header */ |
| 850 | pjsip_include_allow_hdr_in_dlg = PJ_FALSE; |
| 851 | /* Do not include rtpmap for static payload types (<96) */ |
| 852 | pjmedia_add_rtpmap_for_static_pt = PJ_FALSE; |
| 853 | } |
| 854 | break; |
| 855 | |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 856 | case OPT_ACCEPT_REDIRECT: |
| 857 | cfg->redir_op = my_atoi(pj_optarg); |
| 858 | if (cfg->redir_op<0 || cfg->redir_op>PJSIP_REDIRECT_STOP) { |
| 859 | PJ_LOG(1,(THIS_FILE, |
| 860 | "Error: accept-redirect value '%s' ", pj_optarg)); |
| 861 | return PJ_EINVAL; |
| 862 | } |
| 863 | break; |
| 864 | |
Benny Prijono | 91d06b6 | 2008-09-20 12:16:56 +0000 | [diff] [blame] | 865 | case OPT_NO_FORCE_LR: |
| 866 | cfg->cfg.force_lr = PJ_FALSE; |
| 867 | break; |
| 868 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 869 | case OPT_NEXT_ACCOUNT: /* Add more account. */ |
| 870 | cfg->acc_cnt++; |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 871 | cur_acc = &cfg->acc_cfg[cfg->acc_cnt]; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 872 | break; |
| 873 | |
| 874 | case OPT_USERNAME: /* Default authentication user */ |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 875 | cur_acc->cred_info[cur_acc->cred_count].username = pj_str(pj_optarg); |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 876 | cur_acc->cred_info[cur_acc->cred_count].scheme = pj_str("Digest"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | case OPT_REALM: /* Default authentication realm. */ |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 880 | cur_acc->cred_info[cur_acc->cred_count].realm = pj_str(pj_optarg); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | case OPT_PASSWORD: /* authentication password */ |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 884 | cur_acc->cred_info[cur_acc->cred_count].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; |
| 885 | cur_acc->cred_info[cur_acc->cred_count].data = pj_str(pj_optarg); |
Benny Prijono | 28f673a | 2007-10-15 07:04:59 +0000 | [diff] [blame] | 886 | #if PJSIP_HAS_DIGEST_AKA_AUTH |
| 887 | cur_acc->cred_info[cur_acc->cred_count].data_type |= PJSIP_CRED_DATA_EXT_AKA; |
| 888 | cur_acc->cred_info[cur_acc->cred_count].ext.aka.k = pj_str(pj_optarg); |
| 889 | cur_acc->cred_info[cur_acc->cred_count].ext.aka.cb = &pjsip_auth_create_aka_response; |
| 890 | #endif |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 891 | break; |
| 892 | |
| 893 | case OPT_NEXT_CRED: /* next credential */ |
| 894 | cur_acc->cred_count++; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 895 | break; |
| 896 | |
Benny Prijono | fa9e5b1 | 2006-10-08 12:39:34 +0000 | [diff] [blame] | 897 | case OPT_NAMESERVER: /* nameserver */ |
| 898 | cfg->cfg.nameserver[cfg->cfg.nameserver_count++] = pj_str(pj_optarg); |
| 899 | if (cfg->cfg.nameserver_count > PJ_ARRAY_SIZE(cfg->cfg.nameserver)) { |
| 900 | PJ_LOG(1,(THIS_FILE, "Error: too many nameservers")); |
| 901 | return PJ_ETOOMANY; |
| 902 | } |
| 903 | break; |
| 904 | |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 905 | case OPT_STUN_DOMAIN: /* STUN domain */ |
| 906 | cfg->cfg.stun_domain = pj_str(pj_optarg); |
| 907 | break; |
| 908 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 909 | case OPT_STUN_SRV: /* STUN server */ |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 910 | cfg->cfg.stun_host = pj_str(pj_optarg); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 911 | break; |
| 912 | |
| 913 | case OPT_ADD_BUDDY: /* Add to buddy list. */ |
| 914 | if (pjsua_verify_sip_url(pj_optarg) != 0) { |
| 915 | PJ_LOG(1,(THIS_FILE, |
| 916 | "Error: invalid URL '%s' in " |
| 917 | "--add-buddy option", pj_optarg)); |
| 918 | return -1; |
| 919 | } |
| 920 | if (cfg->buddy_cnt == PJ_ARRAY_SIZE(cfg->buddy_cfg)) { |
| 921 | PJ_LOG(1,(THIS_FILE, |
| 922 | "Error: too many buddies in buddy list.")); |
| 923 | return -1; |
| 924 | } |
| 925 | cfg->buddy_cfg[cfg->buddy_cnt].uri = pj_str(pj_optarg); |
| 926 | cfg->buddy_cnt++; |
| 927 | break; |
| 928 | |
| 929 | case OPT_AUTO_PLAY: |
| 930 | cfg->auto_play = 1; |
| 931 | break; |
| 932 | |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 933 | case OPT_AUTO_PLAY_HANGUP: |
| 934 | cfg->auto_play_hangup = 1; |
| 935 | break; |
| 936 | |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 937 | case OPT_AUTO_REC: |
| 938 | cfg->auto_rec = 1; |
| 939 | break; |
| 940 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 941 | case OPT_AUTO_LOOP: |
| 942 | cfg->auto_loop = 1; |
| 943 | break; |
| 944 | |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 945 | case OPT_AUTO_CONF: |
| 946 | cfg->auto_conf = 1; |
| 947 | break; |
| 948 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 949 | case OPT_PLAY_FILE: |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 950 | cfg->wav_files[cfg->wav_count++] = pj_str(pj_optarg); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 951 | break; |
| 952 | |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 953 | case OPT_PLAY_TONE: |
| 954 | { |
| 955 | int f1, f2, on, off; |
| 956 | int n; |
| 957 | |
| 958 | n = sscanf(pj_optarg, "%d,%d,%d,%d", &f1, &f2, &on, &off); |
| 959 | if (n != 4) { |
| 960 | puts("Expecting f1,f2,on,off in --play-tone"); |
| 961 | return -1; |
| 962 | } |
| 963 | |
| 964 | cfg->tones[cfg->tone_count].freq1 = (short)f1; |
| 965 | cfg->tones[cfg->tone_count].freq2 = (short)f2; |
| 966 | cfg->tones[cfg->tone_count].on_msec = (short)on; |
| 967 | cfg->tones[cfg->tone_count].off_msec = (short)off; |
| 968 | ++cfg->tone_count; |
| 969 | } |
| 970 | break; |
| 971 | |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 972 | case OPT_REC_FILE: |
| 973 | cfg->rec_file = pj_str(pj_optarg); |
| 974 | break; |
| 975 | |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 976 | case OPT_USE_ICE: |
| 977 | cfg->media_cfg.enable_ice = PJ_TRUE; |
| 978 | break; |
| 979 | |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 980 | case OPT_USE_TURN: |
| 981 | cfg->media_cfg.enable_turn = PJ_TRUE; |
| 982 | break; |
| 983 | |
| 984 | case OPT_ICE_NO_HOST: |
| 985 | cfg->media_cfg.ice_no_host_cands = PJ_TRUE; |
| 986 | break; |
| 987 | |
Benny Prijono | 551af42 | 2008-08-07 09:55:52 +0000 | [diff] [blame] | 988 | case OPT_ICE_NO_RTCP: |
| 989 | cfg->media_cfg.ice_no_rtcp = PJ_TRUE; |
| 990 | break; |
| 991 | |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 992 | case OPT_TURN_SRV: |
| 993 | cfg->media_cfg.turn_server = pj_str(pj_optarg); |
| 994 | break; |
| 995 | |
| 996 | case OPT_TURN_TCP: |
| 997 | cfg->media_cfg.turn_conn_type = PJ_TURN_TP_TCP; |
| 998 | break; |
| 999 | |
| 1000 | case OPT_TURN_USER: |
| 1001 | cfg->media_cfg.turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC; |
| 1002 | cfg->media_cfg.turn_auth_cred.data.static_cred.realm = pj_str("*"); |
| 1003 | cfg->media_cfg.turn_auth_cred.data.static_cred.username = pj_str(pj_optarg); |
| 1004 | break; |
| 1005 | |
| 1006 | case OPT_TURN_PASSWD: |
| 1007 | cfg->media_cfg.turn_auth_cred.data.static_cred.data_type = PJ_STUN_PASSWD_PLAIN; |
| 1008 | cfg->media_cfg.turn_auth_cred.data.static_cred.data = pj_str(pj_optarg); |
| 1009 | break; |
| 1010 | |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 1011 | #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) |
| 1012 | case OPT_USE_SRTP: |
| 1013 | app_config.cfg.use_srtp = my_atoi(pj_optarg); |
| 1014 | if (!pj_isdigit(*pj_optarg) || app_config.cfg.use_srtp > 2) { |
| 1015 | PJ_LOG(1,(THIS_FILE, "Invalid value for --use-srtp option")); |
| 1016 | return -1; |
| 1017 | } |
Benny Prijono | 3ec13c7 | 2008-01-29 11:52:58 +0000 | [diff] [blame] | 1018 | cur_acc->use_srtp = app_config.cfg.use_srtp; |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 1019 | break; |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 1020 | case OPT_SRTP_SECURE: |
| 1021 | app_config.cfg.srtp_secure_signaling = my_atoi(pj_optarg); |
| 1022 | if (!pj_isdigit(*pj_optarg) || |
| 1023 | app_config.cfg.srtp_secure_signaling > 2) |
| 1024 | { |
| 1025 | PJ_LOG(1,(THIS_FILE, "Invalid value for --srtp-secure option")); |
| 1026 | return -1; |
| 1027 | } |
Benny Prijono | 3ec13c7 | 2008-01-29 11:52:58 +0000 | [diff] [blame] | 1028 | cur_acc->srtp_secure_signaling = app_config.cfg.srtp_secure_signaling; |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 1029 | break; |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 1030 | #endif |
| 1031 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1032 | case OPT_RTP_PORT: |
| 1033 | cfg->rtp_cfg.port = my_atoi(pj_optarg); |
Benny Prijono | 5583a80 | 2007-06-26 12:20:37 +0000 | [diff] [blame] | 1034 | if (cfg->rtp_cfg.port == 0) { |
| 1035 | enum { START_PORT=4000 }; |
| 1036 | unsigned range; |
| 1037 | |
| 1038 | range = (65535-START_PORT-PJSUA_MAX_CALLS*2); |
| 1039 | cfg->rtp_cfg.port = START_PORT + |
| 1040 | ((pj_rand() % range) & 0xFFFE); |
| 1041 | } |
| 1042 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1043 | if (cfg->rtp_cfg.port < 1 || cfg->rtp_cfg.port > 65535) { |
| 1044 | PJ_LOG(1,(THIS_FILE, |
| 1045 | "Error: rtp-port argument value " |
| 1046 | "(expecting 1-65535")); |
| 1047 | return -1; |
| 1048 | } |
| 1049 | break; |
| 1050 | |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1051 | case OPT_DIS_CODEC: |
| 1052 | cfg->codec_dis[cfg->codec_dis_cnt++] = pj_str(pj_optarg); |
| 1053 | break; |
| 1054 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1055 | case OPT_ADD_CODEC: |
| 1056 | cfg->codec_arg[cfg->codec_cnt++] = pj_str(pj_optarg); |
| 1057 | break; |
| 1058 | |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 1059 | /* These options were no longer valid after new pjsua */ |
| 1060 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1061 | case OPT_COMPLEXITY: |
| 1062 | cfg->complexity = my_atoi(pj_optarg); |
| 1063 | if (cfg->complexity < 0 || cfg->complexity > 10) { |
| 1064 | PJ_LOG(1,(THIS_FILE, |
| 1065 | "Error: invalid --complexity (expecting 0-10")); |
| 1066 | return -1; |
| 1067 | } |
| 1068 | break; |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 1069 | */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1070 | |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 1071 | case OPT_DURATION: |
| 1072 | cfg->duration = my_atoi(pj_optarg); |
| 1073 | break; |
| 1074 | |
Benny Prijono | f521eb0 | 2006-08-06 23:07:25 +0000 | [diff] [blame] | 1075 | case OPT_THREAD_CNT: |
| 1076 | cfg->cfg.thread_cnt = my_atoi(pj_optarg); |
| 1077 | if (cfg->cfg.thread_cnt > 128) { |
| 1078 | PJ_LOG(1,(THIS_FILE, |
| 1079 | "Error: invalid --thread-cnt option")); |
| 1080 | return -1; |
| 1081 | } |
| 1082 | break; |
| 1083 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1084 | case OPT_PTIME: |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 1085 | cfg->media_cfg.ptime = my_atoi(pj_optarg); |
| 1086 | if (cfg->media_cfg.ptime < 10 || cfg->media_cfg.ptime > 1000) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1087 | PJ_LOG(1,(THIS_FILE, |
| 1088 | "Error: invalid --ptime option")); |
| 1089 | return -1; |
| 1090 | } |
| 1091 | break; |
| 1092 | |
Benny Prijono | 0a12f00 | 2006-07-26 17:05:39 +0000 | [diff] [blame] | 1093 | case OPT_NO_VAD: |
| 1094 | cfg->media_cfg.no_vad = PJ_TRUE; |
| 1095 | break; |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 1096 | |
Benny Prijono | d79f25c | 2006-08-02 19:41:37 +0000 | [diff] [blame] | 1097 | case OPT_EC_TAIL: |
| 1098 | cfg->media_cfg.ec_tail_len = my_atoi(pj_optarg); |
| 1099 | if (cfg->media_cfg.ec_tail_len > 1000) { |
| 1100 | PJ_LOG(1,(THIS_FILE, "I think the ec-tail length setting " |
| 1101 | "is too big")); |
| 1102 | return -1; |
| 1103 | } |
| 1104 | break; |
| 1105 | |
Benny Prijono | 59b3ffe | 2008-08-11 18:10:42 +0000 | [diff] [blame] | 1106 | case OPT_EC_OPT: |
| 1107 | cfg->media_cfg.ec_options = my_atoi(pj_optarg); |
| 1108 | break; |
| 1109 | |
Benny Prijono | 0498d90 | 2006-06-19 14:49:14 +0000 | [diff] [blame] | 1110 | case OPT_QUALITY: |
| 1111 | cfg->media_cfg.quality = my_atoi(pj_optarg); |
| 1112 | if (cfg->media_cfg.quality < 0 || cfg->media_cfg.quality > 10) { |
| 1113 | PJ_LOG(1,(THIS_FILE, |
| 1114 | "Error: invalid --quality (expecting 0-10")); |
| 1115 | return -1; |
| 1116 | } |
| 1117 | break; |
| 1118 | |
Benny Prijono | 00cae61 | 2006-07-31 15:19:36 +0000 | [diff] [blame] | 1119 | case OPT_ILBC_MODE: |
| 1120 | cfg->media_cfg.ilbc_mode = my_atoi(pj_optarg); |
| 1121 | if (cfg->media_cfg.ilbc_mode!=20 && cfg->media_cfg.ilbc_mode!=30) { |
| 1122 | PJ_LOG(1,(THIS_FILE, |
| 1123 | "Error: invalid --ilbc-mode (expecting 20 or 30")); |
| 1124 | return -1; |
| 1125 | } |
| 1126 | break; |
| 1127 | |
| 1128 | case OPT_RX_DROP_PCT: |
| 1129 | cfg->media_cfg.rx_drop_pct = my_atoi(pj_optarg); |
| 1130 | if (cfg->media_cfg.rx_drop_pct > 100) { |
| 1131 | PJ_LOG(1,(THIS_FILE, |
| 1132 | "Error: invalid --rx-drop-pct (expecting <= 100")); |
| 1133 | return -1; |
| 1134 | } |
| 1135 | break; |
| 1136 | |
| 1137 | case OPT_TX_DROP_PCT: |
| 1138 | cfg->media_cfg.tx_drop_pct = my_atoi(pj_optarg); |
| 1139 | if (cfg->media_cfg.tx_drop_pct > 100) { |
| 1140 | PJ_LOG(1,(THIS_FILE, |
| 1141 | "Error: invalid --tx-drop-pct (expecting <= 100")); |
| 1142 | return -1; |
| 1143 | } |
| 1144 | break; |
| 1145 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1146 | case OPT_AUTO_ANSWER: |
| 1147 | cfg->auto_answer = my_atoi(pj_optarg); |
| 1148 | if (cfg->auto_answer < 100 || cfg->auto_answer > 699) { |
| 1149 | PJ_LOG(1,(THIS_FILE, |
| 1150 | "Error: invalid code in --auto-answer " |
| 1151 | "(expecting 100-699")); |
| 1152 | return -1; |
| 1153 | } |
| 1154 | break; |
| 1155 | |
| 1156 | case OPT_MAX_CALLS: |
| 1157 | cfg->cfg.max_calls = my_atoi(pj_optarg); |
Benny Prijono | 48af79c | 2006-07-22 12:49:17 +0000 | [diff] [blame] | 1158 | if (cfg->cfg.max_calls < 1 || cfg->cfg.max_calls > PJSUA_MAX_CALLS) { |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 1159 | PJ_LOG(1,(THIS_FILE,"Error: maximum call setting exceeds " |
| 1160 | "compile time limit (PJSUA_MAX_CALLS=%d)", |
Benny Prijono | 48af79c | 2006-07-22 12:49:17 +0000 | [diff] [blame] | 1161 | PJSUA_MAX_CALLS)); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1162 | return -1; |
| 1163 | } |
| 1164 | break; |
| 1165 | |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1166 | case OPT_USE_TLS: |
| 1167 | cfg->use_tls = PJ_TRUE; |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1168 | #if !defined(PJSIP_HAS_TLS_TRANSPORT) || PJSIP_HAS_TLS_TRANSPORT==0 |
| 1169 | PJ_LOG(1,(THIS_FILE, "Error: TLS support is not configured")); |
| 1170 | return -1; |
| 1171 | #endif |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1172 | break; |
| 1173 | |
| 1174 | case OPT_TLS_CA_FILE: |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1175 | cfg->udp_cfg.tls_setting.ca_list_file = pj_str(pj_optarg); |
| 1176 | #if !defined(PJSIP_HAS_TLS_TRANSPORT) || PJSIP_HAS_TLS_TRANSPORT==0 |
| 1177 | PJ_LOG(1,(THIS_FILE, "Error: TLS support is not configured")); |
| 1178 | return -1; |
| 1179 | #endif |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1180 | break; |
| 1181 | |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1182 | case OPT_TLS_CERT_FILE: |
| 1183 | cfg->udp_cfg.tls_setting.cert_file = pj_str(pj_optarg); |
| 1184 | #if !defined(PJSIP_HAS_TLS_TRANSPORT) || PJSIP_HAS_TLS_TRANSPORT==0 |
| 1185 | PJ_LOG(1,(THIS_FILE, "Error: TLS support is not configured")); |
| 1186 | return -1; |
| 1187 | #endif |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1188 | break; |
| 1189 | |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1190 | case OPT_TLS_PRIV_FILE: |
| 1191 | cfg->udp_cfg.tls_setting.privkey_file = pj_str(pj_optarg); |
| 1192 | break; |
| 1193 | |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1194 | case OPT_TLS_PASSWORD: |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1195 | cfg->udp_cfg.tls_setting.password = pj_str(pj_optarg); |
| 1196 | #if !defined(PJSIP_HAS_TLS_TRANSPORT) || PJSIP_HAS_TLS_TRANSPORT==0 |
| 1197 | PJ_LOG(1,(THIS_FILE, "Error: TLS support is not configured")); |
| 1198 | return -1; |
| 1199 | #endif |
| 1200 | break; |
| 1201 | |
| 1202 | case OPT_TLS_VERIFY_SERVER: |
| 1203 | cfg->udp_cfg.tls_setting.verify_server = PJ_TRUE; |
| 1204 | break; |
| 1205 | |
| 1206 | case OPT_TLS_VERIFY_CLIENT: |
| 1207 | cfg->udp_cfg.tls_setting.verify_client = PJ_TRUE; |
| 1208 | break; |
| 1209 | |
| 1210 | case OPT_TLS_NEG_TIMEOUT: |
| 1211 | cfg->udp_cfg.tls_setting.timeout.sec = atoi(pj_optarg); |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1212 | break; |
| 1213 | |
Benny Prijono | e10db84 | 2008-07-01 15:31:59 +0000 | [diff] [blame] | 1214 | case OPT_TLS_SRV_NAME: |
| 1215 | cfg->udp_cfg.tls_setting.server_name = pj_str(pj_optarg); |
| 1216 | break; |
| 1217 | |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 1218 | case OPT_CAPTURE_DEV: |
| 1219 | cfg->capture_dev = atoi(pj_optarg); |
| 1220 | break; |
| 1221 | |
| 1222 | case OPT_PLAYBACK_DEV: |
| 1223 | cfg->playback_dev = atoi(pj_optarg); |
| 1224 | break; |
| 1225 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 1226 | case OPT_STDOUT_REFRESH: |
| 1227 | stdout_refresh = atoi(pj_optarg); |
| 1228 | break; |
| 1229 | |
| 1230 | case OPT_STDOUT_REFRESH_TEXT: |
| 1231 | stdout_refresh_text = pj_optarg; |
| 1232 | break; |
| 1233 | |
Benny Prijono | 4d0da3a | 2008-06-26 20:23:47 +0000 | [diff] [blame] | 1234 | #ifdef _IONBF |
| 1235 | case OPT_STDOUT_NO_BUF: |
| 1236 | setvbuf(stdout, NULL, _IONBF, 0); |
| 1237 | break; |
| 1238 | #endif |
| 1239 | |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 1240 | case OPT_CAPTURE_LAT: |
| 1241 | cfg->capture_lat = atoi(pj_optarg); |
| 1242 | break; |
| 1243 | |
| 1244 | case OPT_PLAYBACK_LAT: |
| 1245 | cfg->playback_lat = atoi(pj_optarg); |
| 1246 | break; |
| 1247 | |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 1248 | case OPT_SND_AUTO_CLOSE: |
| 1249 | cfg->media_cfg.snd_auto_close_time = atoi(pj_optarg); |
| 1250 | break; |
| 1251 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1252 | case OPT_NO_TONES: |
| 1253 | cfg->no_tones = PJ_TRUE; |
| 1254 | break; |
| 1255 | |
Nanang Izzuddin | c985354 | 2008-07-17 16:59:07 +0000 | [diff] [blame] | 1256 | case OPT_JB_MAX_SIZE: |
| 1257 | cfg->media_cfg.jb_max = atoi(pj_optarg); |
| 1258 | break; |
| 1259 | |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 1260 | default: |
Benny Prijono | 787b869 | 2006-06-19 12:40:03 +0000 | [diff] [blame] | 1261 | PJ_LOG(1,(THIS_FILE, |
Benny Prijono | d6388ac | 2006-09-09 13:23:09 +0000 | [diff] [blame] | 1262 | "Argument \"%s\" is not valid. Use --help to see help", |
Benny Prijono | af09dc3 | 2007-04-22 12:48:30 +0000 | [diff] [blame] | 1263 | argv[pj_optind-1])); |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 1264 | return -1; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | if (pj_optind != argc) { |
| 1269 | pj_str_t uri_arg; |
| 1270 | |
| 1271 | if (pjsua_verify_sip_url(argv[pj_optind]) != PJ_SUCCESS) { |
| 1272 | PJ_LOG(1,(THIS_FILE, "Invalid SIP URI %s", argv[pj_optind])); |
| 1273 | return -1; |
| 1274 | } |
| 1275 | uri_arg = pj_str(argv[pj_optind]); |
| 1276 | if (uri_to_call) |
| 1277 | *uri_to_call = uri_arg; |
| 1278 | pj_optind++; |
| 1279 | |
| 1280 | /* Add URI to call to buddy list if it's not already there */ |
| 1281 | for (i=0; i<cfg->buddy_cnt; ++i) { |
| 1282 | if (pj_stricmp(&cfg->buddy_cfg[i].uri, &uri_arg)==0) |
| 1283 | break; |
| 1284 | } |
| 1285 | if (i == cfg->buddy_cnt && cfg->buddy_cnt < PJSUA_MAX_BUDDIES) { |
| 1286 | cfg->buddy_cfg[cfg->buddy_cnt++].uri = uri_arg; |
| 1287 | } |
| 1288 | |
| 1289 | } else { |
| 1290 | if (uri_to_call) |
| 1291 | uri_to_call->slen = 0; |
| 1292 | } |
| 1293 | |
| 1294 | if (pj_optind != argc) { |
| 1295 | PJ_LOG(1,(THIS_FILE, "Error: unknown options %s", argv[pj_optind])); |
| 1296 | return PJ_EINVAL; |
| 1297 | } |
| 1298 | |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 1299 | if (cfg->acc_cfg[cfg->acc_cnt].id.slen) |
| 1300 | cfg->acc_cnt++; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1301 | |
| 1302 | for (i=0; i<cfg->acc_cnt; ++i) { |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 1303 | pjsua_acc_config *acfg = &cfg->acc_cfg[i]; |
| 1304 | |
| 1305 | if (acfg->cred_info[acfg->cred_count].username.slen) |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1306 | { |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 1307 | acfg->cred_count++; |
| 1308 | } |
| 1309 | |
| 1310 | /* When IMS mode is enabled for the account, verify that settings |
| 1311 | * are okay. |
| 1312 | */ |
| 1313 | /* For now we check if IMS mode is activated by looking if |
| 1314 | * initial_auth is set. |
| 1315 | */ |
| 1316 | if (acfg->auth_pref.initial_auth && acfg->cred_count) { |
| 1317 | /* Realm must point to the real domain */ |
| 1318 | if (*acfg->cred_info[0].realm.ptr=='*') { |
| 1319 | PJ_LOG(1,(THIS_FILE, |
| 1320 | "Error: cannot use '*' as realm with IMS")); |
| 1321 | return PJ_EINVAL; |
| 1322 | } |
| 1323 | |
| 1324 | /* Username for authentication must be in a@b format */ |
| 1325 | if (strchr(acfg->cred_info[0].username.ptr, '@')==0) { |
| 1326 | PJ_LOG(1,(THIS_FILE, |
| 1327 | "Error: Username for authentication must " |
| 1328 | "be in user@domain format with IMS")); |
| 1329 | return PJ_EINVAL; |
| 1330 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | return PJ_SUCCESS; |
| 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | /* |
| 1340 | * Save account settings |
| 1341 | */ |
| 1342 | static void write_account_settings(int acc_index, pj_str_t *result) |
| 1343 | { |
| 1344 | unsigned i; |
| 1345 | char line[128]; |
| 1346 | pjsua_acc_config *acc_cfg = &app_config.acc_cfg[acc_index]; |
| 1347 | |
| 1348 | |
| 1349 | pj_ansi_sprintf(line, "\n#\n# Account %d:\n#\n", acc_index); |
| 1350 | pj_strcat2(result, line); |
| 1351 | |
| 1352 | |
| 1353 | /* Identity */ |
| 1354 | if (acc_cfg->id.slen) { |
| 1355 | pj_ansi_sprintf(line, "--id %.*s\n", |
| 1356 | (int)acc_cfg->id.slen, |
| 1357 | acc_cfg->id.ptr); |
| 1358 | pj_strcat2(result, line); |
| 1359 | } |
| 1360 | |
| 1361 | /* Registrar server */ |
| 1362 | if (acc_cfg->reg_uri.slen) { |
| 1363 | pj_ansi_sprintf(line, "--registrar %.*s\n", |
| 1364 | (int)acc_cfg->reg_uri.slen, |
| 1365 | acc_cfg->reg_uri.ptr); |
| 1366 | pj_strcat2(result, line); |
| 1367 | |
| 1368 | pj_ansi_sprintf(line, "--reg-timeout %u\n", |
| 1369 | acc_cfg->reg_timeout); |
| 1370 | pj_strcat2(result, line); |
| 1371 | } |
| 1372 | |
| 1373 | /* Contact */ |
Benny Prijono | b4a17c9 | 2006-07-10 14:40:21 +0000 | [diff] [blame] | 1374 | if (acc_cfg->force_contact.slen) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1375 | pj_ansi_sprintf(line, "--contact %.*s\n", |
Benny Prijono | b4a17c9 | 2006-07-10 14:40:21 +0000 | [diff] [blame] | 1376 | (int)acc_cfg->force_contact.slen, |
| 1377 | acc_cfg->force_contact.ptr); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1378 | pj_strcat2(result, line); |
| 1379 | } |
| 1380 | |
Benny Prijono | 30fe485 | 2008-12-10 16:54:16 +0000 | [diff] [blame] | 1381 | /* Contact parameters */ |
| 1382 | if (acc_cfg->contact_params.slen) { |
| 1383 | pj_ansi_sprintf(line, "--contact-params %.*s\n", |
| 1384 | (int)acc_cfg->contact_params.slen, |
| 1385 | acc_cfg->contact_params.ptr); |
| 1386 | pj_strcat2(result, line); |
| 1387 | } |
| 1388 | |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1389 | /* */ |
Benny Prijono | 7f63043 | 2008-09-24 16:52:41 +0000 | [diff] [blame] | 1390 | if (acc_cfg->allow_contact_rewrite!=1) |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1391 | { |
Benny Prijono | 251e02a | 2008-07-25 10:05:55 +0000 | [diff] [blame] | 1392 | pj_ansi_sprintf(line, "--auto-update-nat %i\n", |
Benny Prijono | e8554ef | 2008-03-22 09:33:52 +0000 | [diff] [blame] | 1393 | (int)acc_cfg->allow_contact_rewrite); |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1394 | pj_strcat2(result, line); |
| 1395 | } |
| 1396 | |
Benny Prijono | d817965 | 2008-01-23 20:39:07 +0000 | [diff] [blame] | 1397 | #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) |
| 1398 | /* SRTP */ |
| 1399 | if (acc_cfg->use_srtp) { |
| 1400 | pj_ansi_sprintf(line, "--use-srtp %i\n", |
| 1401 | (int)acc_cfg->use_srtp); |
| 1402 | pj_strcat2(result, line); |
| 1403 | } |
| 1404 | #endif |
| 1405 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1406 | /* Proxy */ |
| 1407 | for (i=0; i<acc_cfg->proxy_cnt; ++i) { |
| 1408 | pj_ansi_sprintf(line, "--proxy %.*s\n", |
| 1409 | (int)acc_cfg->proxy[i].slen, |
| 1410 | acc_cfg->proxy[i].ptr); |
| 1411 | pj_strcat2(result, line); |
| 1412 | } |
| 1413 | |
| 1414 | /* Credentials */ |
| 1415 | for (i=0; i<acc_cfg->cred_count; ++i) { |
| 1416 | if (acc_cfg->cred_info[i].realm.slen) { |
| 1417 | pj_ansi_sprintf(line, "--realm %.*s\n", |
| 1418 | (int)acc_cfg->cred_info[i].realm.slen, |
| 1419 | acc_cfg->cred_info[i].realm.ptr); |
| 1420 | pj_strcat2(result, line); |
| 1421 | } |
| 1422 | |
| 1423 | if (acc_cfg->cred_info[i].username.slen) { |
| 1424 | pj_ansi_sprintf(line, "--username %.*s\n", |
| 1425 | (int)acc_cfg->cred_info[i].username.slen, |
| 1426 | acc_cfg->cred_info[i].username.ptr); |
| 1427 | pj_strcat2(result, line); |
| 1428 | } |
| 1429 | |
| 1430 | if (acc_cfg->cred_info[i].data.slen) { |
| 1431 | pj_ansi_sprintf(line, "--password %.*s\n", |
| 1432 | (int)acc_cfg->cred_info[i].data.slen, |
| 1433 | acc_cfg->cred_info[i].data.ptr); |
| 1434 | pj_strcat2(result, line); |
| 1435 | } |
Benny Prijono | eef4f8c | 2006-06-19 12:07:44 +0000 | [diff] [blame] | 1436 | |
| 1437 | if (i != acc_cfg->cred_count - 1) |
| 1438 | pj_strcat2(result, "--next-cred\n"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | /* |
| 1445 | * Write settings. |
| 1446 | */ |
| 1447 | static int write_settings(const struct app_config *config, |
| 1448 | char *buf, pj_size_t max) |
| 1449 | { |
| 1450 | unsigned acc_index; |
| 1451 | unsigned i; |
| 1452 | pj_str_t cfg; |
| 1453 | char line[128]; |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1454 | extern pj_bool_t pjsip_use_compact_form; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1455 | |
| 1456 | PJ_UNUSED_ARG(max); |
| 1457 | |
| 1458 | cfg.ptr = buf; |
| 1459 | cfg.slen = 0; |
| 1460 | |
| 1461 | /* Logging. */ |
| 1462 | pj_strcat2(&cfg, "#\n# Logging options:\n#\n"); |
| 1463 | pj_ansi_sprintf(line, "--log-level %d\n", |
| 1464 | config->log_cfg.level); |
| 1465 | pj_strcat2(&cfg, line); |
| 1466 | |
| 1467 | pj_ansi_sprintf(line, "--app-log-level %d\n", |
| 1468 | config->log_cfg.console_level); |
| 1469 | pj_strcat2(&cfg, line); |
| 1470 | |
| 1471 | if (config->log_cfg.log_filename.slen) { |
| 1472 | pj_ansi_sprintf(line, "--log-file %.*s\n", |
| 1473 | (int)config->log_cfg.log_filename.slen, |
| 1474 | config->log_cfg.log_filename.ptr); |
| 1475 | pj_strcat2(&cfg, line); |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | /* Save account settings. */ |
| 1480 | for (acc_index=0; acc_index < config->acc_cnt; ++acc_index) { |
| 1481 | |
| 1482 | write_account_settings(acc_index, &cfg); |
| 1483 | |
| 1484 | if (acc_index < config->acc_cnt-1) |
| 1485 | pj_strcat2(&cfg, "--next-account\n"); |
| 1486 | } |
| 1487 | |
| 1488 | |
| 1489 | pj_strcat2(&cfg, "\n#\n# Network settings:\n#\n"); |
| 1490 | |
| 1491 | /* Outbound proxy */ |
| 1492 | for (i=0; i<config->cfg.outbound_proxy_cnt; ++i) { |
| 1493 | pj_ansi_sprintf(line, "--outbound %.*s\n", |
| 1494 | (int)config->cfg.outbound_proxy[i].slen, |
| 1495 | config->cfg.outbound_proxy[i].ptr); |
| 1496 | pj_strcat2(&cfg, line); |
| 1497 | } |
| 1498 | |
| 1499 | |
| 1500 | /* UDP Transport. */ |
| 1501 | pj_ansi_sprintf(line, "--local-port %d\n", config->udp_cfg.port); |
| 1502 | pj_strcat2(&cfg, line); |
| 1503 | |
Benny Prijono | 0a5cad8 | 2006-09-26 13:21:02 +0000 | [diff] [blame] | 1504 | /* IP address, if any. */ |
| 1505 | if (config->udp_cfg.public_addr.slen) { |
| 1506 | pj_ansi_sprintf(line, "--ip-addr %.*s\n", |
| 1507 | (int)config->udp_cfg.public_addr.slen, |
| 1508 | config->udp_cfg.public_addr.ptr); |
| 1509 | pj_strcat2(&cfg, line); |
| 1510 | } |
| 1511 | |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 1512 | /* No TCP ? */ |
| 1513 | if (config->no_tcp) { |
| 1514 | pj_strcat2(&cfg, "--no-tcp\n"); |
| 1515 | } |
| 1516 | |
| 1517 | /* No UDP ? */ |
| 1518 | if (config->no_udp) { |
| 1519 | pj_strcat2(&cfg, "--no-udp\n"); |
| 1520 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1521 | |
| 1522 | /* STUN */ |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 1523 | if (config->cfg.stun_domain.slen) { |
| 1524 | pj_ansi_sprintf(line, "--stun-domain %.*s\n", |
| 1525 | (int)config->cfg.stun_domain.slen, |
| 1526 | config->cfg.stun_domain.ptr); |
| 1527 | pj_strcat2(&cfg, line); |
| 1528 | } |
| 1529 | if (config->cfg.stun_host.slen) { |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 1530 | pj_ansi_sprintf(line, "--stun-srv %.*s\n", |
Benny Prijono | ebbf689 | 2007-03-24 17:37:25 +0000 | [diff] [blame] | 1531 | (int)config->cfg.stun_host.slen, |
| 1532 | config->cfg.stun_host.ptr); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1533 | pj_strcat2(&cfg, line); |
| 1534 | } |
| 1535 | |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1536 | /* TLS */ |
| 1537 | if (config->use_tls) |
| 1538 | pj_strcat2(&cfg, "--use-tls\n"); |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1539 | if (config->udp_cfg.tls_setting.ca_list_file.slen) { |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1540 | pj_ansi_sprintf(line, "--tls-ca-file %.*s\n", |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1541 | (int)config->udp_cfg.tls_setting.ca_list_file.slen, |
| 1542 | config->udp_cfg.tls_setting.ca_list_file.ptr); |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1543 | pj_strcat2(&cfg, line); |
| 1544 | } |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1545 | if (config->udp_cfg.tls_setting.cert_file.slen) { |
| 1546 | pj_ansi_sprintf(line, "--tls-cert-file %.*s\n", |
| 1547 | (int)config->udp_cfg.tls_setting.cert_file.slen, |
| 1548 | config->udp_cfg.tls_setting.cert_file.ptr); |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1549 | pj_strcat2(&cfg, line); |
| 1550 | } |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1551 | if (config->udp_cfg.tls_setting.privkey_file.slen) { |
| 1552 | pj_ansi_sprintf(line, "--tls-privkey-file %.*s\n", |
| 1553 | (int)config->udp_cfg.tls_setting.privkey_file.slen, |
| 1554 | config->udp_cfg.tls_setting.privkey_file.ptr); |
| 1555 | pj_strcat2(&cfg, line); |
| 1556 | } |
| 1557 | |
| 1558 | if (config->udp_cfg.tls_setting.password.slen) { |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1559 | pj_ansi_sprintf(line, "--tls-password %.*s\n", |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1560 | (int)config->udp_cfg.tls_setting.password.slen, |
| 1561 | config->udp_cfg.tls_setting.password.ptr); |
| 1562 | pj_strcat2(&cfg, line); |
| 1563 | } |
| 1564 | |
Benny Prijono | e10db84 | 2008-07-01 15:31:59 +0000 | [diff] [blame] | 1565 | if (config->udp_cfg.tls_setting.server_name.slen) { |
| 1566 | pj_ansi_sprintf(line, "--tls-srv-name %.*s\n", |
| 1567 | (int)config->udp_cfg.tls_setting.server_name.slen, |
| 1568 | config->udp_cfg.tls_setting.server_name.ptr); |
| 1569 | pj_strcat2(&cfg, line); |
| 1570 | } |
| 1571 | |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 1572 | if (config->udp_cfg.tls_setting.verify_server) |
| 1573 | pj_strcat2(&cfg, "--tls-verify-server\n"); |
| 1574 | |
| 1575 | if (config->udp_cfg.tls_setting.verify_client) |
| 1576 | pj_strcat2(&cfg, "--tls-verify-client\n"); |
| 1577 | |
| 1578 | if (config->udp_cfg.tls_setting.timeout.sec) { |
| 1579 | pj_ansi_sprintf(line, "--tls-neg-timeout %d\n", |
Benny Prijono | e960bb5 | 2007-01-21 17:53:39 +0000 | [diff] [blame] | 1580 | (int)config->udp_cfg.tls_setting.timeout.sec); |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 1581 | pj_strcat2(&cfg, line); |
| 1582 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1583 | |
| 1584 | pj_strcat2(&cfg, "\n#\n# Media settings:\n#\n"); |
| 1585 | |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 1586 | /* SRTP */ |
Benny Prijono | fe5a694 | 2008-02-18 12:16:23 +0000 | [diff] [blame] | 1587 | #if PJMEDIA_HAS_SRTP |
Benny Prijono | f650898 | 2008-01-25 09:02:33 +0000 | [diff] [blame] | 1588 | if (app_config.cfg.use_srtp != PJSUA_DEFAULT_USE_SRTP) { |
| 1589 | pj_ansi_sprintf(line, "--use-srtp %d\n", |
| 1590 | app_config.cfg.use_srtp); |
| 1591 | pj_strcat2(&cfg, line); |
| 1592 | } |
| 1593 | if (app_config.cfg.srtp_secure_signaling != |
| 1594 | PJSUA_DEFAULT_SRTP_SECURE_SIGNALING) |
| 1595 | { |
| 1596 | pj_ansi_sprintf(line, "--srtp-secure %d\n", |
| 1597 | app_config.cfg.srtp_secure_signaling); |
| 1598 | pj_strcat2(&cfg, line); |
| 1599 | } |
Benny Prijono | fe5a694 | 2008-02-18 12:16:23 +0000 | [diff] [blame] | 1600 | #endif |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1601 | |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 1602 | /* Media Transport*/ |
Benny Prijono | c97608e | 2007-03-23 16:34:20 +0000 | [diff] [blame] | 1603 | if (config->media_cfg.enable_ice) |
| 1604 | pj_strcat2(&cfg, "--use-ice\n"); |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 1605 | |
| 1606 | if (config->media_cfg.enable_turn) |
| 1607 | pj_strcat2(&cfg, "--use-turn\n"); |
| 1608 | |
| 1609 | if (config->media_cfg.ice_no_host_cands) |
| 1610 | pj_strcat2(&cfg, "--ice-no-host\n"); |
| 1611 | |
Benny Prijono | 551af42 | 2008-08-07 09:55:52 +0000 | [diff] [blame] | 1612 | if (config->media_cfg.ice_no_rtcp) |
| 1613 | pj_strcat2(&cfg, "--ice-no-rtcp\n"); |
| 1614 | |
Benny Prijono | f76e139 | 2008-06-06 14:51:48 +0000 | [diff] [blame] | 1615 | if (config->media_cfg.turn_server.slen) { |
| 1616 | pj_ansi_sprintf(line, "--turn-srv %.*s\n", |
| 1617 | (int)config->media_cfg.turn_server.slen, |
| 1618 | config->media_cfg.turn_server.ptr); |
| 1619 | pj_strcat2(&cfg, line); |
| 1620 | } |
| 1621 | |
| 1622 | if (config->media_cfg.turn_conn_type == PJ_TURN_TP_TCP) |
| 1623 | pj_strcat2(&cfg, "--turn-tcp\n"); |
| 1624 | |
| 1625 | if (config->media_cfg.turn_auth_cred.data.static_cred.username.slen) { |
| 1626 | pj_ansi_sprintf(line, "--turn-user %.*s\n", |
| 1627 | (int)config->media_cfg.turn_auth_cred.data.static_cred.username.slen, |
| 1628 | config->media_cfg.turn_auth_cred.data.static_cred.username.ptr); |
| 1629 | pj_strcat2(&cfg, line); |
| 1630 | } |
| 1631 | |
| 1632 | if (config->media_cfg.turn_auth_cred.data.static_cred.data.slen) { |
| 1633 | pj_ansi_sprintf(line, "--turn-passwd %.*s\n", |
| 1634 | (int)config->media_cfg.turn_auth_cred.data.static_cred.data.slen, |
| 1635 | config->media_cfg.turn_auth_cred.data.static_cred.data.ptr); |
| 1636 | pj_strcat2(&cfg, line); |
| 1637 | } |
| 1638 | |
| 1639 | /* Media */ |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1640 | if (config->null_audio) |
| 1641 | pj_strcat2(&cfg, "--null-audio\n"); |
| 1642 | if (config->auto_play) |
| 1643 | pj_strcat2(&cfg, "--auto-play\n"); |
| 1644 | if (config->auto_loop) |
| 1645 | pj_strcat2(&cfg, "--auto-loop\n"); |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 1646 | if (config->auto_conf) |
| 1647 | pj_strcat2(&cfg, "--auto-conf\n"); |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 1648 | for (i=0; i<config->wav_count; ++i) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1649 | pj_ansi_sprintf(line, "--play-file %s\n", |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 1650 | config->wav_files[i].ptr); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1651 | pj_strcat2(&cfg, line); |
| 1652 | } |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 1653 | for (i=0; i<config->tone_count; ++i) { |
| 1654 | pj_ansi_sprintf(line, "--play-tone %d,%d,%d,%d\n", |
| 1655 | config->tones[i].freq1, config->tones[i].freq2, |
| 1656 | config->tones[i].on_msec, config->tones[i].off_msec); |
| 1657 | pj_strcat2(&cfg, line); |
| 1658 | } |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 1659 | if (config->rec_file.slen) { |
| 1660 | pj_ansi_sprintf(line, "--rec-file %s\n", |
| 1661 | config->rec_file.ptr); |
| 1662 | pj_strcat2(&cfg, line); |
| 1663 | } |
| 1664 | if (config->auto_rec) |
| 1665 | pj_strcat2(&cfg, "--auto-rec\n"); |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 1666 | if (config->capture_dev != PJSUA_INVALID_ID) { |
| 1667 | pj_ansi_sprintf(line, "--capture-dev %d\n", config->capture_dev); |
| 1668 | pj_strcat2(&cfg, line); |
| 1669 | } |
| 1670 | if (config->playback_dev != PJSUA_INVALID_ID) { |
| 1671 | pj_ansi_sprintf(line, "--playback-dev %d\n", config->playback_dev); |
| 1672 | pj_strcat2(&cfg, line); |
| 1673 | } |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 1674 | if (config->media_cfg.snd_auto_close_time != -1) { |
| 1675 | pj_ansi_sprintf(line, "--snd-auto-close %d\n", |
| 1676 | config->media_cfg.snd_auto_close_time); |
| 1677 | pj_strcat2(&cfg, line); |
| 1678 | } |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1679 | if (config->no_tones) { |
| 1680 | pj_strcat2(&cfg, "--no-tones\n"); |
| 1681 | } |
Nanang Izzuddin | c985354 | 2008-07-17 16:59:07 +0000 | [diff] [blame] | 1682 | if (config->media_cfg.jb_max != -1) { |
| 1683 | pj_ansi_sprintf(line, "--jb-max-size %d\n", |
| 1684 | config->media_cfg.jb_max); |
| 1685 | pj_strcat2(&cfg, line); |
| 1686 | } |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 1687 | |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 1688 | /* Sound device latency */ |
| 1689 | if (config->capture_lat != PJMEDIA_SND_DEFAULT_REC_LATENCY) { |
| 1690 | pj_ansi_sprintf(line, "--capture-lat %d\n", config->capture_lat); |
| 1691 | pj_strcat2(&cfg, line); |
| 1692 | } |
| 1693 | if (config->playback_dev != PJMEDIA_SND_DEFAULT_PLAY_LATENCY) { |
| 1694 | pj_ansi_sprintf(line, "--playback-lat %d\n", config->playback_lat); |
| 1695 | pj_strcat2(&cfg, line); |
| 1696 | } |
| 1697 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1698 | /* Media clock rate. */ |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1699 | if (config->media_cfg.clock_rate != PJSUA_DEFAULT_CLOCK_RATE) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1700 | pj_ansi_sprintf(line, "--clock-rate %d\n", |
Benny Prijono | 0498d90 | 2006-06-19 14:49:14 +0000 | [diff] [blame] | 1701 | config->media_cfg.clock_rate); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1702 | pj_strcat2(&cfg, line); |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1703 | } else { |
| 1704 | pj_ansi_sprintf(line, "#using default --clock-rate %d\n", |
| 1705 | config->media_cfg.clock_rate); |
| 1706 | pj_strcat2(&cfg, line); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1707 | } |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1708 | |
Benny Prijono | c59ca6e | 2008-04-10 11:04:49 +0000 | [diff] [blame] | 1709 | if (config->media_cfg.snd_clock_rate && |
| 1710 | config->media_cfg.snd_clock_rate != config->media_cfg.clock_rate) |
| 1711 | { |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 1712 | pj_ansi_sprintf(line, "--snd-clock-rate %d\n", |
| 1713 | config->media_cfg.snd_clock_rate); |
| 1714 | pj_strcat2(&cfg, line); |
Benny Prijono | f3758ee | 2008-02-26 15:32:16 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 1717 | /* Stereo mode. */ |
| 1718 | if (config->media_cfg.channel_count == 2) { |
| 1719 | pj_ansi_sprintf(line, "--stereo\n"); |
| 1720 | pj_strcat2(&cfg, line); |
| 1721 | } |
| 1722 | |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1723 | /* quality */ |
| 1724 | if (config->media_cfg.quality != PJSUA_DEFAULT_CODEC_QUALITY) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1725 | pj_ansi_sprintf(line, "--quality %d\n", |
Benny Prijono | 0498d90 | 2006-06-19 14:49:14 +0000 | [diff] [blame] | 1726 | config->media_cfg.quality); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1727 | pj_strcat2(&cfg, line); |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1728 | } else { |
| 1729 | pj_ansi_sprintf(line, "#using default --quality %d\n", |
| 1730 | config->media_cfg.quality); |
| 1731 | pj_strcat2(&cfg, line); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1732 | } |
Benny Prijono | 0498d90 | 2006-06-19 14:49:14 +0000 | [diff] [blame] | 1733 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1734 | |
| 1735 | /* ptime */ |
Benny Prijono | 2adfe29 | 2007-05-11 10:36:08 +0000 | [diff] [blame] | 1736 | if (config->media_cfg.ptime) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1737 | pj_ansi_sprintf(line, "--ptime %d\n", |
Benny Prijono | 2adfe29 | 2007-05-11 10:36:08 +0000 | [diff] [blame] | 1738 | config->media_cfg.ptime); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1739 | pj_strcat2(&cfg, line); |
| 1740 | } |
| 1741 | |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1742 | /* no-vad */ |
| 1743 | if (config->media_cfg.no_vad) { |
| 1744 | pj_strcat2(&cfg, "--no-vad\n"); |
| 1745 | } |
| 1746 | |
| 1747 | /* ec-tail */ |
| 1748 | if (config->media_cfg.ec_tail_len != PJSUA_DEFAULT_EC_TAIL_LEN) { |
| 1749 | pj_ansi_sprintf(line, "--ec-tail %d\n", |
| 1750 | config->media_cfg.ec_tail_len); |
| 1751 | pj_strcat2(&cfg, line); |
| 1752 | } else { |
| 1753 | pj_ansi_sprintf(line, "#using default --ec-tail %d\n", |
| 1754 | config->media_cfg.ec_tail_len); |
| 1755 | pj_strcat2(&cfg, line); |
| 1756 | } |
| 1757 | |
Benny Prijono | 59b3ffe | 2008-08-11 18:10:42 +0000 | [diff] [blame] | 1758 | /* ec-opt */ |
| 1759 | if (config->media_cfg.ec_options != 0) { |
| 1760 | pj_ansi_sprintf(line, "--ec-opt %d\n", |
| 1761 | config->media_cfg.ec_options); |
| 1762 | pj_strcat2(&cfg, line); |
| 1763 | } |
Benny Prijono | 7097299 | 2006-08-05 11:13:58 +0000 | [diff] [blame] | 1764 | |
| 1765 | /* ilbc-mode */ |
| 1766 | if (config->media_cfg.ilbc_mode != PJSUA_DEFAULT_ILBC_MODE) { |
| 1767 | pj_ansi_sprintf(line, "--ilbc-mode %d\n", |
| 1768 | config->media_cfg.ilbc_mode); |
| 1769 | pj_strcat2(&cfg, line); |
| 1770 | } else { |
| 1771 | pj_ansi_sprintf(line, "#using default --ilbc-mode %d\n", |
| 1772 | config->media_cfg.ilbc_mode); |
| 1773 | pj_strcat2(&cfg, line); |
| 1774 | } |
| 1775 | |
| 1776 | /* RTP drop */ |
| 1777 | if (config->media_cfg.tx_drop_pct) { |
| 1778 | pj_ansi_sprintf(line, "--tx-drop-pct %d\n", |
| 1779 | config->media_cfg.tx_drop_pct); |
| 1780 | pj_strcat2(&cfg, line); |
| 1781 | |
| 1782 | } |
| 1783 | if (config->media_cfg.rx_drop_pct) { |
| 1784 | pj_ansi_sprintf(line, "--rx-drop-pct %d\n", |
| 1785 | config->media_cfg.rx_drop_pct); |
| 1786 | pj_strcat2(&cfg, line); |
| 1787 | |
| 1788 | } |
| 1789 | |
| 1790 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1791 | /* Start RTP port. */ |
| 1792 | pj_ansi_sprintf(line, "--rtp-port %d\n", |
| 1793 | config->rtp_cfg.port); |
| 1794 | pj_strcat2(&cfg, line); |
| 1795 | |
| 1796 | /* Add codec. */ |
| 1797 | for (i=0; i<config->codec_cnt; ++i) { |
| 1798 | pj_ansi_sprintf(line, "--add-codec %s\n", |
| 1799 | config->codec_arg[i].ptr); |
| 1800 | pj_strcat2(&cfg, line); |
| 1801 | } |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1802 | /* Disable codec */ |
| 1803 | for (i=0; i<config->codec_dis_cnt; ++i) { |
| 1804 | pj_ansi_sprintf(line, "--dis-codec %s\n", |
| 1805 | config->codec_dis[i].ptr); |
| 1806 | pj_strcat2(&cfg, line); |
| 1807 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1808 | |
| 1809 | pj_strcat2(&cfg, "\n#\n# User agent:\n#\n"); |
| 1810 | |
| 1811 | /* Auto-answer. */ |
| 1812 | if (config->auto_answer != 0) { |
| 1813 | pj_ansi_sprintf(line, "--auto-answer %d\n", |
| 1814 | config->auto_answer); |
| 1815 | pj_strcat2(&cfg, line); |
| 1816 | } |
| 1817 | |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 1818 | /* accept-redirect */ |
| 1819 | if (config->redir_op != PJSIP_REDIRECT_ACCEPT) { |
| 1820 | pj_ansi_sprintf(line, "--accept-redirect %d\n", |
| 1821 | config->redir_op); |
| 1822 | pj_strcat2(&cfg, line); |
| 1823 | } |
| 1824 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1825 | /* Max calls. */ |
| 1826 | pj_ansi_sprintf(line, "--max-calls %d\n", |
| 1827 | config->cfg.max_calls); |
| 1828 | pj_strcat2(&cfg, line); |
| 1829 | |
| 1830 | /* Uas-duration. */ |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 1831 | if (config->duration != NO_LIMIT) { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1832 | pj_ansi_sprintf(line, "--duration %d\n", |
| 1833 | config->duration); |
| 1834 | pj_strcat2(&cfg, line); |
| 1835 | } |
| 1836 | |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 1837 | /* norefersub ? */ |
| 1838 | if (config->no_refersub) { |
| 1839 | pj_strcat2(&cfg, "--norefersub\n"); |
| 1840 | } |
| 1841 | |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 1842 | if (pjsip_use_compact_form) |
| 1843 | { |
| 1844 | pj_strcat2(&cfg, "--use-compact-form\n"); |
| 1845 | } |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 1846 | |
Benny Prijono | 91d06b6 | 2008-09-20 12:16:56 +0000 | [diff] [blame] | 1847 | if (config->cfg.force_lr) { |
| 1848 | pj_strcat2(&cfg, "--no-force-lr\n"); |
| 1849 | } |
| 1850 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1851 | pj_strcat2(&cfg, "\n#\n# Buddies:\n#\n"); |
| 1852 | |
| 1853 | /* Add buddies. */ |
| 1854 | for (i=0; i<config->buddy_cnt; ++i) { |
| 1855 | pj_ansi_sprintf(line, "--add-buddy %.*s\n", |
| 1856 | (int)config->buddy_cfg[i].uri.slen, |
| 1857 | config->buddy_cfg[i].uri.ptr); |
| 1858 | pj_strcat2(&cfg, line); |
| 1859 | } |
| 1860 | |
| 1861 | |
| 1862 | *(cfg.ptr + cfg.slen) = '\0'; |
| 1863 | return cfg.slen; |
| 1864 | } |
| 1865 | |
| 1866 | |
| 1867 | /* |
| 1868 | * Dump application states. |
| 1869 | */ |
| 1870 | static void app_dump(pj_bool_t detail) |
| 1871 | { |
Benny Prijono | da9785b | 2007-04-02 20:43:06 +0000 | [diff] [blame] | 1872 | pjsua_dump(detail); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Nanang Izzuddin | 660eee8 | 2008-07-17 14:54:03 +0000 | [diff] [blame] | 1875 | /* |
| 1876 | * Print log of call states. Since call states may be too long for logger, |
| 1877 | * printing it is a bit tricky, it should be printed part by part as long |
| 1878 | * as the logger can accept. |
| 1879 | */ |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 1880 | static void log_call_dump(int call_id) |
| 1881 | { |
Nanang Izzuddin | 660eee8 | 2008-07-17 14:54:03 +0000 | [diff] [blame] | 1882 | unsigned call_dump_len; |
| 1883 | unsigned part_len; |
| 1884 | unsigned part_idx; |
| 1885 | unsigned log_decor; |
| 1886 | |
| 1887 | pjsua_call_dump(call_id, PJ_TRUE, some_buf, |
| 1888 | sizeof(some_buf), " "); |
| 1889 | call_dump_len = strlen(some_buf); |
| 1890 | |
| 1891 | log_decor = pj_log_get_decor(); |
| 1892 | pj_log_set_decor(log_decor & ~(PJ_LOG_HAS_NEWLINE | PJ_LOG_HAS_CR)); |
| 1893 | PJ_LOG(3,(THIS_FILE, "\n")); |
| 1894 | pj_log_set_decor(0); |
| 1895 | |
| 1896 | part_idx = 0; |
| 1897 | part_len = PJ_LOG_MAX_SIZE-80; |
| 1898 | while (part_idx < call_dump_len) { |
| 1899 | char p_orig, *p; |
| 1900 | |
| 1901 | p = &some_buf[part_idx]; |
| 1902 | if (part_idx + part_len > call_dump_len) |
| 1903 | part_len = call_dump_len - part_idx; |
| 1904 | p_orig = p[part_len]; |
| 1905 | p[part_len] = '\0'; |
| 1906 | PJ_LOG(3,(THIS_FILE, "%s", p)); |
| 1907 | p[part_len] = p_orig; |
| 1908 | part_idx += part_len; |
| 1909 | } |
| 1910 | pj_log_set_decor(log_decor); |
| 1911 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1912 | |
| 1913 | /***************************************************************************** |
| 1914 | * Console application |
| 1915 | */ |
| 1916 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1917 | static void ringback_start(pjsua_call_id call_id) |
| 1918 | { |
| 1919 | if (app_config.no_tones) |
| 1920 | return; |
| 1921 | |
| 1922 | if (app_config.call_data[call_id].ringback_on) |
| 1923 | return; |
| 1924 | |
| 1925 | app_config.call_data[call_id].ringback_on = PJ_TRUE; |
| 1926 | |
| 1927 | if (++app_config.ringback_cnt==1 && |
| 1928 | app_config.ringback_slot!=PJSUA_INVALID_ID) |
| 1929 | { |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1930 | pjsua_conf_connect(app_config.ringback_slot, 0); |
| 1931 | } |
| 1932 | } |
| 1933 | |
| 1934 | static void ring_stop(pjsua_call_id call_id) |
| 1935 | { |
| 1936 | if (app_config.no_tones) |
| 1937 | return; |
| 1938 | |
| 1939 | if (app_config.call_data[call_id].ringback_on) { |
| 1940 | app_config.call_data[call_id].ringback_on = PJ_FALSE; |
| 1941 | |
| 1942 | pj_assert(app_config.ringback_cnt>0); |
| 1943 | if (--app_config.ringback_cnt == 0 && |
| 1944 | app_config.ringback_slot!=PJSUA_INVALID_ID) |
| 1945 | { |
| 1946 | pjsua_conf_disconnect(app_config.ringback_slot, 0); |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 1947 | pjmedia_tonegen_rewind(app_config.ringback_port); |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | if (app_config.call_data[call_id].ring_on) { |
| 1952 | app_config.call_data[call_id].ring_on = PJ_FALSE; |
| 1953 | |
| 1954 | pj_assert(app_config.ring_cnt>0); |
| 1955 | if (--app_config.ring_cnt == 0 && |
| 1956 | app_config.ring_slot!=PJSUA_INVALID_ID) |
| 1957 | { |
| 1958 | pjsua_conf_disconnect(app_config.ring_slot, 0); |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 1959 | pjmedia_tonegen_rewind(app_config.ring_port); |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1960 | } |
| 1961 | } |
| 1962 | } |
| 1963 | |
| 1964 | static void ring_start(pjsua_call_id call_id) |
| 1965 | { |
| 1966 | if (app_config.no_tones) |
| 1967 | return; |
| 1968 | |
| 1969 | if (app_config.call_data[call_id].ring_on) |
| 1970 | return; |
| 1971 | |
| 1972 | app_config.call_data[call_id].ring_on = PJ_TRUE; |
| 1973 | |
| 1974 | if (++app_config.ring_cnt==1 && |
| 1975 | app_config.ring_slot!=PJSUA_INVALID_ID) |
| 1976 | { |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 1977 | pjsua_conf_connect(app_config.ring_slot, 0); |
| 1978 | } |
| 1979 | } |
| 1980 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 1981 | /* |
| 1982 | * Find next call when current call is disconnected or when user |
| 1983 | * press ']' |
| 1984 | */ |
| 1985 | static pj_bool_t find_next_call(void) |
| 1986 | { |
| 1987 | int i, max; |
| 1988 | |
| 1989 | max = pjsua_call_get_max_count(); |
| 1990 | for (i=current_call+1; i<max; ++i) { |
| 1991 | if (pjsua_call_is_active(i)) { |
| 1992 | current_call = i; |
| 1993 | return PJ_TRUE; |
| 1994 | } |
| 1995 | } |
| 1996 | |
| 1997 | for (i=0; i<current_call; ++i) { |
| 1998 | if (pjsua_call_is_active(i)) { |
| 1999 | current_call = i; |
| 2000 | return PJ_TRUE; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | current_call = PJSUA_INVALID_ID; |
| 2005 | return PJ_FALSE; |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | /* |
| 2010 | * Find previous call when user press '[' |
| 2011 | */ |
| 2012 | static pj_bool_t find_prev_call(void) |
| 2013 | { |
| 2014 | int i, max; |
| 2015 | |
| 2016 | max = pjsua_call_get_max_count(); |
| 2017 | for (i=current_call-1; i>=0; --i) { |
| 2018 | if (pjsua_call_is_active(i)) { |
| 2019 | current_call = i; |
| 2020 | return PJ_TRUE; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | for (i=max-1; i>current_call; --i) { |
| 2025 | if (pjsua_call_is_active(i)) { |
| 2026 | current_call = i; |
| 2027 | return PJ_TRUE; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | current_call = PJSUA_INVALID_ID; |
| 2032 | return PJ_FALSE; |
| 2033 | } |
| 2034 | |
| 2035 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 2036 | /* Callback from timer when the maximum call duration has been |
| 2037 | * exceeded. |
| 2038 | */ |
| 2039 | static void call_timeout_callback(pj_timer_heap_t *timer_heap, |
| 2040 | struct pj_timer_entry *entry) |
| 2041 | { |
| 2042 | pjsua_call_id call_id = entry->id; |
| 2043 | pjsua_msg_data msg_data; |
| 2044 | pjsip_generic_string_hdr warn; |
| 2045 | pj_str_t hname = pj_str("Warning"); |
| 2046 | pj_str_t hvalue = pj_str("399 pjsua \"Call duration exceeded\""); |
| 2047 | |
| 2048 | PJ_UNUSED_ARG(timer_heap); |
| 2049 | |
Benny Prijono | 148c9dd | 2006-09-19 13:37:53 +0000 | [diff] [blame] | 2050 | if (call_id == PJSUA_INVALID_ID) { |
| 2051 | PJ_LOG(1,(THIS_FILE, "Invalid call ID in timer callback")); |
| 2052 | return; |
| 2053 | } |
| 2054 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 2055 | /* Add warning header */ |
| 2056 | pjsua_msg_data_init(&msg_data); |
| 2057 | pjsip_generic_string_hdr_init2(&warn, &hname, &hvalue); |
| 2058 | pj_list_push_back(&msg_data.hdr_list, &warn); |
| 2059 | |
| 2060 | /* Call duration has been exceeded; disconnect the call */ |
| 2061 | PJ_LOG(3,(THIS_FILE, "Duration (%d seconds) has been exceeded " |
| 2062 | "for call %d, disconnecting the call", |
| 2063 | app_config.duration, call_id)); |
| 2064 | entry->id = PJSUA_INVALID_ID; |
| 2065 | pjsua_call_hangup(call_id, 200, NULL, &msg_data); |
| 2066 | } |
| 2067 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2068 | |
| 2069 | /* |
| 2070 | * Handler when invite state has changed. |
| 2071 | */ |
| 2072 | static void on_call_state(pjsua_call_id call_id, pjsip_event *e) |
| 2073 | { |
| 2074 | pjsua_call_info call_info; |
| 2075 | |
| 2076 | PJ_UNUSED_ARG(e); |
| 2077 | |
| 2078 | pjsua_call_get_info(call_id, &call_info); |
| 2079 | |
| 2080 | if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) { |
| 2081 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 2082 | /* Stop all ringback for this call */ |
| 2083 | ring_stop(call_id); |
| 2084 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 2085 | /* Cancel duration timer, if any */ |
| 2086 | if (app_config.call_data[call_id].timer.id != PJSUA_INVALID_ID) { |
| 2087 | struct call_data *cd = &app_config.call_data[call_id]; |
| 2088 | pjsip_endpoint *endpt = pjsua_get_pjsip_endpt(); |
| 2089 | |
| 2090 | cd->timer.id = PJSUA_INVALID_ID; |
| 2091 | pjsip_endpt_cancel_timer(endpt, &cd->timer); |
| 2092 | } |
| 2093 | |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 2094 | /* Rewind play file when hangup automatically, |
| 2095 | * since file is not looped |
| 2096 | */ |
| 2097 | if (app_config.auto_play_hangup) |
| 2098 | pjsua_player_set_pos(app_config.wav_id, 0); |
| 2099 | |
| 2100 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2101 | PJ_LOG(3,(THIS_FILE, "Call %d is DISCONNECTED [reason=%d (%s)]", |
| 2102 | call_id, |
| 2103 | call_info.last_status, |
| 2104 | call_info.last_status_text.ptr)); |
| 2105 | |
| 2106 | if (call_id == current_call) { |
| 2107 | find_next_call(); |
| 2108 | } |
| 2109 | |
Benny Prijono | 4be63b5 | 2006-11-25 14:50:25 +0000 | [diff] [blame] | 2110 | /* Dump media state upon disconnected */ |
| 2111 | if (1) { |
Benny Prijono | 4be63b5 | 2006-11-25 14:50:25 +0000 | [diff] [blame] | 2112 | PJ_LOG(5,(THIS_FILE, |
Nanang Izzuddin | 660eee8 | 2008-07-17 14:54:03 +0000 | [diff] [blame] | 2113 | "Call %d disconnected, dumping media stats..", |
| 2114 | call_id)); |
| 2115 | log_call_dump(call_id); |
Benny Prijono | 4be63b5 | 2006-11-25 14:50:25 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2118 | } else { |
| 2119 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 2120 | if (app_config.duration!=NO_LIMIT && |
| 2121 | call_info.state == PJSIP_INV_STATE_CONFIRMED) |
| 2122 | { |
| 2123 | /* Schedule timer to hangup call after the specified duration */ |
| 2124 | struct call_data *cd = &app_config.call_data[call_id]; |
| 2125 | pjsip_endpoint *endpt = pjsua_get_pjsip_endpt(); |
| 2126 | pj_time_val delay; |
| 2127 | |
| 2128 | cd->timer.id = call_id; |
| 2129 | delay.sec = app_config.duration; |
| 2130 | delay.msec = 0; |
| 2131 | pjsip_endpt_schedule_timer(endpt, &cd->timer, &delay); |
| 2132 | } |
| 2133 | |
Benny Prijono | 4be63b5 | 2006-11-25 14:50:25 +0000 | [diff] [blame] | 2134 | if (call_info.state == PJSIP_INV_STATE_EARLY) { |
| 2135 | int code; |
| 2136 | pj_str_t reason; |
| 2137 | pjsip_msg *msg; |
| 2138 | |
| 2139 | /* This can only occur because of TX or RX message */ |
| 2140 | pj_assert(e->type == PJSIP_EVENT_TSX_STATE); |
| 2141 | |
| 2142 | if (e->body.tsx_state.type == PJSIP_EVENT_RX_MSG) { |
| 2143 | msg = e->body.tsx_state.src.rdata->msg_info.msg; |
| 2144 | } else { |
| 2145 | msg = e->body.tsx_state.src.tdata->msg; |
| 2146 | } |
| 2147 | |
| 2148 | code = msg->line.status.code; |
| 2149 | reason = msg->line.status.reason; |
| 2150 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 2151 | /* Start ringback for 180 for UAC unless there's SDP in 180 */ |
| 2152 | if (call_info.role==PJSIP_ROLE_UAC && code==180 && |
| 2153 | msg->body == NULL && |
| 2154 | call_info.media_status==PJSUA_CALL_MEDIA_NONE) |
| 2155 | { |
| 2156 | ringback_start(call_id); |
| 2157 | } |
| 2158 | |
Benny Prijono | 4be63b5 | 2006-11-25 14:50:25 +0000 | [diff] [blame] | 2159 | PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s (%d %.*s)", |
| 2160 | call_id, call_info.state_text.ptr, |
| 2161 | code, (int)reason.slen, reason.ptr)); |
| 2162 | } else { |
| 2163 | PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s", |
| 2164 | call_id, |
| 2165 | call_info.state_text.ptr)); |
| 2166 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2167 | |
| 2168 | if (current_call==PJSUA_INVALID_ID) |
| 2169 | current_call = call_id; |
| 2170 | |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | /** |
| 2176 | * Handler when there is incoming call. |
| 2177 | */ |
| 2178 | static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, |
| 2179 | pjsip_rx_data *rdata) |
| 2180 | { |
| 2181 | pjsua_call_info call_info; |
| 2182 | |
| 2183 | PJ_UNUSED_ARG(acc_id); |
| 2184 | PJ_UNUSED_ARG(rdata); |
| 2185 | |
| 2186 | pjsua_call_get_info(call_id, &call_info); |
| 2187 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 2188 | /* Start ringback */ |
| 2189 | ring_start(call_id); |
| 2190 | |
Benny Prijono | 2285e7e | 2008-12-17 14:28:18 +0000 | [diff] [blame] | 2191 | if (current_call==PJSUA_INVALID_ID) |
| 2192 | current_call = call_id; |
| 2193 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2194 | if (app_config.auto_answer > 0) { |
| 2195 | pjsua_call_answer(call_id, app_config.auto_answer, NULL, NULL); |
| 2196 | } |
| 2197 | |
| 2198 | if (app_config.auto_answer < 200) { |
| 2199 | PJ_LOG(3,(THIS_FILE, |
| 2200 | "Incoming call for account %d!\n" |
| 2201 | "From: %s\n" |
| 2202 | "To: %s\n" |
| 2203 | "Press a to answer or h to reject call", |
| 2204 | acc_id, |
| 2205 | call_info.remote_info.ptr, |
| 2206 | call_info.local_info.ptr)); |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | |
| 2211 | /* |
Benny Prijono | feb69f4 | 2007-10-05 09:12:26 +0000 | [diff] [blame] | 2212 | * Handler when a transaction within a call has changed state. |
| 2213 | */ |
| 2214 | static void on_call_tsx_state(pjsua_call_id call_id, |
| 2215 | pjsip_transaction *tsx, |
| 2216 | pjsip_event *e) |
| 2217 | { |
| 2218 | const pjsip_method info_method = |
| 2219 | { |
| 2220 | PJSIP_OTHER_METHOD, |
| 2221 | { "INFO", 4 } |
| 2222 | }; |
| 2223 | |
| 2224 | if (pjsip_method_cmp(&tsx->method, &info_method)==0) { |
| 2225 | /* |
| 2226 | * Handle INFO method. |
| 2227 | */ |
| 2228 | if (tsx->role == PJSIP_ROLE_UAC && |
| 2229 | (tsx->state == PJSIP_TSX_STATE_COMPLETED || |
Benny Prijono | b071a78 | 2007-10-10 13:12:37 +0000 | [diff] [blame] | 2230 | (tsx->state == PJSIP_TSX_STATE_TERMINATED && |
| 2231 | e->body.tsx_state.prev_state != PJSIP_TSX_STATE_COMPLETED))) |
Benny Prijono | feb69f4 | 2007-10-05 09:12:26 +0000 | [diff] [blame] | 2232 | { |
| 2233 | /* Status of outgoing INFO request */ |
| 2234 | if (tsx->status_code >= 200 && tsx->status_code < 300) { |
| 2235 | PJ_LOG(4,(THIS_FILE, |
| 2236 | "Call %d: DTMF sent successfully with INFO", |
| 2237 | call_id)); |
| 2238 | } else if (tsx->status_code >= 300) { |
| 2239 | PJ_LOG(4,(THIS_FILE, |
| 2240 | "Call %d: Failed to send DTMF with INFO: %d/%.*s", |
| 2241 | call_id, |
| 2242 | tsx->status_code, |
| 2243 | (int)tsx->status_text.slen, |
| 2244 | tsx->status_text.ptr)); |
| 2245 | } |
| 2246 | } else if (tsx->role == PJSIP_ROLE_UAS && |
| 2247 | tsx->state == PJSIP_TSX_STATE_TRYING) |
| 2248 | { |
| 2249 | /* Answer incoming INFO with 200/OK */ |
| 2250 | pjsip_rx_data *rdata; |
| 2251 | pjsip_tx_data *tdata; |
| 2252 | pj_status_t status; |
| 2253 | |
| 2254 | rdata = e->body.tsx_state.src.rdata; |
| 2255 | |
| 2256 | if (rdata->msg_info.msg->body) { |
| 2257 | status = pjsip_endpt_create_response(tsx->endpt, rdata, |
| 2258 | 200, NULL, &tdata); |
| 2259 | if (status == PJ_SUCCESS) |
| 2260 | status = pjsip_tsx_send_msg(tsx, tdata); |
| 2261 | |
| 2262 | PJ_LOG(3,(THIS_FILE, "Call %d: incoming INFO:\n%.*s", |
| 2263 | call_id, |
| 2264 | (int)rdata->msg_info.msg->body->len, |
| 2265 | rdata->msg_info.msg->body->data)); |
| 2266 | } else { |
| 2267 | status = pjsip_endpt_create_response(tsx->endpt, rdata, |
| 2268 | 400, NULL, &tdata); |
| 2269 | if (status == PJ_SUCCESS) |
| 2270 | status = pjsip_tsx_send_msg(tsx, tdata); |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | } |
| 2275 | |
| 2276 | |
| 2277 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2278 | * Callback on media state changed event. |
| 2279 | * The action may connect the call to sound device, to file, or |
| 2280 | * to loop the call. |
| 2281 | */ |
| 2282 | static void on_call_media_state(pjsua_call_id call_id) |
| 2283 | { |
| 2284 | pjsua_call_info call_info; |
| 2285 | |
| 2286 | pjsua_call_get_info(call_id, &call_info); |
| 2287 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 2288 | /* Stop ringback */ |
| 2289 | ring_stop(call_id); |
| 2290 | |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2291 | /* Connect ports appropriately when media status is ACTIVE or REMOTE HOLD, |
| 2292 | * otherwise we should NOT connect the ports. |
| 2293 | */ |
| 2294 | if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE || |
| 2295 | call_info.media_status == PJSUA_CALL_MEDIA_REMOTE_HOLD) |
| 2296 | { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2297 | pj_bool_t connect_sound = PJ_TRUE; |
| 2298 | |
| 2299 | /* Loopback sound, if desired */ |
| 2300 | if (app_config.auto_loop) { |
| 2301 | pjsua_conf_connect(call_info.conf_slot, call_info.conf_slot); |
| 2302 | connect_sound = PJ_FALSE; |
Benny Prijono | f6c77f4 | 2008-08-13 13:52:19 +0000 | [diff] [blame] | 2303 | } |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 2304 | |
Benny Prijono | f6c77f4 | 2008-08-13 13:52:19 +0000 | [diff] [blame] | 2305 | /* Automatically record conversation, if desired */ |
| 2306 | if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { |
| 2307 | pjsua_conf_connect(call_info.conf_slot, app_config.rec_port); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /* Stream a file, if desired */ |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 2311 | if ((app_config.auto_play || app_config.auto_play_hangup) && |
| 2312 | app_config.wav_port != PJSUA_INVALID_ID) |
| 2313 | { |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2314 | pjsua_conf_connect(app_config.wav_port, call_info.conf_slot); |
| 2315 | connect_sound = PJ_FALSE; |
| 2316 | } |
| 2317 | |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 2318 | /* Put call in conference with other calls, if desired */ |
| 2319 | if (app_config.auto_conf) { |
| 2320 | pjsua_call_id call_ids[PJSUA_MAX_CALLS]; |
Benny Prijono | 10861bc | 2006-08-07 13:22:43 +0000 | [diff] [blame] | 2321 | unsigned call_cnt=PJ_ARRAY_SIZE(call_ids); |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 2322 | unsigned i; |
| 2323 | |
| 2324 | /* Get all calls, and establish media connection between |
| 2325 | * this call and other calls. |
| 2326 | */ |
| 2327 | pjsua_enum_calls(call_ids, &call_cnt); |
Benny Prijono | 10861bc | 2006-08-07 13:22:43 +0000 | [diff] [blame] | 2328 | |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 2329 | for (i=0; i<call_cnt; ++i) { |
| 2330 | if (call_ids[i] == call_id) |
| 2331 | continue; |
| 2332 | |
| 2333 | if (!pjsua_call_has_media(call_ids[i])) |
| 2334 | continue; |
| 2335 | |
| 2336 | pjsua_conf_connect(call_info.conf_slot, |
| 2337 | pjsua_call_get_conf_port(call_ids[i])); |
| 2338 | pjsua_conf_connect(pjsua_call_get_conf_port(call_ids[i]), |
| 2339 | call_info.conf_slot); |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 2340 | |
| 2341 | /* Automatically record conversation, if desired */ |
| 2342 | if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { |
| 2343 | pjsua_conf_connect(pjsua_call_get_conf_port(call_ids[i]), |
| 2344 | app_config.rec_port); |
| 2345 | } |
| 2346 | |
Benny Prijono | 7ca96da | 2006-08-07 12:11:40 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /* Also connect call to local sound device */ |
| 2350 | connect_sound = PJ_TRUE; |
| 2351 | } |
| 2352 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2353 | /* Otherwise connect to sound device */ |
| 2354 | if (connect_sound) { |
| 2355 | pjsua_conf_connect(call_info.conf_slot, 0); |
| 2356 | pjsua_conf_connect(0, call_info.conf_slot); |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 2357 | |
| 2358 | /* Automatically record conversation, if desired */ |
| 2359 | if (app_config.auto_rec && app_config.rec_port != PJSUA_INVALID_ID) { |
| 2360 | pjsua_conf_connect(call_info.conf_slot, app_config.rec_port); |
| 2361 | pjsua_conf_connect(0, app_config.rec_port); |
| 2362 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2363 | } |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2364 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2365 | |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2366 | /* Handle media status */ |
| 2367 | switch (call_info.media_status) { |
| 2368 | case PJSUA_CALL_MEDIA_ACTIVE: |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2369 | PJ_LOG(3,(THIS_FILE, "Media for call %d is active", call_id)); |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2370 | break; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2371 | |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2372 | case PJSUA_CALL_MEDIA_LOCAL_HOLD: |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2373 | PJ_LOG(3,(THIS_FILE, "Media for call %d is suspended (hold) by local", |
| 2374 | call_id)); |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2375 | break; |
| 2376 | |
| 2377 | case PJSUA_CALL_MEDIA_REMOTE_HOLD: |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2378 | PJ_LOG(3,(THIS_FILE, |
| 2379 | "Media for call %d is suspended (hold) by remote", |
| 2380 | call_id)); |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2381 | break; |
Benny Prijono | 096c56c | 2007-09-15 08:30:16 +0000 | [diff] [blame] | 2382 | |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2383 | case PJSUA_CALL_MEDIA_ERROR: |
| 2384 | PJ_LOG(3,(THIS_FILE, |
Benny Prijono | 096c56c | 2007-09-15 08:30:16 +0000 | [diff] [blame] | 2385 | "Media has reported error, disconnecting call")); |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2386 | { |
| 2387 | pj_str_t reason = pj_str("ICE negotiation failed"); |
| 2388 | pjsua_call_hangup(call_id, 500, &reason, NULL); |
| 2389 | } |
| 2390 | break; |
Benny Prijono | 096c56c | 2007-09-15 08:30:16 +0000 | [diff] [blame] | 2391 | |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2392 | case PJSUA_CALL_MEDIA_NONE: |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2393 | PJ_LOG(3,(THIS_FILE, |
| 2394 | "Media for call %d is inactive", |
| 2395 | call_id)); |
Nanang Izzuddin | 99d6952 | 2008-08-04 15:01:38 +0000 | [diff] [blame] | 2396 | break; |
| 2397 | |
| 2398 | default: |
| 2399 | pj_assert(!"Unhandled media status"); |
| 2400 | break; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2401 | } |
| 2402 | } |
| 2403 | |
Benny Prijono | 0875ae8 | 2006-12-26 00:11:48 +0000 | [diff] [blame] | 2404 | /* |
| 2405 | * DTMF callback. |
| 2406 | */ |
| 2407 | static void call_on_dtmf_callback(pjsua_call_id call_id, int dtmf) |
| 2408 | { |
| 2409 | PJ_LOG(3,(THIS_FILE, "Incoming DTMF on call %d: %c", call_id, dtmf)); |
| 2410 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2411 | |
| 2412 | /* |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 2413 | * Redirection handler. |
| 2414 | */ |
Benny Prijono | 08a48b8 | 2008-11-27 12:42:07 +0000 | [diff] [blame] | 2415 | static pjsip_redirect_op call_on_redirected(pjsua_call_id call_id, |
| 2416 | const pjsip_uri *target, |
| 2417 | const pjsip_event *e) |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 2418 | { |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 2419 | PJ_UNUSED_ARG(e); |
| 2420 | |
Benny Prijono | 08a48b8 | 2008-11-27 12:42:07 +0000 | [diff] [blame] | 2421 | if (app_config.redir_op == PJSIP_REDIRECT_PENDING) { |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 2422 | char uristr[PJSIP_MAX_URL_SIZE]; |
| 2423 | int len; |
| 2424 | |
| 2425 | len = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, target, uristr, |
| 2426 | sizeof(uristr)); |
| 2427 | if (len < 1) { |
| 2428 | pj_ansi_strcpy(uristr, "--URI too long--"); |
| 2429 | } |
| 2430 | |
| 2431 | PJ_LOG(3,(THIS_FILE, "Call %d is being redirected to %.*s. " |
| 2432 | "Press 'Ra' to accept, 'Rr' to reject, or 'Rd' to " |
| 2433 | "disconnect.", |
| 2434 | call_id, len, uristr)); |
| 2435 | } |
Benny Prijono | 08a48b8 | 2008-11-27 12:42:07 +0000 | [diff] [blame] | 2436 | |
| 2437 | return app_config.redir_op; |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2441 | * Handler registration status has changed. |
| 2442 | */ |
| 2443 | static void on_reg_state(pjsua_acc_id acc_id) |
| 2444 | { |
| 2445 | PJ_UNUSED_ARG(acc_id); |
| 2446 | |
| 2447 | // Log already written. |
| 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | /* |
Benny Prijono | 563cd7a | 2008-08-19 20:02:15 +0000 | [diff] [blame] | 2452 | * Handler for incoming presence subscription request |
| 2453 | */ |
| 2454 | static void on_incoming_subscribe(pjsua_acc_id acc_id, |
| 2455 | pjsua_srv_pres *srv_pres, |
| 2456 | pjsua_buddy_id buddy_id, |
| 2457 | const pj_str_t *from, |
| 2458 | pjsip_rx_data *rdata, |
| 2459 | pjsip_status_code *code, |
| 2460 | pj_str_t *reason, |
| 2461 | pjsua_msg_data *msg_data) |
| 2462 | { |
| 2463 | /* Just accept the request (the default behavior) */ |
| 2464 | PJ_UNUSED_ARG(acc_id); |
| 2465 | PJ_UNUSED_ARG(srv_pres); |
| 2466 | PJ_UNUSED_ARG(buddy_id); |
| 2467 | PJ_UNUSED_ARG(from); |
| 2468 | PJ_UNUSED_ARG(rdata); |
| 2469 | PJ_UNUSED_ARG(code); |
| 2470 | PJ_UNUSED_ARG(reason); |
| 2471 | PJ_UNUSED_ARG(msg_data); |
| 2472 | } |
| 2473 | |
| 2474 | |
| 2475 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2476 | * Handler on buddy state changed. |
| 2477 | */ |
| 2478 | static void on_buddy_state(pjsua_buddy_id buddy_id) |
| 2479 | { |
| 2480 | pjsua_buddy_info info; |
| 2481 | pjsua_buddy_get_info(buddy_id, &info); |
| 2482 | |
| 2483 | PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", |
| 2484 | (int)info.uri.slen, |
| 2485 | info.uri.ptr, |
| 2486 | (int)info.status_text.slen, |
| 2487 | info.status_text.ptr)); |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | /** |
| 2492 | * Incoming IM message (i.e. MESSAGE request)! |
| 2493 | */ |
| 2494 | static void on_pager(pjsua_call_id call_id, const pj_str_t *from, |
| 2495 | const pj_str_t *to, const pj_str_t *contact, |
| 2496 | const pj_str_t *mime_type, const pj_str_t *text) |
| 2497 | { |
| 2498 | /* Note: call index may be -1 */ |
| 2499 | PJ_UNUSED_ARG(call_id); |
| 2500 | PJ_UNUSED_ARG(to); |
| 2501 | PJ_UNUSED_ARG(contact); |
| 2502 | PJ_UNUSED_ARG(mime_type); |
| 2503 | |
Benny Prijono | f4b538d | 2007-05-14 16:45:20 +0000 | [diff] [blame] | 2504 | PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s (%.*s)", |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2505 | (int)from->slen, from->ptr, |
Benny Prijono | f4b538d | 2007-05-14 16:45:20 +0000 | [diff] [blame] | 2506 | (int)text->slen, text->ptr, |
| 2507 | (int)mime_type->slen, mime_type->ptr)); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | |
| 2511 | /** |
| 2512 | * Received typing indication |
| 2513 | */ |
| 2514 | static void on_typing(pjsua_call_id call_id, const pj_str_t *from, |
| 2515 | const pj_str_t *to, const pj_str_t *contact, |
| 2516 | pj_bool_t is_typing) |
| 2517 | { |
| 2518 | PJ_UNUSED_ARG(call_id); |
| 2519 | PJ_UNUSED_ARG(to); |
| 2520 | PJ_UNUSED_ARG(contact); |
| 2521 | |
| 2522 | PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s", |
| 2523 | (int)from->slen, from->ptr, |
| 2524 | (is_typing?"is typing..":"has stopped typing"))); |
| 2525 | } |
| 2526 | |
| 2527 | |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 2528 | /** |
| 2529 | * Call transfer request status. |
| 2530 | */ |
| 2531 | static void on_call_transfer_status(pjsua_call_id call_id, |
| 2532 | int status_code, |
| 2533 | const pj_str_t *status_text, |
| 2534 | pj_bool_t final, |
| 2535 | pj_bool_t *p_cont) |
| 2536 | { |
| 2537 | PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s", |
| 2538 | call_id, status_code, |
| 2539 | (int)status_text->slen, status_text->ptr, |
| 2540 | (final ? "[final]" : ""))); |
| 2541 | |
| 2542 | if (status_code/100 == 2) { |
| 2543 | PJ_LOG(3,(THIS_FILE, |
| 2544 | "Call %d: call transfered successfully, disconnecting call", |
| 2545 | call_id)); |
| 2546 | pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL); |
| 2547 | *p_cont = PJ_FALSE; |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2552 | /* |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 2553 | * Notification that call is being replaced. |
| 2554 | */ |
| 2555 | static void on_call_replaced(pjsua_call_id old_call_id, |
| 2556 | pjsua_call_id new_call_id) |
| 2557 | { |
| 2558 | pjsua_call_info old_ci, new_ci; |
| 2559 | |
| 2560 | pjsua_call_get_info(old_call_id, &old_ci); |
| 2561 | pjsua_call_get_info(new_call_id, &new_ci); |
| 2562 | |
| 2563 | PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by " |
| 2564 | "call %d with %.*s", |
| 2565 | old_call_id, |
| 2566 | (int)old_ci.remote_info.slen, old_ci.remote_info.ptr, |
| 2567 | new_call_id, |
| 2568 | (int)new_ci.remote_info.slen, new_ci.remote_info.ptr)); |
| 2569 | } |
| 2570 | |
| 2571 | |
| 2572 | /* |
Benny Prijono | 6ba8c54 | 2007-10-16 01:34:14 +0000 | [diff] [blame] | 2573 | * NAT type detection callback. |
| 2574 | */ |
| 2575 | static void on_nat_detect(const pj_stun_nat_detect_result *res) |
| 2576 | { |
| 2577 | if (res->status != PJ_SUCCESS) { |
| 2578 | pjsua_perror(THIS_FILE, "NAT detection failed", res->status); |
| 2579 | } else { |
| 2580 | PJ_LOG(3, (THIS_FILE, "NAT detected as %s", res->nat_type_name)); |
| 2581 | } |
| 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2586 | * Print buddy list. |
| 2587 | */ |
| 2588 | static void print_buddy_list(void) |
| 2589 | { |
| 2590 | pjsua_buddy_id ids[64]; |
| 2591 | int i; |
| 2592 | unsigned count = PJ_ARRAY_SIZE(ids); |
| 2593 | |
| 2594 | puts("Buddy list:"); |
| 2595 | |
| 2596 | pjsua_enum_buddies(ids, &count); |
| 2597 | |
| 2598 | if (count == 0) |
| 2599 | puts(" -none-"); |
| 2600 | else { |
| 2601 | for (i=0; i<(int)count; ++i) { |
| 2602 | pjsua_buddy_info info; |
| 2603 | |
| 2604 | if (pjsua_buddy_get_info(ids[i], &info) != PJ_SUCCESS) |
| 2605 | continue; |
| 2606 | |
Benny Prijono | 4461c7d | 2007-08-25 13:36:15 +0000 | [diff] [blame] | 2607 | printf(" [%2d] <%.*s> %.*s\n", |
| 2608 | ids[i]+1, |
| 2609 | (int)info.status_text.slen, |
| 2610 | info.status_text.ptr, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2611 | (int)info.uri.slen, |
| 2612 | info.uri.ptr); |
| 2613 | } |
| 2614 | } |
| 2615 | puts(""); |
| 2616 | } |
| 2617 | |
| 2618 | |
| 2619 | /* |
| 2620 | * Print account status. |
| 2621 | */ |
| 2622 | static void print_acc_status(int acc_id) |
| 2623 | { |
| 2624 | char buf[80]; |
| 2625 | pjsua_acc_info info; |
| 2626 | |
| 2627 | pjsua_acc_get_info(acc_id, &info); |
| 2628 | |
| 2629 | if (!info.has_registration) { |
| 2630 | pj_ansi_snprintf(buf, sizeof(buf), "%.*s", |
| 2631 | (int)info.status_text.slen, |
| 2632 | info.status_text.ptr); |
| 2633 | |
| 2634 | } else { |
| 2635 | pj_ansi_snprintf(buf, sizeof(buf), |
| 2636 | "%d/%.*s (expires=%d)", |
| 2637 | info.status, |
| 2638 | (int)info.status_text.slen, |
| 2639 | info.status_text.ptr, |
| 2640 | info.expires); |
| 2641 | |
| 2642 | } |
| 2643 | |
| 2644 | printf(" %c[%2d] %.*s: %s\n", (acc_id==current_acc?'*':' '), |
| 2645 | acc_id, (int)info.acc_uri.slen, info.acc_uri.ptr, buf); |
Benny Prijono | 4461c7d | 2007-08-25 13:36:15 +0000 | [diff] [blame] | 2646 | printf(" Online status: %.*s\n", |
| 2647 | (int)info.online_status_text.slen, |
| 2648 | info.online_status_text.ptr); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2649 | } |
| 2650 | |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 2651 | /* Playfile done notification, set timer to hangup calls */ |
| 2652 | pj_status_t on_playfile_done(pjmedia_port *port, void *usr_data) |
| 2653 | { |
| 2654 | pj_time_val delay; |
| 2655 | |
| 2656 | PJ_UNUSED_ARG(port); |
| 2657 | PJ_UNUSED_ARG(usr_data); |
| 2658 | |
| 2659 | /* Just rewind WAV when it is played outside of call */ |
| 2660 | if (pjsua_call_get_count() == 0) { |
| 2661 | pjsua_player_set_pos(app_config.wav_id, 0); |
| 2662 | return PJ_SUCCESS; |
| 2663 | } |
| 2664 | |
| 2665 | /* Timer is already active */ |
| 2666 | if (app_config.auto_hangup_timer.id == 1) |
| 2667 | return PJ_SUCCESS; |
| 2668 | |
| 2669 | app_config.auto_hangup_timer.id = 1; |
| 2670 | delay.sec = 0; |
| 2671 | delay.msec = 200; /* Give 200 ms before hangup */ |
| 2672 | pjsip_endpt_schedule_timer(pjsua_get_pjsip_endpt(), |
| 2673 | &app_config.auto_hangup_timer, |
| 2674 | &delay); |
| 2675 | |
| 2676 | return PJ_SUCCESS; |
| 2677 | } |
| 2678 | |
| 2679 | /* Auto hangup timer callback */ |
| 2680 | static void hangup_timeout_callback(pj_timer_heap_t *timer_heap, |
| 2681 | struct pj_timer_entry *entry) |
| 2682 | { |
| 2683 | PJ_UNUSED_ARG(timer_heap); |
| 2684 | PJ_UNUSED_ARG(entry); |
| 2685 | |
| 2686 | app_config.auto_hangup_timer.id = 0; |
| 2687 | pjsua_call_hangup_all(); |
| 2688 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2689 | |
| 2690 | /* |
| 2691 | * Show a bit of help. |
| 2692 | */ |
| 2693 | static void keystroke_help(void) |
| 2694 | { |
| 2695 | pjsua_acc_id acc_ids[16]; |
| 2696 | unsigned count = PJ_ARRAY_SIZE(acc_ids); |
| 2697 | int i; |
| 2698 | |
| 2699 | printf(">>>>\n"); |
| 2700 | |
| 2701 | pjsua_enum_accs(acc_ids, &count); |
| 2702 | |
| 2703 | printf("Account list:\n"); |
| 2704 | for (i=0; i<(int)count; ++i) |
| 2705 | print_acc_status(acc_ids[i]); |
| 2706 | |
| 2707 | print_buddy_list(); |
| 2708 | |
| 2709 | //puts("Commands:"); |
| 2710 | puts("+=============================================================================+"); |
| 2711 | puts("| Call Commands: | Buddy, IM & Presence: | Account: |"); |
| 2712 | puts("| | | |"); |
| 2713 | puts("| m Make new call | +b Add new buddy .| +a Add new accnt |"); |
| 2714 | puts("| M Make multiple calls | -b Delete buddy | -a Delete accnt. |"); |
Benny Prijono | 4461c7d | 2007-08-25 13:36:15 +0000 | [diff] [blame] | 2715 | puts("| a Answer call | i Send IM | !a Modify accnt. |"); |
| 2716 | puts("| h Hangup call (ha=all) | s Subscribe presence | rr (Re-)register |"); |
| 2717 | puts("| H Hold call | u Unsubscribe presence | ru Unregister |"); |
| 2718 | puts("| v re-inVite (release hold) | t ToGgle Online status | > Cycle next ac.|"); |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 2719 | puts("| U send UPDATE | T Set online status | < Cycle prev ac.|"); |
| 2720 | puts("| ],[ Select next/prev call +--------------------------+-------------------+"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2721 | puts("| x Xfer call | Media Commands: | Status & Config: |"); |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 2722 | puts("| X Xfer with Replaces | | |"); |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 2723 | puts("| # Send RFC 2833 DTMF | cl List ports | d Dump status |"); |
| 2724 | puts("| * Send DTMF with INFO | cc Connect port | dd Dump detailed |"); |
| 2725 | puts("| dq Dump curr. call quality | cd Disconnect port | dc Dump config |"); |
| 2726 | puts("| | V Adjust audio Volume | f Save config |"); |
| 2727 | puts("| S Send arbitrary REQUEST | Cp Codec priorities | f Save config |"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2728 | puts("+------------------------------+--------------------------+-------------------+"); |
Benny Prijono | ddd02de | 2008-06-26 22:20:11 +0000 | [diff] [blame] | 2729 | puts("| q QUIT sleep MS echo [0|1|txt] n: detect NAT type |"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2730 | puts("+=============================================================================+"); |
Benny Prijono | 48af79c | 2006-07-22 12:49:17 +0000 | [diff] [blame] | 2731 | |
| 2732 | i = pjsua_call_get_count(); |
| 2733 | printf("You have %d active call%s\n", i, (i>1?"s":"")); |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 2734 | |
| 2735 | if (current_call != PJSUA_INVALID_ID) { |
| 2736 | pjsua_call_info ci; |
| 2737 | if (pjsua_call_get_info(current_call, &ci)==PJ_SUCCESS) |
| 2738 | printf("Current call id=%d to %.*s [%.*s]\n", current_call, |
| 2739 | (int)ci.remote_info.slen, ci.remote_info.ptr, |
| 2740 | (int)ci.state_text.slen, ci.state_text.ptr); |
| 2741 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | /* |
| 2746 | * Input simple string |
| 2747 | */ |
| 2748 | static pj_bool_t simple_input(const char *title, char *buf, pj_size_t len) |
| 2749 | { |
| 2750 | char *p; |
| 2751 | |
| 2752 | printf("%s (empty to cancel): ", title); fflush(stdout); |
Benny Prijono | 32d267b | 2009-01-01 22:08:21 +0000 | [diff] [blame] | 2753 | if (fgets(buf, len, stdin) == NULL) |
| 2754 | return PJ_FALSE; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2755 | |
| 2756 | /* Remove trailing newlines. */ |
| 2757 | for (p=buf; ; ++p) { |
| 2758 | if (*p=='\r' || *p=='\n') *p='\0'; |
| 2759 | else if (!*p) break; |
| 2760 | } |
| 2761 | |
| 2762 | if (!*buf) |
| 2763 | return PJ_FALSE; |
| 2764 | |
| 2765 | return PJ_TRUE; |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | #define NO_NB -2 |
| 2770 | struct input_result |
| 2771 | { |
| 2772 | int nb_result; |
| 2773 | char *uri_result; |
| 2774 | }; |
| 2775 | |
| 2776 | |
| 2777 | /* |
| 2778 | * Input URL. |
| 2779 | */ |
| 2780 | static void ui_input_url(const char *title, char *buf, int len, |
| 2781 | struct input_result *result) |
| 2782 | { |
| 2783 | result->nb_result = NO_NB; |
| 2784 | result->uri_result = NULL; |
| 2785 | |
| 2786 | print_buddy_list(); |
| 2787 | |
| 2788 | printf("Choices:\n" |
| 2789 | " 0 For current dialog.\n" |
| 2790 | " -1 All %d buddies in buddy list\n" |
| 2791 | " [1 -%2d] Select from buddy list\n" |
| 2792 | " URL An URL\n" |
| 2793 | " <Enter> Empty input (or 'q') to cancel\n" |
| 2794 | , pjsua_get_buddy_count(), pjsua_get_buddy_count()); |
| 2795 | printf("%s: ", title); |
| 2796 | |
| 2797 | fflush(stdout); |
Benny Prijono | 32d267b | 2009-01-01 22:08:21 +0000 | [diff] [blame] | 2798 | if (fgets(buf, len, stdin) == NULL) |
| 2799 | return; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2800 | len = strlen(buf); |
| 2801 | |
| 2802 | /* Left trim */ |
| 2803 | while (pj_isspace(*buf)) { |
| 2804 | ++buf; |
| 2805 | --len; |
| 2806 | } |
| 2807 | |
| 2808 | /* Remove trailing newlines */ |
| 2809 | while (len && (buf[len-1] == '\r' || buf[len-1] == '\n')) |
| 2810 | buf[--len] = '\0'; |
| 2811 | |
| 2812 | if (len == 0 || buf[0]=='q') |
| 2813 | return; |
| 2814 | |
| 2815 | if (pj_isdigit(*buf) || *buf=='-') { |
| 2816 | |
| 2817 | int i; |
| 2818 | |
| 2819 | if (*buf=='-') |
| 2820 | i = 1; |
| 2821 | else |
| 2822 | i = 0; |
| 2823 | |
| 2824 | for (; i<len; ++i) { |
| 2825 | if (!pj_isdigit(buf[i])) { |
| 2826 | puts("Invalid input"); |
| 2827 | return; |
| 2828 | } |
| 2829 | } |
| 2830 | |
| 2831 | result->nb_result = my_atoi(buf); |
| 2832 | |
| 2833 | if (result->nb_result >= 0 && |
| 2834 | result->nb_result <= (int)pjsua_get_buddy_count()) |
| 2835 | { |
| 2836 | return; |
| 2837 | } |
| 2838 | if (result->nb_result == -1) |
| 2839 | return; |
| 2840 | |
| 2841 | puts("Invalid input"); |
| 2842 | result->nb_result = NO_NB; |
| 2843 | return; |
| 2844 | |
| 2845 | } else { |
| 2846 | pj_status_t status; |
| 2847 | |
| 2848 | if ((status=pjsua_verify_sip_url(buf)) != PJ_SUCCESS) { |
| 2849 | pjsua_perror(THIS_FILE, "Invalid URL", status); |
| 2850 | return; |
| 2851 | } |
| 2852 | |
| 2853 | result->uri_result = buf; |
| 2854 | } |
| 2855 | } |
| 2856 | |
| 2857 | /* |
| 2858 | * List the ports in conference bridge |
| 2859 | */ |
| 2860 | static void conf_list(void) |
| 2861 | { |
| 2862 | unsigned i, count; |
| 2863 | pjsua_conf_port_id id[PJSUA_MAX_CALLS]; |
| 2864 | |
| 2865 | printf("Conference ports:\n"); |
| 2866 | |
| 2867 | count = PJ_ARRAY_SIZE(id); |
| 2868 | pjsua_enum_conf_ports(id, &count); |
| 2869 | |
| 2870 | for (i=0; i<count; ++i) { |
| 2871 | char txlist[PJSUA_MAX_CALLS*4+10]; |
| 2872 | unsigned j; |
| 2873 | pjsua_conf_port_info info; |
| 2874 | |
| 2875 | pjsua_conf_get_port_info(id[i], &info); |
| 2876 | |
| 2877 | txlist[0] = '\0'; |
| 2878 | for (j=0; j<info.listener_cnt; ++j) { |
| 2879 | char s[10]; |
| 2880 | pj_ansi_sprintf(s, "#%d ", info.listeners[j]); |
| 2881 | pj_ansi_strcat(txlist, s); |
| 2882 | } |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 2883 | printf("Port #%02d[%2dKHz/%dms/%d] %20.*s transmitting to: %s\n", |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2884 | info.slot_id, |
| 2885 | info.clock_rate/1000, |
Nanang Izzuddin | 81e9bd5 | 2008-06-27 12:52:51 +0000 | [diff] [blame] | 2886 | info.samples_per_frame*1000/info.channel_count/info.clock_rate, |
Benny Prijono | 7d60d05 | 2008-03-29 12:24:20 +0000 | [diff] [blame] | 2887 | info.channel_count, |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 2888 | (int)info.name.slen, |
| 2889 | info.name.ptr, |
| 2890 | txlist); |
| 2891 | |
| 2892 | } |
| 2893 | puts(""); |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | /* |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 2898 | * Send arbitrary request to remote host |
| 2899 | */ |
| 2900 | static void send_request(char *cstr_method, const pj_str_t *dst_uri) |
| 2901 | { |
| 2902 | pj_str_t str_method; |
| 2903 | pjsip_method method; |
| 2904 | pjsip_tx_data *tdata; |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 2905 | pjsip_endpoint *endpt; |
| 2906 | pj_status_t status; |
| 2907 | |
| 2908 | endpt = pjsua_get_pjsip_endpt(); |
| 2909 | |
| 2910 | str_method = pj_str(cstr_method); |
| 2911 | pjsip_method_init_np(&method, &str_method); |
| 2912 | |
Benny Prijono | fff245c | 2007-04-02 11:44:47 +0000 | [diff] [blame] | 2913 | status = pjsua_acc_create_request(current_acc, &method, dst_uri, &tdata); |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 2914 | |
Benny Prijono | b988d76 | 2007-12-05 04:30:04 +0000 | [diff] [blame] | 2915 | status = pjsip_endpt_send_request(endpt, tdata, -1, NULL, NULL); |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 2916 | if (status != PJ_SUCCESS) { |
Benny Prijono | b988d76 | 2007-12-05 04:30:04 +0000 | [diff] [blame] | 2917 | pjsua_perror(THIS_FILE, "Unable to send request", status); |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 2918 | return; |
| 2919 | } |
| 2920 | } |
| 2921 | |
| 2922 | |
| 2923 | /* |
Benny Prijono | 4461c7d | 2007-08-25 13:36:15 +0000 | [diff] [blame] | 2924 | * Change extended online status. |
| 2925 | */ |
| 2926 | static void change_online_status(void) |
| 2927 | { |
| 2928 | char menuin[32]; |
| 2929 | pj_bool_t online_status; |
| 2930 | pjrpid_element elem; |
| 2931 | int i, choice; |
| 2932 | |
| 2933 | enum { |
| 2934 | AVAILABLE, BUSY, OTP, IDLE, AWAY, BRB, OFFLINE, OPT_MAX |
| 2935 | }; |
| 2936 | |
| 2937 | struct opt { |
| 2938 | int id; |
| 2939 | char *name; |
| 2940 | } opts[] = { |
| 2941 | { AVAILABLE, "Available" }, |
| 2942 | { BUSY, "Busy"}, |
| 2943 | { OTP, "On the phone"}, |
| 2944 | { IDLE, "Idle"}, |
| 2945 | { AWAY, "Away"}, |
| 2946 | { BRB, "Be right back"}, |
| 2947 | { OFFLINE, "Offline"} |
| 2948 | }; |
| 2949 | |
| 2950 | printf("\n" |
| 2951 | "Choices:\n"); |
| 2952 | for (i=0; i<PJ_ARRAY_SIZE(opts); ++i) { |
| 2953 | printf(" %d %s\n", opts[i].id+1, opts[i].name); |
| 2954 | } |
| 2955 | |
| 2956 | if (!simple_input("Select status", menuin, sizeof(menuin))) |
| 2957 | return; |
| 2958 | |
| 2959 | choice = atoi(menuin) - 1; |
| 2960 | if (choice < 0 || choice >= OPT_MAX) { |
| 2961 | puts("Invalid selection"); |
| 2962 | return; |
| 2963 | } |
| 2964 | |
| 2965 | pj_bzero(&elem, sizeof(elem)); |
| 2966 | elem.type = PJRPID_ELEMENT_TYPE_PERSON; |
| 2967 | |
| 2968 | online_status = PJ_TRUE; |
| 2969 | |
| 2970 | switch (choice) { |
| 2971 | case AVAILABLE: |
| 2972 | break; |
| 2973 | case BUSY: |
| 2974 | elem.activity = PJRPID_ACTIVITY_BUSY; |
| 2975 | elem.note = pj_str("Busy"); |
| 2976 | break; |
| 2977 | case OTP: |
| 2978 | elem.activity = PJRPID_ACTIVITY_BUSY; |
| 2979 | elem.note = pj_str("On the phone"); |
| 2980 | break; |
| 2981 | case IDLE: |
| 2982 | elem.activity = PJRPID_ACTIVITY_UNKNOWN; |
| 2983 | elem.note = pj_str("Idle"); |
| 2984 | break; |
| 2985 | case AWAY: |
| 2986 | elem.activity = PJRPID_ACTIVITY_AWAY; |
| 2987 | elem.note = pj_str("Away"); |
| 2988 | break; |
| 2989 | case BRB: |
| 2990 | elem.activity = PJRPID_ACTIVITY_UNKNOWN; |
| 2991 | elem.note = pj_str("Be right back"); |
| 2992 | break; |
| 2993 | case OFFLINE: |
| 2994 | online_status = PJ_FALSE; |
| 2995 | break; |
| 2996 | } |
| 2997 | |
| 2998 | pjsua_acc_set_online_status2(current_acc, online_status, &elem); |
| 2999 | } |
| 3000 | |
| 3001 | |
| 3002 | /* |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 3003 | * Change codec priorities. |
| 3004 | */ |
| 3005 | static void manage_codec_prio(void) |
| 3006 | { |
| 3007 | pjsua_codec_info c[32]; |
| 3008 | unsigned i, count = PJ_ARRAY_SIZE(c); |
| 3009 | char input[32]; |
| 3010 | char *codec, *prio; |
| 3011 | pj_str_t id; |
| 3012 | int new_prio; |
| 3013 | pj_status_t status; |
| 3014 | |
| 3015 | printf("List of codecs:\n"); |
| 3016 | |
| 3017 | pjsua_enum_codecs(c, &count); |
| 3018 | for (i=0; i<count; ++i) { |
| 3019 | printf(" %d\t%.*s\n", c[i].priority, (int)c[i].codec_id.slen, |
| 3020 | c[i].codec_id.ptr); |
| 3021 | } |
| 3022 | |
| 3023 | puts(""); |
Benny Prijono | 88accae | 2008-06-26 15:48:14 +0000 | [diff] [blame] | 3024 | puts("Enter codec id and its new priority " |
| 3025 | "(e.g. \"speex/16000 200\"), empty to cancel:"); |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 3026 | |
Benny Prijono | 88accae | 2008-06-26 15:48:14 +0000 | [diff] [blame] | 3027 | printf("Codec name (\"*\" for all) and priority: "); |
Benny Prijono | 32d267b | 2009-01-01 22:08:21 +0000 | [diff] [blame] | 3028 | if (fgets(input, sizeof(input), stdin) == NULL) |
| 3029 | return; |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 3030 | if (input[0]=='\r' || input[0]=='\n') { |
| 3031 | puts("Done"); |
| 3032 | return; |
| 3033 | } |
| 3034 | |
| 3035 | codec = strtok(input, " \t\r\n"); |
| 3036 | prio = strtok(NULL, " \r\n"); |
| 3037 | |
| 3038 | if (!codec || !prio) { |
| 3039 | puts("Invalid input"); |
| 3040 | return; |
| 3041 | } |
| 3042 | |
| 3043 | new_prio = atoi(prio); |
| 3044 | if (new_prio < 0) |
| 3045 | new_prio = 0; |
| 3046 | else if (new_prio > PJMEDIA_CODEC_PRIO_HIGHEST) |
| 3047 | new_prio = PJMEDIA_CODEC_PRIO_HIGHEST; |
| 3048 | |
| 3049 | status = pjsua_codec_set_priority(pj_cstr(&id, codec), |
| 3050 | (pj_uint8_t)new_prio); |
| 3051 | if (status != PJ_SUCCESS) |
| 3052 | pjsua_perror(THIS_FILE, "Error setting codec priority", status); |
| 3053 | } |
| 3054 | |
| 3055 | |
| 3056 | /* |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3057 | * Main "user interface" loop. |
| 3058 | */ |
| 3059 | void console_app_main(const pj_str_t *uri_to_call) |
| 3060 | { |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3061 | char menuin[32]; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3062 | char buf[128]; |
| 3063 | char text[128]; |
| 3064 | int i, count; |
| 3065 | char *uri; |
| 3066 | pj_str_t tmp; |
| 3067 | struct input_result result; |
| 3068 | pjsua_call_info call_info; |
| 3069 | pjsua_acc_info acc_info; |
| 3070 | |
| 3071 | |
| 3072 | /* If user specifies URI to call, then call the URI */ |
| 3073 | if (uri_to_call->slen) { |
| 3074 | pjsua_call_make_call( current_acc, uri_to_call, 0, NULL, NULL, NULL); |
| 3075 | } |
| 3076 | |
| 3077 | keystroke_help(); |
| 3078 | |
| 3079 | for (;;) { |
| 3080 | |
| 3081 | printf(">>> "); |
| 3082 | fflush(stdout); |
| 3083 | |
Benny Prijono | 990042e | 2007-01-21 19:36:00 +0000 | [diff] [blame] | 3084 | if (fgets(menuin, sizeof(menuin), stdin) == NULL) { |
| 3085 | /* |
| 3086 | * Be friendly to users who redirect commands into |
| 3087 | * program, when file ends, resume with kbd. |
| 3088 | * If exit is desired end script with q for quit |
| 3089 | */ |
| 3090 | /* Reopen stdin/stdout/stderr to /dev/console */ |
| 3091 | #if defined(PJ_WIN32) && PJ_WIN32!=0 |
| 3092 | if (freopen ("CONIN$", "r", stdin) == NULL) { |
| 3093 | #else |
| 3094 | if (1) { |
| 3095 | #endif |
| 3096 | puts("Cannot switch back to console from file redirection"); |
| 3097 | menuin[0] = 'q'; |
| 3098 | menuin[1] = '\0'; |
| 3099 | } else { |
| 3100 | puts("Switched back to console from file redirection"); |
| 3101 | continue; |
| 3102 | } |
| 3103 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3104 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 3105 | if (cmd_echo) { |
| 3106 | printf("%s", menuin); |
| 3107 | } |
| 3108 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3109 | switch (menuin[0]) { |
| 3110 | |
| 3111 | case 'm': |
| 3112 | /* Make call! : */ |
| 3113 | printf("(You currently have %d calls)\n", |
| 3114 | pjsua_call_get_count()); |
| 3115 | |
| 3116 | uri = NULL; |
| 3117 | ui_input_url("Make call", buf, sizeof(buf), &result); |
| 3118 | if (result.nb_result != NO_NB) { |
| 3119 | |
| 3120 | if (result.nb_result == -1 || result.nb_result == 0) { |
| 3121 | puts("You can't do that with make call!"); |
| 3122 | continue; |
| 3123 | } else { |
| 3124 | pjsua_buddy_info binfo; |
| 3125 | pjsua_buddy_get_info(result.nb_result-1, &binfo); |
| 3126 | uri = binfo.uri.ptr; |
| 3127 | } |
| 3128 | |
| 3129 | } else if (result.uri_result) { |
| 3130 | uri = result.uri_result; |
| 3131 | } |
| 3132 | |
| 3133 | tmp = pj_str(uri); |
| 3134 | pjsua_call_make_call( current_acc, &tmp, 0, NULL, NULL, NULL); |
| 3135 | break; |
| 3136 | |
| 3137 | case 'M': |
| 3138 | /* Make multiple calls! : */ |
| 3139 | printf("(You currently have %d calls)\n", |
| 3140 | pjsua_call_get_count()); |
| 3141 | |
| 3142 | if (!simple_input("Number of calls", menuin, sizeof(menuin))) |
| 3143 | continue; |
| 3144 | |
| 3145 | count = my_atoi(menuin); |
| 3146 | if (count < 1) |
| 3147 | continue; |
| 3148 | |
| 3149 | ui_input_url("Make call", buf, sizeof(buf), &result); |
| 3150 | if (result.nb_result != NO_NB) { |
| 3151 | pjsua_buddy_info binfo; |
| 3152 | if (result.nb_result == -1 || result.nb_result == 0) { |
| 3153 | puts("You can't do that with make call!"); |
| 3154 | continue; |
| 3155 | } |
| 3156 | pjsua_buddy_get_info(result.nb_result-1, &binfo); |
| 3157 | uri = binfo.uri.ptr; |
| 3158 | } else { |
| 3159 | uri = result.uri_result; |
| 3160 | } |
| 3161 | |
| 3162 | for (i=0; i<my_atoi(menuin); ++i) { |
| 3163 | pj_status_t status; |
| 3164 | |
| 3165 | tmp = pj_str(uri); |
| 3166 | status = pjsua_call_make_call(current_acc, &tmp, 0, NULL, |
| 3167 | NULL, NULL); |
| 3168 | if (status != PJ_SUCCESS) |
| 3169 | break; |
| 3170 | } |
| 3171 | break; |
| 3172 | |
Benny Prijono | 4ab9fbb | 2007-10-12 12:14:27 +0000 | [diff] [blame] | 3173 | case 'n': |
Benny Prijono | 438e65b | 2007-11-03 21:42:10 +0000 | [diff] [blame] | 3174 | i = pjsua_detect_nat_type(); |
| 3175 | if (i != PJ_SUCCESS) |
| 3176 | pjsua_perror(THIS_FILE, "Error", i); |
Benny Prijono | 4ab9fbb | 2007-10-12 12:14:27 +0000 | [diff] [blame] | 3177 | break; |
| 3178 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3179 | case 'i': |
| 3180 | /* Send instant messaeg */ |
| 3181 | |
| 3182 | /* i is for call index to send message, if any */ |
| 3183 | i = -1; |
| 3184 | |
| 3185 | /* Make compiler happy. */ |
| 3186 | uri = NULL; |
| 3187 | |
| 3188 | /* Input destination. */ |
| 3189 | ui_input_url("Send IM to", buf, sizeof(buf), &result); |
| 3190 | if (result.nb_result != NO_NB) { |
| 3191 | |
| 3192 | if (result.nb_result == -1) { |
| 3193 | puts("You can't send broadcast IM like that!"); |
| 3194 | continue; |
| 3195 | |
| 3196 | } else if (result.nb_result == 0) { |
| 3197 | |
| 3198 | i = current_call; |
| 3199 | |
| 3200 | } else { |
| 3201 | pjsua_buddy_info binfo; |
| 3202 | pjsua_buddy_get_info(result.nb_result-1, &binfo); |
| 3203 | uri = binfo.uri.ptr; |
| 3204 | } |
| 3205 | |
| 3206 | } else if (result.uri_result) { |
| 3207 | uri = result.uri_result; |
| 3208 | } |
| 3209 | |
| 3210 | |
| 3211 | /* Send typing indication. */ |
| 3212 | if (i != -1) |
| 3213 | pjsua_call_send_typing_ind(i, PJ_TRUE, NULL); |
| 3214 | else { |
| 3215 | pj_str_t tmp_uri = pj_str(uri); |
| 3216 | pjsua_im_typing(current_acc, &tmp_uri, PJ_TRUE, NULL); |
| 3217 | } |
| 3218 | |
| 3219 | /* Input the IM . */ |
| 3220 | if (!simple_input("Message", text, sizeof(text))) { |
| 3221 | /* |
| 3222 | * Cancelled. |
| 3223 | * Send typing notification too, saying we're not typing. |
| 3224 | */ |
| 3225 | if (i != -1) |
| 3226 | pjsua_call_send_typing_ind(i, PJ_FALSE, NULL); |
| 3227 | else { |
| 3228 | pj_str_t tmp_uri = pj_str(uri); |
| 3229 | pjsua_im_typing(current_acc, &tmp_uri, PJ_FALSE, NULL); |
| 3230 | } |
| 3231 | continue; |
| 3232 | } |
| 3233 | |
| 3234 | tmp = pj_str(text); |
| 3235 | |
| 3236 | /* Send the IM */ |
| 3237 | if (i != -1) |
| 3238 | pjsua_call_send_im(i, NULL, &tmp, NULL, NULL); |
| 3239 | else { |
| 3240 | pj_str_t tmp_uri = pj_str(uri); |
| 3241 | pjsua_im_send(current_acc, &tmp_uri, NULL, &tmp, NULL, NULL); |
| 3242 | } |
| 3243 | |
| 3244 | break; |
| 3245 | |
| 3246 | case 'a': |
| 3247 | |
| 3248 | if (current_call != -1) { |
| 3249 | pjsua_call_get_info(current_call, &call_info); |
| 3250 | } else { |
| 3251 | /* Make compiler happy */ |
| 3252 | call_info.role = PJSIP_ROLE_UAC; |
| 3253 | call_info.state = PJSIP_INV_STATE_DISCONNECTED; |
| 3254 | } |
| 3255 | |
| 3256 | if (current_call == -1 || |
| 3257 | call_info.role != PJSIP_ROLE_UAS || |
| 3258 | call_info.state >= PJSIP_INV_STATE_CONNECTING) |
| 3259 | { |
| 3260 | puts("No pending incoming call"); |
| 3261 | fflush(stdout); |
| 3262 | continue; |
| 3263 | |
| 3264 | } else { |
Benny Prijono | 20d3672 | 2007-02-22 14:52:24 +0000 | [diff] [blame] | 3265 | int st_code; |
| 3266 | char contact[120]; |
| 3267 | pj_str_t hname = { "Contact", 7 }; |
| 3268 | pj_str_t hvalue; |
| 3269 | pjsip_generic_string_hdr hcontact; |
| 3270 | pjsua_msg_data msg_data; |
| 3271 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3272 | if (!simple_input("Answer with code (100-699)", buf, sizeof(buf))) |
| 3273 | continue; |
| 3274 | |
Benny Prijono | 20d3672 | 2007-02-22 14:52:24 +0000 | [diff] [blame] | 3275 | st_code = my_atoi(buf); |
| 3276 | if (st_code < 100) |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3277 | continue; |
| 3278 | |
Benny Prijono | 20d3672 | 2007-02-22 14:52:24 +0000 | [diff] [blame] | 3279 | pjsua_msg_data_init(&msg_data); |
| 3280 | |
| 3281 | if (st_code/100 == 3) { |
| 3282 | if (!simple_input("Enter URL to be put in Contact", |
| 3283 | contact, sizeof(contact))) |
| 3284 | continue; |
| 3285 | hvalue = pj_str(contact); |
| 3286 | pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue); |
| 3287 | |
| 3288 | pj_list_push_back(&msg_data.hdr_list, &hcontact); |
| 3289 | } |
| 3290 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3291 | /* |
| 3292 | * Must check again! |
| 3293 | * Call may have been disconnected while we're waiting for |
| 3294 | * keyboard input. |
| 3295 | */ |
| 3296 | if (current_call == -1) { |
| 3297 | puts("Call has been disconnected"); |
| 3298 | fflush(stdout); |
| 3299 | continue; |
| 3300 | } |
| 3301 | |
Benny Prijono | 20d3672 | 2007-02-22 14:52:24 +0000 | [diff] [blame] | 3302 | pjsua_call_answer(current_call, st_code, NULL, &msg_data); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | break; |
| 3306 | |
| 3307 | |
| 3308 | case 'h': |
| 3309 | |
| 3310 | if (current_call == -1) { |
| 3311 | puts("No current call"); |
| 3312 | fflush(stdout); |
| 3313 | continue; |
| 3314 | |
| 3315 | } else if (menuin[1] == 'a') { |
| 3316 | |
| 3317 | /* Hangup all calls */ |
| 3318 | pjsua_call_hangup_all(); |
| 3319 | |
| 3320 | } else { |
| 3321 | |
| 3322 | /* Hangup current calls */ |
| 3323 | pjsua_call_hangup(current_call, 0, NULL, NULL); |
| 3324 | } |
| 3325 | break; |
| 3326 | |
| 3327 | case ']': |
| 3328 | case '[': |
| 3329 | /* |
| 3330 | * Cycle next/prev dialog. |
| 3331 | */ |
| 3332 | if (menuin[0] == ']') { |
| 3333 | find_next_call(); |
| 3334 | |
| 3335 | } else { |
| 3336 | find_prev_call(); |
| 3337 | } |
| 3338 | |
| 3339 | if (current_call != -1) { |
| 3340 | |
| 3341 | pjsua_call_get_info(current_call, &call_info); |
| 3342 | PJ_LOG(3,(THIS_FILE,"Current dialog: %.*s", |
| 3343 | (int)call_info.remote_info.slen, |
| 3344 | call_info.remote_info.ptr)); |
| 3345 | |
| 3346 | } else { |
| 3347 | PJ_LOG(3,(THIS_FILE,"No current dialog")); |
| 3348 | } |
| 3349 | break; |
| 3350 | |
| 3351 | |
| 3352 | case '>': |
| 3353 | case '<': |
| 3354 | if (!simple_input("Enter account ID to select", buf, sizeof(buf))) |
| 3355 | break; |
| 3356 | |
| 3357 | i = my_atoi(buf); |
| 3358 | if (pjsua_acc_is_valid(i)) { |
Benny Prijono | 21b9ad9 | 2006-08-15 13:11:22 +0000 | [diff] [blame] | 3359 | pjsua_acc_set_default(i); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3360 | PJ_LOG(3,(THIS_FILE, "Current account changed to %d", i)); |
| 3361 | } else { |
| 3362 | PJ_LOG(3,(THIS_FILE, "Invalid account id %d", i)); |
| 3363 | } |
| 3364 | break; |
| 3365 | |
| 3366 | |
| 3367 | case '+': |
| 3368 | if (menuin[1] == 'b') { |
| 3369 | |
| 3370 | pjsua_buddy_config buddy_cfg; |
| 3371 | pjsua_buddy_id buddy_id; |
| 3372 | pj_status_t status; |
| 3373 | |
| 3374 | if (!simple_input("Enter buddy's URI:", buf, sizeof(buf))) |
| 3375 | break; |
| 3376 | |
| 3377 | if (pjsua_verify_sip_url(buf) != PJ_SUCCESS) { |
| 3378 | printf("Invalid SIP URI '%s'\n", buf); |
| 3379 | break; |
| 3380 | } |
| 3381 | |
Benny Prijono | ac623b3 | 2006-07-03 15:19:31 +0000 | [diff] [blame] | 3382 | pj_bzero(&buddy_cfg, sizeof(pjsua_buddy_config)); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3383 | |
| 3384 | buddy_cfg.uri = pj_str(buf); |
| 3385 | buddy_cfg.subscribe = PJ_TRUE; |
| 3386 | |
| 3387 | status = pjsua_buddy_add(&buddy_cfg, &buddy_id); |
| 3388 | if (status == PJ_SUCCESS) { |
| 3389 | printf("New buddy '%s' added at index %d\n", |
| 3390 | buf, buddy_id+1); |
| 3391 | } |
| 3392 | |
| 3393 | } else if (menuin[1] == 'a') { |
| 3394 | |
Benny Prijono | fb2b365 | 2007-06-28 07:15:03 +0000 | [diff] [blame] | 3395 | char id[80], registrar[80], realm[80], uname[80], passwd[30]; |
| 3396 | pjsua_acc_config acc_cfg; |
| 3397 | pj_status_t status; |
| 3398 | |
| 3399 | if (!simple_input("Your SIP URL:", id, sizeof(id))) |
| 3400 | break; |
| 3401 | if (!simple_input("URL of the registrar:", registrar, sizeof(registrar))) |
| 3402 | break; |
| 3403 | if (!simple_input("Auth Realm:", realm, sizeof(realm))) |
| 3404 | break; |
| 3405 | if (!simple_input("Auth Username:", uname, sizeof(uname))) |
| 3406 | break; |
| 3407 | if (!simple_input("Auth Password:", passwd, sizeof(passwd))) |
| 3408 | break; |
| 3409 | |
| 3410 | pjsua_acc_config_default(&acc_cfg); |
| 3411 | acc_cfg.id = pj_str(id); |
| 3412 | acc_cfg.reg_uri = pj_str(registrar); |
| 3413 | acc_cfg.cred_count = 1; |
Benny Prijono | 48ab2b7 | 2007-11-08 09:24:30 +0000 | [diff] [blame] | 3414 | acc_cfg.cred_info[0].scheme = pj_str("Digest"); |
Benny Prijono | fb2b365 | 2007-06-28 07:15:03 +0000 | [diff] [blame] | 3415 | acc_cfg.cred_info[0].realm = pj_str(realm); |
| 3416 | acc_cfg.cred_info[0].username = pj_str(uname); |
| 3417 | acc_cfg.cred_info[0].data_type = 0; |
| 3418 | acc_cfg.cred_info[0].data = pj_str(passwd); |
| 3419 | |
| 3420 | status = pjsua_acc_add(&acc_cfg, PJ_TRUE, NULL); |
| 3421 | if (status != PJ_SUCCESS) { |
| 3422 | pjsua_perror(THIS_FILE, "Error adding new account", status); |
| 3423 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3424 | |
| 3425 | } else { |
| 3426 | printf("Invalid input %s\n", menuin); |
| 3427 | } |
| 3428 | break; |
| 3429 | |
| 3430 | case '-': |
| 3431 | if (menuin[1] == 'b') { |
| 3432 | if (!simple_input("Enter buddy ID to delete",buf,sizeof(buf))) |
| 3433 | break; |
| 3434 | |
| 3435 | i = my_atoi(buf) - 1; |
| 3436 | |
| 3437 | if (!pjsua_buddy_is_valid(i)) { |
| 3438 | printf("Invalid buddy id %d\n", i); |
| 3439 | } else { |
| 3440 | pjsua_buddy_del(i); |
| 3441 | printf("Buddy %d deleted\n", i); |
| 3442 | } |
| 3443 | |
| 3444 | } else if (menuin[1] == 'a') { |
| 3445 | |
| 3446 | if (!simple_input("Enter account ID to delete",buf,sizeof(buf))) |
| 3447 | break; |
| 3448 | |
| 3449 | i = my_atoi(buf); |
| 3450 | |
| 3451 | if (!pjsua_acc_is_valid(i)) { |
| 3452 | printf("Invalid account id %d\n", i); |
| 3453 | } else { |
| 3454 | pjsua_acc_del(i); |
| 3455 | printf("Account %d deleted\n", i); |
| 3456 | } |
| 3457 | |
| 3458 | } else { |
| 3459 | printf("Invalid input %s\n", menuin); |
| 3460 | } |
| 3461 | break; |
| 3462 | |
| 3463 | case 'H': |
| 3464 | /* |
| 3465 | * Hold call. |
| 3466 | */ |
| 3467 | if (current_call != -1) { |
| 3468 | |
| 3469 | pjsua_call_set_hold(current_call, NULL); |
| 3470 | |
| 3471 | } else { |
| 3472 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3473 | } |
| 3474 | break; |
| 3475 | |
| 3476 | case 'v': |
| 3477 | /* |
| 3478 | * Send re-INVITE (to release hold, etc). |
| 3479 | */ |
| 3480 | if (current_call != -1) { |
| 3481 | |
| 3482 | pjsua_call_reinvite(current_call, PJ_TRUE, NULL); |
| 3483 | |
| 3484 | } else { |
| 3485 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3486 | } |
| 3487 | break; |
| 3488 | |
Benny Prijono | c08682e | 2007-10-04 06:17:58 +0000 | [diff] [blame] | 3489 | case 'U': |
| 3490 | /* |
| 3491 | * Send UPDATE |
| 3492 | */ |
| 3493 | if (current_call != -1) { |
| 3494 | |
| 3495 | pjsua_call_update(current_call, 0, NULL); |
| 3496 | |
| 3497 | } else { |
| 3498 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3499 | } |
| 3500 | break; |
| 3501 | |
| 3502 | case 'C': |
| 3503 | if (menuin[1] == 'p') { |
| 3504 | manage_codec_prio(); |
| 3505 | } |
| 3506 | break; |
| 3507 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3508 | case 'x': |
| 3509 | /* |
| 3510 | * Transfer call. |
| 3511 | */ |
| 3512 | if (current_call == -1) { |
| 3513 | |
| 3514 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3515 | |
| 3516 | } else { |
| 3517 | int call = current_call; |
Benny Prijono | d524e82 | 2006-09-22 12:48:18 +0000 | [diff] [blame] | 3518 | pjsua_msg_data msg_data; |
| 3519 | pjsip_generic_string_hdr refer_sub; |
| 3520 | pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 }; |
| 3521 | pj_str_t STR_FALSE = { "false", 5 }; |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 3522 | pjsua_call_info ci; |
| 3523 | |
| 3524 | pjsua_call_get_info(current_call, &ci); |
| 3525 | printf("Transfering current call [%d] %.*s\n", |
| 3526 | current_call, |
| 3527 | (int)ci.remote_info.slen, ci.remote_info.ptr); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3528 | |
| 3529 | ui_input_url("Transfer to URL", buf, sizeof(buf), &result); |
| 3530 | |
| 3531 | /* Check if call is still there. */ |
| 3532 | |
| 3533 | if (call != current_call) { |
| 3534 | puts("Call has been disconnected"); |
| 3535 | continue; |
| 3536 | } |
| 3537 | |
Benny Prijono | d524e82 | 2006-09-22 12:48:18 +0000 | [diff] [blame] | 3538 | pjsua_msg_data_init(&msg_data); |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 3539 | if (app_config.no_refersub) { |
| 3540 | /* Add Refer-Sub: false in outgoing REFER request */ |
| 3541 | pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB, |
| 3542 | &STR_FALSE); |
| 3543 | pj_list_push_back(&msg_data.hdr_list, &refer_sub); |
| 3544 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3545 | if (result.nb_result != NO_NB) { |
| 3546 | if (result.nb_result == -1 || result.nb_result == 0) |
| 3547 | puts("You can't do that with transfer call!"); |
| 3548 | else { |
| 3549 | pjsua_buddy_info binfo; |
| 3550 | pjsua_buddy_get_info(result.nb_result-1, &binfo); |
Benny Prijono | d524e82 | 2006-09-22 12:48:18 +0000 | [diff] [blame] | 3551 | pjsua_call_xfer( current_call, &binfo.uri, &msg_data); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | } else if (result.uri_result) { |
| 3555 | pj_str_t tmp; |
| 3556 | tmp = pj_str(result.uri_result); |
Benny Prijono | d524e82 | 2006-09-22 12:48:18 +0000 | [diff] [blame] | 3557 | pjsua_call_xfer( current_call, &tmp, &msg_data); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3558 | } |
| 3559 | } |
| 3560 | break; |
| 3561 | |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 3562 | case 'X': |
| 3563 | /* |
| 3564 | * Transfer call with replaces. |
| 3565 | */ |
| 3566 | if (current_call == -1) { |
| 3567 | |
| 3568 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3569 | |
| 3570 | } else { |
| 3571 | int call = current_call; |
| 3572 | int dst_call; |
| 3573 | pjsua_msg_data msg_data; |
| 3574 | pjsip_generic_string_hdr refer_sub; |
| 3575 | pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 }; |
| 3576 | pj_str_t STR_FALSE = { "false", 5 }; |
| 3577 | pjsua_call_id ids[PJSUA_MAX_CALLS]; |
| 3578 | pjsua_call_info ci; |
| 3579 | unsigned i, count; |
| 3580 | |
| 3581 | count = PJ_ARRAY_SIZE(ids); |
| 3582 | pjsua_enum_calls(ids, &count); |
| 3583 | |
| 3584 | if (count <= 1) { |
| 3585 | puts("There are no other calls"); |
| 3586 | continue; |
| 3587 | } |
| 3588 | |
| 3589 | pjsua_call_get_info(current_call, &ci); |
| 3590 | printf("Transfer call [%d] %.*s to one of the following:\n", |
| 3591 | current_call, |
| 3592 | (int)ci.remote_info.slen, ci.remote_info.ptr); |
| 3593 | |
| 3594 | for (i=0; i<count; ++i) { |
| 3595 | pjsua_call_info call_info; |
| 3596 | |
| 3597 | if (ids[i] == call) |
| 3598 | continue; |
| 3599 | |
| 3600 | pjsua_call_get_info(ids[i], &call_info); |
| 3601 | printf("%d %.*s [%.*s]\n", |
| 3602 | ids[i], |
| 3603 | (int)call_info.remote_info.slen, |
| 3604 | call_info.remote_info.ptr, |
| 3605 | (int)call_info.state_text.slen, |
| 3606 | call_info.state_text.ptr); |
| 3607 | } |
| 3608 | |
| 3609 | if (!simple_input("Enter call number to be replaced", |
| 3610 | buf, sizeof(buf))) |
| 3611 | continue; |
| 3612 | |
| 3613 | dst_call = my_atoi(buf); |
| 3614 | |
| 3615 | /* Check if call is still there. */ |
| 3616 | |
| 3617 | if (call != current_call) { |
| 3618 | puts("Call has been disconnected"); |
| 3619 | continue; |
| 3620 | } |
| 3621 | |
| 3622 | /* Check that destination call is valid. */ |
| 3623 | if (dst_call == call) { |
| 3624 | puts("Destination call number must not be the same " |
| 3625 | "as the call being transfered"); |
| 3626 | continue; |
| 3627 | } |
| 3628 | if (dst_call >= PJSUA_MAX_CALLS) { |
| 3629 | puts("Invalid destination call number"); |
| 3630 | continue; |
| 3631 | } |
| 3632 | if (!pjsua_call_is_active(dst_call)) { |
| 3633 | puts("Invalid destination call number"); |
| 3634 | continue; |
| 3635 | } |
| 3636 | |
| 3637 | pjsua_msg_data_init(&msg_data); |
| 3638 | if (app_config.no_refersub) { |
| 3639 | /* Add Refer-Sub: false in outgoing REFER request */ |
| 3640 | pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB, |
| 3641 | &STR_FALSE); |
| 3642 | pj_list_push_back(&msg_data.hdr_list, &refer_sub); |
| 3643 | } |
| 3644 | |
| 3645 | pjsua_call_xfer_replaces(call, dst_call, 0, &msg_data); |
| 3646 | } |
| 3647 | break; |
| 3648 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3649 | case '#': |
| 3650 | /* |
| 3651 | * Send DTMF strings. |
| 3652 | */ |
| 3653 | if (current_call == -1) { |
| 3654 | |
| 3655 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3656 | |
| 3657 | } else if (!pjsua_call_has_media(current_call)) { |
| 3658 | |
| 3659 | PJ_LOG(3,(THIS_FILE, "Media is not established yet!")); |
| 3660 | |
| 3661 | } else { |
| 3662 | pj_str_t digits; |
| 3663 | int call = current_call; |
| 3664 | pj_status_t status; |
| 3665 | |
| 3666 | if (!simple_input("DTMF strings to send (0-9*#A-B)", buf, |
| 3667 | sizeof(buf))) |
| 3668 | { |
| 3669 | break; |
| 3670 | } |
| 3671 | |
| 3672 | if (call != current_call) { |
| 3673 | puts("Call has been disconnected"); |
| 3674 | continue; |
| 3675 | } |
| 3676 | |
| 3677 | digits = pj_str(buf); |
| 3678 | status = pjsua_call_dial_dtmf(current_call, &digits); |
| 3679 | if (status != PJ_SUCCESS) { |
| 3680 | pjsua_perror(THIS_FILE, "Unable to send DTMF", status); |
| 3681 | } else { |
| 3682 | puts("DTMF digits enqueued for transmission"); |
| 3683 | } |
| 3684 | } |
| 3685 | break; |
| 3686 | |
Benny Prijono | feb69f4 | 2007-10-05 09:12:26 +0000 | [diff] [blame] | 3687 | case '*': |
| 3688 | /* Send DTMF with INFO */ |
| 3689 | if (current_call == -1) { |
| 3690 | |
| 3691 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3692 | |
| 3693 | } else { |
| 3694 | const pj_str_t SIP_INFO = pj_str("INFO"); |
| 3695 | pj_str_t digits; |
| 3696 | int call = current_call; |
| 3697 | int i; |
| 3698 | pj_status_t status; |
| 3699 | |
| 3700 | if (!simple_input("DTMF strings to send (0-9*#A-B)", buf, |
| 3701 | sizeof(buf))) |
| 3702 | { |
| 3703 | break; |
| 3704 | } |
| 3705 | |
| 3706 | if (call != current_call) { |
| 3707 | puts("Call has been disconnected"); |
| 3708 | continue; |
| 3709 | } |
| 3710 | |
| 3711 | digits = pj_str(buf); |
| 3712 | for (i=0; i<digits.slen; ++i) { |
| 3713 | pjsua_msg_data msg_data; |
| 3714 | char body[80]; |
| 3715 | |
| 3716 | pjsua_msg_data_init(&msg_data); |
| 3717 | msg_data.content_type = pj_str("application/dtmf-relay"); |
| 3718 | |
| 3719 | pj_ansi_snprintf(body, sizeof(body), |
| 3720 | "Signal=%c\r\n" |
| 3721 | "Duration=160", |
| 3722 | buf[i]); |
| 3723 | msg_data.msg_body = pj_str(body); |
| 3724 | |
| 3725 | status = pjsua_call_send_request(current_call, &SIP_INFO, |
| 3726 | &msg_data); |
| 3727 | if (status != PJ_SUCCESS) { |
| 3728 | break; |
| 3729 | } |
| 3730 | } |
| 3731 | } |
| 3732 | break; |
| 3733 | |
Benny Prijono | 5631561 | 2006-07-18 14:39:40 +0000 | [diff] [blame] | 3734 | case 'S': |
| 3735 | /* |
| 3736 | * Send arbitrary request |
| 3737 | */ |
| 3738 | if (pjsua_acc_get_count() == 0) { |
| 3739 | puts("Sorry, need at least one account configured"); |
| 3740 | break; |
| 3741 | } |
| 3742 | |
| 3743 | puts("Send arbitrary request to remote host"); |
| 3744 | |
| 3745 | /* Input METHOD */ |
| 3746 | if (!simple_input("Request method:",text,sizeof(text))) |
| 3747 | break; |
| 3748 | |
| 3749 | /* Input destination URI */ |
| 3750 | uri = NULL; |
| 3751 | ui_input_url("Destination URI", buf, sizeof(buf), &result); |
| 3752 | if (result.nb_result != NO_NB) { |
| 3753 | |
| 3754 | if (result.nb_result == -1 || result.nb_result == 0) { |
| 3755 | puts("Sorry you can't do that!"); |
| 3756 | continue; |
| 3757 | } else { |
| 3758 | pjsua_buddy_info binfo; |
| 3759 | pjsua_buddy_get_info(result.nb_result-1, &binfo); |
| 3760 | uri = binfo.uri.ptr; |
| 3761 | } |
| 3762 | |
| 3763 | } else if (result.uri_result) { |
| 3764 | uri = result.uri_result; |
| 3765 | } |
| 3766 | |
| 3767 | tmp = pj_str(uri); |
| 3768 | |
| 3769 | send_request(text, &tmp); |
| 3770 | break; |
| 3771 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 3772 | case 'e': |
| 3773 | if (pj_ansi_strnicmp(menuin, "echo", 4)==0) { |
| 3774 | pj_str_t tmp; |
| 3775 | |
| 3776 | tmp.ptr = menuin+5; |
| 3777 | tmp.slen = pj_ansi_strlen(menuin)-6; |
| 3778 | |
| 3779 | if (tmp.slen < 1) { |
| 3780 | puts("Usage: echo [0|1]"); |
| 3781 | break; |
| 3782 | } |
| 3783 | |
Benny Prijono | ddd02de | 2008-06-26 22:20:11 +0000 | [diff] [blame] | 3784 | cmd_echo = *tmp.ptr != '0' || tmp.slen!=1; |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 3785 | } |
| 3786 | break; |
| 3787 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3788 | case 's': |
Benny Prijono | 990042e | 2007-01-21 19:36:00 +0000 | [diff] [blame] | 3789 | if (pj_ansi_strnicmp(menuin, "sleep", 5)==0) { |
| 3790 | pj_str_t tmp; |
| 3791 | int delay; |
| 3792 | |
| 3793 | tmp.ptr = menuin+6; |
| 3794 | tmp.slen = pj_ansi_strlen(menuin)-7; |
| 3795 | |
| 3796 | if (tmp.slen < 1) { |
| 3797 | puts("Usage: sleep MSEC"); |
| 3798 | break; |
| 3799 | } |
| 3800 | |
| 3801 | delay = pj_strtoul(&tmp); |
| 3802 | if (delay < 0) delay = 0; |
| 3803 | pj_thread_sleep(delay); |
| 3804 | break; |
| 3805 | } |
| 3806 | /* Continue below */ |
| 3807 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3808 | case 'u': |
| 3809 | /* |
| 3810 | * Subscribe/unsubscribe presence. |
| 3811 | */ |
| 3812 | ui_input_url("(un)Subscribe presence of", buf, sizeof(buf), &result); |
| 3813 | if (result.nb_result != NO_NB) { |
| 3814 | if (result.nb_result == -1) { |
| 3815 | int i, count; |
| 3816 | count = pjsua_get_buddy_count(); |
| 3817 | for (i=0; i<count; ++i) |
| 3818 | pjsua_buddy_subscribe_pres(i, menuin[0]=='s'); |
| 3819 | } else if (result.nb_result == 0) { |
| 3820 | puts("Sorry, can only subscribe to buddy's presence, " |
| 3821 | "not from existing call"); |
| 3822 | } else { |
| 3823 | pjsua_buddy_subscribe_pres(result.nb_result-1, (menuin[0]=='s')); |
| 3824 | } |
| 3825 | |
| 3826 | } else if (result.uri_result) { |
| 3827 | puts("Sorry, can only subscribe to buddy's presence, " |
| 3828 | "not arbitrary URL (for now)"); |
| 3829 | } |
| 3830 | |
| 3831 | break; |
| 3832 | |
| 3833 | case 'r': |
| 3834 | switch (menuin[1]) { |
| 3835 | case 'r': |
| 3836 | /* |
| 3837 | * Re-Register. |
| 3838 | */ |
| 3839 | pjsua_acc_set_registration(current_acc, PJ_TRUE); |
| 3840 | break; |
| 3841 | case 'u': |
| 3842 | /* |
| 3843 | * Unregister |
| 3844 | */ |
| 3845 | pjsua_acc_set_registration(current_acc, PJ_FALSE); |
| 3846 | break; |
| 3847 | } |
| 3848 | break; |
| 3849 | |
| 3850 | case 't': |
| 3851 | pjsua_acc_get_info(current_acc, &acc_info); |
| 3852 | acc_info.online_status = !acc_info.online_status; |
| 3853 | pjsua_acc_set_online_status(current_acc, acc_info.online_status); |
| 3854 | printf("Setting %s online status to %s\n", |
| 3855 | acc_info.acc_uri.ptr, |
| 3856 | (acc_info.online_status?"online":"offline")); |
| 3857 | break; |
| 3858 | |
Benny Prijono | 4461c7d | 2007-08-25 13:36:15 +0000 | [diff] [blame] | 3859 | case 'T': |
| 3860 | change_online_status(); |
| 3861 | break; |
| 3862 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3863 | case 'c': |
| 3864 | switch (menuin[1]) { |
| 3865 | case 'l': |
| 3866 | conf_list(); |
| 3867 | break; |
| 3868 | case 'c': |
| 3869 | case 'd': |
| 3870 | { |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3871 | char tmp[10], src_port[10], dst_port[10]; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3872 | pj_status_t status; |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3873 | int cnt; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3874 | const char *src_title, *dst_title; |
| 3875 | |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3876 | cnt = sscanf(menuin, "%s %s %s", tmp, src_port, dst_port); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3877 | |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3878 | if (cnt != 3) { |
| 3879 | conf_list(); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3880 | |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3881 | src_title = (menuin[1]=='c'? |
| 3882 | "Connect src port #": |
| 3883 | "Disconnect src port #"); |
| 3884 | dst_title = (menuin[1]=='c'? |
| 3885 | "To dst port #": |
| 3886 | "From dst port #"); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3887 | |
Benny Prijono | 2b6ec1a | 2006-11-26 10:49:58 +0000 | [diff] [blame] | 3888 | if (!simple_input(src_title, src_port, sizeof(src_port))) |
| 3889 | break; |
| 3890 | |
| 3891 | if (!simple_input(dst_title, dst_port, sizeof(dst_port))) |
| 3892 | break; |
| 3893 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3894 | |
| 3895 | if (menuin[1]=='c') { |
| 3896 | status = pjsua_conf_connect(my_atoi(src_port), |
| 3897 | my_atoi(dst_port)); |
| 3898 | } else { |
| 3899 | status = pjsua_conf_disconnect(my_atoi(src_port), |
| 3900 | my_atoi(dst_port)); |
| 3901 | } |
| 3902 | if (status == PJ_SUCCESS) { |
| 3903 | puts("Success"); |
| 3904 | } else { |
| 3905 | puts("ERROR!!"); |
| 3906 | } |
| 3907 | } |
| 3908 | break; |
| 3909 | } |
| 3910 | break; |
| 3911 | |
Benny Prijono | 6dd967c | 2006-12-26 02:27:14 +0000 | [diff] [blame] | 3912 | case 'V': |
| 3913 | /* Adjust audio volume */ |
| 3914 | sprintf(buf, "Adjust mic level: [%4.1fx] ", app_config.mic_level); |
| 3915 | if (simple_input(buf,text,sizeof(text))) { |
| 3916 | char *err; |
| 3917 | app_config.mic_level = (float)strtod(text, &err); |
| 3918 | pjsua_conf_adjust_rx_level(0, app_config.mic_level); |
| 3919 | } |
| 3920 | sprintf(buf, "Adjust speaker level: [%4.1fx] ", |
| 3921 | app_config.speaker_level); |
| 3922 | if (simple_input(buf,text,sizeof(text))) { |
| 3923 | char *err; |
| 3924 | app_config.speaker_level = (float)strtod(text, &err); |
| 3925 | pjsua_conf_adjust_tx_level(0, app_config.speaker_level); |
| 3926 | } |
| 3927 | |
| 3928 | break; |
| 3929 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3930 | case 'd': |
| 3931 | if (menuin[1] == 'c') { |
| 3932 | char settings[2000]; |
| 3933 | int len; |
| 3934 | |
| 3935 | len = write_settings(&app_config, settings, sizeof(settings)); |
| 3936 | if (len < 1) |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 3937 | PJ_LOG(1,(THIS_FILE, "Error: not enough buffer")); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3938 | else |
| 3939 | PJ_LOG(3,(THIS_FILE, |
| 3940 | "Dumping configuration (%d bytes):\n%s\n", |
| 3941 | len, settings)); |
Benny Prijono | 819506c | 2006-06-22 22:29:51 +0000 | [diff] [blame] | 3942 | |
| 3943 | } else if (menuin[1] == 'q') { |
| 3944 | |
| 3945 | if (current_call != PJSUA_INVALID_ID) { |
Nanang Izzuddin | 660eee8 | 2008-07-17 14:54:03 +0000 | [diff] [blame] | 3946 | log_call_dump(current_call); |
Benny Prijono | 819506c | 2006-06-22 22:29:51 +0000 | [diff] [blame] | 3947 | } else { |
| 3948 | PJ_LOG(3,(THIS_FILE, "No current call")); |
| 3949 | } |
| 3950 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3951 | } else { |
| 3952 | app_dump(menuin[1]=='d'); |
| 3953 | } |
| 3954 | break; |
| 3955 | |
| 3956 | |
| 3957 | case 'f': |
| 3958 | if (simple_input("Enter output filename", buf, sizeof(buf))) { |
| 3959 | char settings[2000]; |
| 3960 | int len; |
| 3961 | |
| 3962 | len = write_settings(&app_config, settings, sizeof(settings)); |
| 3963 | if (len < 1) |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 3964 | PJ_LOG(1,(THIS_FILE, "Error: not enough buffer")); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 3965 | else { |
| 3966 | pj_oshandle_t fd; |
| 3967 | pj_status_t status; |
| 3968 | |
| 3969 | status = pj_file_open(app_config.pool, buf, |
| 3970 | PJ_O_WRONLY, &fd); |
| 3971 | if (status != PJ_SUCCESS) { |
| 3972 | pjsua_perror(THIS_FILE, "Unable to open file", status); |
| 3973 | } else { |
| 3974 | pj_ssize_t size = len; |
| 3975 | pj_file_write(fd, settings, &size); |
| 3976 | pj_file_close(fd); |
| 3977 | |
| 3978 | printf("Settings successfully written to '%s'\n", buf); |
| 3979 | } |
| 3980 | } |
| 3981 | |
| 3982 | } |
| 3983 | break; |
| 3984 | |
| 3985 | |
| 3986 | case 'q': |
| 3987 | goto on_exit; |
| 3988 | |
| 3989 | |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 3990 | case 'R': |
| 3991 | if (!pjsua_call_is_active(current_call)) { |
| 3992 | PJ_LOG(1,(THIS_FILE, "Call %d has gone", current_call)); |
| 3993 | } else if (menuin[1] == 'a') { |
| 3994 | pjsua_call_process_redirect(current_call, |
| 3995 | PJSIP_REDIRECT_ACCEPT); |
| 3996 | } else if (menuin[1] == 'r') { |
| 3997 | pjsua_call_process_redirect(current_call, |
| 3998 | PJSIP_REDIRECT_REJECT); |
| 3999 | } else { |
| 4000 | pjsua_call_process_redirect(current_call, |
| 4001 | PJSIP_REDIRECT_STOP); |
| 4002 | } |
| 4003 | break; |
| 4004 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4005 | default: |
| 4006 | if (menuin[0] != '\n' && menuin[0] != '\r') { |
| 4007 | printf("Invalid input %s", menuin); |
| 4008 | } |
| 4009 | keystroke_help(); |
| 4010 | break; |
| 4011 | } |
| 4012 | } |
| 4013 | |
| 4014 | on_exit: |
| 4015 | ; |
| 4016 | } |
| 4017 | |
| 4018 | |
| 4019 | /***************************************************************************** |
| 4020 | * Public API |
| 4021 | */ |
| 4022 | |
| 4023 | pj_status_t app_init(int argc, char *argv[]) |
| 4024 | { |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4025 | pjsua_transport_id transport_id = -1; |
Benny Prijono | e347cb0 | 2007-02-14 14:36:13 +0000 | [diff] [blame] | 4026 | pjsua_transport_config tcp_cfg; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4027 | unsigned i; |
| 4028 | pj_status_t status; |
| 4029 | |
| 4030 | /* Create pjsua */ |
| 4031 | status = pjsua_create(); |
| 4032 | if (status != PJ_SUCCESS) |
| 4033 | return status; |
| 4034 | |
| 4035 | /* Create pool for application */ |
Benny Prijono | c91ed8d | 2008-07-13 12:24:55 +0000 | [diff] [blame] | 4036 | app_config.pool = pjsua_pool_create("pjsua-app", 1000, 1000); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4037 | |
| 4038 | /* Initialize default config */ |
| 4039 | default_config(&app_config); |
| 4040 | |
| 4041 | /* Parse the arguments */ |
| 4042 | status = parse_args(argc, argv, &app_config, &uri_arg); |
| 4043 | if (status != PJ_SUCCESS) |
| 4044 | return status; |
| 4045 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4046 | /* Initialize application callbacks */ |
| 4047 | app_config.cfg.cb.on_call_state = &on_call_state; |
| 4048 | app_config.cfg.cb.on_call_media_state = &on_call_media_state; |
| 4049 | app_config.cfg.cb.on_incoming_call = &on_incoming_call; |
Benny Prijono | feb69f4 | 2007-10-05 09:12:26 +0000 | [diff] [blame] | 4050 | app_config.cfg.cb.on_call_tsx_state = &on_call_tsx_state; |
Benny Prijono | 0875ae8 | 2006-12-26 00:11:48 +0000 | [diff] [blame] | 4051 | app_config.cfg.cb.on_dtmf_digit = &call_on_dtmf_callback; |
Benny Prijono | 5e51a4e | 2008-11-27 00:06:46 +0000 | [diff] [blame] | 4052 | app_config.cfg.cb.on_call_redirected = &call_on_redirected; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4053 | app_config.cfg.cb.on_reg_state = &on_reg_state; |
Benny Prijono | 563cd7a | 2008-08-19 20:02:15 +0000 | [diff] [blame] | 4054 | app_config.cfg.cb.on_incoming_subscribe = &on_incoming_subscribe; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4055 | app_config.cfg.cb.on_buddy_state = &on_buddy_state; |
| 4056 | app_config.cfg.cb.on_pager = &on_pager; |
| 4057 | app_config.cfg.cb.on_typing = &on_typing; |
Benny Prijono | 4ddad2c | 2006-10-18 17:16:34 +0000 | [diff] [blame] | 4058 | app_config.cfg.cb.on_call_transfer_status = &on_call_transfer_status; |
Benny Prijono | f7b1c39 | 2006-11-11 16:46:34 +0000 | [diff] [blame] | 4059 | app_config.cfg.cb.on_call_replaced = &on_call_replaced; |
Benny Prijono | 6ba8c54 | 2007-10-16 01:34:14 +0000 | [diff] [blame] | 4060 | app_config.cfg.cb.on_nat_detect = &on_nat_detect; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4061 | |
| 4062 | /* Initialize pjsua */ |
| 4063 | status = pjsua_init(&app_config.cfg, &app_config.log_cfg, |
| 4064 | &app_config.media_cfg); |
| 4065 | if (status != PJ_SUCCESS) |
| 4066 | return status; |
| 4067 | |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4068 | #ifdef STEREO_DEMO |
| 4069 | stereo_demo(); |
| 4070 | #endif |
| 4071 | |
Benny Prijono | 804ff0a | 2006-09-14 11:17:48 +0000 | [diff] [blame] | 4072 | /* Initialize calls data */ |
| 4073 | for (i=0; i<PJ_ARRAY_SIZE(app_config.call_data); ++i) { |
| 4074 | app_config.call_data[i].timer.id = PJSUA_INVALID_ID; |
| 4075 | app_config.call_data[i].timer.cb = &call_timeout_callback; |
| 4076 | } |
| 4077 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4078 | /* Optionally registers WAV file */ |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 4079 | for (i=0; i<app_config.wav_count; ++i) { |
| 4080 | pjsua_player_id wav_id; |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 4081 | unsigned play_options = 0; |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 4082 | |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 4083 | if (app_config.auto_play_hangup) |
| 4084 | play_options |= PJMEDIA_FILE_NO_LOOP; |
| 4085 | |
| 4086 | status = pjsua_player_create(&app_config.wav_files[i], play_options, |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 4087 | &wav_id); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4088 | if (status != PJ_SUCCESS) |
| 4089 | goto on_error; |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 4090 | |
Benny Prijono | 72c04d2 | 2007-02-17 22:20:58 +0000 | [diff] [blame] | 4091 | if (app_config.wav_id == PJSUA_INVALID_ID) { |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 4092 | app_config.wav_id = wav_id; |
| 4093 | app_config.wav_port = pjsua_player_get_conf_port(app_config.wav_id); |
Nanang Izzuddin | b6133fb | 2008-06-20 21:45:50 +0000 | [diff] [blame] | 4094 | if (app_config.auto_play_hangup) { |
| 4095 | pjmedia_port *port; |
| 4096 | |
| 4097 | pjsua_player_get_port(app_config.wav_id, &port); |
| 4098 | status = pjmedia_wav_player_set_eof_cb(port, NULL, |
| 4099 | &on_playfile_done); |
| 4100 | if (status != PJ_SUCCESS) |
| 4101 | goto on_error; |
| 4102 | |
| 4103 | pj_timer_entry_init(&app_config.auto_hangup_timer, 0, NULL, |
| 4104 | &hangup_timeout_callback); |
| 4105 | } |
Benny Prijono | 32e4f49 | 2007-01-24 00:44:26 +0000 | [diff] [blame] | 4106 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4107 | } |
| 4108 | |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 4109 | /* Optionally registers tone players */ |
| 4110 | for (i=0; i<app_config.tone_count; ++i) { |
| 4111 | pjmedia_port *tport; |
| 4112 | char name[80]; |
| 4113 | pj_str_t label; |
| 4114 | pj_status_t status; |
| 4115 | |
| 4116 | pj_ansi_snprintf(name, sizeof(name), "tone-%d,%d", |
| 4117 | app_config.tones[i].freq1, |
| 4118 | app_config.tones[i].freq2); |
| 4119 | label = pj_str(name); |
| 4120 | status = pjmedia_tonegen_create2(app_config.pool, &label, |
| 4121 | 8000, 1, 160, 16, |
| 4122 | PJMEDIA_TONEGEN_LOOP, &tport); |
| 4123 | if (status != PJ_SUCCESS) { |
| 4124 | pjsua_perror(THIS_FILE, "Unable to create tone generator", status); |
| 4125 | goto on_error; |
| 4126 | } |
| 4127 | |
| 4128 | status = pjsua_conf_add_port(app_config.pool, tport, |
| 4129 | &app_config.tone_slots[i]); |
| 4130 | pj_assert(status == PJ_SUCCESS); |
| 4131 | |
| 4132 | status = pjmedia_tonegen_play(tport, 1, &app_config.tones[i], 0); |
| 4133 | pj_assert(status == PJ_SUCCESS); |
| 4134 | } |
| 4135 | |
Benny Prijono | 1ebd614 | 2006-10-19 15:48:02 +0000 | [diff] [blame] | 4136 | /* Optionally create recorder file, if any. */ |
| 4137 | if (app_config.rec_file.slen) { |
| 4138 | status = pjsua_recorder_create(&app_config.rec_file, 0, NULL, 0, 0, |
| 4139 | &app_config.rec_id); |
| 4140 | if (status != PJ_SUCCESS) |
| 4141 | goto on_error; |
| 4142 | |
| 4143 | app_config.rec_port = pjsua_recorder_get_conf_port(app_config.rec_id); |
| 4144 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4145 | |
Benny Prijono | e347cb0 | 2007-02-14 14:36:13 +0000 | [diff] [blame] | 4146 | pj_memcpy(&tcp_cfg, &app_config.udp_cfg, sizeof(tcp_cfg)); |
| 4147 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4148 | /* Create ringback tones */ |
| 4149 | if (app_config.no_tones == PJ_FALSE) { |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4150 | unsigned i, samples_per_frame; |
| 4151 | pjmedia_tone_desc tone[RING_CNT+RINGBACK_CNT]; |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4152 | pj_str_t name; |
| 4153 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4154 | samples_per_frame = app_config.media_cfg.audio_frame_ptime * |
| 4155 | app_config.media_cfg.clock_rate * |
| 4156 | app_config.media_cfg.channel_count / 1000; |
| 4157 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4158 | /* Ringback tone (call is ringing) */ |
| 4159 | name = pj_str("ringback"); |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4160 | status = pjmedia_tonegen_create2(app_config.pool, &name, |
| 4161 | app_config.media_cfg.clock_rate, |
| 4162 | app_config.media_cfg.channel_count, |
| 4163 | samples_per_frame, |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4164 | 16, PJMEDIA_TONEGEN_LOOP, |
| 4165 | &app_config.ringback_port); |
| 4166 | if (status != PJ_SUCCESS) |
| 4167 | goto on_error; |
| 4168 | |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4169 | pj_bzero(&tone, sizeof(tone)); |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4170 | for (i=0; i<RINGBACK_CNT; ++i) { |
| 4171 | tone[i].freq1 = RINGBACK_FREQ1; |
| 4172 | tone[i].freq2 = RINGBACK_FREQ2; |
| 4173 | tone[i].on_msec = RINGBACK_ON; |
| 4174 | tone[i].off_msec = RINGBACK_OFF; |
| 4175 | } |
| 4176 | tone[RINGBACK_CNT-1].off_msec = RINGBACK_INTERVAL; |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4177 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4178 | pjmedia_tonegen_play(app_config.ringback_port, RINGBACK_CNT, tone, |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4179 | PJMEDIA_TONEGEN_LOOP); |
| 4180 | |
| 4181 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4182 | status = pjsua_conf_add_port(app_config.pool, app_config.ringback_port, |
| 4183 | &app_config.ringback_slot); |
| 4184 | if (status != PJ_SUCCESS) |
| 4185 | goto on_error; |
| 4186 | |
| 4187 | /* Ring (to alert incoming call) */ |
| 4188 | name = pj_str("ring"); |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4189 | status = pjmedia_tonegen_create2(app_config.pool, &name, |
| 4190 | app_config.media_cfg.clock_rate, |
| 4191 | app_config.media_cfg.channel_count, |
| 4192 | samples_per_frame, |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4193 | 16, PJMEDIA_TONEGEN_LOOP, |
| 4194 | &app_config.ring_port); |
| 4195 | if (status != PJ_SUCCESS) |
| 4196 | goto on_error; |
| 4197 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4198 | for (i=0; i<RING_CNT; ++i) { |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4199 | tone[i].freq1 = RING_FREQ1; |
| 4200 | tone[i].freq2 = RING_FREQ2; |
| 4201 | tone[i].on_msec = RING_ON; |
| 4202 | tone[i].off_msec = RING_OFF; |
| 4203 | } |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4204 | tone[RING_CNT-1].off_msec = RING_INTERVAL; |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4205 | |
Benny Prijono | 4f96689 | 2008-06-14 22:43:56 +0000 | [diff] [blame] | 4206 | pjmedia_tonegen_play(app_config.ring_port, RING_CNT, |
Benny Prijono | e28cec8 | 2008-06-14 20:40:53 +0000 | [diff] [blame] | 4207 | tone, PJMEDIA_TONEGEN_LOOP); |
| 4208 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4209 | status = pjsua_conf_add_port(app_config.pool, app_config.ring_port, |
| 4210 | &app_config.ring_slot); |
| 4211 | if (status != PJ_SUCCESS) |
| 4212 | goto on_error; |
| 4213 | |
| 4214 | } |
| 4215 | |
Benny Prijono | 87ef89a | 2007-01-14 00:39:45 +0000 | [diff] [blame] | 4216 | /* Add UDP transport unless it's disabled. */ |
| 4217 | if (!app_config.no_udp) { |
| 4218 | pjsua_acc_id aid; |
| 4219 | |
| 4220 | status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, |
| 4221 | &app_config.udp_cfg, |
| 4222 | &transport_id); |
| 4223 | if (status != PJ_SUCCESS) |
| 4224 | goto on_error; |
| 4225 | |
| 4226 | /* Add local account */ |
| 4227 | pjsua_acc_add_local(transport_id, PJ_TRUE, &aid); |
| 4228 | //pjsua_acc_set_transport(aid, transport_id); |
| 4229 | pjsua_acc_set_online_status(current_acc, PJ_TRUE); |
Benny Prijono | e347cb0 | 2007-02-14 14:36:13 +0000 | [diff] [blame] | 4230 | |
| 4231 | if (app_config.udp_cfg.port == 0) { |
| 4232 | pjsua_transport_info ti; |
| 4233 | pj_sockaddr_in *a; |
| 4234 | |
| 4235 | pjsua_transport_get_info(transport_id, &ti); |
| 4236 | a = (pj_sockaddr_in*)&ti.local_addr; |
| 4237 | |
| 4238 | tcp_cfg.port = pj_ntohs(a->sin_port); |
| 4239 | } |
Benny Prijono | 87ef89a | 2007-01-14 00:39:45 +0000 | [diff] [blame] | 4240 | } |
| 4241 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4242 | /* Add TCP transport unless it's disabled */ |
| 4243 | if (!app_config.no_tcp) { |
| 4244 | status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, |
Benny Prijono | e347cb0 | 2007-02-14 14:36:13 +0000 | [diff] [blame] | 4245 | &tcp_cfg, |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4246 | &transport_id); |
| 4247 | if (status != PJ_SUCCESS) |
| 4248 | goto on_error; |
| 4249 | |
| 4250 | /* Add local account */ |
Benny Prijono | 21b9ad9 | 2006-08-15 13:11:22 +0000 | [diff] [blame] | 4251 | pjsua_acc_add_local(transport_id, PJ_TRUE, NULL); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4252 | pjsua_acc_set_online_status(current_acc, PJ_TRUE); |
| 4253 | |
| 4254 | } |
| 4255 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4256 | |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 4257 | #if defined(PJSIP_HAS_TLS_TRANSPORT) && PJSIP_HAS_TLS_TRANSPORT!=0 |
| 4258 | /* Add TLS transport when application wants one */ |
| 4259 | if (app_config.use_tls) { |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 4260 | |
| 4261 | pjsua_acc_id acc_id; |
| 4262 | |
| 4263 | /* Set TLS port as TCP port+1 */ |
Benny Prijono | afc47be | 2007-02-14 14:44:55 +0000 | [diff] [blame] | 4264 | tcp_cfg.port++; |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 4265 | status = pjsua_transport_create(PJSIP_TRANSPORT_TLS, |
Benny Prijono | afc47be | 2007-02-14 14:44:55 +0000 | [diff] [blame] | 4266 | &tcp_cfg, |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 4267 | &transport_id); |
Benny Prijono | afc47be | 2007-02-14 14:44:55 +0000 | [diff] [blame] | 4268 | tcp_cfg.port--; |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 4269 | if (status != PJ_SUCCESS) |
| 4270 | goto on_error; |
Benny Prijono | f3bbc13 | 2006-12-25 06:43:59 +0000 | [diff] [blame] | 4271 | |
| 4272 | /* Add local account */ |
| 4273 | pjsua_acc_add_local(transport_id, PJ_FALSE, &acc_id); |
| 4274 | pjsua_acc_set_online_status(acc_id, PJ_TRUE); |
Benny Prijono | 6e0e54b | 2006-12-08 21:58:31 +0000 | [diff] [blame] | 4275 | } |
| 4276 | #endif |
| 4277 | |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4278 | if (transport_id == -1) { |
Benny Prijono | d6e362a | 2008-07-19 17:53:47 +0000 | [diff] [blame] | 4279 | PJ_LOG(1,(THIS_FILE, "Error: no transport is configured")); |
Benny Prijono | e93e287 | 2006-06-28 16:46:49 +0000 | [diff] [blame] | 4280 | status = -1; |
| 4281 | goto on_error; |
| 4282 | } |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4283 | |
| 4284 | |
| 4285 | /* Add accounts */ |
| 4286 | for (i=0; i<app_config.acc_cnt; ++i) { |
Benny Prijono | 21b9ad9 | 2006-08-15 13:11:22 +0000 | [diff] [blame] | 4287 | status = pjsua_acc_add(&app_config.acc_cfg[i], PJ_TRUE, NULL); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4288 | if (status != PJ_SUCCESS) |
| 4289 | goto on_error; |
| 4290 | pjsua_acc_set_online_status(current_acc, PJ_TRUE); |
| 4291 | } |
| 4292 | |
| 4293 | /* Add buddies */ |
| 4294 | for (i=0; i<app_config.buddy_cnt; ++i) { |
| 4295 | status = pjsua_buddy_add(&app_config.buddy_cfg[i], NULL); |
| 4296 | if (status != PJ_SUCCESS) |
| 4297 | goto on_error; |
| 4298 | } |
| 4299 | |
| 4300 | /* Optionally set codec orders */ |
| 4301 | for (i=0; i<app_config.codec_cnt; ++i) { |
| 4302 | pjsua_codec_set_priority(&app_config.codec_arg[i], |
| 4303 | (pj_uint8_t)(PJMEDIA_CODEC_PRIO_NORMAL+i+9)); |
| 4304 | } |
| 4305 | |
Benny Prijono | fce2854 | 2007-12-09 15:41:10 +0000 | [diff] [blame] | 4306 | /* Optionally disable some codec */ |
| 4307 | for (i=0; i<app_config.codec_dis_cnt; ++i) { |
| 4308 | pjsua_codec_set_priority(&app_config.codec_dis[i],PJMEDIA_CODEC_PRIO_DISABLED); |
| 4309 | } |
| 4310 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4311 | /* Add RTP transports */ |
Benny Prijono | 40860c3 | 2008-09-04 13:55:33 +0000 | [diff] [blame] | 4312 | #ifdef TRANSPORT_ADAPTER_SAMPLE |
| 4313 | status = transport_adapter_sample(); |
| 4314 | |
| 4315 | #else |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4316 | status = pjsua_media_transports_create(&app_config.rtp_cfg); |
Benny Prijono | 40860c3 | 2008-09-04 13:55:33 +0000 | [diff] [blame] | 4317 | #endif |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4318 | if (status != PJ_SUCCESS) |
| 4319 | goto on_error; |
| 4320 | |
Nanang Izzuddin | d7fefd7 | 2008-06-12 12:48:59 +0000 | [diff] [blame] | 4321 | /* Set sound device latency */ |
| 4322 | pjmedia_snd_set_latency(app_config.capture_lat, app_config.playback_lat); |
| 4323 | |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 4324 | /* Use null sound device? */ |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4325 | #ifndef STEREO_DEMO |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 4326 | if (app_config.null_audio) { |
| 4327 | status = pjsua_set_null_snd_dev(); |
| 4328 | if (status != PJ_SUCCESS) |
| 4329 | return status; |
| 4330 | } |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4331 | #endif |
Benny Prijono | 22a300a | 2006-06-14 20:04:55 +0000 | [diff] [blame] | 4332 | |
Nanang Izzuddin | 68559c3 | 2008-06-13 17:01:46 +0000 | [diff] [blame] | 4333 | if (app_config.capture_dev != PJSUA_INVALID_ID || |
| 4334 | app_config.playback_dev != PJSUA_INVALID_ID) |
| 4335 | { |
| 4336 | status = pjsua_set_snd_dev(app_config.capture_dev, |
| 4337 | app_config.playback_dev); |
Benny Prijono | 4e5d551 | 2007-03-06 18:11:30 +0000 | [diff] [blame] | 4338 | if (status != PJ_SUCCESS) |
| 4339 | goto on_error; |
| 4340 | } |
| 4341 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4342 | return PJ_SUCCESS; |
| 4343 | |
| 4344 | on_error: |
Benny Prijono | ad2e0ca | 2007-04-29 12:31:51 +0000 | [diff] [blame] | 4345 | app_destroy(); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4346 | return status; |
| 4347 | } |
| 4348 | |
| 4349 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 4350 | static int stdout_refresh_proc(void *arg) |
| 4351 | { |
| 4352 | PJ_UNUSED_ARG(arg); |
| 4353 | |
| 4354 | /* Set thread to lowest priority so that it doesn't clobber |
| 4355 | * stdout output |
| 4356 | */ |
| 4357 | pj_thread_set_prio(pj_thread_this(), |
| 4358 | pj_thread_get_prio_min(pj_thread_this())); |
| 4359 | |
| 4360 | while (!stdout_refresh_quit) { |
| 4361 | pj_thread_sleep(stdout_refresh * 1000); |
| 4362 | puts(stdout_refresh_text); |
| 4363 | fflush(stdout); |
| 4364 | } |
| 4365 | |
| 4366 | return 0; |
| 4367 | } |
| 4368 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4369 | pj_status_t app_main(void) |
| 4370 | { |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 4371 | pj_thread_t *stdout_refresh_thread = NULL; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4372 | pj_status_t status; |
| 4373 | |
| 4374 | /* Start pjsua */ |
| 4375 | status = pjsua_start(); |
| 4376 | if (status != PJ_SUCCESS) { |
Benny Prijono | ad2e0ca | 2007-04-29 12:31:51 +0000 | [diff] [blame] | 4377 | app_destroy(); |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4378 | return status; |
| 4379 | } |
| 4380 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 4381 | /* Start console refresh thread */ |
| 4382 | if (stdout_refresh > 0) { |
| 4383 | pj_thread_create(app_config.pool, "stdout", &stdout_refresh_proc, |
| 4384 | NULL, 0, 0, &stdout_refresh_thread); |
| 4385 | } |
| 4386 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4387 | console_app_main(&uri_arg); |
| 4388 | |
Benny Prijono | ebc32c3 | 2008-06-12 13:30:39 +0000 | [diff] [blame] | 4389 | if (stdout_refresh_thread) { |
| 4390 | stdout_refresh_quit = PJ_TRUE; |
| 4391 | pj_thread_join(stdout_refresh_thread); |
| 4392 | pj_thread_destroy(stdout_refresh_thread); |
| 4393 | } |
| 4394 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4395 | return PJ_SUCCESS; |
| 4396 | } |
| 4397 | |
| 4398 | pj_status_t app_destroy(void) |
| 4399 | { |
Benny Prijono | f762ee7 | 2006-12-01 11:14:37 +0000 | [diff] [blame] | 4400 | pj_status_t status; |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 4401 | unsigned i; |
Benny Prijono | f762ee7 | 2006-12-01 11:14:37 +0000 | [diff] [blame] | 4402 | |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4403 | #ifdef STEREO_DEMO |
| 4404 | if (app_config.snd) { |
| 4405 | pjmedia_snd_port_destroy(app_config.snd); |
| 4406 | app_config.snd = NULL; |
| 4407 | } |
| 4408 | #endif |
| 4409 | |
Benny Prijono | 91d20f4 | 2008-06-14 19:42:37 +0000 | [diff] [blame] | 4410 | /* Close ringback port */ |
| 4411 | if (app_config.ringback_port && |
| 4412 | app_config.ringback_slot != PJSUA_INVALID_ID) |
| 4413 | { |
| 4414 | pjsua_conf_remove_port(app_config.ringback_slot); |
| 4415 | app_config.ringback_slot = PJSUA_INVALID_ID; |
| 4416 | pjmedia_port_destroy(app_config.ringback_port); |
| 4417 | app_config.ringback_port = NULL; |
| 4418 | } |
| 4419 | |
| 4420 | /* Close ring port */ |
| 4421 | if (app_config.ring_port && app_config.ring_slot != PJSUA_INVALID_ID) { |
| 4422 | pjsua_conf_remove_port(app_config.ring_slot); |
| 4423 | app_config.ring_slot = PJSUA_INVALID_ID; |
| 4424 | pjmedia_port_destroy(app_config.ring_port); |
| 4425 | app_config.ring_port = NULL; |
| 4426 | } |
| 4427 | |
Benny Prijono | 4af234b | 2007-01-24 02:02:09 +0000 | [diff] [blame] | 4428 | /* Close tone generators */ |
| 4429 | for (i=0; i<app_config.tone_count; ++i) { |
| 4430 | pjsua_conf_remove_port(app_config.tone_slots[i]); |
| 4431 | } |
| 4432 | |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4433 | if (app_config.pool) { |
| 4434 | pj_pool_release(app_config.pool); |
| 4435 | app_config.pool = NULL; |
| 4436 | } |
| 4437 | |
Benny Prijono | f762ee7 | 2006-12-01 11:14:37 +0000 | [diff] [blame] | 4438 | status = pjsua_destroy(); |
| 4439 | |
| 4440 | pj_bzero(&app_config, sizeof(app_config)); |
| 4441 | |
| 4442 | return status; |
Benny Prijono | eebe9af | 2006-06-13 22:57:13 +0000 | [diff] [blame] | 4443 | } |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4444 | |
| 4445 | |
| 4446 | #ifdef STEREO_DEMO |
| 4447 | static void stereo_demo() |
| 4448 | { |
| 4449 | pjmedia_port *conf, *splitter, *ch1; |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4450 | pj_status_t status; |
| 4451 | |
| 4452 | /* Disable existing sound device */ |
| 4453 | conf = pjsua_set_no_snd_dev(); |
| 4454 | |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4455 | /* Create stereo-mono splitter/combiner */ |
| 4456 | status = pjmedia_splitcomb_create(app_config.pool, |
Benny Prijono | 478cf7c | 2007-06-02 00:12:29 +0000 | [diff] [blame] | 4457 | conf->info.clock_rate /* clock rate */, |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4458 | 2 /* stereo */, |
Benny Prijono | 478cf7c | 2007-06-02 00:12:29 +0000 | [diff] [blame] | 4459 | 2 * conf->info.samples_per_frame, |
| 4460 | conf->info.bits_per_sample, |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4461 | 0 /* options */, |
| 4462 | &splitter); |
| 4463 | pj_assert(status == PJ_SUCCESS); |
| 4464 | |
| 4465 | /* Connect channel0 (left channel?) to conference port slot0 */ |
| 4466 | status = pjmedia_splitcomb_set_channel(splitter, 0 /* ch0 */, |
| 4467 | 0 /*options*/, |
| 4468 | conf); |
| 4469 | pj_assert(status == PJ_SUCCESS); |
| 4470 | |
| 4471 | /* Create reverse channel for channel1 (right channel?)... */ |
| 4472 | status = pjmedia_splitcomb_create_rev_channel(app_config.pool, |
| 4473 | splitter, |
| 4474 | 1 /* ch1 */, |
| 4475 | 0 /* options */, |
| 4476 | &ch1); |
| 4477 | pj_assert(status == PJ_SUCCESS); |
| 4478 | |
| 4479 | /* .. and register it to conference bridge (it would be slot1 |
| 4480 | * if there's no other devices connected to the bridge) |
| 4481 | */ |
| 4482 | status = pjsua_conf_add_port(app_config.pool, ch1, NULL); |
| 4483 | pj_assert(status == PJ_SUCCESS); |
| 4484 | |
| 4485 | /* Create sound device */ |
| 4486 | status = pjmedia_snd_port_create(app_config.pool, -1, -1, |
Benny Prijono | 478cf7c | 2007-06-02 00:12:29 +0000 | [diff] [blame] | 4487 | conf->info.clock_rate, |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4488 | 2 /* stereo */, |
Benny Prijono | 478cf7c | 2007-06-02 00:12:29 +0000 | [diff] [blame] | 4489 | 2 * conf->info.samples_per_frame, |
| 4490 | conf->info.bits_per_sample, |
Benny Prijono | e909eac | 2006-07-27 22:04:56 +0000 | [diff] [blame] | 4491 | 0, &app_config.snd); |
| 4492 | pj_assert(status == PJ_SUCCESS); |
| 4493 | |
| 4494 | |
| 4495 | /* Connect the splitter to the sound device */ |
| 4496 | status = pjmedia_snd_port_connect(app_config.snd, splitter); |
| 4497 | pj_assert(status == PJ_SUCCESS); |
| 4498 | |
| 4499 | } |
| 4500 | #endif |
| 4501 | |
Benny Prijono | 40860c3 | 2008-09-04 13:55:33 +0000 | [diff] [blame] | 4502 | #ifdef TRANSPORT_ADAPTER_SAMPLE |
| 4503 | static pj_status_t create_transport_adapter(pjmedia_endpt *med_endpt, int port, |
| 4504 | pjmedia_transport **p_tp) |
| 4505 | { |
| 4506 | pjmedia_transport *udp; |
| 4507 | pj_status_t status; |
| 4508 | |
| 4509 | /* Create the UDP media transport */ |
| 4510 | status = pjmedia_transport_udp_create(med_endpt, NULL, port, 0, &udp); |
| 4511 | if (status != PJ_SUCCESS) |
| 4512 | return status; |
| 4513 | |
| 4514 | /* Create the adapter */ |
| 4515 | status = pjmedia_tp_adapter_create(med_endpt, NULL, udp, p_tp); |
| 4516 | if (status != PJ_SUCCESS) { |
| 4517 | pjmedia_transport_close(udp); |
| 4518 | return status; |
| 4519 | } |
| 4520 | |
| 4521 | return PJ_SUCCESS; |
| 4522 | } |
| 4523 | |
| 4524 | static pj_status_t transport_adapter_sample(void) |
| 4525 | { |
| 4526 | pjsua_media_transport tp[PJSUA_MAX_CALLS]; |
| 4527 | pj_status_t status; |
| 4528 | int port = 7000; |
| 4529 | unsigned i; |
| 4530 | |
| 4531 | for (i=0; i<app_config.cfg.max_calls; ++i) { |
| 4532 | status = create_transport_adapter(pjsua_get_pjmedia_endpt(), |
| 4533 | port + i*10, |
| 4534 | &tp[i].transport); |
| 4535 | if (status != PJ_SUCCESS) |
| 4536 | return status; |
| 4537 | } |
| 4538 | |
| 4539 | return pjsua_media_transports_attach(tp, i, PJ_TRUE); |
| 4540 | } |
| 4541 | #endif |
| 4542 | |