diff --git a/sflphone-common/src/audio/audiortp.cpp b/sflphone-common/src/audio/audiortp.cpp index 86837fb88a898ef034b86ff6fc8702a5b03b8ad7..16766e710bd3ecb86accf3c95e7ccf6493774978 100644 --- a/sflphone-common/src/audio/audiortp.cpp +++ b/sflphone-common/src/audio/audiortp.cpp @@ -52,7 +52,7 @@ AudioRtp::~AudioRtp (void) { delete _RTXThread; _RTXThread = 0; } -int +void AudioRtp::createNewSession (SIPCall *ca) { ost::MutexLock m(_threadMutex); @@ -70,6 +70,17 @@ AudioRtp::createNewSession (SIPCall *ca) { // Start RTP Send/Receive threads _symmetric = Manager::instance().getConfigInt(SIGNALISATION,SYMMETRIC) ? true : false; _RTXThread = new AudioRtpRTX (ca, _symmetric); + +} + +int +AudioRtp::start(void) +{ + if(_RTXThread == 0) { + _debug("! ARTP Failure: Cannot start audiortp thread since not yet created\n"); + throw AudioRtpException(); + } + try { if (_RTXThread->start() != 0) { _debug("! ARTP Failure: unable to start RTX Thread\n"); @@ -211,7 +222,7 @@ AudioRtpRTX::initAudioRtpSession (void) try { - setRtpSessionMedia(); + // setRtpSessionMedia(); /* if (_ca == 0) { return; } @@ -228,7 +239,7 @@ AudioRtpRTX::initAudioRtpSession (void) _debug("! ARTP Thread Error: Target IP address [%s] is not correct!\n", _ca->getLocalSDP()->get_remote_ip().data()); return; } - + */ if (!_sym) { _sessionRecv->setSchedulingTimeout (10000); @@ -240,9 +251,9 @@ AudioRtpRTX::initAudioRtpSession (void) _session->setSchedulingTimeout(10000); _session->setExpireTimeout(1000000); } - */ + - setRtpSessionRemoteIp(); + // setRtpSessionRemoteIp(); /* if (!_sym) { diff --git a/sflphone-common/src/audio/audiortp.h b/sflphone-common/src/audio/audiortp.h index d31d3bcb7929feb56aba4447440b6bd7b56dc83f..17bfdb6569773dccbe4e51139d88266ee22308b2 100644 --- a/sflphone-common/src/audio/audiortp.h +++ b/sflphone-common/src/audio/audiortp.h @@ -35,6 +35,17 @@ #define UP_SAMPLING 0 #define DOWN_SAMPLING 1 + + +class AudioRtpException: public std::exception +{ + virtual const char* what() const throw() + { + return "AudioRtpException occured"; + } +}; + + /** * @file audiortp.h * @brief Manage the real-time data transport in a SIP call @@ -225,7 +236,12 @@ class AudioRtp { * Create a brand new RTP session by calling the AudioRtpRTX constructor * @param ca A pointer on a SIP call */ - int createNewSession (SIPCall *ca); + void createNewSession (SIPCall *ca); + + /** + * Start the AudioRtpRTX thread created with createNewSession + */ + int start(void); /** * Close a RTP session and kills the remaining threads diff --git a/sflphone-common/src/sipvoiplink.cpp b/sflphone-common/src/sipvoiplink.cpp index c44726f772eeacfd490263982de676a2cc1cd846..22988b69573fda62c36036d974891fb9f49a4f69 100644 --- a/sflphone-common/src/sipvoiplink.cpp +++ b/sflphone-common/src/sipvoiplink.cpp @@ -506,6 +506,12 @@ SIPVoIPLink::newOutgoingCall ( const CallID& id, const std::string& toUrl ) call->setPeerNumber ( getSipTo ( toUrl, account->getHostname() ) ); setCallAudioLocal ( call, getLocalIPAddress(), useStun(), getStunServer() ); + try { + _audiortp->createNewSession (call); + } catch (...) { + _debug("Failed to create rtp thread from newOutGoingCall\n"); + } + call->initRecFileName(); _debug ( "Try to make a call to: %s with call ID: %s\n", toUrl.data(), id.data() ); @@ -554,6 +560,13 @@ SIPVoIPLink::answer ( const CallID& id ) } local_sdp = call->getLocalSDP(); + + try { + _audiortp->createNewSession (call); + } catch (...) { + _debug("Failed to create rtp thread from newOutGoingCall\n"); + } + inv_session = call->getInvSession(); status = local_sdp->start_negociation (); @@ -568,7 +581,8 @@ SIPVoIPLink::answer ( const CallID& id ) // Start the RTP sessions _debug ( "SIPVoIPLink::answer: Starting AudioRTP when answering : call %s \n", call->getCallId().c_str() ); - if ( _audiortp->createNewSession ( call ) >= 0 ) + // if ( _audiortp->createNewSession ( call ) >= 0 ) + if ( _audiortp->start() >= 0 ) { call->setAudioStart ( true ); call->setConnectionState ( Call::Connected ); @@ -774,6 +788,12 @@ SIPVoIPLink::offhold ( const CallID& id ) return false; } + try { + _audiortp->createNewSession (call); + } catch (...) { + _debug ( "! SIP Failure: Unable to create RTP Session (%s:%d)\n", __FILE__, __LINE__ ); + } + /* Create re-INVITE with new offer */ status = inv_session_reinvite ( call, "sendrecv" ); if ( status != PJ_SUCCESS ) @@ -783,11 +803,15 @@ SIPVoIPLink::offhold ( const CallID& id ) _debug ( "* SIP Info: Starting AudioRTP when offhold\n" ); call->setState ( Call::Active ); // it's sure that this is the current call id... - if ( _audiortp->createNewSession ( call ) < 0 ) + + + // if ( _audiortp->createNewSession ( call ) < 0 ) + if ( _audiortp->start() < 0 ) { _debug ( "! SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__ ); return false; } + return true; } @@ -1224,6 +1248,8 @@ SIPVoIPLink::SIPCallAnswered ( SIPCall *call, pjsip_rx_data *rdata ) _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 ); @@ -1232,7 +1258,8 @@ SIPVoIPLink::SIPCallAnswered ( SIPCall *call, pjsip_rx_data *rdata ) if ( Manager::instance().isCurrentCall ( call->getCallId() ) ) { _debug ( "* SIP Info: Starting AudioRTP when answering\n" ); - if ( _audiortp->createNewSession ( call ) < 0 ) + // if ( _audiortp->createNewSession ( call ) < 0 ) + if ( _audiortp->start() < 0 ) { _debug ( "RTP Failure: unable to create new session\n" ); } @@ -1852,18 +1879,29 @@ void set_voicemail_info ( AccountID account, pjsip_msg_body *body ) void SIPVoIPLink::handle_reinvite ( SIPCall *call ) { + /* _debug("handle_reinvite\n"); - + // Close the previous RTP session _audiortp->closeRtpSession (); call->setAudioStart ( false ); _debug("create new rtp session from handle_reinvite \n"); // Create a new one with new info - if ( _audiortp->createNewSession ( call ) >= 0 ) + // if ( _audiortp->createNewSession ( call ) >= 0 ) + try { + _audiortp->createNewSession (call); + } catch (...) { + _debug ( "! SIP Failure: Unable to create RTP Session (%s:%d)\n", __FILE__, __LINE__ ); + } + if ( _audiortp->start() >= 0 ) { call->setAudioStart ( true ); } + */ + + _audiortp->getRTX()->setRtpSessionRemoteIp(); + _audiortp->getRTX()->setRtpSessionMedia(); } @@ -1879,6 +1917,8 @@ void call_on_state_changed ( pjsip_inv_session *inv, pjsip_event *e ) SIPVoIPLink *link; pjsip_rx_data *rdata; + _debug("---------------------- call_on_state_changed --------------------------\n"); + /* Retrieve the call information */ call = reinterpret_cast<SIPCall*> ( inv->mod_data[_mod_ua.id] ); if ( !call ) @@ -2025,6 +2065,11 @@ void call_on_state_changed ( pjsip_inv_session *inv, pjsip_event *e ) 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; @@ -2042,6 +2087,12 @@ void call_on_media_update ( pjsip_inv_session *inv, pj_status_t status ) call->getLocalSDP()->clean_session_media(); // Set the fresh negociated one call->getLocalSDP()->set_negociated_offer ( r_sdp ); + + accId = Manager::instance().getAccountFromCall ( call->getCallId() ); + link = dynamic_cast<SIPVoIPLink *> ( Manager::instance().getAccountLink ( accId ) ); + + link->_audiortp->getRTX()->setRtpSessionMedia(); + } void call_on_forked ( pjsip_inv_session *inv, pjsip_event *e ) diff --git a/sflphone-common/test/rtpTest.cpp b/sflphone-common/test/rtpTest.cpp index 0b164e76833dced5d2d2dce591f477e5f7b21165..a33e1df141517c7ea61c27db2f3944678439e0c0 100644 --- a/sflphone-common/test/rtpTest.cpp +++ b/sflphone-common/test/rtpTest.cpp @@ -83,7 +83,7 @@ void RtpTest::testRtpInitClose() try { _debug("-------- Open Rtp Session ----------\n"); - CPPUNIT_ASSERT(audiortp->createNewSession(sipcall) == 0); + audiortp->createNewSession(sipcall); } catch(...) { @@ -125,7 +125,7 @@ void RtpTest::testRtpThread() _debug("-------- Open Rtp Session ----------\n"); try { - CPPUNIT_ASSERT(audiortp->createNewSession(sipcall) == 0); + audiortp->createNewSession(sipcall); } catch(...) { @@ -176,7 +176,7 @@ void RtpTest::testRtpResampling() _debug("-------- Open Rtp Session ----------\n"); try { - CPPUNIT_ASSERT(audiortp->createNewSession(sipcall) == 0); + audiortp->createNewSession(sipcall); } catch(...) {