diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp index 13b1e7abe96b3cdf24d8ebc11744ca9ede4973b9..8db80f7ae35d682d296f14addc3a8a12944dc866 100644 --- a/src/audio/audiortp.cpp +++ b/src/audio/audiortp.cpp @@ -128,6 +128,7 @@ AudioRtpRTX::AudioRtpRTX (SIPCall *sipcall, bool sym) : time(new ost::Time()), _ _sessionSend = new ost::RTPSession(local_ip, _ca->getLocalAudioPort()); _session = NULL; } else { + _debug ("%i\n", _ca->getLocalAudioPort()); _session = new ost::SymmetricRTPSession (local_ip, _ca->getLocalAudioPort()); _sessionRecv = NULL; _sessionSend = NULL; @@ -197,8 +198,10 @@ AudioRtpRTX::initAudioRtpSession (void) _codecSampleRate = _audiocodec->getClockRate(); remoteIP = _ca->getLocalSDP()->get_remote_ip(); + remotePort = _ca->getLocalSDP()->get_remote_audio_port(); _debug("Init audio RTP session - remote IP = %s\n", remoteIP.c_str()); ost::InetHostAddress remote_ip(remoteIP.c_str()); + _debug("Init audio RTP session - remote IP = %s\n", remoteIP.c_str()); if (!remote_ip) { _debug("! ARTP Thread Error: Target IP address [%s] is not correct!\n", remoteIP.data()); return; @@ -216,7 +219,7 @@ AudioRtpRTX::initAudioRtpSession (void) } if (!_sym) { - remotePort = _ca->getLocalSDP()->getRemoteAudioPort(); + _debug("! AudioRTP Thread: Added session destination %s:%d\n", remote_ip.getHostname(), remotePort ); if ( !_sessionRecv->addDestination(remote_ip, (unsigned short) remotePort) ) { _debug("AudioRTP Thread Error: could not connect to port %d\n", remotePort); return; @@ -238,9 +241,10 @@ AudioRtpRTX::initAudioRtpSession (void) _sessionSend->setMark(true); } else { - //_debug("AudioRTP Thread: Added session destination %s\n", remote_ip.getHostname() ); + _debug("AudioRTP Thread: Added session destination %s:%d\n", remote_ip.getHostname(), remotePort ); if (!_session->addDestination (remote_ip, (unsigned short) remotePort)) { + _debug ("could not connect to port %d\n", remotePort); return; } diff --git a/src/sdp.cpp b/src/sdp.cpp index f3a53b4b0d3ce614472801abe23432d6c6ec494e..bf2f92858842699ba02748d8b7137408229a5219 100644 --- a/src/sdp.cpp +++ b/src/sdp.cpp @@ -29,11 +29,11 @@ static const pj_str_t STR_IN = { (char*)"IN", 2 }; static const pj_str_t STR_IP4 = { (char*)"IP4", 3}; static const pj_str_t STR_IP6 = { (char*)"IP6", 3}; static const pj_str_t STR_RTP_AVP = { (char*)"RTP/AVP", 7 }; -static const pj_str_t STR_SDP_NAME = { (char*)"sflphone", 7 }; +static const pj_str_t STR_SDP_NAME = { (char*)"sflphone", 8 }; static const pj_str_t STR_SENDRECV = { (char*)"sendrecv", 8 }; - Sdp::Sdp( pj_pool_t *pool ) - : _local_media_cap(), _session_media(0), _ip_addr( "" ), _local_offer( NULL ), _negociated_offer(NULL), _negociator(NULL), _pool(NULL) +Sdp::Sdp( pj_pool_t *pool ) + : _local_media_cap(), _session_media(0), _ip_addr( "" ), _local_offer( NULL ), _negociated_offer(NULL), _negociator(NULL), _pool(NULL), _local_extern_audio_port(0) { _pool = pool; } @@ -46,10 +46,15 @@ Sdp::~Sdp() { delete _session_media[k]; _session_media[k] = 0; } + + //for( k=0; k<_local_media_cap.size(); k++ ){ + // delete _local_media_cap[k]; + //_local_media_cap[k] = 0; + //} } void Sdp::set_media_descriptor_line( sdpMedia *media, - pjmedia_sdp_media** p_med ) { + pjmedia_sdp_media** p_med ) { pjmedia_sdp_media* med; pjmedia_sdp_rtpmap rtpmap; pjmedia_sdp_attr *attr; @@ -61,7 +66,7 @@ void Sdp::set_media_descriptor_line( sdpMedia *media, // Get the right media format pj_strdup(_pool, &med->desc.media, - ( media->get_media_type() == MIME_TYPE_AUDIO ) ? &STR_AUDIO : &STR_VIDEO ); + ( media->get_media_type() == MIME_TYPE_AUDIO ) ? &STR_AUDIO : &STR_VIDEO ); med->desc.port_count = 1; med->desc.port = media->get_port(); pj_strdup (_pool, &med->desc.transport, &STR_RTP_AVP); @@ -92,7 +97,7 @@ void Sdp::set_media_descriptor_line( sdpMedia *media, pjmedia_sdp_rtpmap_to_attr( _pool, &rtpmap, &attr ); med->attr[med->attr_count++] = attr; } - + // Add the direction stream attr = (pjmedia_sdp_attr*)pj_pool_zalloc( _pool, sizeof(pjmedia_sdp_attr) ); pj_strdup2( _pool, &attr->name, media->get_stream_direction_str().c_str()); @@ -129,7 +134,7 @@ int Sdp::create_local_offer (){ status = pjmedia_sdp_validate( this->_local_offer ); if (status != PJ_SUCCESS) return status; - + return PJ_SUCCESS; } @@ -170,7 +175,7 @@ int Sdp::receiving_initial_offer( pjmedia_sdp_session* remote ){ //this->fetch_remote_audio_port_from_sdp (); status = pjmedia_sdp_neg_create_w_remote_offer( _pool, - get_local_sdp_session(), remote, &_negociator ); + get_local_sdp_session(), remote, &_negociator ); state = pjmedia_sdp_neg_get_state( _negociator ); PJ_ASSERT_RETURN( status == PJ_SUCCESS, 1 ); @@ -269,7 +274,9 @@ void Sdp::set_negociated_offer( const pjmedia_sdp_session *sdp ){ AudioCodec *codec_to_add; _negociated_offer = (pjmedia_sdp_session*)sdp; - + + //this->fetch_remote_ip_from_sdp ((pjmedia_sdp_session*)sdp); + codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap(); // retrieve the media information @@ -334,25 +341,25 @@ void Sdp::toString (void) { sdp << _local_offer->media[0]->desc.fmt[i].ptr << " "; } sdp << "\n"; - + _debug ("LOCAL SDP: \n%s\n", sdp.str().c_str()); } void Sdp::set_local_media_capabilities () { - + CodecOrder selected_codecs; int i; sdpMedia *audio; CodecsMap codecs_list; CodecsMap::iterator iter; - _debug ("Fetch local media capabilities .......... %i" , getLocalExternAudioPort()); + _debug ("Fetch local media capabilities .......... %i" , get_local_extern_audio_port()); /* Only one audio media used right now */ audio = new sdpMedia(MIME_TYPE_AUDIO); - audio->set_port (getocalAudioPort); - + audio->set_port (get_local_extern_audio_port()); + /* We retrieve the codecs selected by the user */ selected_codecs = Manager::instance().getCodecDescriptorMap().getActiveCodecs(); codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap(); @@ -379,7 +386,6 @@ void Sdp::attribute_port_to_all_media (int port) { for(i=0; i<size; i++) { medias[i]->set_port (port); } - } std::string Sdp::convert_int_to_string (int value) { @@ -391,8 +397,49 @@ std::string Sdp::convert_int_to_string (int value) { 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); + this->set_remote_ip(remote_ip); } + + +void Sdp::fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media){ + + int remote_port; + + remote_port = r_media->desc.port; + _debug(" Remote Audio Port: %d\n", remote_port); + this->set_remote_audio_port(remote_port); +} + +void Sdp::fetch_media_transport_info_from_remote_sdp (pjmedia_sdp_session *remote_sdp) { + + pjmedia_sdp_media *r_media; + + this->get_remote_sdp_media_from_offer (remote_sdp, &r_media); + + if (r_media==NULL){ + _debug("SDP Failure: no remote sdp media found in the remote offer\n"); + return; + } + + this->fetch_remote_ip_from_sdp (remote_sdp); + this->fetch_remote_audio_port_from_sdp (r_media); +} + +void Sdp::get_remote_sdp_media_from_offer (pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media){ + int count, i; + + count = remote_sdp->media_count; + *r_media = NULL; + for(i = 0; i < count; ++i) { + if(pj_stricmp2(&remote_sdp->media[i]->desc.media, "audio") == 0) { + *r_media = remote_sdp->media[i]; + return; + } + } +} + + + diff --git a/src/sdp.h b/src/sdp.h index 12f71d031434c6265d158483fe2dece58a32fc94..9bbd0d5344e43b37594a759067e9a9f4b82f7695 100644 --- a/src/sdp.h +++ b/src/sdp.h @@ -152,7 +152,6 @@ class Sdp { void set_local_extern_audio_port(int port){ _local_extern_audio_port = port; } int get_local_extern_audio_port (void){ return _local_extern_audio_port; } - ///////////////////////////////////////////////////////////////////////////33 void toString (void); @@ -160,7 +159,13 @@ class Sdp { * Set remote's IP addr. [not protected] * @param ip The remote IP address */ - void set_remote_ip(const std::string& ip) { _remoteIPAddress = ip; } + void set_remote_ip(const std::string& ip) { _remote_ip_addr = ip; } + + /** + * Return IP of destination [mutex protected] + * @return const std:string The remote IP address + */ + const std::string& get_remote_ip() { return _remote_ip_addr; } /** * Set remote's audio port. [not protected] @@ -174,14 +179,7 @@ class Sdp { */ 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& get_remote_ip() { return _remoteIPAddress; } - - ///////////////////////////////////////////////////////////////////////// - + void fetch_media_transport_info_from_remote_sdp (pjmedia_sdp_session *remote_sdp); private: /** Codec Map */ std::vector<sdpMedia*> _local_media_cap; @@ -195,6 +193,9 @@ class Sdp { /** IP address */ std::string _ip_addr; + /** Remote's IP address */ + std::string _remote_ip_addr; + /** Local SDP */ pjmedia_sdp_session *_local_offer; @@ -203,6 +204,12 @@ class Sdp { // negociation, with the compatible media from each part pjmedia_sdp_session *_negociated_offer; + /** Local audio port */ + int _local_extern_audio_port; + + /** Remote's audio port */ + unsigned int _remote_audio_port; + // The pool to allocate memory pj_pool_t *_pool; @@ -290,16 +297,11 @@ class Sdp { void fetch_remote_ip_from_sdp (pjmedia_sdp_session *r_sdp); - void fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_sdp); + void fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media); - int _local_extern_audio_port; + void get_remote_sdp_media_from_offer (pjmedia_sdp_session* r_sdp, pjmedia_sdp_media** r_media); //////////////////////////////////////////////////////////////////3 - /** Remote's IP address */ - std::string _remoteIPAddress; - - /** Remote's audio port */ - unsigned int _remoteAudioPort; //////////////////////////////////////////////////////////////////// }; diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp index 6c23ce550dbb82095170481d4305ba0fff111b6c..a3b308405b75bc33da04ed4808399248003184ae 100644 --- a/src/sipvoiplink.cpp +++ b/src/sipvoiplink.cpp @@ -274,7 +274,6 @@ void get_remote_sdp_from_offer( pjsip_rx_data *rdata, pjmedia_sdp_session** r_sd *r_sdp = sdp; } - void SIPVoIPLink::getEvent() { @@ -450,6 +449,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl) } call->setPeerNumber(getSipTo(toUrl, account->getHostname())); + setCallAudioLocal(call, getLocalIPAddress(), useStun(), getStunServer()); call->initRecFileName(); @@ -958,8 +958,6 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject UNUSED) &dialog); PJ_ASSERT_RETURN(status == PJ_SUCCESS, false); - setCallAudioLocal(call, getLocalIPAddress(), useStun(), getStunServer()); - // Create the invite session for this call status = pjsip_inv_create_uac(dialog, call->getLocalSDP()->get_local_sdp_session(), 0, &inv); PJ_ASSERT_RETURN(status == PJ_SUCCESS, false); @@ -1075,6 +1073,9 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam void SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata) { + + pjmedia_sdp_session *r_sdp; + //SIPCall* call = dynamic_cast<SIPCall *>(theCall);//findSIPCallWithCid(event->cid); if (!call) { _debug("! SIP Failure: unknown call\n"); @@ -1083,8 +1084,12 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam //call->setDid(event->did); if (call->getConnectionState() != Call::Connected) { - //call->SIPCallAnswered(event); - //call->getLocalSDP()->SIPCallAnsweredWithoutHold(rdata); + get_remote_sdp_from_offer (rdata, &r_sdp); + if (r_sdp==NULL) { + _debug("SIP Failure: no remote sdp session\n"); + return; + } + call->getLocalSDP()->fetch_media_transport_info_from_remote_sdp (r_sdp); call->setConnectionState(Call::Connected); call->setState(Call::Active); @@ -1100,7 +1105,6 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam } } else { _debug("* SIP Info: Answering call (on/off hold to send ACK)\n"); - //call->SIPCallAnswered(event); } } @@ -1510,6 +1514,7 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam PJ_UNUSED_ARG(inv); + _debug (" ***************************** NEW CALL STATE %i **************************\n", inv->state); SIPCall *call = reinterpret_cast<SIPCall*> (inv->mod_data[_mod_ua.id]); if(!call) @@ -1619,8 +1624,7 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam switch (tsx->state) { case PJSIP_TSX_STATE_TERMINATED: - if (tsx->status_code == 200 && - pjsip_method_cmp(&tsx->method, pjsip_get_refer_method()) != 0) { + if (tsx->status_code == 200 && pjsip_method_cmp(&tsx->method, pjsip_get_refer_method()) != 0) { // Peer answered the outgoing call _debug("UserAgent: Peer answered the outgoing call!\n"); call = reinterpret_cast<SIPCall *> (inv->mod_data[_mod_ua.id]); @@ -1631,8 +1635,11 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam accId = Manager::instance().getAccountFromCall(call->getCallId()); link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getAccountLink(accId)); - if (link) + if (link) { link->SIPCallAnswered(call, rdata); + } else { + } + } else if (tsx->status_code / 100 == 5) { _debug("UserAgent: 5xx error message received\n"); } @@ -1891,7 +1898,6 @@ std::string SIPVoIPLink::getSipTo(const std::string& to_url, std::string hostnam get_remote_sdp_from_offer( rdata, &r_sdp ); call->getLocalSDP()->receiving_initial_offer( r_sdp ); - call->setConnectionState(Call::Progressing); call->setPeerNumber(peerNumber);