2013-12-15 16 views
1

我正在嘗試偵聽基於Qt控制檯的應用程序中的多個端口上的SIP消息。我只是創建我的班級的多個對象代理。 proxy.cpp的使用Qt和pjsip在一個應用程序內監聽多個端口上的SIP

樣品例如:

proxy* thisProxy; 
proxy::proxy(quint16 port, QObject *parent) : 
    QObject(parent), portFromConfig(port) 
{ 
    thisProxy = this; 
    thread = new QThread(this); 
    connect(thread, SIGNAL(started()), this, SLOT(start())); 
    connect(thread, SIGNAL(finished()), this, SLOT(deleteLater())); 
    this->moveToThread(thread); 
    thread->start(); 
} 

void proxy::start() 
{ 
    pj_status_t status; 
    pj_caching_pool caching_pool; 
    pj_sockaddr_in sockaddr; 
    pj_str_t ourAddressFromConfig; 

    pj_thread_desc initdec; 
    pj_thread_t* thread = 0; 

    if (!pj_thread_is_registered() && pj_thread_register("PJ_THREAD", initdec, &thread) != PJ_SUCCESS) 
     return; 

    pjsip_module proxy = { 
     NULL, 
     NULL, 
     pj_str("proxy"), 
     -1, 
     PJSIP_MOD_PRIORITY_UA_PROXY_LAYER, 
     NULL, 
     NULL, 
     NULL, 
     NULL, 
     &onReceivedRequest, 
     &onReceivedResponse, 
     NULL, 
     NULL, 
     NULL 
    }; 

    pj_log_set_level(4); 

    //initialize pj 
    status = pj_init(); 
    if (status != PJ_SUCCESS) 
    { 
     qDebug() << "pj_init failed"; 
     return; 
    } 

    //initilaize pjlib_util 
    status = pjlib_util_init(); 
    if (status != PJ_SUCCESS) 
    { 
     qDebug() << "pjlib_util_init failed"; 
     return; 
    } 

    //initialize caching pool 
    pj_caching_pool_init(&caching_pool, &pj_pool_factory_default_policy, 0); 

    //create the endpoint 
    status = pjsip_endpt_create(&caching_pool.factory, NULL, &endpoint); 
    if (status != PJ_SUCCESS) 
    { 
     qDebug() << "pjsip_endpt_create failed"; 
     return; 
    } 

    //specify our socket 
    ourAddressFromConfig = pj_str(addressFromConfig.toLatin1().data()); 
    sockaddr.sin_family = pj_AF_INET(); 

    if (ourAddressFromConfig.slen) 
     pj_inet_aton(&ourAddressFromConfig, &sockaddr.sin_addr); 
    else 
     sockaddr.sin_addr.s_addr = 0; 

    sockaddr.sin_port = pj_htons((pj_uint16_t) portFromConfig); 

    //start the socket 
    status = pjsip_udp_transport_start(endpoint, &sockaddr, NULL, 1, &transport); 
    if (status != PJ_SUCCESS) 
    { 
     qDebug() << "pjsip_udp_transport_start failed"; 
     return; 
    } 

    //create the caching pool 
    poolt = pj_pool_create(&caching_pool.factory, "UDPproxy", 4000, 4000, NULL); 

    //register the proxy module 
    status = pjsip_endpt_register_module(endpoint, &proxy); 
    if (status != PJ_SUCCESS) 
    { 
     qDebug() << "pjsip_endpt_register_module failed"; 
     return; 
    } 

    pj_time_val delay = {0, 10}; 

    while(true) 
    { 
     pjsip_endpt_handle_events(endpoint, &delay); 
    } 

    qDebug() << "finished"; 
} 

最有趣的事情是,當我創建代理其工作的前兩個實例,但是,當我創建的第三個實例我的應用程序與這些錯誤終止:從傾倒芯

server: ../src/pjsip/sip_tel_uri.c:173: pjsip_tel_uri_subsys_init: Assertion `status==0' failed. 
Aborted (core dumped) 

回溯:

(gdb) bt 
#0 0xb777d424 in __kernel_vsyscall() 
#1 0xb6e881df in raise() from /lib/i386-linux-gnu/libc.so.6 
#2 0xb6e8b825 in abort() from /lib/i386-linux-gnu/libc.so.6 
#3 0xb6e81085 in ??() from /lib/i386-linux-gnu/libc.so.6 
#4 0xb6e81137 in __assert_fail() from /lib/i386-linux-gnu/libc.so.6 
#5 0x08079344 in pjsip_tel_uri_subsys_init() 
#6 0x08069265 in pjsip_endpt_create() 
#7 0x080569a7 in proxy::start (this=0x8905db8) at ../server/proxy.cpp:93 
#8 0x0805f0c1 in proxy::qt_static_metacall (_o=0x8905db8, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0xb3aff270) at moc_proxy.cpp:75 
#9 0xb73d4c5d in QMetaObject::activate(QObject*, int, int, void**)() from /home/dev/Qt/5.1.1/gcc/lib/libQt5Core.so.5 
#10 0xb73d567b in QMetaObject::activate(QObject*, QMetaObject const*, int, void**)() from /home/dev/Qt/5.1.1/gcc/lib/libQt5Core.so.5 
#11 0xb7444ef5 in QThread::started(QThread::QPrivateSignal)() from /home/dev/Qt/5.1.1/gcc/lib/libQt5Core.so.5 
#12 0xb71d7388 in ??() from /home/dev/Qt/5.1.1/gcc/lib/libQt5Core.so.5 
#13 0xb713ad4c in start_thread() from /lib/i386-linux-gnu/libpthread.so.0 
#14 0xb6f49bae in clone() from /lib/i386-linux-gnu/libc.so.6 

我不知道我在做什麼錯。請有人幫忙嗎?

在此先感謝您的幫助。

+0

可能'endpoint'是一個靜態變量它連接到終點?似乎你想創建一個tel端點,但是'endpoint'變量的狀態不是NULL。 – jcm

+0

對不起,變量endpoint在_proxy.h_中聲明爲這樣的保護變量:'protected:pjsip_endpoint * endpoint;' – Cockootec

回答

0

主要問題是您要在每個proxy實例上創建一個新的SIP端點,儘管當前文檔聲明「理論上」支持多個SIP端點實例,但事實上並非如此。

更具體地說,第一次調用pjsip_endpt_create三個靜態URI解析器的登記(用於sip:sips:tel:),tel:再次註冊第二次(有檢查,以避免sip:sips:而不是tel:),當試圖在第三次再次註冊tel:時,超過了URI解析器(4)的最大數量,註冊失敗並且斷言轉儲。

我建議你只有一個SIP終端工作,爲每一位proxy實例創建一個新的UDP套接字,並通過使用pjsip_udp_transport_attach2

+0

謝謝。我會嘗試一下,我會給予反饋。 – Cockootec

+0

@IvanBarlog你能檢查它嗎? – jcm

+0

我很抱歉,但我沒有嘗試。我不再需要這個。我認爲我反正會嘗試,但我無法爲此找到時間。 – Cockootec

相關問題