Dear All, I am trying to develop Proxy switch using PJSIP. I received INVITE message from server1 and I want to send INVITE message to server2. After receiving a response from server2 I will send response to server1. However, after receiving the INVITE message I send INVITE message but I get assertion error. My Logic : Server1 ------------> INVITE <----------- TRY INVITE ---------------------> Server 2 <------------------ TRY/ Response <----------- Response Here is my code: /** * Handler when there is incoming call. */ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata) { pjsua_call_info call_info; pjsua_msg_data msg_data; pjsua_call_setting call_opt; //PJ_UNUSED_ARG(acc_id); PJ_UNUSED_ARG(rdata); pjsua_call_get_info(call_id, &call_info); if (current_call==PJSUA_INVALID_ID) current_call = call_id; pjsua_call_setting_default(&call_opt); call_opt.aud_cnt = app_config.aud_cnt; call_opt.vid_cnt = app_config.vid.vid_cnt; int flag = prepare_for_invite_sw2(); if(flag) make_call("sip:server2.com"); int st_code; char contact[120]; pj_str_t hname = { "Contact", 7 }; pj_str_t hvalue; pjsip_generic_string_hdr hcontact; if(strcmp(call_info.remote_info.ptr,"<sip:panda at 192.168.1.11>") == 0) st_code = 403; else st_code = 404; /** Local URI */ pj_str_t local_info; /** Local Contact */ pj_str_t local_contact; /** Remote URI */ pj_str_t remote_info; /** Remote contact */ pj_str_t remote_contact; pjsua_msg_data_init(&msg_data); pjsua_call_answer2(call_id, &call_opt, st_code, NULL, &msg_data); ring_start(call_id); if (app_config.auto_answer > 0) { pjsua_call_setting call_opt; pjsua_call_setting_default(&call_opt); call_opt.aud_cnt = app_config.aud_cnt; call_opt.vid_cnt = app_config.vid.vid_cnt; pjsua_call_answer2(call_id, &call_opt, app_config.auto_answer, NULL, NULL); } } static pjsip_module mod_app = { NULL, NULL, /* prev, next. */ { "mod-app", 7 }, /* Name. */ -1, /* Id */ PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */ NULL, /* load() */ NULL, /* start() */ NULL, /* stop() */ NULL, /* unload() */ NULL, /* on_rx_request() */ NULL, /* on_rx_response() */ NULL, /* on_tx_request. */ NULL, /* on_tx_response() */ &on_tsx_state /* on_tsx_state() */ }; /* Worker thread */ static int worker_thread(void *arg) { PJ_UNUSED_ARG(arg); while (!quit_flag) { pj_time_val timeout = {0, 500}; pjsip_endpt_handle_events(pjsua_get_pjsip_endpt(), &timeout); } return 0; } /* Send request */ static void send_request_to_sw2(const pjsip_method *method, int cseq, const pj_str_t *branch, pj_bool_t with_offer) { pjsip_tx_data *tdata; pj_str_t dummy_sdp_str = { "v=0\r\n" "o=VoipSwitch 7434 7434 IN IP4 server1.com\r\n" "s=VoipSIP\r\n" "i=Audio Session\r\n" "c=IN IP4 server1.com\r\n" "t=0 0\r\n" "m=audio 6434 RTP/AVP 18\r\n" "a=rtpmap:18 G729/8000/1\r\n" "a=fmtp:18 annexb=no\r\n" "a=sendrecv\r\n", 0 }; pj_status_t status; status = pjsip_dlg_create_request(dlg, method, cseq, &tdata); pj_assert(status == PJ_SUCCESS); if (branch) { pjsip_via_hdr *via; via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); pj_strdup(tdata->pool, &via->branch_param, branch); } if (with_offer) { pjsip_msg_body *body; pj_str_t mime_application = { "application", 11}; pj_str_t mime_sdp = {"sdp", 3}; dummy_sdp_str.slen = pj_ansi_strlen(dummy_sdp_str.ptr); body = pjsip_msg_body_create(tdata->pool, &mime_application, &mime_sdp, &dummy_sdp_str); tdata->msg->body = body; } status = pjsip_dlg_send_request(dlg, tdata, -1, NULL); pj_assert(status == PJ_SUCCESS); } /* Callback to handle incoming requests. */ static void on_tsx_state(pjsip_transaction *tsx, pjsip_event *event) { if (tsx->role == PJSIP_ROLE_UAC) { if (tsx->method.id == PJSIP_INVITE_METHOD && tsx->state == PJSIP_TSX_STATE_TERMINATED) { #if SAME_BRANCH send_request_to_sw2(&pjsip_ack_method, tsx->cseq, &tsx->branch, ACK_HAS_SDP); #else send_request_to_sw2(&pjsip_ack_method, tsx->cseq, NULL, ACK_HAS_SDP); #endif } } else { if (event->type == PJSIP_EVENT_RX_MSG && tsx->state == PJSIP_TSX_STATE_TRYING) { pjsip_tx_data *tdata; pjsip_dlg_create_response(dlg, event->body.tsx_state.src.rdata, 200, NULL, &tdata); pjsip_dlg_send_response(dlg, tsx, tdata); } } } /* make call */ void make_call(char *uri) { pj_bool_t with_offer = PJ_FALSE; pj_str_t local = pj_str("sip:myserver.com:5060"); pj_str_t remote = pj_str(uri); pj_status_t status; status = pjsip_dlg_create_uac(pjsip_ua_instance(), &local, &local, &remote, &remote, &dlg); pj_assert(status == PJ_SUCCESS); pjsip_dlg_inc_lock(dlg); status = pjsip_dlg_add_usage(dlg, &mod_app, NULL); pj_assert(status == PJ_SUCCESS); pjsip_dlg_inc_session(dlg, &mod_app); send_request_to_sw2(&pjsip_invite_method, -1, NULL, with_offer); pjsip_dlg_dec_lock(dlg); } int prepare_for_invite_sw2(void) { pj_caching_pool cp; pj_thread_t *thread; pj_pool_t *pool; pj_status_t status; /* Must create a pool factory before we can allocate any memory. */ pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); /* Create the endpoint: */ status = pjsip_endpt_create(&cp.factory, "sipstateless", &pjsua_get_pjsip_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); //* Add UDP transport, with hard-coded port { pj_sockaddr_in addr; addr.sin_family = pj_AF_INET(); addr.sin_addr.s_addr = 0; addr.sin_port = pj_htons(PORT); status = pjsip_udp_transport_start( pjsua_get_pjsip_endpt(), &addr, NULL, 1, NULL); if (status != PJ_SUCCESS) { PJ_LOG(3,(THIS_FILE, "Error starting UDP transport (port in use?)")); return 1; } } status = pjsip_tsx_layer_init_module(pjsua_get_pjsip_endpt()); pj_assert(status == PJ_SUCCESS); status = pjsip_ua_init_module(pjsua_get_pjsip_endpt(), NULL); pj_assert(status == PJ_SUCCESS); //* Register our module to receive incoming requests. status = pjsip_endpt_register_module( pjsua_get_pjsip_endpt(), &mod_app); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); pool = pjsip_endpt_create_pool(pjsua_get_pjsip_endpt(), "", 1000, 1000); status = pj_thread_create(pool, "", &worker_thread, NULL, 0, 0, &thread); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); return 1; } ?do I need initializing endpoint, transacton, poll, etc 2nd time?? ? ? ?I can receive INVITE message by on_incoming_call callback and all are initialized previously.? ?Thanks? -- Tasfin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20140217/250efe0f/attachment-0001.html>