我使用以下代码初始化pjsua。
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:%s@%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链接中发布的问题。
答案 0 :(得分:0)
删除此部分:
// Init the logging config structure
pjsua_logging_config log_cfg;
pjsua_logging_config_default(&log_cfg);
og_cfg.console_level = 4;
并检查
答案 1 :(得分:0)
请查看此代码,您可能会得到您的解决方案。
pj_status_t sip_startup(app_config_t *app_config)
{
pj_status_t status;
long val;
char tmp[80];
pjsua_transport_id transport_id = -1;
const char *srv;
const char *ip_addr;
NSArray * array;
NSString *dns;
AppDelegate *app = (AppDelegate *)[AppDelegate sharedApplication];
/* Create pjsua first! */
status = pjsua_create();
if (status != PJ_SUCCESS)
return status;
/* Create pool for application */
app_config->pool = pjsua_pool_create("pjsua", 1000, 1000);
/* Initialize default config */
pjsua_config_default(&(app_config->cfg));
pj_ansi_snprintf(tmp, 80, "Siphon PjSip v%s/%s", pj_get_version(), PJ_OS_NAME);
pj_strdup2_with_null(app_config->pool, &(app_config->cfg.user_agent), tmp);
pjsua_logging_config_default(&(app_config->log_cfg));
val = [[NSUserDefaults standardUserDefaults] integerForKey:
@"logLevel"];
#ifdef RELEASE_VERSION
app_config->log_cfg.msg_logging = PJ_FALSE;
app_config->log_cfg.console_level = 0;
app_config->log_cfg.level = 0;
#else
app_config->log_cfg.msg_logging = (val!=0 ? PJ_TRUE : PJ_FALSE);
app_config->log_cfg.console_level = val;
app_config->log_cfg.level = val;
if (val != 0)
{
#if defined(CYDIA) && (CYDIA == 1)
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *path = [NSString stringWithFormat:@"%@/Siphon", [filePaths objectAtIndex:0]];
#else
NSArray *filePaths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *path = [filePaths objectAtIndex: 0];
#endif
//NSString *path = NSTemporaryDirectory();
path = [path stringByAppendingString: @"/log.txt"];
app_config->log_cfg.log_filename = pj_strdup3(app_config->pool,
[path UTF8String]);
}
#endif
pjsua_media_config_default(&(app_config->media_cfg));
// TODO select clock rate with enabled codec (8000 if nb codec only, or 16000 and more if wb codec)
//app_config->media_cfg.clock_rate = 8000;
//app_config->media_cfg.snd_clock_rate = 8000;
app_config->media_cfg.clock_rate = 16000;
app_config->media_cfg.snd_clock_rate = 16000;
//app_config->media_cfg.ec_options = 0;//0=default,1=speex, 2=suppressor
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"enableEC"])
app_config->media_cfg.ec_tail_len = 0;
// Enable/Disable VAD/silence detector
app_config->media_cfg.no_vad = [[NSUserDefaults standardUserDefaults]
boolForKey:@"disableVad"];
app_config->media_cfg.snd_auto_close_time = 0;
//app_config->media_cfg.quality = 2;
//app_config->media_cfg.channel_count = 2;
app_config->media_cfg.enable_ice = [[NSUserDefaults standardUserDefaults]
boolForKey:@"enableICE"];
pjsua_transport_config_default(&(app_config->udp_cfg));
val = [[NSUserDefaults standardUserDefaults] integerForKey: @"localPort"];
if (val < 0 || val > 65535)
{
PJ_LOG(1,(THIS_FILE,
"Error: local-port argument value (expecting 0-65535"));
[app displayParameterError:
@"Invalid value for Local Port (expecting 1-65535)."];
status = PJ_EINVAL;
goto error;
}
app_config->udp_cfg.port = val;
pjsua_transport_config_default(&(app_config->rtp_cfg));
app_config->rtp_cfg.port = [[NSUserDefaults standardUserDefaults]
integerForKey: @"rtpPort"];
if (app_config->rtp_cfg.port == 0)
{
enum { START_PORT=4000 };
unsigned range;
range = (65535-START_PORT-PJSUA_MAX_CALLS*2);
app_config->rtp_cfg.port = START_PORT +
((pj_rand() % range) & 0xFFFE);
}
if (app_config->rtp_cfg.port < 1 || app_config->rtp_cfg.port > 65535)
{
PJ_LOG(1,(THIS_FILE,
"Error: rtp-port argument value (expecting 1-65535)"));
[app displayParameterError:
@"Invalid value for RTP port (expecting 1-65535)."];
status = PJ_EINVAL;
goto error;
}
#if 1 // TEST pour le vpn
ip_addr = [[[NSUserDefaults standardUserDefaults] stringForKey:
@"boundAddr"] UTF8String];
if (ip_addr && strlen(ip_addr))
{
pj_strdup2_with_null(app_config->pool,
&(app_config->udp_cfg.bound_addr),
ip_addr);
pj_strdup2_with_null(app_config->pool,
&(app_config->rtp_cfg.bound_addr),
ip_addr);
}
ip_addr = [[[NSUserDefaults standardUserDefaults] stringForKey:
@"publicAddr"] UTF8String];
if (ip_addr && strlen(ip_addr))
{
pj_strdup2_with_null(app_config->pool,
&(app_config->udp_cfg.public_addr),
ip_addr);
pj_strdup2_with_null(app_config->pool,
&(app_config->rtp_cfg.public_addr),
ip_addr);
}
#endif
/* Initialize application callbacks */
app_config->cfg.cb.on_call_state = &on_call_state;
app_config->cfg.cb.on_call_media_state = &on_call_media_state;
app_config->cfg.cb.on_incoming_call = &on_incoming_call;
app_config->cfg.cb.on_reg_state = &on_reg_state;
#if defined(MWI) && MWI==1
app_config->cfg.cb.on_mwi_info = &on_mwi_info;
app_config->cfg.enable_unsolicited_mwi = PJ_TRUE;
#endif
srv = [[[NSUserDefaults standardUserDefaults] stringForKey:
@"stunServer"] UTF8String];
if (srv && strlen(srv))
{
if (app_config->cfg.stun_srv_cnt==PJ_ARRAY_SIZE(app_config->cfg.stun_srv))
{
PJ_LOG(1,(THIS_FILE, "Error: too many STUN servers"));
return PJ_ETOOMANY;
}
pj_strdup2_with_null(app_config->pool,
&(app_config->cfg.stun_srv[app_config->cfg.stun_srv_cnt++]),
srv);
}
// app_config->cfg.outbound_proxy[0] = pj_str(outbound_proxy);
// app_config->cfg.outbound_proxy_cnt = 1;
dns = [[NSUserDefaults standardUserDefaults] stringForKey: @"dnsServer"];
array = [dns componentsSeparatedByString:@","];
NSEnumerator *enumerator = [array objectEnumerator];
NSString *anObject;
while (anObject = [enumerator nextObject])
{
NSMutableString *mutableStr = [anObject mutableCopy];
CFStringTrimWhitespace((CFMutableStringRef)mutableStr);
srv = [mutableStr UTF8String];
if (srv && strlen(srv))
{
if (app_config->cfg.nameserver_count==PJ_ARRAY_SIZE(app_config->cfg.nameserver))
{
PJ_LOG(1,(THIS_FILE, "Error: too many DNS servers"));
[mutableStr release];
break;
}
pj_strdup2_with_null(app_config->pool,
&(app_config->cfg.nameserver[app_config->cfg.nameserver_count++]),
srv);
}
[mutableStr release];
}
//[enumerator release];
//[array release];
/* Initialize pjsua */
status = pjsua_init(&app_config->cfg, &app_config->log_cfg,
&app_config->media_cfg);
if (status != PJ_SUCCESS)
goto error;
/* Initialize Ring and Ringback */
sip_ring_init(app_config);
/* Add UDP transport. */
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP,
&app_config->udp_cfg, &transport_id);
if (status != PJ_SUCCESS)
goto error;
/* Add RTP transports */
// status = pjsua_media_transports_create(&app_config->rtp_cfg);
// if (status != PJ_SUCCESS)
// goto error;
#if LOCAL_ACCOUNT
{
if (status == PJ_SUCCESS && transport_id != -1)
{
/* Add local account */
pjsua_acc_add_local(transport_id, PJ_TRUE, &aid);
}
}
#endif
/* */
sip_manage_codec();
/* Initialization is done, now start pjsua */
status = pjsua_start();
if (status != PJ_SUCCESS)
goto error;
return status;
error:
sip_cleanup(app_config);
return status;
}