Esempio n. 1
1
static BOOL OnInitStack (void)
{
    pjsua_config	    cfg;
    pjsua_logging_config    log_cfg;
    pjsua_media_config	    media_cfg;
    pjsua_transport_config  udp_cfg;
    pjsua_transport_config  rtp_cfg;
    pjsua_transport_id	    transport_id;
    pjsua_transport_info    transport_info;
    pj_str_t		    tmp;
    pj_status_t status;

    /* Create pjsua */
    status = pjsua_create();

    if (status != PJ_SUCCESS) {
        OnError (TEXT ("Error creating pjsua"), status);
        return FALSE;
    }

    /* Create global pool for application */
    g_pool = pjsua_pool_create ("pjsua", 4000, 4000);

    /* Init configs */
    pjsua_config_default (&cfg);
    pjsua_media_config_default (&media_cfg);
    pjsua_transport_config_default (&udp_cfg);
    udp_cfg.port = SIP_PORT;

    pjsua_transport_config_default (&rtp_cfg);
    rtp_cfg.port = 40000;

    pjsua_logging_config_default (&log_cfg);
    log_cfg.level = 5;
    log_cfg.log_filename = pj_str ("\\pjsua.txt");
    log_cfg.msg_logging = 1;
    log_cfg.decor = pj_log_get_decor() | PJ_LOG_HAS_CR;

    /* Setup media */
    media_cfg.clock_rate = 8000;
    media_cfg.ec_options = PJMEDIA_ECHO_SIMPLE;
    media_cfg.ec_tail_len = 256;
    // use default quality setting
    //media_cfg.quality = 1;
    media_cfg.ptime = 20;
    media_cfg.enable_ice = USE_ICE;

    /* Initialize application callbacks */
    cfg.cb.on_call_state = &on_call_state;
    cfg.cb.on_call_media_state = &on_call_media_state;
    cfg.cb.on_incoming_call = &on_incoming_call;
    cfg.cb.on_reg_state = &on_reg_state;
    cfg.cb.on_buddy_state = &on_buddy_state;
    cfg.cb.on_pager = &on_pager;
    cfg.cb.on_typing = &on_typing;
    cfg.cb.on_nat_detect = &nat_detect_cb;

    if (SIP_PROXY) {
        cfg.outbound_proxy_cnt = 1;
        cfg.outbound_proxy[0] = pj_str (SIP_PROXY);
    }

    if (NAMESERVER) {
        cfg.nameserver_count = 1;
        cfg.nameserver[0] = pj_str (NAMESERVER);
    }

    if (NAMESERVER && STUN_DOMAIN) {
        cfg.stun_domain = pj_str (STUN_DOMAIN);
    } else if (STUN_SERVER) {
        cfg.stun_host = pj_str (STUN_SERVER);
    }


    /* Initialize pjsua */
    status = pjsua_init (&cfg, &log_cfg, &media_cfg);

    if (status != PJ_SUCCESS) {
        OnError (TEXT ("Initialization error"), status);
        return FALSE;
    }

    /* Set codec priority */
    pjsua_codec_set_priority (pj_cstr (&tmp, "pcmu"), 240);
    pjsua_codec_set_priority (pj_cstr (&tmp, "pcma"), 230);
    pjsua_codec_set_priority (pj_cstr (&tmp, "speex/8000"), 190);
    pjsua_codec_set_priority (pj_cstr (&tmp, "ilbc"), 189);
    pjsua_codec_set_priority (pj_cstr (&tmp, "speex/16000"), 180);
    pjsua_codec_set_priority (pj_cstr (&tmp, "speex/32000"), 0);
    pjsua_codec_set_priority (pj_cstr (&tmp, "gsm"), 100);


    /* Add UDP transport and the corresponding PJSUA account */
    status = pjsua_transport_create (PJSIP_TRANSPORT_UDP,
                                     &udp_cfg, &transport_id);

    if (status != PJ_SUCCESS) {
        OnError (TEXT ("Error starting SIP transport"), status);
        return FALSE;
    }

    pjsua_transport_get_info (transport_id, &transport_info);

    g_local_uri.ptr = (char*) pj_pool_alloc (g_pool, 128);
    g_local_uri.slen = pj_ansi_sprintf (g_local_uri.ptr,
                                        "<sip:%.*s:%d>",
                                        (int) transport_info.local_name.host.slen,
                                        transport_info.local_name.host.ptr,
                                        transport_info.local_name.port);


    /* Add local account */
    pjsua_acc_add_local (transport_id, PJ_TRUE, &g_current_acc);
    pjsua_acc_set_online_status (g_current_acc, PJ_TRUE);

    /* Add account */
    if (HAS_SIP_ACCOUNT) {
        pjsua_acc_config cfg;

        pjsua_acc_config_default (&cfg);
        cfg.id = pj_str ("sip:" SIP_USER "@" SIP_DOMAIN);
        cfg.reg_uri = pj_str ("sip:" SIP_DOMAIN);
        cfg.cred_count = 1;
        cfg.cred_info[0].realm = pj_str (SIP_REALM);
        cfg.cred_info[0].scheme = pj_str ("digest");
        cfg.cred_info[0].username = pj_str (SIP_USER);
        cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
        cfg.cred_info[0].data = pj_str (SIP_PASSWD);

        status = pjsua_acc_add (&cfg, PJ_TRUE, &g_current_acc);

        if (status != PJ_SUCCESS) {
            pjsua_destroy();
            return PJ_FALSE;
        }
    }

    /* Add buddy */
    if (SIP_DST_URI) {
        pjsua_buddy_config bcfg;

        pjsua_buddy_config_default (&bcfg);
        bcfg.uri = pj_str (SIP_DST_URI);
        bcfg.subscribe = PJ_FALSE;

        pjsua_buddy_add (&bcfg, NULL);
    }

    /* Start pjsua */
    status = pjsua_start();

    if (status != PJ_SUCCESS) {
        OnError (TEXT ("Error starting pjsua"), status);
        return FALSE;
    }

    return TRUE;
}
Esempio n. 2
0
static void ui_toggle_state()
{
    pjsua_acc_info acc_info;

    pjsua_acc_get_info(current_acc, &acc_info);
    acc_info.online_status = !acc_info.online_status;
    pjsua_acc_set_online_status(current_acc, acc_info.online_status);
    printf("Setting %s online status to %s\n",
	   acc_info.acc_uri.ptr,
	   (acc_info.online_status?"online":"offline"));
}
Esempio n. 3
0
//----------------------------------------------------------------------
void SipPhone::init()
{
    pj_status_t status;
    /* Create pjsua first! */
    status = pjsua_create();

    if (status != PJ_SUCCESS)
    {
        LogInfo info(LogInfo::STATUS_FATAL_ERROR, "pjsip", status, "Error in pjsua_create()");
        signalLogData(info);
        return;
    }

    /* Init pjsua */
    {
        pjsua_config cfg;
        pjsua_logging_config log_cfg;
        ConfigFileHandler &config = ConfigFileHandler::getInstance();
        QString stun = config.getStunServer();
        pjsua_config_default(&cfg);

        if (stun.size())
        {
            char ch_stun[100];
            if (stun.size() > 99)
            {
                LogInfo info(LogInfo::STATUS_ERROR, "pjsip", 0, "Error init pjsip, stun-server too long");
                signalLogData(info);
                return;
            }

            strcpy(ch_stun, stun.toLocal8Bit().data());
            ch_stun[stun.size()] = 0;

            cfg.stun_srv[cfg.stun_srv_cnt++] = pj_str(ch_stun);
        }
        cfg.enable_unsolicited_mwi = PJ_FALSE;
        cfg.cb.on_incoming_call = &incomingCallCb;
        cfg.cb.on_call_state = &callStateCb;
        cfg.cb.on_call_media_state = &callMediaStateCb;
        cfg.cb.on_reg_state = &regStateCb;

        pjsua_logging_config_default(&log_cfg);
        log_cfg.console_level = 4;

        status = pjsua_init(&cfg, &log_cfg, NULL);
        printf("init successfull\n");
        if (status != PJ_SUCCESS)
        {
            LogInfo info(LogInfo::STATUS_FATAL_ERROR, "pjsip", status, "Error in pjsua_init()");
            signalLogData(info);
            return;
        }
    }

    /* Add UDP transport. */
    {
        pjsua_transport_config cfg;
        pjsua_acc_id aid;
        pjsua_transport_id transport_id = -1;
        pjsua_transport_config tcp_cfg;

        pjsua_transport_config_default(&cfg);
        cfg.port = 5060;

        status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, &transport_id);

        if (status != PJ_SUCCESS)
        {
            LogInfo info(LogInfo::STATUS_FATAL_ERROR, "pjsip", status, "Error creating transport");
            signalLogData(info);
            return;
        }

        /* Add local account */
        pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
        pjsua_acc_set_online_status(aid, PJ_TRUE);

        if (cfg.port == 0)
        {
            pjsua_transport_info ti;
            pj_sockaddr_in *a;

            pjsua_transport_get_info(transport_id, &ti);
            a = (pj_sockaddr_in*)&ti.local_addr;

            tcp_cfg.port = pj_ntohs(a->sin_port);
        }

    }
    /* Initialization is done, now start pjsua */
    status = pjsua_start();

    if (status != PJ_SUCCESS)
    {
        LogInfo info(LogInfo::STATUS_FATAL_ERROR, "pjsip", status, "Error starting PJSUA");
        signalLogData(info);
        return;
    }
    pjsua_conf_adjust_rx_level(0, 1.f);
    pjsua_conf_adjust_tx_level(0, 1.f);
    speaker_level_ = 1.f;
    mic_level_ = 1.f;
}