Benny Prijono | ba5926a | 2007-05-02 11:29:37 +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) |
| 4 | * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org> |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +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 | */ |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 20 | #include <pjsua-lib/pjsua.h> |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 21 | #include <pjsua-lib/pjsua_internal.h> |
Nanang Izzuddin | a940b36 | 2009-02-23 13:53:30 +0000 | [diff] [blame] | 22 | //#include <pjmedia/symbian_sound_aps.h> |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 23 | #include "ua.h" |
| 24 | |
| 25 | #define THIS_FILE "symbian_ua.cpp" |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 26 | #define CON_LOG_LEVEL 3 // console log level |
| 27 | #define FILE_LOG_LEVEL 4 // logfile log level |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 28 | |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 29 | // |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 30 | // Basic config. |
| 31 | // |
| 32 | #define SIP_PORT 5060 |
| 33 | |
| 34 | |
| 35 | // |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 36 | // Destination URI (to make call, or to subscribe presence) |
| 37 | // |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 38 | #define SIP_DST_URI "<sip:100@pjsip.lab>" |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 39 | |
| 40 | // |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 41 | // Account |
| 42 | // |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 43 | #define HAS_SIP_ACCOUNT 0 // 1 to enable registration |
Benny Prijono | 0e2c646 | 2008-02-14 13:39:24 +0000 | [diff] [blame] | 44 | #define SIP_DOMAIN "pjsip.lab" |
| 45 | #define SIP_USER "400" |
| 46 | #define SIP_PASSWD "400" |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 47 | |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 48 | // |
| 49 | // Outbound proxy for all accounts |
| 50 | // |
| 51 | #define SIP_PROXY NULL |
Benny Prijono | 4b55e0a | 2008-12-18 13:22:52 +0000 | [diff] [blame] | 52 | //#define SIP_PROXY "<sip:192.168.0.8;lr>" |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 53 | |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 54 | // |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 55 | // SIP transports |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 56 | // |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 57 | #define ENABLE_SIP_UDP 1 |
| 58 | #define ENABLE_SIP_TCP 0 // experimental |
| 59 | #define ENABLE_SIP_TLS 0 // experimental |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 60 | |
Benny Prijono | 28efe81 | 2009-11-09 09:52:23 +0000 | [diff] [blame] | 61 | #define TLS_SRV_NAME "pjsip.org" // TLS servername (required for |
| 62 | // TLS transport) |
| 63 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 64 | // |
| 65 | // Configure nameserver if DNS SRV is to be used with both SIP |
| 66 | // or STUN (for STUN see other settings below) |
| 67 | // |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 68 | #define NAMESERVER NULL |
| 69 | //#define NAMESERVER "192.168.0.2" |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 70 | |
| 71 | // |
| 72 | // STUN server |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 73 | #if 0 |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 74 | // Use this to have the STUN server resolved normally |
| 75 | # define STUN_DOMAIN NULL |
Benny Prijono | 4b55e0a | 2008-12-18 13:22:52 +0000 | [diff] [blame] | 76 | # define STUN_SERVER "stun.pjsip.org" |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 77 | #elif 0 |
| 78 | // Use this to have the STUN server resolved with DNS SRV |
Benny Prijono | 4b55e0a | 2008-12-18 13:22:52 +0000 | [diff] [blame] | 79 | # define STUN_DOMAIN "pjsip.org" |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 80 | # define STUN_SERVER NULL |
| 81 | #else |
| 82 | // Use this to disable STUN |
| 83 | # define STUN_DOMAIN NULL |
| 84 | # define STUN_SERVER NULL |
| 85 | #endif |
| 86 | |
| 87 | // |
| 88 | // Use ICE? |
| 89 | // |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 90 | #define USE_ICE 1 |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 91 | |
Nanang Izzuddin | 6a6392f | 2008-06-02 18:30:15 +0000 | [diff] [blame] | 92 | // |
| 93 | // Use SRTP? |
| 94 | // |
| 95 | #define USE_SRTP PJSUA_DEFAULT_USE_SRTP |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 96 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 97 | // |
Benny Prijono | a25bc9d | 2009-11-09 08:51:34 +0000 | [diff] [blame] | 98 | // Set QoS on transports? Yes! |
| 99 | // As an example, we set SIP transports DSCP value to CS3 (DSCP |
| 100 | // value 24 or 0x18), for no reason, and tag RTP/RTCP packets |
| 101 | // with VOICE type. |
| 102 | // |
| 103 | #define SIP_QOS_DSCP 0x18 |
| 104 | #define RTP_QOS_TYPE PJ_QOS_TYPE_VOICE |
| 105 | |
| 106 | |
| 107 | // |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 108 | // Globals |
| 109 | // |
| 110 | static pjsua_acc_id g_acc_id = PJSUA_INVALID_ID; |
| 111 | static pjsua_call_id g_call_id = PJSUA_INVALID_ID; |
| 112 | static pjsua_buddy_id g_buddy_id = PJSUA_INVALID_ID; |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 113 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 114 | |
| 115 | /* Callback called by the library upon receiving incoming call */ |
| 116 | static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, |
| 117 | pjsip_rx_data *rdata) |
| 118 | { |
| 119 | pjsua_call_info ci; |
| 120 | |
| 121 | PJ_UNUSED_ARG(acc_id); |
| 122 | PJ_UNUSED_ARG(rdata); |
| 123 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 124 | if (g_call_id != PJSUA_INVALID_ID) { |
| 125 | pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL); |
| 126 | return; |
| 127 | } |
| 128 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 129 | pjsua_call_get_info(call_id, &ci); |
| 130 | |
| 131 | PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", |
| 132 | (int)ci.remote_info.slen, |
| 133 | ci.remote_info.ptr)); |
| 134 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 135 | g_call_id = call_id; |
| 136 | |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 137 | /* Automatically answer incoming calls with 180/Ringing */ |
| 138 | pjsua_call_answer(call_id, 180, NULL, NULL); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* Callback called by the library when call's state has changed */ |
| 142 | static void on_call_state(pjsua_call_id call_id, pjsip_event *e) |
| 143 | { |
| 144 | pjsua_call_info ci; |
| 145 | |
| 146 | PJ_UNUSED_ARG(e); |
| 147 | |
| 148 | pjsua_call_get_info(call_id, &ci); |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 149 | |
| 150 | if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { |
| 151 | if (call_id == g_call_id) |
| 152 | g_call_id = PJSUA_INVALID_ID; |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 153 | } else if (ci.state != PJSIP_INV_STATE_INCOMING) { |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 154 | if (g_call_id == PJSUA_INVALID_ID) |
| 155 | g_call_id = call_id; |
| 156 | } |
| 157 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 158 | PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, |
| 159 | (int)ci.state_text.slen, |
| 160 | ci.state_text.ptr)); |
| 161 | } |
| 162 | |
| 163 | /* Callback called by the library when call's media state has changed */ |
| 164 | static void on_call_media_state(pjsua_call_id call_id) |
| 165 | { |
| 166 | pjsua_call_info ci; |
| 167 | |
| 168 | pjsua_call_get_info(call_id, &ci); |
| 169 | |
| 170 | if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) { |
| 171 | // When media is active, connect call to sound device. |
| 172 | pjsua_conf_connect(ci.conf_slot, 0); |
| 173 | pjsua_conf_connect(0, ci.conf_slot); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 178 | /* Handler on buddy state changed. */ |
| 179 | static void on_buddy_state(pjsua_buddy_id buddy_id) |
| 180 | { |
| 181 | pjsua_buddy_info info; |
| 182 | pjsua_buddy_get_info(buddy_id, &info); |
| 183 | |
| 184 | PJ_LOG(3,(THIS_FILE, "%.*s status is %.*s", |
| 185 | (int)info.uri.slen, |
| 186 | info.uri.ptr, |
| 187 | (int)info.status_text.slen, |
| 188 | info.status_text.ptr)); |
| 189 | } |
| 190 | |
| 191 | |
| 192 | /* Incoming IM message (i.e. MESSAGE request)! */ |
| 193 | static void on_pager(pjsua_call_id call_id, const pj_str_t *from, |
| 194 | const pj_str_t *to, const pj_str_t *contact, |
| 195 | const pj_str_t *mime_type, const pj_str_t *text) |
| 196 | { |
| 197 | /* Note: call index may be -1 */ |
| 198 | PJ_UNUSED_ARG(call_id); |
| 199 | PJ_UNUSED_ARG(to); |
| 200 | PJ_UNUSED_ARG(contact); |
| 201 | PJ_UNUSED_ARG(mime_type); |
| 202 | |
| 203 | PJ_LOG(3,(THIS_FILE,"MESSAGE from %.*s: %.*s", |
| 204 | (int)from->slen, from->ptr, |
| 205 | (int)text->slen, text->ptr)); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /* Received typing indication */ |
| 210 | static void on_typing(pjsua_call_id call_id, const pj_str_t *from, |
| 211 | const pj_str_t *to, const pj_str_t *contact, |
| 212 | pj_bool_t is_typing) |
| 213 | { |
| 214 | PJ_UNUSED_ARG(call_id); |
| 215 | PJ_UNUSED_ARG(to); |
| 216 | PJ_UNUSED_ARG(contact); |
| 217 | |
| 218 | PJ_LOG(3,(THIS_FILE, "IM indication: %.*s %s", |
| 219 | (int)from->slen, from->ptr, |
| 220 | (is_typing?"is typing..":"has stopped typing"))); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | /* Call transfer request status. */ |
| 225 | static void on_call_transfer_status(pjsua_call_id call_id, |
| 226 | int status_code, |
| 227 | const pj_str_t *status_text, |
| 228 | pj_bool_t final, |
| 229 | pj_bool_t *p_cont) |
| 230 | { |
| 231 | PJ_LOG(3,(THIS_FILE, "Call %d: transfer status=%d (%.*s) %s", |
| 232 | call_id, status_code, |
| 233 | (int)status_text->slen, status_text->ptr, |
| 234 | (final ? "[final]" : ""))); |
| 235 | |
| 236 | if (status_code/100 == 2) { |
| 237 | PJ_LOG(3,(THIS_FILE, |
| 238 | "Call %d: call transfered successfully, disconnecting call", |
| 239 | call_id)); |
| 240 | pjsua_call_hangup(call_id, PJSIP_SC_GONE, NULL, NULL); |
| 241 | *p_cont = PJ_FALSE; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
Benny Prijono | aecabfc | 2007-10-26 05:35:42 +0000 | [diff] [blame] | 246 | /* NAT detection result */ |
| 247 | static void on_nat_detect(const pj_stun_nat_detect_result *res) |
| 248 | { |
| 249 | if (res->status != PJ_SUCCESS) { |
| 250 | pjsua_perror(THIS_FILE, "NAT detection failed", res->status); |
| 251 | } else { |
| 252 | PJ_LOG(3, (THIS_FILE, "NAT detected as %s", res->nat_type_name)); |
| 253 | } |
| 254 | } |
| 255 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 256 | /* Notification that call is being replaced. */ |
| 257 | static void on_call_replaced(pjsua_call_id old_call_id, |
| 258 | pjsua_call_id new_call_id) |
| 259 | { |
| 260 | pjsua_call_info old_ci, new_ci; |
| 261 | |
| 262 | pjsua_call_get_info(old_call_id, &old_ci); |
| 263 | pjsua_call_get_info(new_call_id, &new_ci); |
| 264 | |
| 265 | PJ_LOG(3,(THIS_FILE, "Call %d with %.*s is being replaced by " |
| 266 | "call %d with %.*s", |
| 267 | old_call_id, |
| 268 | (int)old_ci.remote_info.slen, old_ci.remote_info.ptr, |
| 269 | new_call_id, |
| 270 | (int)new_ci.remote_info.slen, new_ci.remote_info.ptr)); |
| 271 | } |
| 272 | |
| 273 | |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 274 | //#include<e32debug.h> |
| 275 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 276 | /* Logging callback */ |
Benny Prijono | 797e338 | 2007-12-01 09:10:07 +0000 | [diff] [blame] | 277 | static void log_writer(int level, const char *buf, int len) |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 278 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 279 | static wchar_t buf16[PJ_LOG_MAX_SIZE]; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 280 | |
| 281 | PJ_UNUSED_ARG(level); |
| 282 | |
| 283 | pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16)); |
| 284 | |
| 285 | TPtrC16 aBuf((const TUint16*)buf16, (TInt)len); |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 286 | //RDebug::Print(aBuf); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 287 | console->Write(aBuf); |
Benny Prijono | 797e338 | 2007-12-01 09:10:07 +0000 | [diff] [blame] | 288 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* |
| 292 | * app_startup() |
| 293 | * |
| 294 | * url may contain URL to call. |
| 295 | */ |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 296 | static pj_status_t app_startup() |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 297 | { |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 298 | pj_status_t status; |
| 299 | |
| 300 | /* Redirect log before pjsua_init() */ |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 301 | pj_log_set_log_func(&log_writer); |
| 302 | |
| 303 | /* Set log level */ |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 304 | pj_log_set_level(CON_LOG_LEVEL); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 305 | |
| 306 | /* Create pjsua first! */ |
| 307 | status = pjsua_create(); |
| 308 | if (status != PJ_SUCCESS) { |
| 309 | pjsua_perror(THIS_FILE, "pjsua_create() error", status); |
| 310 | return status; |
| 311 | } |
| 312 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 313 | /* Init pjsua */ |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 314 | pjsua_config cfg; |
| 315 | pjsua_logging_config log_cfg; |
| 316 | pjsua_media_config med_cfg; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 317 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 318 | pjsua_config_default(&cfg); |
| 319 | cfg.max_calls = 2; |
| 320 | cfg.thread_cnt = 0; // Disable threading on Symbian |
Nanang Izzuddin | 6a6392f | 2008-06-02 18:30:15 +0000 | [diff] [blame] | 321 | cfg.use_srtp = USE_SRTP; |
| 322 | cfg.srtp_secure_signaling = 0; |
| 323 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 324 | cfg.cb.on_incoming_call = &on_incoming_call; |
| 325 | cfg.cb.on_call_media_state = &on_call_media_state; |
| 326 | cfg.cb.on_call_state = &on_call_state; |
| 327 | cfg.cb.on_buddy_state = &on_buddy_state; |
| 328 | cfg.cb.on_pager = &on_pager; |
| 329 | cfg.cb.on_typing = &on_typing; |
| 330 | cfg.cb.on_call_transfer_status = &on_call_transfer_status; |
| 331 | cfg.cb.on_call_replaced = &on_call_replaced; |
Benny Prijono | aecabfc | 2007-10-26 05:35:42 +0000 | [diff] [blame] | 332 | cfg.cb.on_nat_detect = &on_nat_detect; |
| 333 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 334 | if (SIP_PROXY) { |
| 335 | cfg.outbound_proxy_cnt = 1; |
| 336 | cfg.outbound_proxy[0] = pj_str(SIP_PROXY); |
| 337 | } |
| 338 | |
| 339 | if (NAMESERVER) { |
| 340 | cfg.nameserver_count = 1; |
| 341 | cfg.nameserver[0] = pj_str(NAMESERVER); |
| 342 | } |
| 343 | |
| 344 | if (NAMESERVER && STUN_DOMAIN) { |
| 345 | cfg.stun_domain = pj_str(STUN_DOMAIN); |
| 346 | } else if (STUN_SERVER) { |
| 347 | cfg.stun_host = pj_str(STUN_SERVER); |
| 348 | } |
| 349 | |
| 350 | |
| 351 | pjsua_logging_config_default(&log_cfg); |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 352 | log_cfg.level = FILE_LOG_LEVEL; |
| 353 | log_cfg.console_level = CON_LOG_LEVEL; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 354 | log_cfg.cb = &log_writer; |
Nanang Izzuddin | 83457d5 | 2009-02-16 16:29:05 +0000 | [diff] [blame] | 355 | log_cfg.log_filename = pj_str("C:\\data\\symbian_ua.log"); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 356 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 357 | pjsua_media_config_default(&med_cfg); |
| 358 | med_cfg.thread_cnt = 0; // Disable threading on Symbian |
| 359 | med_cfg.has_ioqueue = PJ_FALSE; |
| 360 | med_cfg.clock_rate = 8000; |
Benny Prijono | 5df8bb6 | 2007-12-28 18:55:02 +0000 | [diff] [blame] | 361 | med_cfg.audio_frame_ptime = 40; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 362 | med_cfg.ec_tail_len = 0; |
| 363 | med_cfg.enable_ice = USE_ICE; |
Nanang Izzuddin | 81db8c7 | 2009-02-05 10:59:14 +0000 | [diff] [blame] | 364 | med_cfg.snd_auto_close_time = 0; // wait for 0 seconds idle before sound dev get auto-closed |
Nanang Izzuddin | a377597 | 2009-03-03 18:25:55 +0000 | [diff] [blame] | 365 | //med_cfg.no_vad = PJ_TRUE; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 366 | |
| 367 | status = pjsua_init(&cfg, &log_cfg, &med_cfg); |
| 368 | if (status != PJ_SUCCESS) { |
| 369 | pjsua_perror(THIS_FILE, "pjsua_init() error", status); |
| 370 | pjsua_destroy(); |
| 371 | return status; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 372 | } |
Nanang Izzuddin | 829ac02 | 2008-05-27 00:24:26 +0000 | [diff] [blame] | 373 | |
| 374 | /* Adjust Speex priority and enable only the narrowband */ |
| 375 | { |
| 376 | pj_str_t codec_id = pj_str("speex/8000"); |
| 377 | pjmedia_codec_mgr_set_codec_priority( |
| 378 | pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt), |
| 379 | &codec_id, PJMEDIA_CODEC_PRIO_NORMAL+1); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 380 | |
Nanang Izzuddin | 829ac02 | 2008-05-27 00:24:26 +0000 | [diff] [blame] | 381 | codec_id = pj_str("speex/16000"); |
| 382 | pjmedia_codec_mgr_set_codec_priority( |
| 383 | pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt), |
| 384 | &codec_id, PJMEDIA_CODEC_PRIO_DISABLED); |
| 385 | |
| 386 | codec_id = pj_str("speex/32000"); |
| 387 | pjmedia_codec_mgr_set_codec_priority( |
| 388 | pjmedia_endpt_get_codec_mgr(pjsua_var.med_endpt), |
| 389 | &codec_id, PJMEDIA_CODEC_PRIO_DISABLED); |
| 390 | } |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 391 | |
Nanang Izzuddin | 829ac02 | 2008-05-27 00:24:26 +0000 | [diff] [blame] | 392 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 393 | pjsua_transport_config tcfg; |
| 394 | pjsua_transport_id tid; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 395 | |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 396 | #if ENABLE_SIP_UDP |
| 397 | /* Add UDP transport. */ |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 398 | pjsua_transport_config_default(&tcfg); |
| 399 | tcfg.port = SIP_PORT; |
Benny Prijono | a25bc9d | 2009-11-09 08:51:34 +0000 | [diff] [blame] | 400 | if (SIP_QOS_DSCP) { |
| 401 | tcfg.qos_params.flags |= PJ_QOS_PARAM_HAS_DSCP; |
| 402 | tcfg.qos_params.dscp_val = SIP_QOS_DSCP; |
| 403 | } |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 404 | status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tcfg, &tid); |
| 405 | if (status != PJ_SUCCESS) { |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 406 | pjsua_perror(THIS_FILE, "Error creating UDP transport", status); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 407 | pjsua_destroy(); |
| 408 | return status; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 409 | } |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 410 | #endif |
| 411 | |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 412 | #if ENABLE_SIP_TCP |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 413 | /* Add TCP transport */ |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 414 | pjsua_transport_config_default(&tcfg); |
| 415 | tcfg.port = SIP_PORT; |
Benny Prijono | a25bc9d | 2009-11-09 08:51:34 +0000 | [diff] [blame] | 416 | if (SIP_QOS_DSCP) { |
| 417 | tcfg.qos_params.flags |= PJ_QOS_PARAM_HAS_DSCP; |
| 418 | tcfg.qos_params.dscp_val = SIP_QOS_DSCP; |
| 419 | } |
Nanang Izzuddin | 940d3f6 | 2009-06-22 14:06:40 +0000 | [diff] [blame] | 420 | status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcfg, &tid); |
| 421 | if (status != PJ_SUCCESS) { |
| 422 | pjsua_perror(THIS_FILE, "Error creating TCP transport", status); |
| 423 | pjsua_destroy(); |
| 424 | return status; |
| 425 | } |
| 426 | #endif |
| 427 | |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 428 | #if ENABLE_SIP_TLS |
| 429 | /* Add TLS transport */ |
| 430 | pjsua_transport_config_default(&tcfg); |
| 431 | tcfg.port = SIP_PORT + 1; |
Benny Prijono | a25bc9d | 2009-11-09 08:51:34 +0000 | [diff] [blame] | 432 | if (SIP_QOS_DSCP) { |
| 433 | tcfg.qos_params.flags |= PJ_QOS_PARAM_HAS_DSCP; |
| 434 | tcfg.qos_params.dscp_val = SIP_QOS_DSCP; |
| 435 | tcfg.tls_setting.qos_params = tcfg.qos_params; |
| 436 | } |
Benny Prijono | 28efe81 | 2009-11-09 09:52:23 +0000 | [diff] [blame] | 437 | tcfg.tls_setting.server_name = pj_str(TLS_SRV_NAME); |
Nanang Izzuddin | 6c62bf4 | 2009-08-27 19:55:13 +0000 | [diff] [blame] | 438 | status = pjsua_transport_create(PJSIP_TRANSPORT_TLS, &tcfg, &tid); |
| 439 | if (status != PJ_SUCCESS) { |
| 440 | pjsua_perror(THIS_FILE, "Error creating TLS transport", status); |
| 441 | pjsua_destroy(); |
| 442 | return status; |
| 443 | } |
| 444 | #endif |
| 445 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 446 | /* Add account for the transport */ |
| 447 | pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id); |
| 448 | |
Benny Prijono | a25bc9d | 2009-11-09 08:51:34 +0000 | [diff] [blame] | 449 | /* Create media transports */ |
| 450 | pjsua_transport_config mtcfg; |
| 451 | pjsua_transport_config_default(&mtcfg); |
| 452 | mtcfg.port = 4000; |
| 453 | mtcfg.qos_type = RTP_QOS_TYPE; |
| 454 | status = pjsua_media_transports_create(&mtcfg); |
| 455 | if (status != PJ_SUCCESS) { |
| 456 | pjsua_perror(THIS_FILE, "Error creating media transports", status); |
| 457 | pjsua_destroy(); |
| 458 | return status; |
| 459 | } |
| 460 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 461 | /* Initialization is done, now start pjsua */ |
| 462 | status = pjsua_start(); |
| 463 | if (status != PJ_SUCCESS) { |
| 464 | pjsua_perror(THIS_FILE, "Error starting pjsua", status); |
| 465 | pjsua_destroy(); |
| 466 | return status; |
| 467 | } |
| 468 | |
| 469 | /* Register to SIP server by creating SIP account. */ |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 470 | if (HAS_SIP_ACCOUNT) { |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 471 | pjsua_acc_config cfg; |
| 472 | |
| 473 | pjsua_acc_config_default(&cfg); |
| 474 | cfg.id = pj_str("sip:" SIP_USER "@" SIP_DOMAIN); |
| 475 | cfg.reg_uri = pj_str("sip:" SIP_DOMAIN); |
| 476 | cfg.cred_count = 1; |
Benny Prijono | 0e2c646 | 2008-02-14 13:39:24 +0000 | [diff] [blame] | 477 | cfg.cred_info[0].realm = pj_str("*"); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 478 | cfg.cred_info[0].scheme = pj_str("digest"); |
| 479 | cfg.cred_info[0].username = pj_str(SIP_USER); |
| 480 | cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; |
| 481 | cfg.cred_info[0].data = pj_str(SIP_PASSWD); |
| 482 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 483 | status = pjsua_acc_add(&cfg, PJ_TRUE, &g_acc_id); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 484 | if (status != PJ_SUCCESS) { |
| 485 | pjsua_perror(THIS_FILE, "Error adding account", status); |
| 486 | pjsua_destroy(); |
| 487 | return status; |
| 488 | } |
| 489 | } |
| 490 | |
Benny Prijono | b2c9682 | 2007-05-03 13:31:21 +0000 | [diff] [blame] | 491 | if (SIP_DST_URI) { |
| 492 | pjsua_buddy_config bcfg; |
| 493 | |
| 494 | pjsua_buddy_config_default(&bcfg); |
| 495 | bcfg.uri = pj_str(SIP_DST_URI); |
| 496 | bcfg.subscribe = PJ_FALSE; |
| 497 | |
| 498 | pjsua_buddy_add(&bcfg, &g_buddy_id); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 499 | } |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 500 | return PJ_SUCCESS; |
| 501 | } |
| 502 | |
| 503 | |
| 504 | //////////////////////////////////////////////////////////////////////////// |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 505 | /* |
| 506 | * The interractive console UI |
| 507 | */ |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 508 | #include <e32base.h> |
| 509 | |
| 510 | class ConsoleUI : public CActive |
| 511 | { |
| 512 | public: |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 513 | ConsoleUI(CConsoleBase *con); |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 514 | ~ConsoleUI(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 515 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 516 | // Run console UI |
| 517 | void Run(); |
| 518 | |
| 519 | // Stop |
| 520 | void Stop(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 521 | |
| 522 | protected: |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 523 | // Cancel asynchronous read. |
| 524 | void DoCancel(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 525 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 526 | // Implementation: called when read has completed. |
| 527 | void RunL(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 528 | |
| 529 | private: |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 530 | CConsoleBase *con_; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 531 | }; |
| 532 | |
| 533 | |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 534 | ConsoleUI::ConsoleUI(CConsoleBase *con) |
| 535 | : CActive(EPriorityStandard), con_(con) |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 536 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 537 | CActiveScheduler::Add(this); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 538 | } |
| 539 | |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 540 | ConsoleUI::~ConsoleUI() |
| 541 | { |
| 542 | Stop(); |
| 543 | } |
| 544 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 545 | // Run console UI |
| 546 | void ConsoleUI::Run() |
| 547 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 548 | con_->Read(iStatus); |
| 549 | SetActive(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | // Stop console UI |
| 553 | void ConsoleUI::Stop() |
| 554 | { |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 555 | Cancel(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | // Cancel asynchronous read. |
| 559 | void ConsoleUI::DoCancel() |
| 560 | { |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 561 | con_->ReadCancel(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 564 | static void PrintMainMenu() |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 565 | { |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 566 | const char *menu = |
| 567 | "\n\n" |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 568 | "Main Menu:\n" |
| 569 | " d Enable/disable codecs\n" |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 570 | " m Call " SIP_DST_URI "\n" |
| 571 | " a Answer call\n" |
| 572 | " g Hangup all calls\n" |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 573 | " t Toggle audio route\n" |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 574 | #if !defined(PJMEDIA_CONF_USE_SWITCH_BOARD) || PJMEDIA_CONF_USE_SWITCH_BOARD==0 |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 575 | " j Toggle loopback audio\n" |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 576 | #endif |
Nanang Izzuddin | 08694ea | 2009-03-10 15:03:04 +0000 | [diff] [blame] | 577 | "up/dn Increase/decrease output volume\n" |
Benny Prijono | 1f61a8f | 2007-08-16 10:11:44 +0000 | [diff] [blame] | 578 | " s Subscribe " SIP_DST_URI "\n" |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 579 | " S Unsubscribe presence\n" |
| 580 | " o Set account online\n" |
| 581 | " O Set account offline\n" |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 582 | " w Quit\n"; |
| 583 | |
| 584 | PJ_LOG(3, (THIS_FILE, menu)); |
Benny Prijono | 72a81aa | 2007-05-02 23:06:11 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 587 | static void PrintCodecMenu() |
| 588 | { |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 589 | const char *menu = |
| 590 | "\n\n" |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 591 | "Codec Menu:\n" |
| 592 | " a Enable all codecs\n" |
Nanang Izzuddin | a377597 | 2009-03-03 18:25:55 +0000 | [diff] [blame] | 593 | #if PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 594 | " d Enable only AMR\n" |
Nanang Izzuddin | a377597 | 2009-03-03 18:25:55 +0000 | [diff] [blame] | 595 | #endif |
| 596 | #if PJMEDIA_HAS_PASSTHROUGH_CODEC_G729 |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 597 | " g Enable only G.729\n" |
Nanang Izzuddin | a377597 | 2009-03-03 18:25:55 +0000 | [diff] [blame] | 598 | #endif |
| 599 | #if PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 600 | " j Enable only iLBC\n" |
| 601 | #endif |
| 602 | " m Enable only Speex\n" |
| 603 | " p Enable only GSM\n" |
| 604 | " t Enable only PCMU\n" |
Nanang Izzuddin | da37ea3 | 2009-03-06 16:24:43 +0000 | [diff] [blame] | 605 | " w Enable only PCMA\n"; |
| 606 | |
| 607 | PJ_LOG(3, (THIS_FILE, menu)); |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | static void HandleMainMenu(TKeyCode kc) { |
| 611 | switch (kc) { |
| 612 | |
Nanang Izzuddin | 08694ea | 2009-03-10 15:03:04 +0000 | [diff] [blame] | 613 | case EKeyUpArrow: |
| 614 | case EKeyDownArrow: |
| 615 | { |
| 616 | unsigned vol; |
| 617 | pj_status_t status; |
| 618 | |
| 619 | status = pjsua_snd_get_setting( |
| 620 | PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING, &vol); |
| 621 | if (status == PJ_SUCCESS) { |
| 622 | if (kc == EKeyUpArrow) |
| 623 | vol = PJ_MIN(100, vol+10); |
| 624 | else |
| 625 | vol = (vol>=10 ? vol-10 : 0); |
| 626 | status = pjsua_snd_set_setting( |
| 627 | PJMEDIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING, |
| 628 | &vol, PJ_TRUE); |
| 629 | } |
| 630 | |
| 631 | if (status == PJ_SUCCESS) { |
| 632 | PJ_LOG(3,(THIS_FILE, "Output volume set to %d", vol)); |
| 633 | } else { |
| 634 | pjsua_perror(THIS_FILE, "Error setting volume", status); |
| 635 | } |
| 636 | } |
| 637 | break; |
| 638 | |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 639 | case 't': |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 640 | { |
Nanang Izzuddin | fcb92d0 | 2009-03-10 13:32:09 +0000 | [diff] [blame] | 641 | pjmedia_aud_dev_route route; |
| 642 | pj_status_t status; |
| 643 | |
| 644 | status = pjsua_snd_get_setting(PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE, |
| 645 | &route); |
| 646 | |
| 647 | if (status == PJ_SUCCESS) { |
| 648 | if (route == PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER) |
| 649 | route = PJMEDIA_AUD_DEV_ROUTE_EARPIECE; |
| 650 | else |
| 651 | route = PJMEDIA_AUD_DEV_ROUTE_LOUDSPEAKER; |
Nanang Izzuddin | 452b66b | 2009-02-18 15:23:47 +0000 | [diff] [blame] | 652 | |
Nanang Izzuddin | fcb92d0 | 2009-03-10 13:32:09 +0000 | [diff] [blame] | 653 | status = pjsua_snd_set_setting( |
| 654 | PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE, |
| 655 | &route, PJ_TRUE); |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 656 | } |
Nanang Izzuddin | fcb92d0 | 2009-03-10 13:32:09 +0000 | [diff] [blame] | 657 | |
| 658 | if (status != PJ_SUCCESS) |
| 659 | pjsua_perror(THIS_FILE, "Error switch audio route", status); |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 660 | } |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 661 | break; |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 662 | |
| 663 | case 'j': |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 664 | { |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 665 | static pj_bool_t loopback_active = PJ_FALSE; |
| 666 | if (!loopback_active) |
| 667 | pjsua_conf_connect(0, 0); |
| 668 | else |
| 669 | pjsua_conf_disconnect(0, 0); |
| 670 | loopback_active = !loopback_active; |
Nanang Izzuddin | 0cb3b02 | 2009-02-27 17:37:35 +0000 | [diff] [blame] | 671 | } |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 672 | break; |
| 673 | |
| 674 | case 'm': |
| 675 | if (g_call_id != PJSUA_INVALID_ID) { |
| 676 | PJ_LOG(3,(THIS_FILE, "Another call is active")); |
| 677 | break; |
| 678 | } |
| 679 | |
| 680 | if (pjsua_verify_sip_url(SIP_DST_URI) == PJ_SUCCESS) { |
| 681 | pj_str_t dst = pj_str(SIP_DST_URI); |
| 682 | pjsua_call_make_call(g_acc_id, &dst, 0, NULL, |
| 683 | NULL, &g_call_id); |
| 684 | } else { |
| 685 | PJ_LOG(3,(THIS_FILE, "Invalid SIP URI")); |
| 686 | } |
| 687 | break; |
| 688 | case 'a': |
| 689 | if (g_call_id != PJSUA_INVALID_ID) |
| 690 | pjsua_call_answer(g_call_id, 200, NULL, NULL); |
| 691 | break; |
| 692 | case 'g': |
| 693 | pjsua_call_hangup_all(); |
| 694 | break; |
| 695 | case 's': |
| 696 | case 'S': |
| 697 | if (g_buddy_id != PJSUA_INVALID_ID) |
| 698 | pjsua_buddy_subscribe_pres(g_buddy_id, kc=='s'); |
| 699 | break; |
| 700 | case 'o': |
| 701 | case 'O': |
| 702 | pjsua_acc_set_online_status(g_acc_id, kc=='o'); |
| 703 | break; |
| 704 | |
| 705 | default: |
| 706 | PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", kc, kc)); |
| 707 | break; |
| 708 | } |
| 709 | |
| 710 | PrintMainMenu(); |
| 711 | } |
| 712 | |
| 713 | static void HandleCodecMenu(TKeyCode kc) { |
| 714 | const pj_str_t ID_ALL = {"*", 1}; |
| 715 | pj_str_t codec = {NULL, 0}; |
| 716 | |
| 717 | if (kc == 'a') { |
| 718 | pjsua_codec_set_priority(&ID_ALL, PJMEDIA_CODEC_PRIO_NORMAL); |
| 719 | PJ_LOG(3,(THIS_FILE, "All codecs activated")); |
| 720 | } else { |
| 721 | switch (kc) { |
| 722 | case 'd': |
| 723 | codec = pj_str("AMR"); |
| 724 | break; |
| 725 | case 'g': |
| 726 | codec = pj_str("G729"); |
| 727 | break; |
| 728 | case 'j': |
| 729 | codec = pj_str("ILBC"); |
| 730 | break; |
| 731 | case 'm': |
| 732 | codec = pj_str("SPEEX/8000"); |
| 733 | break; |
| 734 | case 'p': |
| 735 | codec = pj_str("GSM"); |
| 736 | break; |
| 737 | case 't': |
| 738 | codec = pj_str("PCMU"); |
| 739 | break; |
| 740 | case 'w': |
| 741 | codec = pj_str("PCMA"); |
| 742 | break; |
| 743 | default: |
| 744 | PJ_LOG(3,(THIS_FILE, "Keycode '%c' (%d) is pressed", kc, kc)); |
| 745 | break; |
| 746 | } |
| 747 | |
| 748 | if (codec.slen) { |
| 749 | pj_status_t status; |
| 750 | |
| 751 | pjsua_codec_set_priority(&ID_ALL, PJMEDIA_CODEC_PRIO_DISABLED); |
| 752 | |
| 753 | status = pjsua_codec_set_priority(&codec, |
| 754 | PJMEDIA_CODEC_PRIO_NORMAL); |
| 755 | if (status == PJ_SUCCESS) |
| 756 | PJ_LOG(3,(THIS_FILE, "%s activated", codec.ptr)); |
| 757 | else |
| 758 | PJ_LOG(3,(THIS_FILE, "Failed activating %s, err=%d", |
| 759 | codec.ptr, status)); |
| 760 | } |
| 761 | } |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | // Implementation: called when read has completed. |
| 765 | void ConsoleUI::RunL() |
| 766 | { |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 767 | enum { |
| 768 | MENU_TYPE_MAIN = 0, |
| 769 | MENU_TYPE_CODEC = 1 |
| 770 | }; |
| 771 | static int menu_type = MENU_TYPE_MAIN; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 772 | TKeyCode kc = con_->KeyCode(); |
| 773 | pj_bool_t reschedule = PJ_TRUE; |
| 774 | |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 775 | if (menu_type == MENU_TYPE_MAIN) { |
| 776 | if (kc == 'w') { |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 777 | CActiveScheduler::Stop(); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 778 | reschedule = PJ_FALSE; |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 779 | } else if (kc == 'd') { |
| 780 | menu_type = MENU_TYPE_CODEC; |
| 781 | PrintCodecMenu(); |
| 782 | } else { |
| 783 | HandleMainMenu(kc); |
| 784 | } |
| 785 | } else { |
| 786 | HandleCodecMenu(kc); |
| 787 | |
| 788 | menu_type = MENU_TYPE_MAIN; |
| 789 | PrintMainMenu(); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 790 | } |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 791 | |
| 792 | if (reschedule) |
| 793 | Run(); |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 796 | #if 0 |
| 797 | // IP networking related testing |
| 798 | static pj_status_t test_addr(void) |
| 799 | { |
| 800 | int af; |
| 801 | unsigned i, count; |
| 802 | pj_addrinfo ai[8]; |
| 803 | pj_sockaddr ifs[8]; |
| 804 | const pj_str_t *hostname; |
| 805 | pj_hostent he; |
| 806 | pj_status_t status; |
| 807 | |
| 808 | pj_log_set_log_func(&log_writer); |
| 809 | |
| 810 | status = pj_init(); |
| 811 | if (status != PJ_SUCCESS) { |
| 812 | pjsua_perror(THIS_FILE, "pj_init() error", status); |
| 813 | return status; |
| 814 | } |
| 815 | |
| 816 | af = pj_AF_INET(); |
| 817 | |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 818 | #if 0 |
| 819 | pj_in_addr in_addr; |
| 820 | pj_str_t aa = pj_str("1.1.1.1"); |
| 821 | in_addr = pj_inet_addr(&aa); |
| 822 | char *the_addr = pj_inet_ntoa(in_addr); |
| 823 | PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr)); |
| 824 | |
| 825 | aa = pj_str("192.168.0.15"); |
| 826 | in_addr = pj_inet_addr(&aa); |
| 827 | the_addr = pj_inet_ntoa(in_addr); |
| 828 | PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr)); |
| 829 | |
| 830 | aa = pj_str("2.2.2.2"); |
| 831 | in_addr = pj_inet_addr(&aa); |
| 832 | the_addr = pj_inet_ntoa(in_addr); |
| 833 | PJ_LOG(3,(THIS_FILE, "IP addr=%s", the_addr)); |
| 834 | |
| 835 | return -1; |
| 836 | #endif |
| 837 | |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 838 | // Hostname |
| 839 | hostname = pj_gethostname(); |
| 840 | if (hostname == NULL) { |
| 841 | status = PJ_ERESOLVE; |
| 842 | pjsua_perror(THIS_FILE, "pj_gethostname() error", status); |
| 843 | goto on_return; |
| 844 | } |
| 845 | |
| 846 | PJ_LOG(3,(THIS_FILE, "Hostname: %.*s", hostname->slen, hostname->ptr)); |
| 847 | |
| 848 | // Gethostbyname |
| 849 | status = pj_gethostbyname(hostname, &he); |
| 850 | if (status != PJ_SUCCESS) { |
| 851 | pjsua_perror(THIS_FILE, "pj_gethostbyname() error", status); |
| 852 | } else { |
| 853 | PJ_LOG(3,(THIS_FILE, "gethostbyname: %s", |
| 854 | pj_inet_ntoa(*(pj_in_addr*)he.h_addr))); |
| 855 | } |
| 856 | |
| 857 | // Getaddrinfo |
| 858 | count = PJ_ARRAY_SIZE(ai); |
| 859 | status = pj_getaddrinfo(af, hostname, &count, ai); |
| 860 | if (status != PJ_SUCCESS) { |
| 861 | pjsua_perror(THIS_FILE, "pj_getaddrinfo() error", status); |
| 862 | } else { |
| 863 | for (i=0; i<count; ++i) { |
| 864 | char ipaddr[PJ_INET6_ADDRSTRLEN+2]; |
| 865 | PJ_LOG(3,(THIS_FILE, "Addrinfo: %s", |
| 866 | pj_sockaddr_print(&ai[i].ai_addr, ipaddr, sizeof(ipaddr), 2))); |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | // Enum interface |
| 871 | count = PJ_ARRAY_SIZE(ifs); |
| 872 | status = pj_enum_ip_interface(af, &count, ifs); |
| 873 | if (status != PJ_SUCCESS) { |
| 874 | pjsua_perror(THIS_FILE, "pj_enum_ip_interface() error", status); |
| 875 | } else { |
| 876 | for (i=0; i<count; ++i) { |
| 877 | char ipaddr[PJ_INET6_ADDRSTRLEN+2]; |
| 878 | PJ_LOG(3,(THIS_FILE, "Interface: %s", |
| 879 | pj_sockaddr_print(&ifs[i], ipaddr, sizeof(ipaddr), 2))); |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | // Get default iinterface |
| 884 | status = pj_getdefaultipinterface(af, &ifs[0]); |
| 885 | if (status != PJ_SUCCESS) { |
| 886 | pjsua_perror(THIS_FILE, "pj_getdefaultipinterface() error", status); |
| 887 | } else { |
| 888 | char ipaddr[PJ_INET6_ADDRSTRLEN+2]; |
| 889 | PJ_LOG(3,(THIS_FILE, "Default IP: %s", |
| 890 | pj_sockaddr_print(&ifs[0], ipaddr, sizeof(ipaddr), 2))); |
| 891 | } |
| 892 | |
| 893 | // Get default IP address |
| 894 | status = pj_gethostip(af, &ifs[0]); |
| 895 | if (status != PJ_SUCCESS) { |
| 896 | pjsua_perror(THIS_FILE, "pj_gethostip() error", status); |
| 897 | } else { |
| 898 | char ipaddr[PJ_INET6_ADDRSTRLEN+2]; |
| 899 | PJ_LOG(3,(THIS_FILE, "Host IP: %s", |
| 900 | pj_sockaddr_print(&ifs[0], ipaddr, sizeof(ipaddr), 2))); |
| 901 | } |
| 902 | |
| 903 | status = -1; |
| 904 | |
| 905 | on_return: |
| 906 | pj_shutdown(); |
| 907 | return status; |
| 908 | } |
| 909 | #endif |
| 910 | |
| 911 | |
Benny Prijono | 6b3ccdf | 2008-01-14 11:54:21 +0000 | [diff] [blame] | 912 | #include <es_sock.h> |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 913 | |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 914 | #if 0 |
| 915 | // Force network connection to use the first IAP, |
| 916 | // this is useful for debugging on emulator without GUI. |
| 917 | // Include commdb.lib & apengine.lib in symbian_ua.mmp file |
| 918 | // if this is enabled. |
| 919 | |
| 920 | #include <apdatahandler.h> |
| 921 | |
| 922 | inline void ForceUseFirstIAP() |
| 923 | { |
| 924 | TUint32 rank = 1; |
| 925 | TUint32 bearers; |
| 926 | TUint32 prompt; |
| 927 | TUint32 iap; |
| 928 | |
| 929 | CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP); |
| 930 | CleanupStack::PushL(commDb); |
| 931 | |
| 932 | CApDataHandler* apDataHandler = CApDataHandler::NewLC(*commDb); |
| 933 | |
| 934 | TCommDbConnectionDirection direction = ECommDbConnectionDirectionOutgoing; |
| 935 | apDataHandler->GetPreferredIfDbIapTypeL(rank, direction, bearers, prompt, iap); |
| 936 | prompt = ECommDbDialogPrefDoNotPrompt; |
| 937 | apDataHandler->SetPreferredIfDbIapTypeL(rank, direction, bearers, (TCommDbDialogPref)prompt, iap, ETrue); |
| 938 | CleanupStack::PopAndDestroy(2); // apDataHandler, commDb |
| 939 | } |
| 940 | |
| 941 | static void SelectIAP() |
| 942 | { |
| 943 | ForceUseFirstIAP(); |
| 944 | } |
| 945 | |
| 946 | #else |
| 947 | |
| 948 | static void SelectIAP() |
| 949 | { |
| 950 | } |
| 951 | |
| 952 | #endif |
| 953 | |
| 954 | |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 955 | // Class CConnMon to monitor network connection (RConnection). Whenever |
| 956 | // the connection is down, it will notify PJLIB and restart PJSUA-LIB. |
| 957 | class CConnMon : public CActive { |
| 958 | public: |
| 959 | static CConnMon* NewL(RConnection &conn, RSocketServ &sserver) { |
| 960 | CConnMon *self = new (ELeave) CConnMon(conn, sserver); |
| 961 | CleanupStack::PushL(self); |
| 962 | self->ConstructL(); |
| 963 | CleanupStack::Pop(self); |
| 964 | return self; |
| 965 | } |
| 966 | |
| 967 | void Start() { |
| 968 | conn_.ProgressNotification(nif_progress_, iStatus); |
| 969 | SetActive(); |
| 970 | } |
| 971 | |
| 972 | void Stop() { |
| 973 | Cancel(); |
| 974 | } |
| 975 | |
| 976 | ~CConnMon() { Stop(); } |
| 977 | |
| 978 | private: |
| 979 | CConnMon(RConnection &conn, RSocketServ &sserver) : |
| 980 | CActive(EPriorityHigh), |
| 981 | conn_(conn), |
| 982 | sserver_(sserver) |
| 983 | { |
| 984 | CActiveScheduler::Add(this); |
| 985 | } |
| 986 | |
| 987 | void ConstructL() {} |
| 988 | |
| 989 | void DoCancel() { |
| 990 | conn_.CancelProgressNotification(); |
| 991 | } |
| 992 | |
| 993 | void RunL() { |
| 994 | int stage = nif_progress_().iStage; |
| 995 | |
| 996 | if (stage == KLinkLayerClosed) { |
| 997 | pj_status_t status; |
| 998 | TInt err; |
| 999 | |
| 1000 | // Tell pjlib that connection is down. |
| 1001 | pj_symbianos_set_connection_status(PJ_FALSE); |
| 1002 | |
| 1003 | PJ_LOG(3, (THIS_FILE, "RConnection closed, restarting PJSUA..")); |
| 1004 | |
| 1005 | // Destroy pjsua |
| 1006 | pjsua_destroy(); |
| 1007 | PJ_LOG(3, (THIS_FILE, "PJSUA destroyed.")); |
| 1008 | |
| 1009 | // Reopen the connection |
| 1010 | err = conn_.Open(sserver_); |
| 1011 | if (err == KErrNone) |
| 1012 | err = conn_.Start(); |
| 1013 | if (err != KErrNone) { |
| 1014 | CActiveScheduler::Stop(); |
| 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | // Reinit Symbian OS param before pj_init() |
| 1019 | pj_symbianos_params sym_params; |
| 1020 | pj_bzero(&sym_params, sizeof(sym_params)); |
| 1021 | sym_params.rsocketserv = &sserver_; |
| 1022 | sym_params.rconnection = &conn_; |
| 1023 | pj_symbianos_set_params(&sym_params); |
| 1024 | |
| 1025 | // Reinit pjsua |
| 1026 | status = app_startup(); |
| 1027 | if (status != PJ_SUCCESS) { |
| 1028 | pjsua_perror(THIS_FILE, "app_startup() error", status); |
| 1029 | CActiveScheduler::Stop(); |
| 1030 | return; |
| 1031 | } |
| 1032 | |
| 1033 | PJ_LOG(3, (THIS_FILE, "PJSUA restarted.")); |
Benny Prijono | 9920dc3 | 2009-03-12 18:11:37 +0000 | [diff] [blame] | 1034 | PrintMainMenu(); |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | Start(); |
| 1038 | } |
| 1039 | |
| 1040 | RConnection& conn_; |
| 1041 | RSocketServ& sserver_; |
| 1042 | TNifProgressBuf nif_progress_; |
| 1043 | }; |
| 1044 | |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 1045 | //////////////////////////////////////////////////////////////////////////// |
| 1046 | int ua_main() |
| 1047 | { |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1048 | RSocketServ aSocketServer; |
| 1049 | RConnection aConn; |
| 1050 | TInt err; |
| 1051 | pj_symbianos_params sym_params; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1052 | pj_status_t status; |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1053 | |
| 1054 | SelectIAP(); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1055 | |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 1056 | // Initialize RSocketServ |
| 1057 | if ((err=aSocketServer.Connect()) != KErrNone) |
| 1058 | return PJ_STATUS_FROM_OS(err); |
| 1059 | |
| 1060 | // Open up a connection |
| 1061 | if ((err=aConn.Open(aSocketServer)) != KErrNone) { |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1062 | aSocketServer.Close(); |
| 1063 | return PJ_STATUS_FROM_OS(err); |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | if ((err=aConn.Start()) != KErrNone) { |
| 1067 | aSocketServer.Close(); |
| 1068 | return PJ_STATUS_FROM_OS(err); |
| 1069 | } |
| 1070 | |
| 1071 | // Set Symbian OS parameters in pjlib. |
| 1072 | // This must be done before pj_init() is called. |
| 1073 | pj_bzero(&sym_params, sizeof(sym_params)); |
| 1074 | sym_params.rsocketserv = &aSocketServer; |
| 1075 | sym_params.rconnection = &aConn; |
| 1076 | pj_symbianos_set_params(&sym_params); |
| 1077 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1078 | // Initialize pjsua |
| 1079 | status = app_startup(); |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 1080 | //status = test_addr(); |
| 1081 | if (status != PJ_SUCCESS) { |
| 1082 | aConn.Close(); |
| 1083 | aSocketServer.Close(); |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1084 | return status; |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 1085 | } |
Benny Prijono | 897f9f8 | 2007-05-03 19:56:21 +0000 | [diff] [blame] | 1086 | |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 1087 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1088 | // Run the UI |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1089 | ConsoleUI *con = new ConsoleUI(console); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1090 | |
| 1091 | con->Run(); |
Nanang Izzuddin | 798bf45 | 2009-02-12 12:35:27 +0000 | [diff] [blame] | 1092 | PrintMainMenu(); |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1093 | |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 1094 | // Init & start connection monitor |
| 1095 | CConnMon *connmon = CConnMon::NewL(aConn, aSocketServer); |
| 1096 | connmon->Start(); |
| 1097 | |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1098 | CActiveScheduler::Start(); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1099 | |
Nanang Izzuddin | 90b8320 | 2009-03-02 15:48:45 +0000 | [diff] [blame] | 1100 | delete connmon; |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1101 | delete con; |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 1102 | |
| 1103 | // Dump memory statistics |
| 1104 | PJ_LOG(3,(THIS_FILE, "Max heap usage: %u.%03uMB", |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1105 | pjsua_var.cp.peak_used_size / 1000000, |
| 1106 | (pjsua_var.cp.peak_used_size % 1000000)/1000)); |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1107 | |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 1108 | // check max stack usage |
| 1109 | #if defined(PJ_OS_HAS_CHECK_STACK) && PJ_OS_HAS_CHECK_STACK!=0 |
| 1110 | pj_thread_t* this_thread = pj_thread_this(); |
| 1111 | if (!this_thread) |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1112 | return status; |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 1113 | |
| 1114 | const char* max_stack_file; |
| 1115 | int max_stack_line; |
| 1116 | status = pj_thread_get_stack_info(this_thread, &max_stack_file, &max_stack_line); |
| 1117 | |
| 1118 | PJ_LOG(3,(THIS_FILE, "Max stack usage: %u at %s:%d", |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1119 | pj_thread_get_stack_max_usage(this_thread), |
| 1120 | max_stack_file, max_stack_line)); |
Benny Prijono | 684c0ad | 2008-01-03 18:50:27 +0000 | [diff] [blame] | 1121 | #endif |
| 1122 | |
Benny Prijono | c71ad43 | 2007-05-04 07:25:19 +0000 | [diff] [blame] | 1123 | // Shutdown pjsua |
| 1124 | pjsua_destroy(); |
| 1125 | |
Benny Prijono | 70c5ba0 | 2007-12-31 11:27:35 +0000 | [diff] [blame] | 1126 | // Close connection and socket server |
| 1127 | aConn.Close(); |
Nanang Izzuddin | 82f7a41 | 2008-12-17 11:36:22 +0000 | [diff] [blame] | 1128 | aSocketServer.Close(); |
Nanang Izzuddin | a940b36 | 2009-02-23 13:53:30 +0000 | [diff] [blame] | 1129 | |
Benny Prijono | 797e338 | 2007-12-01 09:10:07 +0000 | [diff] [blame] | 1130 | return status; |
Benny Prijono | ba5926a | 2007-05-02 11:29:37 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |