From fcf865c4deb374fad719c5003f9a554f8ca40b82 Mon Sep 17 00:00:00 2001 From: Riza Sulistyo Date: Tue, 10 May 2016 14:58:41 +0000 Subject: Fixed #1914: onCreateMediaTransport() callback might not be called on PJSUA2. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5288 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsua-lib/pjsua_internal.h | 7 +++++++ pjsip/src/pjsua-lib/pjsua_call.c | 12 +++++++++++- pjsip/src/pjsua2/endpoint.cpp | 30 +++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index e1fad139..1c4d0a1d 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -189,6 +189,13 @@ struct pjsua_call pj_timer_entry reinv_timer; /**< Reinvite retry timer. */ pj_bool_t reinv_pending;/**< Pending until CONFIRMED state. */ pj_bool_t reinv_ice_sent;/**< Has reinvite for ICE upd sent? */ + pjsip_rx_data *incoming_data;/**< Cloned incoming call rdata. + On pjsua2, when handling incoming + call, onCreateMediaTransport() will + not be called since the call isn't + created yet. This temporary + variable is used to handle such + case, see ticket #1916. */ }; diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c index d8cf68ec..638ae3cf 100644 --- a/pjsip/src/pjsua-lib/pjsua_call.c +++ b/pjsip/src/pjsua-lib/pjsua_call.c @@ -1100,7 +1100,7 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) unsigned options = 0; pjsip_inv_session *inv = NULL; int acc_id; - pjsua_call *call; + pjsua_call *call = NULL; int call_id = -1; int sip_err_code = PJSIP_SC_INTERNAL_SERVER_ERROR; pjmedia_sdp_session *offer=NULL; @@ -1223,6 +1223,11 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata) } } + if (!replaced_dlg) { + /* Clone rdata. */ + pjsip_rx_data_clone(rdata, 0, &call->incoming_data); + } + /* * Get which account is most likely to be associated with this incoming * call. We need the account to find which contact URI to put for @@ -1637,6 +1642,11 @@ on_return: if (dlg) { pjsip_dlg_dec_lock(dlg); } + + if (call && call->incoming_data) { + pjsip_rx_data_free_cloned(call->incoming_data); + call->incoming_data = NULL; + } pj_log_pop_indent(); PJSUA_UNLOCK(); diff --git a/pjsip/src/pjsua2/endpoint.cpp b/pjsip/src/pjsua2/endpoint.cpp index cf3a4039..d089b0c9 100644 --- a/pjsip/src/pjsua2/endpoint.cpp +++ b/pjsip/src/pjsua2/endpoint.cpp @@ -602,6 +602,15 @@ void Endpoint::on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, return; } + pjsua_call *call = &pjsua_var.calls[call_id]; + if (!call->incoming_data) { + /* This happens when the incoming call callback has been called from + * inside the on_create_media_transport() callback. So we simply + * return here to avoid calling the callback twice. + */ + return; + } + /* call callback */ OnIncomingCallParam prm; prm.callId = call_id; @@ -609,6 +618,10 @@ void Endpoint::on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, acc->onIncomingCall(prm); + /* Free cloned rdata. */ + pjsip_rx_data_free_cloned(call->incoming_data); + call->incoming_data = NULL; + /* disconnect if callback doesn't handle the call */ pjsua_call_info ci; @@ -1225,7 +1238,22 @@ Endpoint::on_create_media_transport(pjsua_call_id call_id, { Call *call = Call::lookup(call_id); if (!call) { - return base_tp; + pjsua_call *in_call = &pjsua_var.calls[call_id]; + if (in_call->incoming_data) { + /* This can happen when there is an incoming call but the + * on_incoming_call() callback hasn't been called. So we need to + * call the callback here. + */ + on_incoming_call(in_call->acc_id, call_id, in_call->incoming_data); + + /* New call should already be created by app. */ + call = Call::lookup(call_id); + if (!call) { + return base_tp; + } + } else { + return base_tp; + } } OnCreateMediaTransportParam prm; -- cgit v1.2.3