Beispiel #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;
}
Beispiel #2
0
void PjsuaManager::SetCodecPriority(const char* codec, int value)
{
	pj_str_t tmpstr;
	pjsua_codec_set_priority(pj_cstr(&tmpstr, codec), value);
}
Beispiel #3
0
// REITEK: Added insecure and secure SIP ports
PjsuaManager::PjsuaManager(const std::string& executionPath, bool enableIce,
	const std::string& stunServer, const int& sipPort, const int& sipTlsPort)
{
	pj_status_t status;
	pjsua_config cfg;
	pjsua_logging_config log_cfg;
	pjsua_media_config media_cfg;
	pjsua_transport_config tran_cfg, tls_tran_cfg;

	pjsua_transport_config_default(&tran_cfg);
	pjsua_transport_config_default(&tls_tran_cfg);
	pjsua_media_config_default(&media_cfg);
	pjsua_config_default(&cfg);
	pjsua_logging_config_default(&log_cfg);

	//cfg.max_calls = 511;
	cfg.max_calls = 2;

	cfg.cb.on_incoming_call = &PjsuaManager::OnIncomingCall;
	cfg.cb.on_call_media_state = &PjsuaManager::OnCallMediaState;
	cfg.cb.on_call_state = &PjsuaManager::OnCallState;
	cfg.cb.on_reg_state = &PjsuaManager::OnRegState;
	cfg.cb.on_transport_state = &PjsuaManager::OnTransportState;
	cfg.cb.on_call_transfer_status = &PjsuaManager::OnCallTransferStatus;
	cfg.cb.on_call_tsx_state = &PjsuaManager::OnCallTsxState;

	log_cfg.level = 4;
	log_cfg.console_level = 4;
	// REITEK: Log messages!
	log_cfg.msg_logging = PJ_TRUE;
	log_cfg.decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_SPACE | PJ_LOG_HAS_LEVEL_TEXT;
	log_cfg.cb = BlabbleLogging::blabbleLog;

	// REITEK: !!! CHECK: Make TLS port configurable ?
	tls_tran_cfg.port = 0;
	//tran_cfg.tls_setting.verify_server = PJ_TRUE;
	tls_tran_cfg.tls_setting.timeout.sec = 5;
	tls_tran_cfg.tls_setting.method = PJSIP_TLSV1_METHOD;

	tran_cfg.port = sipPort;

	// REITEK: !!! CHECK: Make port range configurable ?
	tran_cfg.port_range = 200;

	media_cfg.no_vad = 1;
	media_cfg.enable_ice = enableIce ? PJ_TRUE : PJ_FALSE;

	// REITEK: Disable EC
	media_cfg.ec_tail_len = 0;

	if (!stunServer.empty()) 
	{
		cfg.stun_srv_cnt = 1;
		cfg.stun_srv[0] = pj_str(const_cast<char*>(stunServer.c_str()));
	}

	// REITEK: User-Agent header handling
	cfg.user_agent = pj_str("Reitek PluginSIP");

	status = pjsua_create();
	if (status != PJ_SUCCESS)
		throw std::runtime_error("pjsua_create failed");

	status = pjsua_init(&cfg, &log_cfg, &media_cfg);
	if (status != PJ_SUCCESS) 
		throw std::runtime_error("Error in pjsua_init()");

	try
	{
		status = pjsua_transport_create(PJSIP_TRANSPORT_TLS, &tls_tran_cfg, &this->tls_transport);
		has_tls_ = status == PJ_SUCCESS;
		if (!has_tls_) {
			BLABBLE_LOG_DEBUG("Error in tls pjsua_transport_create. Tls will not be enabled");
			this->tls_transport = -1;
		}

		status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tran_cfg, &this->udp_transport);
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Error in pjsua_transport_create for UDP transport");

		status = pjsua_start();
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Error in pjsua_start()");

		// REITEK: Codecs priority handling
		pj_str_t tmpstr;

		// !!! FIXME: Hardwired now in order to test G. 729
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "*"), 0);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "g729"), 255);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "pcmu"), 240);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "pcma"), 230);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/8000"), 190);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "ilbc"), 189);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/16000"), 180);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/32000"), 0);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "gsm"), 100);

#if 0
		// REITEK: G.729 codec handling
		pjmedia_codec_param g729_param;

		status = pjsua_codec_get_param(pj_cstr(&tmpstr, "g729"), &g729_param);
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Cannot get G.729 default parameters");

		g729_param.setting.frm_per_pkt = m_config.getG729FramesPerPacket();
		pjsua_codec_set_param(pj_cstr(&tmp, "g729"), &g729_param);
#endif

		// REITEK: Use our own directory for ringtones etc
#if 0
		std::string path = executionPath;
		unsigned int tmp = path.find("plugins");
		if (tmp != std::string::npos)
		{
			path = path.substr(0, tmp + 7);
		}
		tmp = path.find(FBSTRING_PluginFileName".");
		if (tmp != std::string::npos)
		{
			path = path.substr(0, tmp - 1);
		}
#endif
		
		std::string path;

#if defined(XP_WIN)
		std::string appdata = getenv("ALLUSERSPROFILE");
		path = appdata + "\\Mozilla\\Plugins";
#elif defined(XP_LINUX)
		std::string appdata = getenv("HOME");
		path = appdata + "/Reitek/Contact/BrowserPlugin";
#endif
		
		audio_manager_ = boost::make_shared<BlabbleAudioManager>(path);

		BLABBLE_LOG_DEBUG("PjsuaManager startup complete.");
	}
	catch (std::runtime_error& e)
	{
		std::string str = "Error in PjsuaManager. " + boost::lexical_cast<std::string>(e.what());
		BlabbleLogging::blabbleLog(0, str.c_str(), 0);
		//BLABBLE_LOG_ERROR("Error in PjsuaManager. " << e.what());
		pjsua_destroy();
		throw e;
	}
}
Beispiel #4
0
/*
 * Change codec priorities.
 */
static void ui_manage_codec_prio()
{
    pjsua_codec_info c[32];
    unsigned i, count = PJ_ARRAY_SIZE(c);
    char input[32];
    char *codec, *prio;
    pj_str_t id;
    int new_prio;
    pj_status_t status;

    printf("List of audio codecs:\n");
    pjsua_enum_codecs(c, &count);
    for (i=0; i<count; ++i) {
	printf("  %d\t%.*s\n", c[i].priority, (int)c[i].codec_id.slen,
			       c[i].codec_id.ptr);
    }

#if PJSUA_HAS_VIDEO
    puts("");
    printf("List of video codecs:\n");
    pjsua_vid_enum_codecs(c, &count);
    for (i=0; i<count; ++i) {
	printf("  %d\t%.*s%s%.*s\n", c[i].priority,
				     (int)c[i].codec_id.slen,
				     c[i].codec_id.ptr,
				     c[i].desc.slen? " - ":"",
				     (int)c[i].desc.slen,
				     c[i].desc.ptr);
    }
#endif

    puts("");
    puts("Enter codec id and its new priority (e.g. \"speex/16000 200\", "
	 """\"H263 200\"),");
    puts("or empty to cancel.");

    printf("Codec name (\"*\" for all) and priority: ");
    if (fgets(input, sizeof(input), stdin) == NULL)
	return;
    if (input[0]=='\r' || input[0]=='\n') {
	puts("Done");
	return;
    }

    codec = strtok(input, " \t\r\n");
    prio = strtok(NULL, " \r\n");

    if (!codec || !prio) {
	puts("Invalid input");
	return;
    }

    new_prio = atoi(prio);
    if (new_prio < 0)
	new_prio = 0;
    else if (new_prio > PJMEDIA_CODEC_PRIO_HIGHEST)
	new_prio = PJMEDIA_CODEC_PRIO_HIGHEST;

    status = pjsua_codec_set_priority(pj_cstr(&id, codec),
				      (pj_uint8_t)new_prio);
#if PJSUA_HAS_VIDEO
    if (status != PJ_SUCCESS) {
	status = pjsua_vid_codec_set_priority(pj_cstr(&id, codec),
					      (pj_uint8_t)new_prio);
    }
#endif
    if (status != PJ_SUCCESS)
	pjsua_perror(THIS_FILE, "Error setting codec priority", status);
}