Commit 77b55d14 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

AudioRtpFactory: each instance is associated to exactly one SipCall

parent b2f8867b
......@@ -45,7 +45,7 @@
namespace sfl
{
AudioRtpFactory::AudioRtpFactory() : _rtpSession (NULL), remoteContext(NULL), localContext(NULL)
AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : _rtpSession (NULL), remoteContext(NULL), localContext(NULL), ca_(ca)
{
}
......@@ -55,17 +55,15 @@ AudioRtpFactory::~AudioRtpFactory()
stop();
}
void AudioRtpFactory::initAudioRtpConfig (SIPCall *ca)
void AudioRtpFactory::initAudioRtpConfig ()
{
assert (ca);
if (_rtpSession != NULL) {
_debugException ("An audio rtp thread was already created but not" \
"destroyed. Forcing it before continuing.");
stop();
}
std::string accountId(Manager::instance().getAccountFromCall (ca->getCallId()));
std::string accountId(Manager::instance().getAccountFromCall (ca_->getCallId()));
_debug ("AudioRtpFactory: Init rtp session for account %s", accountId.c_str());
......@@ -102,7 +100,7 @@ void AudioRtpFactory::registerAccount(SIPAccount *sipaccount, const std::string&
_helloHashEnabled = sipaccount->getZrtpHelloHash();
}
void AudioRtpFactory::initAudioSymmetricRtpSession (SIPCall * ca)
void AudioRtpFactory::initAudioSymmetricRtpSession ()
{
ost::MutexLock m (_audioRtpThreadMutex);
......@@ -114,12 +112,12 @@ void AudioRtpFactory::initAudioSymmetricRtpSession (SIPCall * ca)
switch (_keyExchangeProtocol) {
case Zrtp:
_rtpSession = new AudioZrtpSession (ca, zidFilename);
_rtpSession = new AudioZrtpSession (ca_, zidFilename);
if (_helloHashEnabled) {
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
// not even available at that point.
ca->getLocalSDP()->setZrtpHash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash());
ca_->getLocalSDP()->setZrtpHash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash());
_debug ("AudioRtpFactory: Zrtp hello hash fed to SDP");
}
......@@ -127,7 +125,7 @@ void AudioRtpFactory::initAudioSymmetricRtpSession (SIPCall * ca)
case Sdes:
_rtpSession = new AudioSrtpSession (ca);
_rtpSession = new AudioSrtpSession (ca_);
break;
default:
......@@ -135,7 +133,7 @@ void AudioRtpFactory::initAudioSymmetricRtpSession (SIPCall * ca)
throw UnsupportedRtpSessionType();
}
} else {
_rtpSession = new AudioSymmetricRtpSession (ca);
_rtpSession = new AudioSymmetricRtpSession (ca_);
_debug ("AudioRtpFactory: Starting a symmetric unencrypted rtp session");
}
}
......@@ -222,12 +220,12 @@ sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession()
}
}
void sfl::AudioRtpFactory::initLocalCryptoInfo (SIPCall * ca)
void sfl::AudioRtpFactory::initLocalCryptoInfo ()
{
if (_rtpSession && _rtpSession->getAudioRtpType() == Sdes) {
static_cast<AudioSrtpSession *> (_rtpSession)->initLocalCryptoInfo ();
ca->getLocalSDP()->setLocalSdpCrypto (static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
ca_->getLocalSDP()->setLocalSdpCrypto (static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo());
}
}
......
......@@ -65,10 +65,10 @@ class AudioRtpFactoryException : public std::logic_error
class AudioRtpFactory
{
public:
AudioRtpFactory();
AudioRtpFactory(SIPCall *ca);
~AudioRtpFactory();
void initAudioRtpConfig (SIPCall *ca);
void initAudioRtpConfig ();
/**
* Lazy instantiation method. Create a new RTP session of a given
......@@ -76,7 +76,7 @@ class AudioRtpFactory
* @param ca A pointer on a SIP call
* @return A new AudioSymmetricRtpSession object
*/
void initAudioSymmetricRtpSession (SIPCall *ca);
void initAudioSymmetricRtpSession ();
/**
* Start the audio rtp thread of the type specified in the configuration
......@@ -147,7 +147,7 @@ class AudioRtpFactory
*/
sfl::AudioZrtpSession * getAudioZrtpSession();
void initLocalCryptoInfo (SIPCall *ca);
void initLocalCryptoInfo ();
/**
* Set remote cryptographic info. Should be called after negotiation in SDP
......@@ -188,6 +188,8 @@ class AudioRtpFactory
/** Local srtp crypto context to be set into outgoing data queue. */
ost::CryptoContext *localContext;
SIPCall *ca_;
};
}
#endif // __AUDIO_RTP_FACTORY_H__
......@@ -43,7 +43,7 @@ SIPCall::SIPCall (const CallID& id, Call::CallType type, pj_caching_pool *cachin
, _cid (0)
, _did (0)
, _tid (0)
, _audiortp (new sfl::AudioRtpFactory())
, _audiortp (new sfl::AudioRtpFactory(this))
, _xferSub (NULL)
, _invSession (NULL)
, _local_sdp (NULL)
......
......@@ -715,9 +715,9 @@ Call *SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl)
try {
_info ("UserAgent: Creating new rtp session");
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioSymmetricRtpSession (call);
call->getAudioRtp()->initLocalCryptoInfo (call);
call->getAudioRtp()->initAudioRtpConfig ();
call->getAudioRtp()->initAudioSymmetricRtpSession ();
call->getAudioRtp()->initLocalCryptoInfo ();
_info ("UserAgent: Start audio rtp session");
call->getAudioRtp()->start (static_cast<sfl::AudioCodec *>(audiocodec));
} catch (...) {
......@@ -1019,8 +1019,8 @@ SIPVoIPLink::offhold (const CallID& id) throw (VoipLinkException)
throw VoipLinkException("Could not instantiate codec");
}
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioSymmetricRtpSession (call);
call->getAudioRtp()->initAudioRtpConfig ();
call->getAudioRtp()->initAudioSymmetricRtpSession ();
call->getAudioRtp()->start (static_cast<sfl::AudioCodec *>(audiocodec));
}
......@@ -1789,9 +1789,9 @@ bool SIPVoIPLink::SIPNewIpToIpCall (const CallID& id, const std::string& to)
// Audio Rtp Session must be initialized before creating initial offer in SDP session
// since SDES require crypto attribute.
try {
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioSymmetricRtpSession (call);
call->getAudioRtp()->initLocalCryptoInfo (call);
call->getAudioRtp()->initAudioRtpConfig ();
call->getAudioRtp()->initAudioSymmetricRtpSession ();
call->getAudioRtp()->initLocalCryptoInfo ();
call->getAudioRtp()->start (static_cast<sfl::AudioCodec *>(audiocodec));
} catch (...) {
_debug ("UserAgent: Unable to create RTP Session in new IP2IP call (%s:%d)", __FILE__, __LINE__);
......@@ -3495,7 +3495,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status)
SIPAccount *account = (SIPAccount *) Manager::instance().getAccount (accountID);
if (account->getSrtpFallback())
call->getAudioRtp()->initAudioSymmetricRtpSession (call);
call->getAudioRtp()->initAudioSymmetricRtpSession ();
}
if (!sdpSession)
......@@ -3971,8 +3971,8 @@ transaction_request_cb (pjsip_rx_data *rdata)
// Init audio rtp session
try {
_debug ("UserAgent: Create RTP session for this call");
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioSymmetricRtpSession (call);
call->getAudioRtp()->initAudioRtpConfig ();
call->getAudioRtp()->initAudioSymmetricRtpSession ();
} catch (...) {
_warn ("UserAgent: Error: Failed to create rtp thread from answer");
}
......@@ -4016,7 +4016,7 @@ transaction_request_cb (pjsip_rx_data *rdata)
try {
_debug ("UserAgent: Create RTP session for this call");
call->getAudioRtp()->setRemoteCryptoInfo (sdesnego);
call->getAudioRtp()->initLocalCryptoInfo (call);
call->getAudioRtp()->initLocalCryptoInfo ();
} catch (...) {
_warn ("UserAgent: Error: Failed to create rtp thread from answer");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment