diff --git a/core/AmSession.cpp b/core/AmSession.cpp index 73182358..4dc9121a 100644 --- a/core/AmSession.cpp +++ b/core/AmSession.cpp @@ -125,7 +125,7 @@ AmSession::AmSession() : AmEventQueue(this), // AmDialogState(), dlg(this), detached(true), - sess_stopped(false),rtp_str(this),first_negotiation(true), + sess_stopped(false),rtp_str(this),negotiate_onreply(false), input(0), output(0), payload(0), m_dtmfDetector(this), m_dtmfEventQueue(&m_dtmfDetector), m_dtmfHandler(this), m_dtmfOutputQueue(&m_dtmfHandler), @@ -503,26 +503,49 @@ void AmSession::onSipRequest(const AmSipRequest& req) void AmSession::onSipReply(const AmSipReply& reply) { - CALL_EVENT_H(onSipReply,reply); + CALL_EVENT_H(onSipReply,reply); - if (dlg.get_uac_trans_method(reply.cseq) == "INVITE") { - if ((reply.code == 200) || (reply.code == 183)) { - DBG("Got 200 or 183 reply to INVITE.\n"); - string sdp_reply; - if(acceptAudio(reply.body,reply.hdrs,&sdp_reply)!=0) { - DBG("acceptAudio failed.\n"); - return; - } + int status = dlg.getStatus(); + dlg.updateStatus(reply); + + if (negotiate_onreply) { + if(status < AmSipDialog::Connected){ - if(detached.get() && !getStopped()){ - onSessionStart(reply); + switch(dlg.getStatus()){ + + case AmSipDialog::Connected: + + // connected! + if(acceptAudio(reply.body,reply.hdrs)){ + ERROR("could not connect audio!!!\n"); + dlg.bye(); + setStopped(); + } + else { + if(detached.get() && !getStopped()){ + + onSessionStart(reply); - if(input || output) - AmSessionScheduler::instance()->addSession(this, callgroup); + if(input || output) + AmSessionScheduler::instance()->addSession(this, + callgroup); + else { + ERROR("missing audio input and/or ouput.\n"); + } + } + } + break; + + case AmSipDialog::Pending: + + switch(reply.code){ + case 180: break;//TODO: local ring tone. + case 183: break;//TODO: remote ring tone. + default: break;// continue waiting. } } } - dlg.updateStatus(reply); + } } void AmSession::onInvite(const AmSipRequest& req) diff --git a/core/AmSession.h b/core/AmSession.h index d0e19e92..1d0a9835 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -106,7 +106,7 @@ class AmSession : public AmThread, AmAudio* output; SdpPayload payload; - bool first_negotiation; + bool negotiate_onreply; AmDtmfDetector m_dtmfDetector; AmDtmfEventQueue m_dtmfEventQueue; @@ -235,6 +235,10 @@ public: /** Gets the port number of the remote part of the session */ int getRPort(); + + /** Set whether on positive reply session should be negotiated */ + void setNegotiateOnReply(bool n) { negotiate_onreply = n; } + /** handle SDP negotiation: only for INVITEs & re-INVITEs */ virtual void negotiate(const string& sdp_body, bool force_symmetric_rtp, diff --git a/core/AmSessionContainer.cpp b/core/AmSessionContainer.cpp index aa1db8d0..462936a8 100644 --- a/core/AmSessionContainer.cpp +++ b/core/AmSessionContainer.cpp @@ -166,6 +166,7 @@ AmSession* AmSessionContainer::startSessionUAC(AmSipRequest& req) { session->dlg.updateStatusFromLocalRequest(req); // sets local tag as well session->setCallgroup(req.from_tag); + session->setNegotiateOnReply(true); session->sendInvite(); session->start();