~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/pjsip-apps/src/symbian_ua/ua.cpp

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: ua.cpp 3999 2012-03-30 07:10:13Z bennylp $ */
2
 
/*
3
 
 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
 
 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 */
20
 
#include <pjsua-lib/pjsua.h>
21
 
#include <pjsua-lib/pjsua_internal.h>
22
 
//#include <pjmedia/symbian_sound_aps.h>
23
 
#include "ua.h"
24
 
 
25
 
#define THIS_FILE       "symbian_ua.cpp"
26
 
#define CON_LOG_LEVEL   3 // console log level
27
 
#define FILE_LOG_LEVEL  4 // logfile log level
28
 
 
29
 
//
30
 
// Basic config.
31
 
//
32
 
#define SIP_PORT        5060
33
 
 
34
 
 
35
 
//
36
 
// Destination URI (to make call, or to subscribe presence)
37
 
//
38
 
#define SIP_DST_URI     "<sip:100@pjsip.lab>"
39
 
 
40
 
//
41
 
// Account
42
 
//
43
 
#define HAS_SIP_ACCOUNT 0       // 1 to enable registration
44
 
#define SIP_DOMAIN      "pjsip.lab"
45
 
#define SIP_USER        "400"
46
 
#define SIP_PASSWD      "400"
47
 
 
48
 
//
49
 
// Outbound proxy for all accounts
50
 
//
51
 
#define SIP_PROXY       NULL
52
 
//#define SIP_PROXY     "<sip:192.168.0.8;lr>"
53
 
 
54
 
//
55
 
// SIP transports
56
 
//
57
 
#define ENABLE_SIP_UDP  1
58
 
#define ENABLE_SIP_TCP  0 // experimental
59
 
#define ENABLE_SIP_TLS  0 // experimental
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
 
//
65
 
#define NAMESERVER      NULL
66
 
//#define NAMESERVER    "192.168.0.2"
67
 
 
68
 
//
69
 
// STUN server
70
 
#if 0
71
 
        // Use this to have the STUN server resolved normally
72
 
#   define STUN_DOMAIN  NULL
73
 
#   define STUN_SERVER  "stun.pjsip.org"
74
 
#elif 0
75
 
        // Use this to have the STUN server resolved with DNS SRV
76
 
#   define STUN_DOMAIN  "pjsip.org"
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
 
//
87
 
#define USE_ICE         1
88
 
 
89
 
//
90
 
// Use SRTP?
91
 
//
92
 
#define USE_SRTP        PJSUA_DEFAULT_USE_SRTP
93
 
 
94
 
//
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
 
//
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;
110
 
 
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
 
 
121
 
    if (g_call_id != PJSUA_INVALID_ID) {
122
 
        pjsua_call_answer(call_id, PJSIP_SC_BUSY_HERE, NULL, NULL);
123
 
        return;
124
 
    }
125
 
 
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
 
 
132
 
    g_call_id = call_id;
133
 
 
134
 
    /* Automatically answer incoming calls with 180/Ringing */
135
 
    pjsua_call_answer(call_id, 180, NULL, NULL);
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);
146
 
 
147
 
    if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
148
 
        if (call_id == g_call_id)
149
 
            g_call_id = PJSUA_INVALID_ID;
150
 
    } else if (ci.state != PJSIP_INV_STATE_INCOMING) {
151
 
        if (g_call_id == PJSUA_INVALID_ID)
152
 
            g_call_id = call_id;
153
 
    }
154
 
 
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
 
 
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
 
 
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
 
 
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
 
 
270
 
/*
271
 
 * Transport status notification
272
 
 */
273
 
static void on_transport_state(pjsip_transport *tp,
274
 
                               pjsip_transport_state state,
275
 
                               const pjsip_transport_state_info *info)
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
 
 
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;
291
 
 
292
 
    case PJSIP_TP_STATE_DISCONNECTED:
293
 
        {
294
 
            char buf[100];
295
 
 
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;
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 &&
309
 
        state == PJSIP_TP_STATE_CONNECTED)
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
323
 
}
324
 
 
325
 
 
326
 
//#include<e32debug.h>
327
 
 
328
 
/* Logging callback */
329
 
static void log_writer(int level, const char *buf, int len)
330
 
{
331
 
    static wchar_t buf16[PJ_LOG_MAX_SIZE];
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);
338
 
    //RDebug::Print(aBuf);
339
 
    console->Write(aBuf);
340
 
 
341
 
}
342
 
 
343
 
/*
344
 
 * app_startup()
345
 
 *
346
 
 * url may contain URL to call.
347
 
 */
348
 
static pj_status_t app_startup()
349
 
{
350
 
    pj_status_t status;
351
 
 
352
 
    /* Redirect log before pjsua_init() */
353
 
    pj_log_set_log_func(&log_writer);
354
 
 
355
 
    /* Set log level */
356
 
    pj_log_set_level(CON_LOG_LEVEL);
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
 
 
365
 
    /* Init pjsua */
366
 
    pjsua_config cfg;
367
 
    pjsua_logging_config log_cfg;
368
 
    pjsua_media_config med_cfg;
369
 
 
370
 
    pjsua_config_default(&cfg);
371
 
    cfg.max_calls = 2;
372
 
    cfg.thread_cnt = 0; // Disable threading on Symbian
373
 
    cfg.use_srtp = USE_SRTP;
374
 
    cfg.srtp_secure_signaling = 0;
375
 
 
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;
384
 
    cfg.cb.on_nat_detect = &on_nat_detect;
385
 
    cfg.cb.on_transport_state = &on_transport_state;
386
 
 
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);
405
 
    log_cfg.level = FILE_LOG_LEVEL;
406
 
    log_cfg.console_level = CON_LOG_LEVEL;
407
 
    log_cfg.cb = &log_writer;
408
 
    log_cfg.log_filename = pj_str("C:\\data\\symbian_ua.log");
409
 
 
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;
414
 
    med_cfg.audio_frame_ptime = 40;
415
 
    med_cfg.ec_tail_len = 0;
416
 
    med_cfg.enable_ice = USE_ICE;
417
 
    med_cfg.snd_auto_close_time = 0; // wait for 0 seconds idle before sound dev get auto-closed
418
 
    //med_cfg.no_vad = PJ_TRUE;
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;
425
 
    }
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);
433
 
 
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
 
    }
444
 
 
445
 
 
446
 
    pjsua_transport_config tcfg;
447
 
    pjsua_transport_id tid;
448
 
 
449
 
#if ENABLE_SIP_UDP
450
 
    /* Add UDP transport. */
451
 
    pjsua_transport_config_default(&tcfg);
452
 
    tcfg.port = SIP_PORT;
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
 
    }
457
 
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tcfg, &tid);
458
 
    if (status != PJ_SUCCESS) {
459
 
            pjsua_perror(THIS_FILE, "Error creating UDP transport", status);
460
 
            pjsua_destroy();
461
 
            return status;
462
 
    }
463
 
#endif
464
 
 
465
 
#if ENABLE_SIP_TCP
466
 
    /* Add TCP transport */
467
 
    pjsua_transport_config_default(&tcfg);
468
 
    tcfg.port = SIP_PORT;
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
 
    }
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
 
 
481
 
#if ENABLE_SIP_TLS
482
 
    /* Add TLS transport */
483
 
    pjsua_transport_config_default(&tcfg);
484
 
    tcfg.port = SIP_PORT + 1;
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
 
    }
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
 
 
498
 
    /* Add account for the transport */
499
 
    pjsua_acc_add_local(tid, PJ_TRUE, &g_acc_id);
500
 
 
501
 
#if DISABLED_FOR_TICKET_1185
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
 
    }
513
 
#endif
514
 
 
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. */
524
 
    if (HAS_SIP_ACCOUNT) {
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;
531
 
        cfg.cred_info[0].realm = pj_str("*");
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
 
 
537
 
        status = pjsua_acc_add(&cfg, PJ_TRUE, &g_acc_id);
538
 
        if (status != PJ_SUCCESS) {
539
 
                pjsua_perror(THIS_FILE, "Error adding account", status);
540
 
                pjsua_destroy();
541
 
                return status;
542
 
        }
543
 
    }
544
 
 
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);
553
 
    }
554
 
    return PJ_SUCCESS;
555
 
}
556
 
 
557
 
 
558
 
////////////////////////////////////////////////////////////////////////////
559
 
/*
560
 
 * The interractive console UI
561
 
 */
562
 
#include <e32base.h>
563
 
 
564
 
class ConsoleUI : public CActive
565
 
{
566
 
public:
567
 
    ConsoleUI(CConsoleBase *con);
568
 
    ~ConsoleUI();
569
 
 
570
 
    // Run console UI
571
 
    void Run();
572
 
 
573
 
    // Stop
574
 
    void Stop();
575
 
 
576
 
protected:
577
 
    // Cancel asynchronous read.
578
 
    void DoCancel();
579
 
 
580
 
    // Implementation: called when read has completed.
581
 
    void RunL();
582
 
 
583
 
private:
584
 
    CConsoleBase *con_;
585
 
};
586
 
 
587
 
 
588
 
ConsoleUI::ConsoleUI(CConsoleBase *con)
589
 
: CActive(EPriorityStandard), con_(con)
590
 
{
591
 
    CActiveScheduler::Add(this);
592
 
}
593
 
 
594
 
ConsoleUI::~ConsoleUI()
595
 
{
596
 
    Stop();
597
 
}
598
 
 
599
 
// Run console UI
600
 
void ConsoleUI::Run()
601
 
{
602
 
    con_->Read(iStatus);
603
 
    SetActive();
604
 
}
605
 
 
606
 
// Stop console UI
607
 
void ConsoleUI::Stop()
608
 
{
609
 
    Cancel();
610
 
}
611
 
 
612
 
// Cancel asynchronous read.
613
 
void ConsoleUI::DoCancel()
614
 
{
615
 
    con_->ReadCancel();
616
 
}
617
 
 
618
 
static void PrintMainMenu()
619
 
{
620
 
    const char *menu =
621
 
            "\n\n"
622
 
            "Main Menu:\n"
623
 
            "  d    Enable/disable codecs\n"
624
 
            "  m    Call " SIP_DST_URI "\n"
625
 
            "  a    Answer call\n"
626
 
            "  g    Hangup all calls\n"
627
 
            "  t    Toggle audio route\n"
628
 
#if !defined(PJMEDIA_CONF_USE_SWITCH_BOARD) || PJMEDIA_CONF_USE_SWITCH_BOARD==0
629
 
            "  j    Toggle loopback audio\n"
630
 
#endif
631
 
            "up/dn  Increase/decrease output volume\n"
632
 
            "  s    Subscribe " SIP_DST_URI "\n"
633
 
            "  S    Unsubscribe presence\n"
634
 
            "  o    Set account online\n"
635
 
            "  O    Set account offline\n"
636
 
            "  w    Quit\n";
637
 
 
638
 
    PJ_LOG(3, (THIS_FILE, menu));
639
 
}
640
 
 
641
 
static void PrintCodecMenu()
642
 
{
643
 
    const char *menu =
644
 
            "\n\n"
645
 
            "Codec Menu:\n"
646
 
            "  a    Enable all codecs\n"
647
 
#if PJMEDIA_HAS_PASSTHROUGH_CODECS && PJMEDIA_HAS_PASSTHROUGH_CODEC_AMR
648
 
            "  d    Enable only AMR\n"
649
 
#endif
650
 
#if PJMEDIA_HAS_PASSTHROUGH_CODECS && PJMEDIA_HAS_PASSTHROUGH_CODEC_G729
651
 
            "  g    Enable only G.729\n"
652
 
#endif
653
 
#if PJMEDIA_HAS_PASSTHROUGH_CODECS && PJMEDIA_HAS_PASSTHROUGH_CODEC_ILBC
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"
659
 
            "  w    Enable only PCMA\n";
660
 
 
661
 
    PJ_LOG(3, (THIS_FILE, menu));
662
 
}
663
 
 
664
 
static void HandleMainMenu(TKeyCode kc) {
665
 
    switch (kc) {
666
 
 
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
 
 
693
 
    case 't':
694
 
        {
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;
706
 
 
707
 
                status = pjsua_snd_set_setting(
708
 
                                    PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE,
709
 
                                    &route, PJ_TRUE);
710
 
            }
711
 
 
712
 
            if (status != PJ_SUCCESS)
713
 
                pjsua_perror(THIS_FILE, "Error switch audio route", status);
714
 
        }
715
 
        break;
716
 
 
717
 
    case 'j':
718
 
        {
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;
725
 
        }
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
 
 
734
 
        if (pjsua_verify_url(SIP_DST_URI) == PJ_SUCCESS) {
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
 
    }
816
 
}
817
 
 
818
 
// Implementation: called when read has completed.
819
 
void ConsoleUI::RunL()
820
 
{
821
 
    enum {
822
 
        MENU_TYPE_MAIN = 0,
823
 
        MENU_TYPE_CODEC = 1
824
 
    };
825
 
    static int menu_type = MENU_TYPE_MAIN;
826
 
    TKeyCode kc = con_->KeyCode();
827
 
    pj_bool_t reschedule = PJ_TRUE;
828
 
 
829
 
    if (menu_type == MENU_TYPE_MAIN) {
830
 
        if (kc == 'w') {
831
 
            CActiveScheduler::Stop();
832
 
            reschedule = PJ_FALSE;
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();
844
 
    }
845
 
 
846
 
    if (reschedule)
847
 
        Run();
848
 
}
849
 
 
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
 
 
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
 
 
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
 
 
966
 
#include <es_sock.h>
967
 
 
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
 
 
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."));
1088
 
            PrintMainMenu();
1089
 
        }
1090
 
 
1091
 
        Start();
1092
 
    }
1093
 
 
1094
 
    RConnection& conn_;
1095
 
    RSocketServ& sserver_;
1096
 
    TNifProgressBuf nif_progress_;
1097
 
};
1098
 
 
1099
 
////////////////////////////////////////////////////////////////////////////
1100
 
int ua_main()
1101
 
{
1102
 
    RSocketServ aSocketServer;
1103
 
    RConnection aConn;
1104
 
    TInt err;
1105
 
    pj_symbianos_params sym_params;
1106
 
    pj_status_t status;
1107
 
 
1108
 
    SelectIAP();
1109
 
 
1110
 
    // Initialize RSocketServ
1111
 
    if ((err=aSocketServer.Connect(32)) != KErrNone)
1112
 
        return PJ_STATUS_FROM_OS(err);
1113
 
 
1114
 
    // Open up a connection
1115
 
    if ((err=aConn.Open(aSocketServer)) != KErrNone) {
1116
 
        aSocketServer.Close();
1117
 
        return PJ_STATUS_FROM_OS(err);
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
 
 
1132
 
    // Initialize pjsua
1133
 
    status  = app_startup();
1134
 
    //status = test_addr();
1135
 
    if (status != PJ_SUCCESS) {
1136
 
        aConn.Close();
1137
 
        aSocketServer.Close();
1138
 
        return status;
1139
 
    }
1140
 
 
1141
 
 
1142
 
    // Run the UI
1143
 
    ConsoleUI *con = new ConsoleUI(console);
1144
 
 
1145
 
    con->Run();
1146
 
    PrintMainMenu();
1147
 
 
1148
 
    // Init & start connection monitor
1149
 
    CConnMon *connmon = CConnMon::NewL(aConn, aSocketServer);
1150
 
    connmon->Start();
1151
 
 
1152
 
    CActiveScheduler::Start();
1153
 
 
1154
 
    delete connmon;
1155
 
    delete con;
1156
 
 
1157
 
    // Dump memory statistics
1158
 
    PJ_LOG(3,(THIS_FILE, "Max heap usage: %u.%03uMB",
1159
 
              pjsua_var.cp.peak_used_size / 1000000,
1160
 
              (pjsua_var.cp.peak_used_size % 1000000)/1000));
1161
 
 
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)
1166
 
            return status;
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",
1173
 
                  pj_thread_get_stack_max_usage(this_thread),
1174
 
                  max_stack_file, max_stack_line));
1175
 
#endif
1176
 
 
1177
 
    // Shutdown pjsua
1178
 
    pjsua_destroy();
1179
 
 
1180
 
    // Close connection and socket server
1181
 
    aConn.Close();
1182
 
    aSocketServer.Close();
1183
 
 
1184
 
    return status;
1185
 
}