gpt4 book ai didi

c++ - 使用 Qt 和 pjsip 在一个应用程序中的多个端口上监听 SIP

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:58 26 4
gpt4 key购买 nike

我正在尝试在基于 Qt 控制台的应用程序中的多个端口上监听 SIP 消息。我只是在创建我的类代理的多个对象。

proxy.cpp 示例:

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";
}

最有趣的是,当我创建前两个 proxy 实例时,它可以正常工作,但是当我创建第三个实例时,我的应用程序因这些错误而终止:

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

我不知道我做错了什么。有人可以帮忙吗?

在此先感谢您的帮助。

最佳答案

主要问题是您要在每个 proxy 实例上创建一个新的 SIP 端点,尽管当前文档指出“理论上”支持 SIP 端点的多个实例,但实际上并非如此.

更具体地说,当您第一次调用 pjsip_endpt_create 时,会注册三个静态 URI 解析器(用于 sip:sips:tel :), 第二次tel:又被注册了(有检查避免sip:sips:但不是tel:) 并且,当第三次尝试再次注册 tel: 时,超过了 URI 解析器的最大数量 (4),注册失败并且断言转储。

我建议您只使用一个 SIP 端点,为每个 proxy 实例创建一个新的 UDP 套接字,并使用 pjsip_udp_transport_attach2 将其附加到端点

关于c++ - 使用 Qt 和 pjsip 在一个应用程序中的多个端口上监听 SIP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20595836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com