Commit 9a77110b authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews

sip: move call dedicated code into SIPCall class

Change-Id: Ib72cceca6c1c08ca9f8fa5ccec3a3bb1d5f5469a
Refs: #51555
parent ff28ec7a
......@@ -63,17 +63,6 @@ static const int INCREMENT_SIZE = INITIAL_SIZE;
* Given a SIP call ID (usefull for transaction sucha as transfer)*/
static std::map<std::string, std::string> transferCallID;
static void
stopRtpIfCurrent(SIPCall& call)
{
if (Manager::instance().isCurrentCall(call.getCallId())) {
call.getAudioRtp().stop();
#ifdef SFL_VIDEO
call.getVideoRtp().stop();
#endif
}
}
static void
dtmfSend(SIPCall &call, char code, const std::string &dtmf)
{
......@@ -125,6 +114,17 @@ SIPCall::~SIPCall()
pj_pool_release(pool_);
}
void
SIPCall::stopRtpIfCurrent()
{
if (Manager::instance().isCurrentCall(getCallId())) {
getAudioRtp().stop();
#ifdef SFL_VIDEO
getVideoRtp().stop();
#endif
}
}
SIPAccount&
SIPCall::getSIPAccount() const
{
......@@ -331,7 +331,7 @@ SIPCall::hangup(int reason)
inv->mod_data[siplink.getMod()->id] = NULL;
// Stop all RTP streams
stopRtpIfCurrent(*this);
stopRtpIfCurrent();
siplink.removeSipCall(getCallId());
}
......@@ -661,7 +661,7 @@ SIPCall::peerHungup()
inv->mod_data[siplink.getMod()->id ] = NULL;
// Stop all RTP streams
stopRtpIfCurrent(*this);
stopRtpIfCurrent();
siplink.removeSipCall(getCallId());
}
......@@ -686,3 +686,33 @@ SIPCall::sendTextMessage(const std::string &message, const std::string &from)
send_sip_message(inv, getCallId(), appendUriList(message, list));
}
#endif // HAVE_INSTANT_MESSAGING
void
SIPCall::onServerFailure()
{
const std::string id(getCallId());
Manager::instance().callFailure(id);
SIPVoIPLink::instance().removeSipCall(id);
}
void
SIPCall::onClosed()
{
const std::string id(getCallId());
stopRtpIfCurrent();
Manager::instance().peerHungupCall(id);
SIPVoIPLink::instance().removeSipCall(id);
Manager::instance().checkAudio();
}
void
SIPCall::onAnswered()
{
if (getConnectionState() != Call::CONNECTED) {
setConnectionState(Call::CONNECTED);
setState(Call::ACTIVE);
Manager::instance().peerAnsweredCall(getCallId());
}
}
......@@ -145,6 +145,24 @@ class SIPCall : public Call {
void updateSDPFromSTUN();
/**
* Tell the user that the call was answered
* @param
*/
void onAnswered();
/**
* Handling 5XX/6XX error
* @param
*/
void onServerFailure();
/**
* Peer close the connection
* @param
*/
void onClosed();
private:
// override of Call::createHistoryEntry
......@@ -153,6 +171,8 @@ class SIPCall : public Call {
NON_COPYABLE(SIPCall);
void stopRtpIfCurrent();
/**
* Transfer method used for both type of transfer
*/
......
......@@ -849,17 +849,6 @@ void SIPVoIPLink::cancelKeepAliveTimer(pj_timer_entry& timer)
pjsip_endpt_cancel_timer(endpt_, &timer);
}
static void
stopRtpIfCurrent(const std::string &id, SIPCall &call)
{
if (Manager::instance().isCurrentCall(id)) {
call.getAudioRtp().stop();
#ifdef SFL_VIDEO
call.getVideoRtp().stop();
#endif
}
}
void
SIPVoIPLink::clearSipCallMap()
{
......@@ -1006,36 +995,6 @@ SIPVoIPLink::requestKeyframe(const std::string &callID)
}
#endif
void
SIPVoIPLink::SIPCallServerFailure(SIPCall *call)
{
std::string id(call->getCallId());
Manager::instance().callFailure(id);
removeSipCall(id);
}
void
SIPVoIPLink::SIPCallClosed(SIPCall *call)
{
const std::string id(call->getCallId());
stopRtpIfCurrent(id, *call);
Manager::instance().peerHungupCall(id);
removeSipCall(id);
Manager::instance().checkAudio();
}
void
SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data * /*rdata*/)
{
if (call->getConnectionState() != Call::CONNECTED) {
call->setConnectionState(Call::CONNECTED);
call->setState(Call::ACTIVE);
Manager::instance().peerAnsweredCall(call->getCallId());
}
}
///////////////////////////////////////////////////////////////////////////////
// Private functions
///////////////////////////////////////////////////////////////////////////////
......@@ -1071,14 +1030,12 @@ invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev)
}
}
SIPVoIPLink& link = SIPVoIPLink::instance();
if (inv->state == PJSIP_INV_STATE_EARLY and ev and ev->body.tsx_state.tsx and
ev->body.tsx_state.tsx->role == PJSIP_ROLE_UAC) {
makeCallRing(*call);
} else if (inv->state == PJSIP_INV_STATE_CONFIRMED and ev) {
// After we sent or received a ACK - The connection is established
link.SIPCallAnswered(call, ev->body.tsx_state.src.rdata);
call->onAnswered();
} else if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
std::string accId(call->getAccountId());
......@@ -1086,7 +1043,7 @@ invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev)
// The call terminates normally - BYE / CANCEL
case PJSIP_SC_OK:
case PJSIP_SC_REQUEST_TERMINATED:
link.SIPCallClosed(call);
call->onClosed();
break;
case PJSIP_SC_DECLINE:
......@@ -1103,7 +1060,7 @@ invite_session_state_changed_cb(pjsip_inv_session *inv, pjsip_event *ev)
case PJSIP_SC_REQUEST_PENDING:
case PJSIP_SC_ADDRESS_INCOMPLETE:
default:
link.SIPCallServerFailure(call);
call->onServerFailure();
break;
}
}
......
......@@ -142,24 +142,6 @@ class SIPVoIPLink : public VoIPLink {
*/
std::shared_ptr<Call> SIPNewIpToIpCall(const std::string& id, const std::string& to);
/**
* Tell the user that the call was answered
* @param
*/
void SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata);
/**
* Handling 5XX/6XX error
* @param
*/
void SIPCallServerFailure(SIPCall *call);
/**
* Peer close the connection
* @param
*/
void SIPCallClosed(SIPCall *call);
/**
* Get the memory pool factory since each calls has its own memory pool
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment