0
我正在使用下面的代碼來初始化pjsua。pjsip聲明失敗:mod_tsx_layer.endpt ==((void *)0)
status = pjsua_create();
if (status != PJ_SUCCESS)
error_exit("Error in pjsua_create()", status);
// Init pjsua
{
// Init the config structure
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;
cfg.cb.on_reg_state2 = &on_reg_state2;
cfg.cb.on_call_tsx_state = &on_call_tsx_state;
// Init the logging config structure
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4;
// Init the pjsua
status = pjsua_init(&cfg, &log_cfg, NULL);
if (status != PJ_SUCCESS)
error_exit("Error in pjsua_init()", status);
}
// Add UDP transport.
{
// Init transport config structure
pjsua_transport_config cfg; //For the one on public
pjsua_transport_config_default(&cfg);
cfg.port = SIP_PORT;
// Add UDP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
}
// Add TCP transport.
{
// Init transport config structure
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = SIP_PORT;
//cfg.port=sipPORT;
// Add TCP transport.
status = pjsua_transport_create(PJSIP_TRANSPORT_TCP, &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 the account on local sip server
{
pjsua_acc_config cfg;
pjsua_acc_config_default(&cfg);
// Account ID
char sipId[MAX_SIP_ID_LENGTH];
sprintf(sipId, "sip:%[email protected]%s", sipUser, sipDomain);
cfg.id = pj_str(sipId);
// Reg URI
char regUri[MAX_SIP_REG_URI_LENGTH];
//sprintf(regUri, "sip:%s", sipDomain);
sprintf(regUri, "sip:%s", sipDomain);
cfg.reg_uri = pj_str(regUri);
NSLog(@"regUri %s",regUri);
// Account cred info
cfg.cred_count = 1;
cfg.cred_info[0].scheme = pj_str("digest");
cfg.cred_info[0].realm = pj_str("*");
//cfg.cred_info[0].realm = pj_str(sipDomain);
cfg.cred_info[0].username = pj_str(sipUser);
cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
cfg.cred_info[0].data = pj_str(password);
status = pjsua_acc_add(&cfg, PJ_TRUE, &_acc_id);
if (status != PJ_SUCCESS) error_exit("Error adding account", status);
}
pj_pool_t *pool = NULL;
unsigned i;
/* Must init PJLIB first: */
status = pj_init();
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
pj_log_set_level(5);
/* Then init PJLIB-UTIL: */
status = pjlib_util_init();
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
/* Must create a pool factory before we can allocate any memory. */
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
/* Create global endpoint: */
{
const pj_str_t *hostname;
const char *endpt_name;
/* Endpoint MUST be assigned a globally unique name.
* The name will be used as the hostname in Warning header.
*/
/* For this implementation, we'll use hostname for simplicity */
hostname = pj_gethostname();
endpt_name = hostname->ptr;
/* Create the endpoint: */
status = pjsip_endpt_create(&cp.factory, endpt_name,
&g_endpt);
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
}
/*
* Add UDP transport, with hard-coded port
* Alternatively, application can use pjsip_udp_transport_attach() to
* start UDP transport, if it already has an UDP socket (e.g. after it
* resolves the address with STUN).
*/
{
pj_sockaddr addr;
pj_sock_t sock;
pjsip_transport *p_trans;
pjsip_host_port *host_port;
host_port->host=pj_str("10.10.10.10");
host_port->port=5060;
status=pj_sock_socket(AF,pj_SOCK_DGRAM(),PJSIP_TRANSPORT_UDP,&sock);
if (status != PJ_SUCCESS)
{
app_perror(THIS_FILE, "Unable to init pj sock", status);
return 1;
}
if (AF == pj_AF_INET())
{
status = pjsip_udp_transport_attach(g_endpt,sock,host_port,1,&p_trans);
}
else if (AF == pj_AF_INET6()) {
status = pjsip_udp_transport_start6(g_endpt, &addr.ipv6, NULL,
1, NULL);
}
else
{
status = PJ_EAFNOTSUP;
}
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Unable to start UDP transport", status);
return 1;
}
}
/*
* Init transaction layer.
* This will create/initialize transaction hash tables etc.
*/
//printf("Endpoint: %s\n", pjsip_endpt_name(g_endpt)->ptr);
status = pjsip_tsx_layer_init_module(g_endpt);
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
/*
* Initialize UA layer module.
* This will create/initialize dialog hash tables etc.
*/
status = pjsip_ua_init_module(g_endpt, NULL);
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
但是我面臨嚴重的問題。程序執行停止在這個錯誤。
Assertion failed: mod_tsx_layer.endpt==((void *)0),
file pjsip\src\pjsip\sip_transaction.c, line 436
雖然我初始化並附加UDP事務層兩次不同。我沒有第二次創建傳輸層。這段代碼有什麼問題?您還可以檢查發佈在this鏈接中的問題。