diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index c6666e36b00e16c0ba450bd4b41b58312444c266..13b1e7abe96b3cdf24d8ebc11744ca9ede4973b9 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -196,7 +196,7 @@ AudioRtpRTX::initAudioRtpSession (void) _codecSampleRate = _audiocodec->getClockRate(); - remoteIP = _ca->getRemoteIp(); + remoteIP = _ca->getLocalSDP()->get_remote_ip(); _debug("Init audio RTP session - remote IP = %s\n", remoteIP.c_str()); ost::InetHostAddress remote_ip(remoteIP.c_str()); if (!remote_ip) { diff --git a/src/sdp.cpp b/src/sdp.cpp index b4b813ada4bca70fd55d5586ba3830b97a942056..f3a53b4b0d3ce614472801abe23432d6c6ec494e 100644 --- a/src/sdp.cpp +++ b/src/sdp.cpp @@ -165,6 +165,10 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote ){ // Build the local offer to respond create_local_offer( ); + // Retrieve some useful remote information + this->fetch_remote_ip_from_sdp (remote); + //this->fetch_remote_audio_port_from_sdp (); + status = pjmedia_sdp_neg_create_w_remote_offer( _pool, get_local_sdp_session(), remote, &_negociator ); state = pjmedia_sdp_neg_get_state( _negociator ); @@ -347,7 +351,7 @@ void Sdp::set_local_media_capabilities () { /* Only one audio media used right now */ audio = new sdpMedia(MIME_TYPE_AUDIO); - audio->set_port (_localAudioPort); + audio->set_port (getocalAudioPort); /* We retrieve the codecs selected by the user */ selected_codecs = Manager::instance().getCodecDescriptorMap().getActiveCodecs(); @@ -367,6 +371,8 @@ void Sdp::attribute_port_to_all_media (int port) { std::vector<sdpMedia*> medias; int i, size; + set_local_extern_audio_port (port); + medias = get_local_media_cap (); size = medias.size(); @@ -381,3 +387,12 @@ std::string Sdp::convert_int_to_string (int value) { result << value; return result.str(); } + +void Sdp::fetch_remote_ip_from_sdp (pjmedia_sdp_session *r_sdp) { + + std::string remote_ip; + + remote_ip = r_sdp->conn->addr.ptr; + _debug(" Remote Audio IP: %s\n", remote_ip.c_str()); + set_remote_ip(remote_ip); +} diff --git a/src/sdp.h b/src/sdp.h index 6bd55777f11964d0f8dbddc3c6f49eb78f354c0b..12f71d031434c6265d158483fe2dece58a32fc94 100644 --- a/src/sdp.h +++ b/src/sdp.h @@ -149,10 +149,10 @@ class Sdp { */ void attribute_port_to_all_media (int port); - ///////////////////////////////////////////////////////////////////////////33 - void setLocalExternAudioPort(int port){ _localAudioPort = port; } + void set_local_extern_audio_port(int port){ _local_extern_audio_port = port; } - int getLocalExternAudioPort (void){ return _localAudioPort; } + int get_local_extern_audio_port (void){ return _local_extern_audio_port; } + ///////////////////////////////////////////////////////////////////////////33 void toString (void); @@ -160,25 +160,25 @@ class Sdp { * Set remote's IP addr. [not protected] * @param ip The remote IP address */ - void setRemoteIP(const std::string& ip) { _remoteIPAddress = ip; } + void set_remote_ip(const std::string& ip) { _remoteIPAddress = ip; } /** * Set remote's audio port. [not protected] * @param port The remote audio port */ - void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; } + void set_remote_audio_port(unsigned int port) { _remote_audio_port = port; } /** * Return audio port at destination [mutex protected] * @return unsigned int The remote audio port */ - unsigned int getRemoteAudioPort() { return _remoteAudioPort; } + unsigned int get_remote_audio_port() { return _remote_audio_port; } /** * Return IP of destination [mutex protected] * @return const std:string The remote IP address */ - const std::string& getRemoteIp() { return _remoteIPAddress; } + const std::string& get_remote_ip() { return _remoteIPAddress; } ///////////////////////////////////////////////////////////////////////// @@ -288,7 +288,11 @@ class Sdp { std::string convert_int_to_string (int value); - int _localAudioPort; + void fetch_remote_ip_from_sdp (pjmedia_sdp_session *r_sdp); + + void fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_sdp); + + int _local_extern_audio_port; //////////////////////////////////////////////////////////////////3 /** Remote's IP address */ diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index d1869d176d51a0c56e8291b392ad13e7b66ee80b..6c23ce550dbb82095170481d4305ba0fff111b6c 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -469,7 +469,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl) return call; } - bool + bool SIPVoIPLink::answer(const CallID& id) { @@ -477,6 +477,8 @@ SIPVoIPLink::answer(const CallID& id) SIPCall *call; pj_status_t status; pjsip_tx_data *tdata; + Sdp *local_sdp; + pjsip_inv_session *inv_session; _debug("SIPVoIPLink::answer: start answering \n"); @@ -487,15 +489,19 @@ SIPVoIPLink::answer(const CallID& id) return false; } - // User answered the incoming call, tell peer this news - if (call->getLocalSDP()->start_negociation()) { - // Create and send a 200(OK) response + local_sdp = call->getLocalSDP(); + inv_session = call->getInvSession(); + status = local_sdp->start_negociation (); + + if (status == PJ_SUCCESS) { _debug("SIPVoIPLink::answer:UserAgent: Negociation success! : call %s \n", call->getCallId().c_str()); - status = pjsip_inv_answer(call->getInvSession(), PJSIP_SC_OK, NULL, NULL, &tdata); + // Create and send a 200(OK) response + status = pjsip_inv_answer(inv_session, PJSIP_SC_OK, NULL, NULL, &tdata); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); - status = pjsip_inv_send_msg(call->getInvSession(), tdata); + status = pjsip_inv_send_msg(inv_session, tdata); PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); - + + // Start the RTP sessions _debug("SIPVoIPLink::answer: Starting AudioRTP when answering : call %s \n", call->getCallId().c_str()); if (_audiortp->createNewSession(call) >= 0) { call->setAudioStart(true); @@ -506,10 +512,21 @@ SIPVoIPLink::answer(const CallID& id) _debug("SIPVoIPLink::answer: Unable to start sound when answering %s/%d\n", __FILE__, __LINE__); } } - _debug("SIPVoIPLink::answer: fail terminate call %s \n",call->getCallId().c_str()); - terminateOneCall(call->getCallId()); - removeCall(call->getCallId()); - return false; + else { + // Create and send a 488/Not acceptable here + // because the SDP negociation failed + status = pjsip_inv_answer( inv_session, PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL, NULL, + &tdata ); + PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 ); + status = pjsip_inv_send_msg( inv_session, tdata ); + PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 ); + + // Terminate the call + _debug("SIPVoIPLink::answer: fail terminate call %s \n",call->getCallId().c_str()); + terminateOneCall(call->getCallId()); + removeCall(call->getCallId()); + return false; + } } bool diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h index 597ec1c32794b9f142d13f978a6f98d136b9d65f..693f20fd282bc226e783abc5a9a64c87e9310129 100644 --- a/src/sipvoiplink.h +++ b/src/sipvoiplink.h @@ -112,7 +112,7 @@ class SIPVoIPLink : public VoIPLink /** * Answer the call * @param id The call identifier - * @return bool True on success + * @return int True on success */ bool answer(const CallID& id);