diff --git a/sflphone-common/src/audio/audiortp.cpp b/sflphone-common/src/audio/audiortp.cpp index 51f7f7286e7662f22c2ae4cdd8c18131e6307fef..6ed965723b49260918130b4dc79ecb39d8685059 100644 --- a/sflphone-common/src/audio/audiortp.cpp +++ b/sflphone-common/src/audio/audiortp.cpp @@ -127,14 +127,6 @@ AudioRtp::closeRtpSession () return true; } - -AudioRtpRTX* -AudioRtp::getRTX() -{ - return _RTXThread; -} - - void AudioRtp::setRecording() { @@ -144,10 +136,6 @@ AudioRtp::setRecording() } - - - - //////////////////////////////////////////////////////////////////////////////// // AudioRtpRTX Class // //////////////////////////////////////////////////////////////////////////////// diff --git a/sflphone-common/src/audio/audiortp.h b/sflphone-common/src/audio/audiortp.h index e40f7a39798c0f154afdf32de62418d81b2b7055..49330c2fd8a90781baadef125d3ada416dec4697 100644 --- a/sflphone-common/src/audio/audiortp.h +++ b/sflphone-common/src/audio/audiortp.h @@ -256,11 +256,6 @@ class AudioRtp { */ bool closeRtpSession( void ); - /** - * Return a pointer to the RTP thead - */ - AudioRtpRTX* getRTX(); - /** * Start recording */ @@ -268,6 +263,10 @@ class AudioRtp { friend class RtpTest; + /** + * + */ + inline AudioRtpRTX * getAudioRtpRtxThread(void) { return _RTXThread; } private: // copy constructor AudioRtp(const AudioRtp& rh); diff --git a/sflphone-common/src/sdp.cpp b/sflphone-common/src/sdp.cpp index 1a4005d4c722e06fa23ba7e58e18a2674a182820..9256b238b8ca8db8dd1cf6341e296940d5b1c4da 100644 --- a/sflphone-common/src/sdp.cpp +++ b/sflphone-common/src/sdp.cpp @@ -195,7 +195,7 @@ int Sdp::receiving_initial_offer (pjmedia_sdp_session* remote) } // Retrieve some useful remote information - this->fetch_media_transport_info_from_remote_sdp (remote); + this->set_media_transport_info_from_remote_sdp (remote); status = pjmedia_sdp_neg_create_w_remote_offer (_pool, get_local_sdp_session(), remote, &_negociator); @@ -314,8 +314,6 @@ void Sdp::set_negociated_offer (const pjmedia_sdp_session *sdp) _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 @@ -358,7 +356,7 @@ AudioCodec* Sdp::get_session_media (void) AudioCodec *codec = NULL; std::vector<sdpMedia*> media_list; - _debug ("sdp line 314 - get_session_media ()\n"); + _debug ("sdp line %d - get_session_media ()\n", __LINE__); media_list = get_session_media_list (); nb_media = media_list.size(); @@ -470,17 +468,15 @@ std::string Sdp::convert_int_to_string (int value) return result.str(); } -void Sdp::fetch_remote_ip_from_sdp (pjmedia_sdp_session *r_sdp) +void Sdp::set_remote_ip_from_sdp (const pjmedia_sdp_session *r_sdp) { - std::string remote_ip; - - remote_ip = r_sdp->conn->addr.ptr; + std::string remote_ip(r_sdp->conn->addr.ptr, r_sdp->conn->addr.slen); _debug (" Remote IP from fetching SDP: %s\n", remote_ip.c_str()); this->set_remote_ip (remote_ip); } -void Sdp::fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media) +void Sdp::set_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media) { int remote_port; @@ -490,7 +486,7 @@ void Sdp::fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media) this->set_remote_audio_port (remote_port); } -void Sdp::fetch_media_transport_info_from_remote_sdp (pjmedia_sdp_session *remote_sdp) +void Sdp::set_media_transport_info_from_remote_sdp (const pjmedia_sdp_session *remote_sdp) { _debug ("Fetching media from sdp\n"); @@ -504,12 +500,12 @@ void Sdp::fetch_media_transport_info_from_remote_sdp (pjmedia_sdp_session *remot return; } - this->fetch_remote_audio_port_from_sdp (r_media); + this->set_remote_audio_port_from_sdp (r_media); - this->fetch_remote_ip_from_sdp (remote_sdp); + this->set_remote_ip_from_sdp (remote_sdp); } -void Sdp::get_remote_sdp_media_from_offer (pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media) +void Sdp::get_remote_sdp_media_from_offer (const pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media) { int count, i; diff --git a/sflphone-common/src/sdp.h b/sflphone-common/src/sdp.h index 3a0eee5c6e67f4ed7c90757d21368bf2539d1598..ec3178955b57c5370872d43ada2c92302f9f18af 100644 --- a/sflphone-common/src/sdp.h +++ b/sflphone-common/src/sdp.h @@ -179,7 +179,7 @@ class Sdp { */ unsigned int get_remote_audio_port() { return _remote_audio_port; } - void fetch_media_transport_info_from_remote_sdp (pjmedia_sdp_session *remote_sdp); + void set_media_transport_info_from_remote_sdp (const pjmedia_sdp_session *remote_sdp); std::vector<sdpMedia*> get_session_media_list (void) { return _session_media; } @@ -298,11 +298,11 @@ class Sdp { std::string convert_int_to_string (int value); - void fetch_remote_ip_from_sdp (pjmedia_sdp_session *r_sdp); + void set_remote_ip_from_sdp (const pjmedia_sdp_session *r_sdp); - void fetch_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media); + void set_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media); - void get_remote_sdp_media_from_offer (pjmedia_sdp_session* r_sdp, pjmedia_sdp_media** r_media); + void get_remote_sdp_media_from_offer (const pjmedia_sdp_session* r_sdp, pjmedia_sdp_media** r_media); //////////////////////////////////////////////////////////////////3 //////////////////////////////////////////////////////////////////// diff --git a/sflphone-common/src/sipvoiplink.cpp b/sflphone-common/src/sipvoiplink.cpp index 6d8d8f4b964a7754c4ce4baa051be474303c00ad..7692fab7d5544a55a96dd1c68df8e0f632fb8d13 100644 --- a/sflphone-common/src/sipvoiplink.cpp +++ b/sflphone-common/src/sipvoiplink.cpp @@ -341,8 +341,8 @@ int SIPVoIPLink::sendRegister (AccountID id) account = dynamic_cast<SIPAccount *> (Manager::instance().getAccount (id)); hostname = account->getHostname(); username = account->getUsername(); - password = account->getPassword(); - + password = account->getPassword(); + _mutexSIP.enterMutex(); /* Get the client registration information for this particular account */ @@ -545,16 +545,9 @@ SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) } if (SIPOutgoingInvite (call)) { - call->setConnectionState (Call::Progressing); call->setState (Call::Active); addCall (call); - - // _audiortp->start(); - - // call->setAudioStart ( true ); - - } else { delete call; call = 0; @@ -841,17 +834,8 @@ SIPVoIPLink::offhold (const CallID& id) if (status != PJ_SUCCESS) return false; - // Enable audio - _debug ("* SIP Info: Starting AudioRTP when offhold\n"); - call->setState (Call::Active); - // it's sure that this is the current call id... - - _audiortp->start(); - - call->setAudioStart (true); - return true; } @@ -1287,51 +1271,16 @@ SIPVoIPLink::SIPCallAnswered (SIPCall *call, pjsip_rx_data *rdata) _debug ("SIPCallAnswered\n"); - pjmedia_sdp_session *r_sdp; - if (!call) { _debug ("! SIP Failure: unknown call\n"); return; } if (call->getConnectionState() != Call::Connected) { - _debug ("Get remote SDP from offer\n"); - get_remote_sdp_from_offer (rdata, &r_sdp); - - if (r_sdp==NULL) { - _debug ("SIP Failure: no remote sdp session\n"); - return; - } - - _debug ("Get remote media information from offer\n"); - - call->getLocalSDP()->fetch_media_transport_info_from_remote_sdp (r_sdp); - - // _audiortp->getRTX()->setRtpSessionRemoteIp(); - _debug ("Update call state , id = %s\n", call->getCallId().c_str()); call->setConnectionState (Call::Connected); call->setState (Call::Active); - Manager::instance().peerAnsweredCall (call->getCallId()); - - if (Manager::instance().isCurrentCall (call->getCallId())) { - /* - _debug("CREATE NEW RTP SESSION FROM SIPCALLANSWERED\n"); - try { - _audiortp->createNewSession (call); - call->setAudioStart(true); - } catch (...) { - _debug("Failed to create rtp thread from answer\n"); - } - */ - - call->setAudioStart (true); - - _audiortp->start(); - - } - } else { _debug ("* SIP Info: Answering call (on/off hold to send ACK)\n"); } @@ -1405,7 +1354,6 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) _debug ("! SIP Failure: Unable to create RTP Session in SIPVoIPLink::new_ip_to_ip_call (%s:%d)\n", __FILE__, __LINE__); } - // Generate the contact URI // uri_contact << "<" << uri_from << ":" << call->getLocalSDP()->get_local_extern_audio_port() << ">"; uri_contact << "<" << uri_from << ":" << _localExternPort << ">"; @@ -1450,10 +1398,6 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) call->setState (Call::Active); addCall (call); - // _audiortp->start(); - - // call->setAudioStart ( true ); - return true; } else return false; @@ -1813,10 +1757,6 @@ int SIPVoIPLink::createUDPServer (void) return PJ_SUCCESS; } - - - - bool SIPVoIPLink::loadSIPLocalIP() { @@ -1940,7 +1880,6 @@ void set_voicemail_info (AccountID account, pjsip_msg_body *body) void SIPVoIPLink::handle_reinvite (SIPCall *call) { - // Close the previous RTP session _audiortp->closeRtpSession (); call->setAudioStart (false); @@ -1952,12 +1891,6 @@ void SIPVoIPLink::handle_reinvite (SIPCall *call) } catch (...) { _debug ("! SIP Failure: Unable to create RTP Session (%s:%d)\n", __FILE__, __LINE__); } - - _audiortp->start(); - - call->setAudioStart (true); - - } @@ -2121,21 +2054,18 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e) break; } } - - } } void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) { - _debug ("--------------------- call_on_media_update --------------------- \n"); - - AccountID accId; - SIPVoIPLink *link; - - const pjmedia_sdp_session *r_sdp; - SIPCall *call; + + const pjmedia_sdp_session *local_sdp; + const pjmedia_sdp_session *remote_sdp; + + SIPVoIPLink * link = NULL; + SIPCall * call; if (status != PJ_SUCCESS) { _debug ("Error while negociating the offer\n"); @@ -2143,48 +2073,38 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) } // Get the new sdp, result of the negociation - pjmedia_sdp_neg_get_active_local (inv->neg, &r_sdp); - + pjmedia_sdp_neg_get_active_local (inv->neg, &local_sdp); + pjmedia_sdp_neg_get_active_remote(inv->neg, &remote_sdp); + call = reinterpret_cast<SIPCall *> (inv->mod_data[getModId() ]); if (!call) { _debug ("Call declined by peer, SDP negociation stopped\n"); return; } - + // Clean the resulting sdp offer to create a new one (in case of a reinvite) call->getLocalSDP()->clean_session_media(); - + // Set the fresh negociated one - call->getLocalSDP()->set_negociated_offer (r_sdp); - - // call->getLocalSDP()->fetch_media_transport_info_from_remote_sdp( r_sdp ); - // call->getLocalSDP()->fetch_remote_ip_from_sdp( r_sdp ); - // call->getLocalSDP()->fetch_remote_audio_port_from_sdp( r_sdp ); - - accId = Manager::instance().getAccountFromCall (call->getCallId()); - - link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getAccountLink (accId)); - - if (!link) { - _debug ("No Voip Account Link, impossible to init RTP session with SDP info"); + call->getLocalSDP()->set_negociated_offer (local_sdp); + + // Set remote ip / port + call->getLocalSDP()->set_media_transport_info_from_remote_sdp (remote_sdp); + + link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getSIPAccountLink()); + if(link == NULL) { + _debug ("Failed to get sip link\n"); return; } - - if (call->getState() != Call::Hold) { - _debug ("Set media parameters in RTP session\n"); - // link->_audiortp->getRTX()->setRtpSessionMedia(); - // link->_audiortp->getRTX()->setRtpSessionRemoteIp(); - - // link->_audiortp->start(); - - // call->setAudioStart ( true ); - // link->_audiortp->start(); - } else { - _debug ("Didn't set RTP parameters since call is on hold\n"); + + try { + link->getAudioRtp()->start(); + call->setAudioStart (true); + } catch(exception& rtpException) { + _debug("%s\n", rtpException.what()); } - } void call_on_forked (pjsip_inv_session *inv, pjsip_event *e) @@ -2924,7 +2844,7 @@ void on_rx_offer (pjsip_inv_session *inv, const pjmedia_sdp_session *offer) #ifdef CAN_REINVITE - _debug ("reinvite SIP\n"); + _debug ("%s (%d): on_rx_offer REINVITE\n", __FILE__, __LINE__); SIPCall *call; pj_status_t status; diff --git a/sflphone-common/src/sipvoiplink.h b/sflphone-common/src/sipvoiplink.h index 028fcd8a2fd6173135816df5c1682348813daaa4..3a0387c36ef7f044f3a5952601c6b5f6b27b8bd9 100644 --- a/sflphone-common/src/sipvoiplink.h +++ b/sflphone-common/src/sipvoiplink.h @@ -284,8 +284,8 @@ class SIPVoIPLink : public VoIPLink /** when we init the listener, how many times we try to bind a port? */ int _nbTryListenAddr; - /** Starting sound */ - AudioRtp* _audiortp; + /** Returns a pointer to the AudioRtp object */ + inline AudioRtp * getAudioRtp(void) { return _audiortp; } /** Increment the number of SIP account connected to this link */ void incrementClients (void) { _clients++; } @@ -363,6 +363,9 @@ class SIPVoIPLink : public VoIPLink std::string getLocalIP() {return _localExternAddress;} + /** Starting sound */ + AudioRtp* _audiortp; + /** For registration use only */ int _regPort;