diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index e532515d604c30dac6e10e9e3a0fe8c3ce2fe2f7..646aa89b95d65652bb446f860364e011cc0ec92f 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -125,14 +125,14 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) void AudioRtpFactory::start (void) { if (_rtpSession == NULL) { - throw AudioRtpFactoryException ("_rtpSession was null when trying to start audio thread"); + throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to start audio thread"); } switch (_rtpSessionType) { case Sdes: if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioSRtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSRtpSession thread"); } break; @@ -140,7 +140,7 @@ void AudioRtpFactory::start (void) _debug ("Starting symmetric rtp thread"); if (static_cast<AudioSymmetricRtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioSymmetricRtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSymmetricRtpSession thread"); } break; @@ -148,9 +148,8 @@ void AudioRtpFactory::start (void) case Zrtp: if (static_cast<AudioZrtpSession *> (_rtpSession)->startRtpThread() != 0) { - throw AudioRtpFactoryException ("Failed to start AudioZrtpSession thread"); + throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioZrtpSession thread"); } - break; } } @@ -158,10 +157,10 @@ void AudioRtpFactory::start (void) void AudioRtpFactory::stop (void) { ost::MutexLock mutex (_audioRtpThreadMutex); - _debug ("Stopping audio rtp session"); + _info("RTP: Stopping audio rtp session"); if (_rtpSession == NULL) { - _debugException ("_rtpSession is null when trying to stop. Returning."); + _debugException ("RTP: Error: _rtpSession is null when trying to stop. Returning."); return; } @@ -183,16 +182,16 @@ void AudioRtpFactory::stop (void) _rtpSession = NULL; } catch (...) { - _debugException ("Exception caught when stopping the audio rtp session"); - throw AudioRtpFactoryException("caught exception in AudioRtpFactory::stop"); + _debugException ("RTP: Error: Exception caught when stopping the audio rtp session"); + throw AudioRtpFactoryException("RTP: Error: caught exception in AudioRtpFactory::stop"); } } void AudioRtpFactory::updateDestinationIpAddress (void) { - _debug ("Updating IP address"); + _info ("RTP: Updating IP address"); if (_rtpSession == NULL) { - throw AudioRtpFactoryException ("_rtpSession was null when trying to update IP address"); + throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to update IP address"); } switch (_rtpSessionType) { @@ -216,19 +215,20 @@ sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession() if ( (_rtpSessionType == Zrtp) && (_rtpSessionType != NULL)) { return static_cast<AudioZrtpSession *> (_rtpSession); } else { - throw AudioRtpFactoryException("_rtpSession is NULL in getAudioZrtpSession"); + throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioZrtpSession"); } } - void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) +void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) { if ( _rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) { static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo(nego); } else { - throw AudioRtpFactoryException("_rtpSession is NULL in setRemoteCryptoInfo"); + throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo"); } } + } diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h index cfa14165f1cf0f85960eb775b4b09fd476df7062..0076c968c8262ccd743a56b53d421439b1878dd4 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h @@ -63,27 +63,27 @@ namespace sfl { void initAudioRtpConfig(SIPCall *ca); - /** - * Lazy instantiation method. Create a new RTP session of a given - * type according to the content of the configuration file. - * @param ca A pointer on a SIP call - * @return A new AudioRtpSession object - */ - void initAudioRtpSession(SIPCall *ca); - - /** - * Start the audio rtp thread of the type specified in the configuration - * file. initAudioRtpSession must have been called prior to that. - * @param None - */ - void start(); - - /** - * Stop the audio rtp thread of the type specified in the configuration - * file. initAudioRtpSession must have been called prior to that. - * @param None - */ - void stop(); + /** + * Lazy instantiation method. Create a new RTP session of a given + * type according to the content of the configuration file. + * @param ca A pointer on a SIP call + * @return A new AudioRtpSession object + */ + void initAudioRtpSession(SIPCall *ca); + + /** + * Start the audio rtp thread of the type specified in the configuration + * file. initAudioRtpSession must have been called prior to that. + * @param None + */ + void start(); + + /** + * Stop the audio rtp thread of the type specified in the configuration + * file. initAudioRtpSession must have been called prior to that. + * @param None + */ + void stop(); /** * Update current RTP destination address with one stored in call diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.h b/sflphone-common/src/audio/audiortp/AudioRtpSession.h index 29057bec3ec82fbcb302f8e172164d1f8a20bbf0..b6d4908445ba7cee17c3230976ec340413329f93 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.h @@ -67,10 +67,10 @@ namespace sfl { int startRtpThread(); - /** - * Used mostly when receiving a reinvite - */ - void updateDestinationIpAddress(void); + /** + * Used mostly when receiving a reinvite + */ + void updateDestinationIpAddress(void); private: @@ -104,15 +104,16 @@ namespace sfl { // start() with no semaphore at all. ost::Semaphore * _mainloopSemaphore; - // Main destination address for this rtp session. - // Stored in case or reINVITE, which may require to forget - // this destination and update a new one. - ost::InetHostAddress _remote_ip; + // Main destination address for this rtp session. + // Stored in case or reINVITE, which may require to forget + // this destination and update a new one. + ost::InetHostAddress _remote_ip; + - // Main destination port for this rtp session. - // Stored in case reINVITE, which may require to forget - // this destination and update a new one - unsigned short _remote_port; + // Main destination port for this rtp session. + // Stored in case reINVITE, which may require to forget + // this destination and update a new one + unsigned short _remote_port; AudioCodec * _audiocodec; @@ -163,23 +164,23 @@ namespace sfl { */ ManagerImpl * _manager; - /** - * Sampling rate of audio converter - */ - int _converterSamplingRate; + /** + * Sampling rate of audio converter + */ + int _converterSamplingRate; - /** - * Timestamp for this session - */ - int _timestamp; + /** + * Timestamp for this session + */ + int _timestamp; - /** - * Time counter used to trigger incoming call notification - */ - int _countNotificationTime; + /** + * Time counter used to trigger incoming call notification + */ + int _countNotificationTime; protected: - SIPCall * _ca; + SIPCall * _ca; }; @@ -208,7 +209,7 @@ namespace sfl { assert(_ca); - _debug ("Local audio port %i will be used", _ca->getLocalAudioPort()); + _info ("Rtp: Local audio port %i will be used", _ca->getLocalAudioPort()); //mic, we receive from soundcard in stereo, and we send encoded _audiolayer = _manager->getAudioDriver(); @@ -223,7 +224,7 @@ namespace sfl { template <typename D> AudioRtpSession<D>::~AudioRtpSession() { - _debug ("Delete AudioRtpSession instance"); + _debug ("Rtp: Delete AudioRtpSession instance"); try { terminate(); @@ -232,9 +233,7 @@ namespace sfl { throw; } - _debug("Unbind audio RTP stream for call id %s", _ca->getCallId().c_str()); - // _audiolayer->getMainBuffer()->unBindAll(_ca->getCallId()); - _manager->getAudioDriver()->getMainBuffer()->unBindAll(_ca->getCallId()); + _manager->getAudioDriver()->getMainBuffer()->unBindAll(_ca->getCallId()); delete [] _micData; delete [] _micDataConverted; @@ -243,22 +242,21 @@ namespace sfl { delete [] _spkrDataConverted; delete _time; delete _converter; - _debug ("AudioRtpSession instance deleted"); } template <typename D> void AudioRtpSession<D>::initBuffers() { - // Set sampling rate, main buffer choose the highest one - // _audiolayer->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); + // Set sampling rate, main buffer choose the highest one + // _audiolayer->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); _manager->getAudioDriver()->getMainBuffer()->setInternalSamplingRate(_codecSampleRate); - // may be different than one already setted - // converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); - _converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate(); + // may be different than one already setted + // converterSamplingRate = _audiolayer->getMainBuffer()->getInternalSamplingRate(); + _converterSamplingRate = _manager->getAudioDriver()->getMainBuffer()->getInternalSamplingRate(); - // initialize SampleRate converter using AudioLayer's sampling rate - // (internal buffers initialized with maximal sampling rate and frame size) + // initialize SampleRate converter using AudioLayer's sampling rate + // (internal buffers initialized with maximal sampling rate and frame size) _converter = new SamplerateConverter(_layerSampleRate, _layerFrameSize); int nbSamplesMax = (int)(_codecSampleRate * _layerFrameSize /1000)*2; @@ -268,7 +266,7 @@ namespace sfl { _spkrDataConverted = new SFLDataFormat[nbSamplesMax]; _spkrDataDecoded = new SFLDataFormat[nbSamplesMax]; - _manager->addStream(_ca->getCallId()); + _manager->addStream(_ca->getCallId()); } template <typename D> @@ -288,8 +286,8 @@ namespace sfl { { assert(_ca); - AudioCodecType pl = (AudioCodecType)_ca->getLocalSDP()->get_session_media()->getPayload(); - _audiocodec = _manager->getCodecDescriptorMap().instantiateCodec(pl); + AudioCodecType pl = (AudioCodecType)_ca->getLocalSDP()->get_session_media()->getPayload(); + _audiocodec = _manager->getCodecDescriptorMap().instantiateCodec(pl); if (_audiocodec == NULL) { _debug ("No audiocodec, can't init RTP media"); @@ -318,26 +316,29 @@ namespace sfl { void AudioRtpSession<D>::setDestinationIpAddress(void) { if (_ca == NULL) { - _debug ("Sipcall is gone."); + _warn ("Rtp: Sipcall is gone."); throw AudioRtpSessionException(); } - _debug ("Setting IP address for the RTP session"); + _info ("RTP: Setting IP address for the RTP session"); - // Store remote ip in case we would need to forget current destination + // Store remote ip in case we would need to forget current destination _remote_ip = ost::InetHostAddress(_ca->getLocalSDP()->get_remote_ip().c_str()); - _debug ("Init audio RTP session: remote ip %s", _ca->getLocalSDP()->get_remote_ip().data()); if (!_remote_ip) { - _debug ("Target IP address [%s] is not correct!", _ca->getLocalSDP()->get_remote_ip().data()); + _warn("Rtp: Target IP address (%s) is not correct!", + _ca->getLocalSDP()->get_remote_ip().data()); return; } - // Store remote port in case we would need to forget current destination - _remote_port = (unsigned short) _ca->getLocalSDP()->get_remote_audio_port(); + // Store remote port in case we would need to forget current destination + _remote_port = (unsigned short) _ca->getLocalSDP()->get_remote_audio_port(); + + _info("RTP: New remote address for session: %s:%d", + _ca->getLocalSDP()->get_remote_ip().data(), _remote_port); if (! static_cast<D*>(this)->addDestination (_remote_ip, _remote_port)) { - _debug ("Can't add destination to session!"); + _warn("Rtp: Can't add new destination to session!"); return; } } @@ -346,12 +347,13 @@ namespace sfl { void AudioRtpSession<D>::updateDestinationIpAddress(void) { // Destination address are stored in a list in ccrtp - // This method clear off this entry - _debug("updateDestinationIpAddress: remove destination %s", _ca->getLocalSDP()->get_remote_ip().c_str()); - static_cast<D*>(this)->forgetDestination(_remote_ip, _remote_port); + // This method remove the current destination entry + + if(!static_cast<D*>(this)->forgetDestination(_remote_ip, _remote_port, _remote_port+1)) + _warn("Rtp: Could not remove previous destination"); - // new destination is stored in call - // we just need to recall this method + // new destination is stored in call + // we just need to recall this method setDestinationIpAddress(); } @@ -534,7 +536,6 @@ namespace sfl { { setSessionTimeouts(); - setDestinationIpAddress(); setSessionMedia(); initBuffers(); diff --git a/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp index 5b6b67101f740635b5eb7f9ebcc77343689eba93..cb82fe29e227fe0071d48c6aeda2cab3be5e9008 100644 --- a/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioZrtpSession.cpp @@ -38,7 +38,6 @@ AudioZrtpSession::AudioZrtpSession (ManagerImpl * manager, SIPCall * sipcall, co { _debug ("AudioZrtpSession initialized"); initializeZid(); - // startZrtp(); } void AudioZrtpSession::initializeZid (void) diff --git a/sflphone-common/src/audio/audiortp/AudioZrtpSession.h b/sflphone-common/src/audio/audiortp/AudioZrtpSession.h index 2e41e04b45b42086f903e551207563cdd9fdfba7..138bd2684733881494e2e26f8e1af01c85fe931c 100644 --- a/sflphone-common/src/audio/audiortp/AudioZrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioZrtpSession.h @@ -38,8 +38,8 @@ namespace sfl { class AudioZrtpSession : public ost::SymmetricZRTPSession, public AudioRtpSession<AudioZrtpSession> { public: - AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename); - + AudioZrtpSession(ManagerImpl * manager, SIPCall * sipcall, const std::string& zidFilename); + private: void initializeZid(void); std::string _zidFilename; diff --git a/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp b/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp index f866b39e007a7b9ffd11fb4c5307a05c6b9f0547..145792e0bce09f97977772b4602a12559e2d4566 100644 --- a/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp +++ b/sflphone-common/src/audio/audiortp/ZrtpSessionCallback.cpp @@ -150,7 +150,6 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _infoMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } @@ -158,7 +157,6 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _warningMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } @@ -166,10 +164,11 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _severeMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug:"); } } + + if (sev == ZrtpError) { if (subCode < 0) { // received an error packet from peer subCode *= -1; @@ -181,7 +180,7 @@ ZrtpSessionCallback::showMessage (GnuZrtpCodes::MessageSeverity sev, int32_t sub msg = _zrtpMap[subCode]; if (msg != NULL) { - _debug ("ZRTP Debug: %s", msg->c_str()); + } } } diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index ba4e856b301a3009fd1a222f60b157bcbd67fa27..886dc1430f588511d7b3794f3cf77b96a6a31c83 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -489,9 +489,6 @@ void Sdp::set_negotiated_sdp (const pjmedia_sdp_session *sdp) pjmedia_sdp_attr_to_rtpmap (_pool, attribute, &rtpmap); - // _debug("================== set_negociated_offer ===================== %i", pj_strtoul(&rtpmap->pt)); - // _debug("================== set_negociated_offer ===================== %s", current->desc.fmt[j].ptr); - // _debug("================== set_negociated_offer ===================== %i", atoi(current->desc.fmt[j].ptr)); iter = codecs_list.find ( (AudioCodecType) pj_strtoul (&rtpmap->pt)); if (iter==codecs_list.end()) @@ -627,7 +624,7 @@ void Sdp::set_remote_ip_from_sdp (const pjmedia_sdp_session *r_sdp) { std::string remote_ip (r_sdp->conn->addr.ptr, r_sdp->conn->addr.slen); - _debug (" Remote IP from fetching SDP: %s", remote_ip.c_str()); + _info ("SDP: Remote IP from fetching SDP: %s", remote_ip.c_str()); this->set_remote_ip (remote_ip); } @@ -637,21 +634,21 @@ void Sdp::set_remote_audio_port_from_sdp (pjmedia_sdp_media *r_media) int remote_port; remote_port = r_media->desc.port; - _debug (" Remote Audio Port from fetching SDP: %d", remote_port); + _info ("SDP: Remote Audio Port from fetching SDP: %d", remote_port); this->set_remote_audio_port (remote_port); } void Sdp::set_media_transport_info_from_remote_sdp (const pjmedia_sdp_session *remote_sdp) { - _debug ("Fetching media from sdp"); + _info ("SDP: Fetching media from 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"); + _warn ("SDP: Error: no remote sdp media found in the remote offer"); return; } diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 9e25418377d8708030acd33bb9c0a9adb8a38cd6..5c5bed594177da1b7dd388a7f38b1b50cb699d4b 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -1020,7 +1020,7 @@ int SIPVoIPLink::inv_session_reinvite (SIPCall *call, std::string direction) local_sdp = call->getLocalSDP()->get_local_sdp_session(); if (local_sdp == NULL) { - _debug ("! SIP Failure: unable to find local_sdp"); + _debug ("SIP: Error: unable to find local sdp"); return !PJ_SUCCESS; } @@ -3142,7 +3142,7 @@ void call_on_state_changed (pjsip_inv_session *inv, pjsip_event *e) // This callback is called after SDP offer/answer session has completed. void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) { - _debug ("UserAgent: call_on_media_update"); + _debug ("UserAgent: Call on media update"); const pjmedia_sdp_session *local_sdp; const pjmedia_sdp_session *remote_sdp; @@ -3153,19 +3153,19 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) call = reinterpret_cast<SIPCall *> (inv->mod_data[getModId() ]); if (!call) { - _debug ("Call declined by peer, SDP negociation stopped"); + _debug ("UserAgent: Call declined by peer, SDP negociation stopped"); return; } link = dynamic_cast<SIPVoIPLink *> (Manager::instance().getAccountLink (AccountNULL)); if (link == NULL) { - _debug ("Failed to get sip link"); + _warn ("UserAgent: Error: Failed to get sip link"); return; } if (status != PJ_SUCCESS) { - _debug ("Error while negotiating the offer"); + _warn ("UserAgent: Error: while negotiating the offer"); link->hangup (call->getCallId()); Manager::instance().callFailure (call->getCallId()); return; @@ -3198,39 +3198,39 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) } + // Get the crypto attribute containing srtp's cryptographic context (keys, cipher) CryptoOffer crypto_offer; call->getLocalSDP()->get_remote_sdp_crypto_from_offer(remote_sdp, crypto_offer); - bool nego_success = false; if(!crypto_offer.empty()) { - _debug("Crypto attribute in SDP: init Srtp session"); + _debug("Crypto attribute in SDP: init Srtp session"); - // init local cryptografic capabilities for negotiation - std::vector<sfl::CryptoSuiteDefinition>localCapabilities; - for(int i = 0; i < 3; i++) { - localCapabilities.push_back(sfl::CryptoSuites[i]); - } + // init local cryptografic capabilities for negotiation + std::vector<sfl::CryptoSuiteDefinition>localCapabilities; + for(int i = 0; i < 3; i++) { + localCapabilities.push_back(sfl::CryptoSuites[i]); + } - sfl::SdesNegotiator sdesnego(localCapabilities, crypto_offer); + sfl::SdesNegotiator sdesnego(localCapabilities, crypto_offer); - if(sdesnego.negotiate()) { - _debug("SDES negociation successfull \n"); - nego_success = true; + if(sdesnego.negotiate()) { + _debug("SDES negociation successfull \n"); + nego_success = true; _debug("Set remote cryptographic context\n"); try { - call->getAudioRtp()->setRemoteCryptoInfo(sdesnego); + call->getAudioRtp()->setRemoteCryptoInfo(sdesnego); } catch(...) {} - DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); - } - else { - DBusManager::instance().getCallManager()->secureSdesOff (call->getCallId()); - } + DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); + } + else { + DBusManager::instance().getCallManager()->secureSdesOff (call->getCallId()); + } } // We did not found any crypto context for this media @@ -3256,6 +3256,7 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) _debug("Sdes not initialized for this call\n"); } + try { call->setAudioStart (true); call->getAudioRtp()->start();