Exemplo 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;
}
Exemplo n.º 2
0
//=============================================================================
void SIPConference::start_sip_stack_ ()
{
	VFVW_LOG("entering start_sip_stack_()");

	status = pjsua_create ();
    if (status != PJ_SUCCESS) 
        error_exit ("Error in pjsua_create()", status);
    
    pj_log_set_log_func (my_pj_log_);
    
    pjsua_config cfg;
    pjsua_config_default (&cfg);

    cfg.cb.on_incoming_call = &on_incoming_call;
    cfg.cb.on_call_media_state = &on_call_media_state;
    cfg.cb.on_call_state = &on_call_state;

    status = pjsua_init (&cfg, NULL, NULL);
    if (status != PJ_SUCCESS) 
        error_exit ("Error in pjsua_init()", status);

    pjsua_transport_config tcfg;
    pjsua_transport_config_default (&tcfg);

    tcfg.port = 6060;
    status = pjsua_transport_create (PJSIP_TRANSPORT_UDP, &tcfg, NULL);
    if (status != PJ_SUCCESS) 
        error_exit ("Error creating transport", status);

    status = pjsua_start ();
    if (status != PJ_SUCCESS) 
        error_exit ("Error starting pjsua", status);
} 
Exemplo n.º 3
0
int systest_init(void)
{
    pjsua_logging_config log_cfg;
    pj_status_t status = PJ_SUCCESS;

    status = pjsua_create();
    if (status != PJ_SUCCESS) {
	systest_perror("Sorry we've had error in pjsua_create(): ", status);
	return status;
    }

    pjsua_logging_config_default(&log_cfg);
    log_cfg.log_filename = pj_str(add_path(doc_path, LOG_OUT_PATH));

    pjsua_config_default(&systest.ua_cfg);
    pjsua_media_config_default(&systest.media_cfg);
    systest.media_cfg.clock_rate = TEST_CLOCK_RATE;
    systest.media_cfg.snd_clock_rate = DEV_CLOCK_RATE;
    if (OVERRIDE_AUD_FRAME_PTIME)
	systest.media_cfg.audio_frame_ptime = OVERRIDE_AUD_FRAME_PTIME;
    systest.media_cfg.channel_count = CHANNEL_COUNT;
    systest.rec_id = REC_DEV_ID;
    systest.play_id = PLAY_DEV_ID;
    systest.media_cfg.ec_tail_len = 0;
    systest.media_cfg.snd_auto_close_time = 0;

#if defined(OVERRIDE_AUDDEV_PLAY_LAT) && OVERRIDE_AUDDEV_PLAY_LAT!=0
    systest.media_cfg.snd_play_latency = OVERRIDE_AUDDEV_PLAY_LAT;
#endif

#if defined(OVERRIDE_AUDDEV_REC_LAT) && OVERRIDE_AUDDEV_REC_LAT!=0
    systest.media_cfg.snd_rec_latency = OVERRIDE_AUDDEV_REC_LAT;
#endif

    status = pjsua_init(&systest.ua_cfg, &log_cfg, &systest.media_cfg);
    if (status != PJ_SUCCESS) {
	pjsua_destroy();
	systest_perror("Sorry we've had error in pjsua_init(): ", status);
	return status;
    }

    status = pjsua_start();
    if (status != PJ_SUCCESS) {
	pjsua_destroy();
	systest_perror("Sorry we've had error in pjsua_start(): ", status);
	return status;
    }

    status = gui_init(&root_menu);
    if (status != 0)
	goto on_return;

    return 0;

on_return:
    gui_destroy();
    return status;
}
Exemplo n.º 4
0
// helper for setting up sip library pjsua
static void setup_sip(void)
{
	pj_status_t status;
	
	log_message("Setting up pjsua ... ");
	
	// create pjsua  
	status = pjsua_create();
	if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);
	
	// configure pjsua	
	pjsua_config cfg;
	pjsua_config_default(&cfg);
	
	// enable just 1 simultaneous call 
	cfg.max_calls = 1;
		
	// callback configuration		
	cfg.cb.on_call_media_state = &on_call_media_state;
	cfg.cb.on_call_state = &on_call_state;
		
	// logging configuration
	pjsua_logging_config log_cfg;		
	pjsua_logging_config_default(&log_cfg);
	log_cfg.console_level = PJSUA_LOG_LEVEL;
		
	// initialize pjsua 
	status = pjsua_init(&cfg, &log_cfg, NULL);
	if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
	
	// add udp transport
	pjsua_transport_config udpcfg;
	pjsua_transport_config_default(&udpcfg);
		
	udpcfg.port = 5060;
	status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &udpcfg, NULL);
	if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
	
	// initialization is done, start pjsua
	status = pjsua_start();
	if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
	
	// disable sound - use null sound device
	status = pjsua_set_null_snd_dev();
	if (status != PJ_SUCCESS) error_exit("Error disabling audio", status);
	
	log_message("Done.\n");
}
Exemplo n.º 5
0
//
// initStack()
//
bool MainWin::initStack()
{
    pj_status_t status;

    //showStatus("Creating stack..");
    status = pjsua_create();
    if (status != PJ_SUCCESS) {
	showError("pjsua_create", status);
	return false;
    }

    showStatus("Initializing stack..");

    pjsua_config ua_cfg;
    pjsua_config_default(&ua_cfg);
    pjsua_callback ua_cb;
    pj_bzero(&ua_cb, sizeof(ua_cb));
    ua_cfg.cb.on_reg_state = &::on_reg_state;
    ua_cfg.cb.on_call_state = &::on_call_state;
    ua_cfg.cb.on_incoming_call = &::on_incoming_call;
    ua_cfg.cb.on_call_media_state = &::on_call_media_state;
#if USE_STUN
    ua_cfg.stun_srv_cnt = 1;
    ua_cfg.stun_srv[0] = pj_str((char*)STUN_SRV);
#endif

    pjsua_logging_config log_cfg;
    pjsua_logging_config_default(&log_cfg);
    log_cfg.log_filename = pj_str((char*)LOG_FILE);

    pjsua_media_config med_cfg;
    pjsua_media_config_default(&med_cfg);
    med_cfg.enable_ice = USE_ICE;

    status = pjsua_init(&ua_cfg, &log_cfg, &med_cfg);
    if (status != PJ_SUCCESS) {
	showError("pjsua_init", status);
	goto on_error;
    }

    //
    // Create UDP and TCP transports
    //
    pjsua_transport_config udp_cfg;
    pjsua_transport_id udp_id;
    pjsua_transport_config_default(&udp_cfg);
    udp_cfg.port = SIP_PORT;

    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP,
                                    &udp_cfg, &udp_id);
    if (status != PJ_SUCCESS) {
	showError("UDP transport creation", status);
	goto on_error;
    }

    pjsua_transport_info udp_info;
    status = pjsua_transport_get_info(udp_id, &udp_info);
    if (status != PJ_SUCCESS) {
	showError("UDP transport info", status);
	goto on_error;
    }

#if SIP_TCP
    pjsua_transport_config tcp_cfg;
    pjsua_transport_config_default(&tcp_cfg);
    tcp_cfg.port = 0;

    status = pjsua_transport_create(PJSIP_TRANSPORT_TCP,
                                    &tcp_cfg, NULL);
    if (status != PJ_SUCCESS) {
	showError("TCP transport creation", status);
	goto on_error;
    }
#endif

    //
    // Create account
    //
    pjsua_acc_config acc_cfg;
    pjsua_acc_config_default(&acc_cfg);
#if USE_REGISTRATION
    acc_cfg.id = pj_str( (char*)"<sip:" SIP_USERNAME "@" SIP_DOMAIN ">");
    acc_cfg.reg_uri = pj_str((char*) ("sip:" SIP_DOMAIN));
    acc_cfg.cred_count = 1;
    acc_cfg.cred_info[0].realm = pj_str((char*)"*");
    acc_cfg.cred_info[0].scheme = pj_str((char*)"digest");
    acc_cfg.cred_info[0].username = pj_str((char*)SIP_USERNAME);
    acc_cfg.cred_info[0].data = pj_str((char*)SIP_PASSWORD);

# if SIP_TCP
    acc_cfg.proxy[acc_cfg.proxy_cnt++] = pj_str((char*) "<sip:" SIP_DOMAIN ";transport=tcp>");
# endif

#else
    char sip_id[80];
    snprintf(sip_id, sizeof(sip_id),
	     "sip:%s@%.*s:%u", SIP_USERNAME,
	     (int)udp_info.local_name.host.slen,
	     udp_info.local_name.host.ptr,
	     udp_info.local_name.port);
    acc_cfg.id = pj_str(sip_id);
#endif

    acc_cfg.vid_cap_dev = DEFAULT_CAP_DEV;
    acc_cfg.vid_rend_dev = DEFAULT_REND_DEV;
    acc_cfg.vid_in_auto_show = PJ_TRUE;
    acc_cfg.vid_out_auto_transmit = PJ_TRUE;

    status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &accountId_);
    if (status != PJ_SUCCESS) {
	showError("Account creation", status);
	goto on_error;
    }

    localUri_->setText(acc_cfg.id.ptr);

    //
    // Start pjsua!
    //
    showStatus("Starting stack..");
    status = pjsua_start();
    if (status != PJ_SUCCESS) {
	showError("pjsua_start", status);
	goto on_error;
    }

    showStatus("Ready");

    return true;

on_error:
    pjsua_destroy();
    return false;
}
Exemplo n.º 6
0
bool SipPhone::init_pjsua() {
  Logger::debug("SipPhone::init_pjsua...");

  // create pjsua  
  pj_status_t status = pjsua_create();
  if (status != PJ_SUCCESS) {
    Logger::error("pjsua_create() failed (%s)", Helper::getPjStatusAsString(status).c_str());
    return false;
  }

  // configure pjsua
  pjsua_config ua_cfg;
  pjsua_config_default(&ua_cfg);
  // enable just 1 simultaneous call 
  ua_cfg.max_calls = 1; // TODO
  // callback configuration
  ua_cfg.cb.on_call_state = &SipAccount::onCallStateCB;
  ua_cfg.cb.on_incoming_call = &SipAccount::onIncomingCallCB;
  //ua_cfg.cb.on_call_media_state = &SipAccount::onCallMediaStateCB;

  // logging configuration
  pjsua_logging_config log_cfg;    
  pjsua_logging_config_default(&log_cfg);
  log_cfg.level = pj_log_get_level();

  // media configuration
  pjsua_media_config media_cfg;
  pjsua_media_config_default(&media_cfg);
  media_cfg.clock_rate = 8000; // TODO: default of 16000 seems not to work :-(

  // initialize pjsua 
  status = pjsua_init(&ua_cfg, &log_cfg, &media_cfg);
  if (status != PJ_SUCCESS) {
    Logger::error("pjsua_init() failed (%s)", Helper::getPjStatusAsString(status).c_str());
    return false;
  }

  // add udp transport
  pjsua_transport_config udpcfg;
  pjsua_transport_config_default(&udpcfg);

  status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &udpcfg, NULL);
  if (status != PJ_SUCCESS) {
    Logger::error("pjsua_transport_create() failed (%s)", Helper::getPjStatusAsString(status).c_str());
    return false;
  }

  // disable sound device - use null sound device
  status = pjsua_set_null_snd_dev();
  if (status != PJ_SUCCESS) {
    Logger::error("pjsua_set_null_snd_dev() failed (%s)", Helper::getPjStatusAsString(status).c_str());
    return false;
  }

  // initialization is done, start pjsua
  status = pjsua_start();
  if (status != PJ_SUCCESS) {
    Logger::error("pjsua_start() failed (%s)", Helper::getPjStatusAsString(status).c_str());
    return false;
  }

#if 0
  m_Pool = pjsua_pool_create("SipPhone.cpp", 128, 128);
  if (m_Pool == NULL) {
    Logger::error("pjsua_pool_create() failed");
    return false;
  }
#endif

  return true;
}
Exemplo n.º 7
0
void PjsipCallFront::run()
{
    pj_thread_desc initdec;
    pj_thread_t* thread = 0;
    pj_status_t status;
    int evt_cnt = 0;

    Q_ASSERT(::globalPjCallback == NULL);
    ::globalPjCallback = new PjCallback();

    status = pjsua_create();
    Q_ASSERT(status == PJ_SUCCESS);

    PJSipEventThread *ethread = new PJSipEventThread();
    ethread->start();
    while (!ethread->isRunning()) {
        msleep(5);
    }

    PjCallback *myCb = (PjCallback*) globalPjCallback;
    QObject::connect(this, SIGNAL(invoke_make_call_fwd(int, pjsua_acc_id, const QString&)),
                     myCb, SLOT(on_make_call_impl(int, pjsua_acc_id, const QString&)));


    QObject::connect(myCb, SIGNAL(sig_make_call_done(int, pj_status_t, pjsua_call_id)),
                     this, SIGNAL(invoke_make_call_result(int, pj_status_t, pjsua_call_id)));


    status = pjsua_init(m_ua_cfg, m_log_cfg, m_media_cfg);
    Q_ASSERT(status == PJ_SUCCESS);

    pjsua_var.mconf_cfg.samples_per_frame = 8000; // pjsua_var from 

    /* Add UDP transport. */
    {
        pjsua_transport_config cfg;
        pjsua_transport_config rtp_cfg;
        pjsua_transport_id udp_tp_id;
        pjsua_transport_id tcp_tp_id;
       
        // 创建指定端口的RTP/RTCP层media后端
        pjsua_transport_config_default(&rtp_cfg);
        rtp_cfg.port = 8050;
        status = pjsua_media_transports_create(&rtp_cfg);

        // SIP 层初始化,可指定端口
        pjsua_transport_config_default(&cfg);
        cfg.port = 15678; // if not set , use random big port 
        // cfg.public_addr = pj_str("123.1.2.3"); // 与上面的port一起可用于穿透,指定特定的公共端口!!!
        status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, m_udp_tp_id);
        if (status != PJ_SUCCESS) {
            pjsua_perror(__FILE__, "Error creating udp transport", status);
            // error_exit("Error creating transport", status);
        }
        status = pjsua_transport_set_enable(*m_udp_tp_id, PJ_TRUE);

        // TCP transport
        pjsua_transport_config_default(&cfg);
        cfg.port = 56789;
        status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &cfg, m_tcp_tp_id);
        if (status != PJ_SUCCESS) {
            pjsua_perror(__FILE__, "Error creating tcp transport", status);
            // error_exit("Error creating transport", status);
        }
        status = pjsua_transport_set_enable(*m_tcp_tp_id, PJ_TRUE);
        status = pjsua_transport_set_enable(*m_udp_tp_id, PJ_TRUE);
    }
    
    status = pjsua_start();
    Q_ASSERT(status == PJ_SUCCESS);

    qLogx()<<"";
    emit this->realStarted(status);
    this->exec();
}
Exemplo n.º 8
0
/*
 * main()
 *
 * argv[1] may contain URL to call.
 */
int main(int argc, char *argv[])
{
 pjsua_acc_id acc_id;
 pj_status_t status;

 /* Create pjsua first! */
 status = pjsua_create();
 if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);

 /* If argument is specified, it's got to be a valid SIP URL */
 if (argc > 1) {
 status = pjsua_verify_url(argv[1]);
 if (status != PJ_SUCCESS) error_exit("Invalid URL in argv", status);
 }

 /* Init pjsua */
 {
 pjsua_config cfg;
 pjsua_logging_config log_cfg;

 pjsua_config_default(&cfg);
 cfg.cb.on_incoming_call = &on_incoming_call;
 cfg.cb.on_call_media_state = &on_call_media_state;
 cfg.cb.on_call_state = &on_call_state;

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

 status = pjsua_init(&cfg, &log_cfg, NULL);
 if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
 }

 /* Add UDP transport. */
 {
 pjsua_transport_config cfg;

 pjsua_transport_config_default(&cfg);
 cfg.port = 5060;
 status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
 if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
 }

 /* Initialization is done, now start pjsua */
 status = pjsua_start();
 if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);

 /* Register to SIP server by creating 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_DOMAIN);
 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, &acc_id);
 if (status != PJ_SUCCESS) error_exit("Error adding account", status);
 }

 /* If URL is specified, make call to the URL. */
 if (argc > 1) {
 pj_str_t uri = pj_str(argv[1]);
 status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL);
 if (status != PJ_SUCCESS) error_exit("Error making call", status);
 }

 /* Wait until user press "q" to quit. */
 for (;;) {
 char option[10];

 puts("Press 'h' to hangup all calls, 'q' to quit");
 if (fgets(option, sizeof(option), stdin) == NULL) {
 puts("EOF while reading stdin, will quit now..");
 break;
 }

 if (option[0] == 'q')
 break;

 if (option[0] == 'h')
 pjsua_call_hangup_all();
 }

 /* Destroy pjsua */
 pjsua_destroy();

 return 0;
}
Exemplo n.º 9
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;
	}
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
/*
 * main()
 *
 * argv[] contains the registration information.
 */
int main(int argc, char *argv[]) {
  pj_status_t status;
  int loglevel = 0;

  if (argc < 4) {
    usage(argv[0]);
    exit(1);
  }

  if (argc > 5){
    sscanf(argv[5], "%d", &loglevel);
  }

  pjsua_acc_id acc_id;

  /* Create pjsua first! */
  status = pjsua_create();
  if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);


  /* Init pjsua */
  {
    pjsua_config cfg;
    pjsua_logging_config log_cfg;
    pjsua_media_config media_cfg;

    // This will prevent the SIP stack from trying to switch to TCP.
    // It will prevent the stack from giving "Transport unavailable" errors.
    // http://trac.pjsip.org/repos/wiki/Using_SIP_TCP
    pjsip_cfg()->endpt.disable_tcp_switch = PJ_TRUE;

    pjsua_config_default(&cfg);
    cfg.cb.on_incoming_call    = &on_incoming_call;
    cfg.cb.on_call_media_state = &on_call_media_state;
    cfg.cb.on_call_state       = &on_call_state;
    cfg.cb.on_call_tsx_state   = &on_call_tsx_state;

    pjsua_logging_config_default(&log_cfg);
    log_cfg.console_level = loglevel; // 0 = Mute console, 3 = somewhat useful, 4 = overly verbose.
    pjsua_media_config_default(&media_cfg);

    status = pjsua_init(&cfg, &log_cfg, &media_cfg);
    if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
  }
  /* Add UDP transport. */
  {
    pjsua_transport_config cfg;

    pjsua_transport_config_default(&cfg);
    sscanf(argv[4], "%d", &cfg.port);
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
    if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
    printf("Created UDP transport on port %d.\n", cfg.port);
  }

 /* Initialization is done, now start pjsua */
  status = pjsua_start();
  if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);

  /* Register to SIP server by creating SIP account. */
  {
    char reg_uri_buf[80] = "sip:";

    char uri_buf[80] = "sip:";
    pjsua_acc_config cfg;
    char* username = argv[1];
    char* password = argv[2];
    char* domain   = argv[3];

    strcat (uri_buf, username);
    strcat (reg_uri_buf, domain);

    strcat (uri_buf, "@");
    strcat (uri_buf, domain);

    pjsua_acc_config_default(&cfg);
    cfg.id = pj_str(uri_buf);

    printf("Registering: %.*s.\n", (int)cfg.id.slen, cfg.id.ptr);

    cfg.reg_uri = pj_str(reg_uri_buf);
    cfg.cred_count = 1;
    cfg.cred_info[0].realm = pj_str(domain);
    cfg.cred_info[0].scheme = pj_str("Digest");
    cfg.cred_info[0].username = pj_str(username);
    cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
    cfg.cred_info[0].data = pj_str(password);
    cfg.register_on_acc_add = PJ_FALSE;


    status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
    if (status != PJ_SUCCESS) error_exit("Error adding account", status);

    or_event(OR_READY, "Agent initialized..");

  }

  /* Start by muting the audio device. This a passive agent, and sound
     is just wasted CPU time and uwanted side effects. */
  pjsua_set_null_snd_dev();
  fflush(stdout);
  /* Wait until user press "q" to quit. */
  for (;;) {
    char option[256];

    if (fgets(option, sizeof (option), stdin) == NULL) {
      or_status (OR_ERROR, "EOF while reading stdin, will quit now..");
      break;
    }

    /* Dial command. */
    if (option[0] == 'd') {
      pj_str_t uri = pj_str(&option[1]);
      status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, NULL);
      if (status != PJ_SUCCESS) {
        or_status (OR_ERROR, "Could not make call");
      }
      else {
        or_status (OR_OK, "Dialling...");
      }
    }

    /* Register */
    else if (option[0] == 'r') {
      register_account(acc_id);
    }

    /* Unregister */
    else if (option[0] == 'u') {
      unregister_account(acc_id);
    }

    /* Enable autoanswer */
    else if (option[0] == 'a') {
      if (option[1] == '1') {
        autoanswer[0] = true;
        or_status(OR_OK, "Autoanswer enabled.");
      } else {
        or_status(OR_ERROR, "Invalid account.");
      }
    }

    /* Disable autoanswer (manual answer) */
    else if (option[0] == 'm') {
      autoanswer[0] = false;
      or_status(OR_OK, "Autoanswer disabled.");
    }

    /* Pickup incoming call, unsupported for now. */
    else if (option[0] == 'p') {
      if (current_call != PJSUA_INVALID_ID) {
        pjsua_call_answer(current_call, 200, NULL, NULL);
        or_status(OR_OK, "Call picked up.");
      } else {
        or_status(OR_ERROR, "No call to pick up.");
      }
    }

    /* Hang up current call */
    else if (option[0] == 'H') {
      if (current_call != PJSUA_INVALID_ID) {
        pjsua_call_hangup (current_call, 0,NULL, NULL);
        or_status (OR_OK, "Hanging up current call...");
      } else {
        or_status(OR_ERROR, "No call to hang up.");
      }
    }

    /* Full hangup.. */
    else if (option[0] == 'h') {
      pjsua_call_hangup_all();
      or_status (OR_OK, "Hanging up all calls...");
    }

    /* Status  */
    else if (option[0] == 's') {
      or_dump_status();
    }

    /* Exit application. */
    else if (option[0] == 'q') {
      break;
    }

    else {
      or_status (OR_ERROR, "Unknown command:");
    }
  }
  pjsua_destroy();
  or_status (OR_OK, "Exiting...");

  return 0;
}
Exemplo n.º 12
0
int main()
{
	/* system variables */
	pj_status_t status;
	pjsua_config			ua_cfg;
	pjsua_acc_config		acc_cfg;
	pjsua_logging_config	log_cfg;
	pjsua_media_config		media_cfg;
	pjsua_transport_config	udp_cfg;
	pjsua_transport_id		transport_id;
	pjsua_acc_id			local_aid;
	pjsua_acc_id			user_aid;
	// used to send message
	pj_str_t		to; 
	pj_str_t		mime_type; 
	pj_str_t		content;
	bShutdown = 0;
	pthread_cond_init(&_cond, NULL);
	pthread_mutex_init(&_mutex, NULL);

   if ( signal( SIGINT, signalHandler ) == SIG_ERR )
   {
      exit( -1 );
   }

   if ( signal( SIGTERM, signalHandler ) == SIG_ERR )
   {
      exit( -1 );
   }


	/**
	 * create pjsua first 
	 */
	status = pjsua_create();
	if(status != PJ_SUCCESS) {
		pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
		return status;
	}
	/**
	 * init pjsua framework 
	 */
	/* configuration of ua */
	pjsua_config_default(&(ua_cfg));
	/**
	 * init callback
	 * set callback functions you need
	 * all the prototype of call are declared in pjsua.h
	 */
//	/* call related handle */
//	ua_cfg.cb.on_call_state					  = on_call_state;
//	ua_cfg.cb.on_incoming_call                = on_incoming_call;
//	ua_cfg.cb.on_call_tsx_state               = on_call_tsx_state;
//	ua_cfg.cb.on_call_media_state             = on_call_media_state;
//	ua_cfg.cb.on_call_sdp_created             = on_call_sdp_created;
//	ua_cfg.cb.on_stream_created               = on_stream_created;
//	ua_cfg.cb.on_stream_destroyed             = on_stream_destroyed;
//	ua_cfg.cb.on_dtmf_digit                   = on_dtmf_digit;
//	ua_cfg.cb.on_call_transfer_request        = on_call_transfer_request;
//	ua_cfg.cb.on_call_transfer_request2       = on_call_transfer_request2;
//	ua_cfg.cb.on_call_transfer_status         = on_call_transfer_status;
//	ua_cfg.cb.on_call_replace_request         = on_call_replace_request;
//	ua_cfg.cb.on_call_replace_request2        = on_call_replace_request2;
//	ua_cfg.cb.on_call_replaced                = on_call_replaced;
//	ua_cfg.cb.on_call_rx_offer                = on_call_rx_offer;
//	/* register handle */
	ua_cfg.cb.on_reg_started                  = on_reg_started;
	ua_cfg.cb.on_reg_state                    = on_reg_state;
	ua_cfg.cb.on_reg_state2                   = on_reg_state2;
//	/* subscirbe handle */
//	ua_cfg.cb.on_incoming_subscribe           = on_incoming_subscribe;
//	ua_cfg.cb.on_srv_subscribe_state          = on_srv_subscribe_state;
//	ua_cfg.cb.on_buddy_state                  = on_buddy_state;
//	ua_cfg.cb.on_buddy_evsub_state            = on_buddy_evsub_state;
//	/* message handle */
//	ua_cfg.cb.on_pager                        = on_pager;
	ua_cfg.cb.on_pager2                       = on_pager2;
//	ua_cfg.cb.on_pager_status                 = on_pager_status;
//	ua_cfg.cb.on_pager_status2                = on_pager_status2;
//	ua_cfg.cb.on_typing                       = on_typing;
//	ua_cfg.cb.on_typing2                      = on_typing2;
//	/* network handle */
//	ua_cfg.cb.on_nat_detect                   = on_nat_detect;
	ua_cfg.cb.on_call_redirected              = on_call_redirected;
//	ua_cfg.cb.on_mwi_state                    = on_mwi_state;
//	ua_cfg.cb.on_mwi_info                     = on_mwi_info;
//	ua_cfg.cb.on_transport_state              = on_transport_state;
//	ua_cfg.cb.on_call_media_transport_state   = on_call_media_transport_state;
//	ua_cfg.cb.on_ice_transport_error          = on_ice_transport_error;
//	ua_cfg.cb.on_snd_dev_operation            = on_snd_dev_operation;
//	/* media module handle */
//	ua_cfg.cb.on_call_media_event             = on_call_media_event;
//	ua_cfg.cb.on_create_media_transport       = on_create_media_transport;
	/* configure logging */
	pjsua_logging_config_default(&(log_cfg));
	log_cfg.msg_logging = PJ_FALSE;
	/* configure media */
	pjsua_media_config_default(&(media_cfg));
	status = pjsua_init(&(ua_cfg), 
			&(log_cfg), 
			NULL);
//			&(media_cfg));
	if(status != PJ_SUCCESS) {
		pjsua_perror(THIS_FILE, "Error initializing pjsua", status);
		return status;
	}

	status = pjsua_start();
	if(status != PJ_SUCCESS) {
		pjsua_perror(THIS_FILE, "Error starting pjsua", status);
		return status;
	}

	/**
	 * Setup transport
	 */
	pjsua_transport_config_default(&udp_cfg);
	udp_cfg.port = 5091;
	status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &udp_cfg, &transport_id);
	if(status != PJ_SUCCESS)
		return -1;

	/**
	 * add local account (sip:domain) which handle sip messages that don't matches any
	 * other accounts
	 */
	pjsua_acc_add_local(transport_id, PJ_TRUE, &local_aid);

	/**
	 * add user account and set it to default account 
	 */
	pjsua_acc_config_default(&acc_cfg);
	acc_cfg.id = pj_str("sip:[email protected]");
	acc_cfg.reg_uri = pj_str("sip:192.168.1.197");
	acc_cfg.reg_timeout = 300;
	acc_cfg.cred_count = 1;
	acc_cfg.cred_info[0].realm = pj_str("192.168.1.197");
	acc_cfg.cred_info[0].scheme = pj_str("digest");
	acc_cfg.cred_info[0].username = pj_str("Server_301007");
	acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
	acc_cfg.cred_info[0].data = pj_str("Server");
	acc_cfg.proxy_cnt = 1;
	acc_cfg.proxy[0] = pj_str("sip:192.168.1.197;lr");

	/**
	 * register_on_acc_add is true by default, add:
	 *
	 *		acc_cfg.register_on_acc_add = PJ_FALSE;
	 *
	 * to disable register on add.add later you can call the following 
	 * code to send a REGISTER.
	 *
	 *		pjsua_acc_set_registration(id_of_the_account, PJ_TRUE);
	 *
	 */
	status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &user_aid);
	sleep(2);
	/**
	 * unregister account before exit
	 */


	to = pj_str("sip:[email protected]");
	to = pj_str("sip:[email protected]");
	mime_type = pj_str("text/plain");
	content = pj_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
			"<SIP_XML EventType=\"TimeSync\">"
			"<Item operation=\"query\" time=\"0-0-0 0:0:0\"/>"
			"</SIP_XML>");
	content = pj_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
			"<SIP_XML EventType=\"MediaPlay\">"
			"<User uri=\"sip:[email protected]\"/>"
			"<Media type=\"1\" id=\"000001-001\"/>"
			"</SIP_XML>");
	content = pj_str("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
			"<SIP_XML EventType=\"MediaTeardown\">"
			"<User uri=\"sip:[email protected]\"/>"
			"<Media type=\"1\" id=\"000001-001\"/>"
			"</SIP_XML>");
	{
		pthread_t tid;
//		pthread_create(&tid, NULL, test_thread, &user_aid);
	}
	pjsua_im_send(user_aid, &to, &mime_type, &content, NULL, NULL);
	sleep(1);
	printf("*******************************\n");
	printf("pjsua_im_send ok @ main\n");
	printf("*******************************\n");
	pthread_mutex_lock(&_mutex);
	pthread_cond_signal(&_cond);
	pthread_mutex_unlock(&_mutex);
//	pjsua_call_setting setting;
//	pjsua_call_setting_default(&setting);
//	setting.aud_cnt = 0;
//	setting.vid_cnt = 0;
//	pjsua_call_id cid;
//	pjsua_msg_data msg_data;
//	pjsua_msg_data_init(&msg_data);
//	msg_data.content_type = pj_str("application/sdp");
//	msg_data.msg_body = pj_str(
//			"v=0\r\n"
//			"o=adapter 0 0 IN IP4 0.0.0.0\r\n"
//			"s=-\r\n"
//			"c=IN IP4 192.168.1.147\r\n"
//			"t=1371053400 1371057000\r\n"
//			"m=video 6000 TCP 96\r\n"
//			"a=rtpmap:98 L16/16000/2\r\n"
//			"a=ResID:301002-0005\r\n"
//			"a=WndIndex:1\r\n"
//			"a=recvonly\r\n");
//	sleep(2);
//	if(pjsua_call_make_call(user_aid, &to, &setting, NULL, NULL, &cid) != PJ_SUCCESS)
//		PJ_LOG(1, (__FILE__, "failed to make call\n"));
	while(!bShutdown)
	{
		sleep(1);
	}
	pjsua_acc_set_registration(user_aid, PJ_FALSE);
	sleep(1);
	return status;

}
Exemplo n.º 13
0
QVDoorcom::QVDoorcom(QDomElement xml_desc, QString container, QWidget *parent) :
    QVElement(xml_desc,container,parent)
{
    if (w < 1) {
        w = 1;
    }
    if (h < 1) {
        h = 1;
    }
    popup = 0;
    if (instance_count > 0) {
        w = h = 0;
        return;
    }
    instance_count = 1;
    doorcom = this;

    popup = new QVPopupFrame(parent);

    QDomElement e_server = xml_desc.firstChildElement("server");
    QDomElement e_user = xml_desc.firstChildElement("user");
    QDomElement e_password = xml_desc.firstChildElement("password");
    if (e_server.isNull() || e_user.isNull() || e_password.isNull()) {
        qDebug() << "SIP client: insufficient auth info";
        return;
    }

    QString s_server = e_server.text();
    QString s_user = e_user.text();
    QString s_password = e_password.text();

    QDomElement e_caller = xml_desc.firstChildElement("source");
    if (!e_caller.isNull()) {
        accepted_caller = e_caller.text();
    }

    QDomElement e_accept = xml_desc.firstChildElement("accept");
    if (!e_accept.isNull()) {
        code_accept = e_accept.text();
    }

    QDomElement e_hangup = xml_desc.firstChildElement("hangup");
    if (!e_hangup.isNull()) {
        code_hangup = e_hangup.text();
    }

    QDomElement e_dooropen = xml_desc.firstChildElement("dooropen");
    if (!e_dooropen.isNull()) {
        code_dooropen = e_dooropen.text();
    }

    QFile f_doorbell;
    QString s_doorbell_name;
    bool doorbell_ok;
    bell_wav = 0;
    QDomElement e_doorbell = xml_desc.firstChildElement("ringtone");
    if (!e_doorbell.isNull()) {
        s_doorbell_name = findFilePath(e_doorbell.text());
        f_doorbell.setFileName(findFilePath(e_doorbell.text()));
        f_doorbell.open(QIODevice::ReadOnly);
    }
    if (!f_doorbell.isOpen()) {
        f_doorbell.setFileName(":/sounds/doorbell.wav");
        f_doorbell.open(QIODevice::ReadOnly);
    }

#ifndef DOORBELL_WAV
    QByteArray riff = f_doorbell.read(12);
    if (riff.length() < 12) {
        doorbell_ok = false;
    } else {
        if (!riff.startsWith("RIFF") || !riff.endsWith("WAVE")) {
            doorbell_ok = false;
        }
    }

    QByteArray fmthdr = f_doorbell.read(8);
    if (!fmthdr.startsWith("fmt")) {
        doorbell_ok = false;
    }
    uint32_t fmt_len;
    memcpy(&fmt_len,fmthdr.mid(4).data(),4);
    qDebug() << "fmt len" << fmt_len;
    if (fmt_len < 16) {
        doorbell_ok = false;
    }
    QByteArray fmt = f_doorbell.read(fmt_len);
    uint16_t audio_format;
    uint16_t num_channels;
    uint32_t sample_rate;
    uint32_t byte_rate;
    uint16_t block_align;
    uint16_t bits_per_sample;
    uint32_t bell_datalen;

#if (BYTE_ORDER != __LITTLE_ENDIAN)
#error Adapt endianness in __FILE__
#endif

    if (fmt.length() < fmt_len) {
        doorbell_ok = false;
    } else {
        memcpy(&audio_format,fmt.mid(0).data(),2);
        memcpy(&num_channels,fmt.mid(2).data(),2);
        memcpy(&sample_rate,fmt.mid(4).data(),4);
        memcpy(&byte_rate,fmt.mid(8).data(),4);
        memcpy(&block_align,fmt.mid(12).data(),2);
        memcpy(&bits_per_sample,fmt.mid(14).data(),2);
    }

    qDebug() << audio_format << "nch" << num_channels << "samplerate" << sample_rate << "byztera" << byte_rate << "blocka" << block_align << "bps" << bits_per_sample;
    if (audio_format != 0x0001) {
        doorbell_ok = false;
    }

    if (doorbell_ok) {
        QByteArray datahdr = f_doorbell.read(8);
        if (!datahdr.startsWith("data") || (datahdr.length() < 8)) {
            doorbell_ok = false;
        } else {
            memcpy(&bell_datalen,datahdr.mid(4).data(),4);
        }
        if (doorbell_ok && (bell_datalen > 0)) {
            QByteArray data = f_doorbell.read(bell_datalen);
            bell_wav = (char*)malloc(bell_datalen);
            if (bell_wav != 0) {
                memcpy(bell_wav,data.data(),bell_datalen);
            }
        }
    }
#endif

    active_call = -1;

    QObject::connect(this,SIGNAL(incomingCall(int)),this,SLOT(onIncomingCall(int)),Qt::QueuedConnection);
    QObject::connect(this,SIGNAL(callState(int,QString)),this,SLOT(onCallState(int,QString)),Qt::QueuedConnection);
    QObject::connect(this,SIGNAL(callMediaState(int)),this,SLOT(onCallMediaState(int)),Qt::QueuedConnection);

    w_accept = new QVSvgWidget(":/icons/phone_call.svg",popup->content());
    w_hangup = new QVSvgWidget(":/icons/phone_call_end.svg",popup->content());
    w_dooropen = new QVSvgWidget(":/icons/door_open.svg",popup->content());
    QObject::connect(w_accept,SIGNAL(clicked(double,double)),this,SLOT(onAcceptPressed()));
    QObject::connect(w_hangup,SIGNAL(clicked(double,double)),this,SLOT(onHangupPressed()));
    QObject::connect(w_dooropen,SIGNAL(clicked(double,double)),this,SLOT(onDoorOpenPressed()));

    hangup_timer.setSingleShot(true);
    hangup_timer.setInterval(800);
    QObject::connect(&hangup_timer,SIGNAL(timeout()),this,SLOT(onHangupTimer()));

    dtmf_timer.setSingleShot(true);
    dtmf_timer.setInterval(200);
    QObject::connect(&dtmf_timer,SIGNAL(timeout()),this,SLOT(onDTMFTimer()));

    /******* Init PJSUA ********/
    pjsua_acc_id acc_id;
    pj_status_t status;

    /* Create pjsua first! */
    status = pjsua_create();
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot create PJSUA SIP client, cause:" << status;
        return;
    }

    /* Init pjsua */
    pjsua_config cfg;
    pjsua_logging_config log_cfg;
    pjsua_media_config media_cfg;

    pjsua_config_default(&cfg);
    cfg.cb.on_incoming_call = &on_incoming_call;
    cfg.cb.on_call_media_state = &on_call_media_state;
    cfg.cb.on_call_state = &on_call_state;

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

    pjsua_media_config_default(&media_cfg);
    media_cfg.clock_rate = 8000;
    media_cfg.ec_tail_len = 0;

    status = pjsua_init(&cfg, &log_cfg, &media_cfg);
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot init PJSUA SIP client, cause: " << status;
        return;
    }

    /* Add UDP transport. */
    pjsua_transport_config transport_cfg;

    pjsua_transport_config_default(&transport_cfg);
    transport_cfg.port = 5060;
    status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &transport_cfg, NULL);
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot init PJSUA UDP transport, cause: " << status;
        return;
    }

    /* Initialization is done, now start pjsua */
    status = pjsua_start();
    if (status != PJ_SUCCESS) {
        qDebug() << "Cannot start PJSUA SIP client, cause: " << status;
        return;
    }
    /* Register to SIP server by creating SIP account. */
    pjsua_acc_config acc_cfg;

    pjsua_acc_config_default(&acc_cfg);
    QString s_id = "sip:" + s_user + "@" + s_server;
    QString s_uri = "sip:" + s_server;
    acc_cfg.cred_count = 1;
    acc_cfg.cred_info[0].realm = pj_str(strdup(s_server.toLocal8Bit().data()));
    acc_cfg.cred_info[0].scheme = pj_str("digest");
    acc_cfg.cred_info[0].username = pj_str(strdup(s_user.toLocal8Bit().data()));
    acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
    acc_cfg.cred_info[0].data = pj_str(strdup(s_password.toLocal8Bit().data()));
    acc_cfg.id = pj_str(strdup(s_id.toLocal8Bit().data()));
    acc_cfg.reg_uri = pj_str(strdup(s_uri.toLocal8Bit().data()));
    status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &acc_id);
    if (status != PJ_SUCCESS) {
        qDebug() << "PJSUA auth data invalid, cause: " << status;
        return;
    }

    qDebug() << "PJSUA ports" << pjsua_conf_get_active_ports();
    pjsua_conf_port_info info;
    pjsua_conf_get_port_info (0, &info);
    qDebug() << pj2qstring(info.name);

//    pjsua_conf_adjust_tx_level(0,0.0);

    pj_caching_pool_init(&pj_cpool, &pj_pool_factory_default_policy, 0);
    pj_pool = pjsua_pool_create("qvisu", 8192, 8192);

#ifndef DOORBELL_WAV
    if (doorbell_ok && (bell_wav != 0)) {
        status = pjmedia_mem_player_create(pj_pool,
                                           bell_wav,
                                           bell_datalen,
                                           sample_rate,
                                           num_channels,
                                           16384,
                                           bits_per_sample,
                                           0,//PJMEDIA_MEM_NO_LOOP,
                                           &bell_file_port);

        qDebug() << "Bell memory player" << status;

        status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id);
        qDebug() << "bell file add status" << status << "id" << bell_port_id;

        status = pjmedia_mem_player_set_eof_cb 	(bell_file_port,
                                                 0,
                                                 &on_file_played);

    } else {
        bell_file_port = 0;
    }
#else
    qDebug() << "Doorbell file" << s_doorbell_name;
    if (s_doorbell_name.isEmpty()) {
        bell_file_port = 0;
    } else {
        /* Create file media port for doorbell from the WAV file */
        status = pjmedia_wav_player_port_create(pj_pool,	/* memory pool	    */
                                                strdup(s_doorbell_name.toUtf8().data()),	/* file to play	    */
                                                20,	/* ptime.	    */
                                                PJMEDIA_FILE_NO_LOOP,	/* flags	    */
                                                0,	/* default buffer   */
                                                &bell_file_port/* returned port    */
                                                );
        if (status != PJ_SUCCESS) {
            qDebug() << "Cannot open wav file" << status;
            bell_file_port = 0;
        }
    }

    if (bell_file_port != 0) {
        status = pjsua_conf_add_port(pj_pool,bell_file_port,&bell_port_id);
        qDebug() << "bell file add status" << status << "id" << bell_port_id;

        status = pjmedia_wav_player_set_eof_cb 	(bell_file_port,
                                                 0,
                                                 &on_file_played);
        if (status != PJ_SUCCESS) {
            qDebug() << "Cannot register callback";
            bell_file_port = 0;
        }
    }
#endif
}
int PjsipEngine::start() {
	pjsua_acc_id acc_id;
	pj_status_t status;
	status = pjsua_create();

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

	{
		pjsua_config cfg;
		pjsua_logging_config log_cfg;

		pjsua_config_default(&cfg);

		// Set up the two static callbacks for session up session down
		// This is where all callbacks are initialized. See PJSIP documentation
		// session up
		cfg.cb.on_reg_started = &on_reg_started;
		// traps session down
		cfg.cb.on_transport_state = &on_tp_state_changed;

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

		pjsua_media_config media_cfg;

		pjsua_media_config_default(&media_cfg);
		status = pjsua_init(&cfg, &log_cfg, &media_cfg);

		if (status != PJ_SUCCESS) {
			handleError("Error initializing pjsua", status);
			return status;
		}

	}

	/* Add UDP transport. */
	{
		pjsua_transport_config cfg;

		pjsua_transport_config_default(&cfg);
		cfg.port = 5060;
		status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
		if (status != PJ_SUCCESS) {
			handleError("Error creating transport", status);
			return status;
		}
	}

	/* Initialization is done, now start pjsua */
	status = pjsua_start();
	if (status != PJ_SUCCESS) {
		handleError("Error starting pjsua", status);
		return status;
	}

	/* Register to SIP server by creating SIP account. */
	{
		pjsua_acc_config cfg;

		pjsua_acc_config_default(&cfg);

		std::string id(sipPrefix + sipUser + atSymbol + sipDomain);
		cfg.id = pj_str((char *) id.c_str());
		std::string uri(sipPrefix + sipDomain);
		cfg.reg_uri = pj_str((char*) uri.c_str());
		cfg.cred_count = 1;
		cfg.cred_info[0].realm = pj_str((char *) sipDomain.c_str());
		cfg.cred_info[0].scheme = pj_str((char*) digest.c_str());
		cfg.cred_info[0].username = pj_str((char*) sipUser.c_str());
		cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
		cfg.cred_info[0].data = pj_str((char *) sipPassword.c_str());

		status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
		if (status != PJ_SUCCESS) {
			handleError("Error adding account", status);
			return status;
		}
	}

	return status;
}
Exemplo n.º 15
0
int main() {
    pj_caching_pool cp;
    pj_cli_cfg cli_cfg;
    pj_cli_telnet_cfg tcfg;
    pj_str_t xml;
    pj_status_t status;
    pj_status_t cli_status;
    int i;
    pj_log_set_level(LOG_LEVEL);
    print_msg(("", "INITING .... \n"));
    status = pj_init();
    PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);

    if (status != PJ_SUCCESS) {
        print_msg(("", "PJ INIT FAILED \n"));
    }

    pj_caching_pool_init(&cp, NULL, 0);
    pjlib_util_init();
    /*
     * Create CLI app.
     */
    pj_cli_cfg_default(&cli_cfg);

    print_msg(("", "INITING CLI CFG....  \n"));
    cli_cfg.pf = &cp.factory;
    cli_cfg.name = pj_str("tinysipcli");
    cli_cfg.title = pj_str("TINYSIP");

    cli_status = pj_cli_create(&cli_cfg, &cli);
    print_msg(("", "AFTER INITING CLI CFG....  \n"));

    if (cli_status != PJ_SUCCESS) {
        print_msg(("", "CLI FAILED \n"));
        goto on_return;
    }

    /*
     * Register some commands.
     */
    for (i = 0; i < sizeof(cmd_xmls) / sizeof(cmd_xmls[0]); i++) {
        xml = pj_str(cmd_xmls[i].xml);
//        print_msg(("",cmd_xmls[i].xml));
        status = pj_cli_add_cmd_from_xml(cli, NULL, &xml, cmd_xmls[i].handler,
                                         NULL, get_cmd_list);
        if (status != PJ_SUCCESS)
            continue;
//        goto on_return;
    }
    /* Create pjsua first! */
    status = pjsua_create();
    if (status != PJ_SUCCESS)
        error_exit("Error in pjsua_create()", status);

    /* Init pjsua */
    {
        pjsua_logging_config log_cfg;
        pjsua_logging_config_default(&log_cfg);
        log_cfg.console_level = LOG_LEVEL;

        pjsua_config cfg;
        pjsua_config_default(&cfg);


        cfg.cb.on_incoming_call = &on_incoming_call;
        cfg.cb.on_call_media_state = &on_call_media_state;
        cfg.cb.on_call_state = &on_call_state;

        status = pjsua_init(&cfg, &log_cfg, NULL);
        if (status != PJ_SUCCESS)
            error_exit("Error in pjsua_init()", status);
    }

    /* Add UDP transport. */
    {
        pjsua_transport_config cfg;

        pjsua_transport_config_default(&cfg);
        cfg.port = 5060;
        status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
        if (status != PJ_SUCCESS)
            error_exit("Error creating transport", status);
    }


    /*
     * Start telnet daemon
     */
    pj_cli_telnet_cfg_default(&tcfg);
//    tcfg.passwd = pj_str("pjsip");
#if USE_RANDOM_PORT
    tcfg.port = 0;
#else
    tcfg.port = 2233;
#endif
    tcfg.prompt_str = pj_str("CMD % ");
    status = pj_cli_telnet_create(cli, &tcfg, NULL);
    if (status != PJ_SUCCESS)
        goto on_return;

    /*
     * Run the system specific main loop.
     */
    status = app_main(cli);

on_return:

    print_msg(("", "There're some issues, application is going down now!\n"));
    /*
     * Destroy
     */
    pj_cli_destroy(cli);
    cli = NULL;
    pj_caching_pool_destroy(&cp);
    pj_shutdown();

    return (status != PJ_SUCCESS ? 1 : 0);
}
Exemplo n.º 16
0
int init(  char *domain, char * user, char * passwd, char *proxy)
{
    pjsua_acc_id acc_id;
    pj_status_t status;

    /* Create pjsua first! */
    status = pjsua_create();
    if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);


    /* Init pjsua */
    {
	pjsua_config cfg;
	pjsua_logging_config log_cfg;

	pjsua_config_default(&cfg);
	cfg.cb.on_incoming_call = &on_incoming_call;
	cfg.cb.on_call_media_state = &on_call_media_state;
	cfg.cb.on_call_state = &on_call_state;

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

	status = pjsua_init(&cfg, &log_cfg, NULL);
	if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
    }
	pjsua_media_config media_cfg;
	 pjsua_media_config_default(&media_cfg);

    /* Add UDP transport. */
    {
		pjsua_transport_config cfg;
		pjsua_transport_config_default(&cfg);
		cfg.port = 55060;
		status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
		if (status != PJ_SUCCESS)
		{
			error_exit("Error creating transport", status) ;
		}
    }

    /* Initialization is done, now start pjsua */
    status = pjsua_start();
    if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);

    /* Register to SIP server by creating SIP account. */
    {
	pjsua_acc_config cfg;

	pjsua_acc_config_default(&cfg);	
	
	char reg_uri[5 + strlen(domain)];
	char id[6+strlen(user)+strlen(passwd)];
	char proxy_uri[22+strlen(proxy)];

	sprintf( reg_uri, "sip:%s", domain);
	sprintf( id, "sip:%s@%s", user, domain);
	sprintf( proxy_uri, "sip:%s;lr;transport=UDP", proxy);
	
	cfg.id = pj_str(id);
    cfg.reg_uri = pj_str(reg_uri);
    cfg.cred_count = 1;
    cfg.cred_info[0].scheme = pj_str((char*)"digest");
    cfg.cred_info[0].realm = pj_str(domain);
    cfg.cred_info[0].username = pj_str(user);
    cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
    cfg.cred_info[0].data = pj_str(passwd);
    cfg.proxy_cnt = 1;

    cfg.proxy[0] = pj_str(proxy_uri);

	status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
	if (status != PJ_SUCCESS) error_exit("Error adding account", status);
    }
	return acc_id;
}