From 2da7b1d53990f297d6f24b411b70a16ff4cfd9f4 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Mon, 23 Apr 2012 13:27:29 +0000 Subject: Fixed #1493: Fixed bug in terminating the invite session when accepting incoming call. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4068 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsua-lib/pjsua_call.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index fc6a7ed3..b8cf6b37 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -850,12 +850,19 @@ on_incoming_call_med_tp_complete(pjsua_call_id call_id, on_return: if (status != PJ_SUCCESS) { - pjsip_tx_data *tdata; - pj_status_t status_; - - status_ = pjsip_inv_end_session(call->inv, sip_err_code, NULL, &tdata); - if (status_ == PJ_SUCCESS && tdata) - status_ = pjsip_inv_send_msg(call->inv, tdata); + /* If the callback is called from pjsua_call_on_incoming(), the + * invite's state is PJSIP_INV_STATE_NULL, so the invite session + * will be terminated later, otherwise we end the session here. + */ + if (call->inv->state > PJSIP_INV_STATE_NULL) { + pjsip_tx_data *tdata; + pj_status_t status_; + + status_ = pjsip_inv_end_session(call->inv, sip_err_code, NULL, + &tdata); + if (status_ == PJ_SUCCESS && tdata) + status_ = pjsip_inv_send_msg(call->inv, tdata); + } pjsua_media_channel_deinit(call->index); } @@ -1225,12 +1232,21 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) status = on_incoming_call_med_tp_complete(call_id, NULL); if (status != PJ_SUCCESS) { sip_err_code = PJSIP_SC_NOT_ACCEPTABLE; + /* Since the call invite's state is still PJSIP_INV_STATE_NULL, + * the invite session was not ended in + * on_incoming_call_med_tp_complete(), so we need to send + * a response message and terminate the invite here. + */ pjsip_dlg_respond(dlg, rdata, sip_err_code, NULL, NULL, NULL); + pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE); + call->inv = NULL; goto on_return; } } else if (status != PJ_EPENDING) { pjsua_perror(THIS_FILE, "Error initializing media channel", status); pjsip_dlg_respond(dlg, rdata, sip_err_code, NULL, NULL, NULL); + pjsip_inv_terminate(call->inv, sip_err_code, PJ_FALSE); + call->inv = NULL; goto on_return; } -- cgit v1.2.3