gpt4 book ai didi

c - PJSip 拨出电话不起作用

转载 作者:行者123 更新时间:2023-12-02 09:57:49 28 4
gpt4 key购买 nike

我正在开发一个iOS应用程序,其功能是使用PJSUA调用电话。同时,我的同事正在使用 PJSUA 2 为 Android 制作相同的应用程序。当我们从 Android 到 iOS 或从 Android 到 Android 进行调用时,一切正常。但是当我们尝试从 iOS 调用 Android 或从 iOS 调用 iOS 时,我们会收到错误:

18:51:46.959  pjsua_media.c  .....Call 0: updating media..
18:51:46.959 pjsua_media.c .......Media stream call00:0 is destroyed
18:51:46.959 pjsua_media.c ......pjmedia_transport_media_start() failed for call_id 0 media 0: SRTP crypto-suite name not match the offerer tag (PJMEDIA_SRTP_ECRYPTONOTMATCH)
18:51:46.959 pjsua_media.c .......Media stream call00:0 is destroyed
18:51:46.960 pjsua_media.c ......Error updating media call00:0: SRTP crypto-suite name not match the offerer tag (PJMEDIA_SRTP_ECRYPTONOTMATCH)
18:51:46.960 pjsua_core.c .....TX 362 bytes Request msg ACK/cseq=19029 (tdta0x1200c1600) to TLS 95.213.169.231:1605:
ACK sip:s2@95.213.169.231:1605;transport=tls SIP/2.0

这是我的类(class),它正在使用 PJSUA:

#import <Foundation/Foundation.h>
#import "SIPConnection.h"
#import <pjlib.h>
#import <pjsua.h>
#import <pj/log.h>
#import <pjmedia-codec.h>
#import <pjmedia.h>

@interface SIPConnection ()

@end

@implementation SIPConnection

pjsua_acc_id acc_id = -1;
pjsua_call_id current_call_id = -1;
bool registration_status_is_ok = false;
bool is_making_call = false;

-(void) registerAccount {
registerAccount();
}

-(void) makeCall {
is_making_call = true;
registerAccount();
}

void registerAccount() {

pjsua_create();

pjsua_config ua_cfg;
pjsua_logging_config log_cfg;
pjsua_media_config media_cfg;

char* user_agent_string = "XChat";
pj_str_t user_agent = pj_str(user_agent_string);
ua_cfg.user_agent = user_agent;
pjsua_config_default(&ua_cfg);
pjsua_logging_config_default(&log_cfg);
pjsua_media_config_default(&media_cfg);

ua_cfg.cb.on_reg_state = &sip_reg_state_changed;
ua_cfg.cb.on_call_state = &sip_call_state_changed;
ua_cfg.cb.on_call_media_state = &sip_call_media_state_changed;
ua_cfg.cb.on_incoming_call = &sip_incoming_call;

media_cfg.ec_options = 3;
media_cfg.ec_tail_len = 1000;

pjsua_init(&ua_cfg, &log_cfg, &media_cfg);

pjsua_transport_config transport_cfg;
pjsua_transport_config_default(&transport_cfg);
transport_cfg.port = 1605;
pjsua_transport_id trasport_id;

pjsua_transport_create(PJSIP_TRANSPORT_TLS, &transport_cfg, &trasport_id);

pjsua_acc_config acc_cfg;
pjsua_acc_config_default(&acc_cfg);

acc_cfg.register_on_acc_add = YES;
acc_cfg.priority = 100;
acc_cfg.reg_retry_interval = 3;
acc_cfg.reg_retry_random_interval = 3;
acc_cfg.publish_enabled = NO;
acc_cfg.unreg_timeout = 1500;
acc_cfg.reg_first_retry_interval = 5;
acc_cfg.reg_delay_before_refresh = 0;
char* reg_uri_string = "sip:95.213.169.231:1605;transport=TLS";
char* acc_uri_string = "sip:s2@95.213.169.231:1605";
pj_str_t reg_uri = pj_str(reg_uri_string);
pj_str_t acc_uri = pj_str(acc_uri_string);
acc_cfg.reg_uri = reg_uri;
acc_cfg.cred_info[0].scheme=pj_str("digest");
acc_cfg.cred_info[0].data_type=0;
acc_cfg.cred_info[0].username=pj_str("s2");
acc_cfg.cred_info[0].realm=pj_str("*");
acc_cfg.cred_info[0].data=pj_str("LHillKkF4Aflc3rR");
acc_cfg.cred_count = 1;
acc_cfg.use_srtp = PJMEDIA_SRTP_MANDATORY;
acc_cfg.srtp_secure_signaling = 1;
acc_cfg.allow_sdp_nat_rewrite = 1;
acc_cfg.allow_contact_rewrite = 1;
acc_cfg.id = acc_uri;



pjsua_acc_add(&acc_cfg, YES, &acc_id);

pjsua_start();

}

static void sip_reg_state_changed(pjsua_acc_id acc_id) {
pjsua_acc_info acc_info;
pj_status_t status = pjsua_acc_get_info(acc_id, &acc_info);
if (status != PJ_SUCCESS) {
NSLog(@"Couldn't get account status");
registration_status_is_ok = false;
return;
}
if (acc_info.status == 200) {
NSLog(@"Account is registered!");
registration_status_is_ok = true;
make_call();
}
}

static void sip_call_state_changed(pjsua_call_id call_id, pjsip_event* event) {

}

static void sip_call_media_state_changed(pjsua_call_id call_id) {
pjsua_call_info call_info;
unsigned mi;
pj_bool_t has_error = PJ_FALSE;
pjsua_call_get_info(call_id, &call_info);



current_call_id = call_id;

mi=0;

//for (mi=0; mi<call_info.media_cnt; ++mi) {
on_call_generic_media_state(&call_info, mi, &has_error);

switch (call_info.media[mi].type) {
case PJMEDIA_TYPE_AUDIO:
on_call_audio_state(&call_info, mi, &has_error);
break;
}
//}
}

static void on_call_audio_state(pjsua_call_info *ci, unsigned mi, pj_bool_t *has_error)
{
PJ_UNUSED_ARG(has_error);
/* Stop ringback */
//ring_stop(ci->id);

/* Connect ports appropriately when media status is ACTIVE or REMOTE HOLD,
457 * otherwise we should NOT connect the ports.
458 */

if (ci->media[mi].status == PJSUA_CALL_MEDIA_ACTIVE || ci->media[mi].status == PJSUA_CALL_MEDIA_REMOTE_HOLD)
{
pj_bool_t connect_sound = PJ_TRUE;
pj_bool_t disconnect_mic = PJ_FALSE;
pjsua_conf_port_id call_conf_slot;

call_conf_slot = ci->media[mi].stream.aud.conf_slot;

if (connect_sound) {
pj_status_t res = pjsua_conf_connect(call_conf_slot, 0);
if (!disconnect_mic)
{
res = pjsua_conf_connect(0, call_conf_slot);
}
}
}
}

static void on_call_generic_media_state(pjsua_call_info *ci, unsigned mi, pj_bool_t *has_error)
{
const char *status_name[] = {
"None",
"Active",
"Local hold",
"Remote hold",
"Error"

};

PJ_UNUSED_ARG(has_error);

pj_assert(ci->media[mi].status <= PJ_ARRAY_SIZE(status_name));
pj_assert(PJSUA_CALL_MEDIA_ERROR == 4);
}



static void sip_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata)
{
pjsua_call_info call_info;
pjsua_call_get_info(call_id, &call_info);

pjsua_call_answer(call_id, 200, NULL, NULL);
}

static void make_call()
{
if ((registration_status_is_ok) && (is_making_call))
{
pjsua_call_setting call_stg;
pjsua_call_setting_default(&call_stg);
call_stg.aud_cnt = 1;
call_stg.vid_cnt = 0;

// pjsua_call_id call_id;

pj_str_t dst_uri = pj_str("sip:s3@95.213.169.231:1605;transport=TLS");

pjsua_call_make_call(acc_id, &dst_uri, &call_stg, NULL, NULL, NULL);

}
}

static void end_call()
{
/*if (current_call_id != -1)
{
pjsua_call_dump(current_call_id, YES, NULL, 8, NULL);
}*/
if (acc_id != -1)
{
pjsua_acc_del(acc_id);
}
pjsua_destroy();
}

- (void)endCall
{
end_call();
}

@end

有人可以帮忙吗?我实在是没主意了。

最佳答案

似乎您在调用电话时还需要发送 callID,

pjsua_call_id call_id;

pj_str_t dst_uri = pj_str("sip:s3@95.213.169.231:1605;transport=TLS");

pjsua_call_make_call(acc_id, &dst_uri, &call_stg, NULL, NULL, &call_id);

关于c - PJSip 拨出电话不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46533727/

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