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