Skip to content
Snippets Groups Projects
Commit 35994466 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#1722] Uncoupled initAudioRtpConfig from initAudioRtpSession

parent 9c574cc3
Branches
Tags
No related merge requests found
......@@ -54,10 +54,8 @@ AudioRtpFactory::~AudioRtpFactory()
stop();
}
void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
void AudioRtpFactory::initAudioRtpConfig(SIPCall *ca)
{
ost::MutexLock m (_audioRtpThreadMutex);
assert (ca);
if (_rtpSession != NULL) {
......@@ -68,36 +66,35 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
AccountID accountId = Manager::instance().getAccountFromCall (ca->getCallId());
bool srtpEnabled = false;
int keyExchangeProtocol = 1;
bool helloHashEnabled = true;
// Check if it is an IP-to-IP call
if (accountId == AccountNULL) {
srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE);
keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE);
_debug ("Ip-to-ip profile selected with key exchange protocol number %d", keyExchangeProtocol);
helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH);
_srtpEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, SRTP_ENABLE);
_keyExchangeProtocol = Manager::instance().getConfigInt (IP2IP_PROFILE, SRTP_KEY_EXCHANGE);
_debug ("Ip-to-ip profile selected with key exchange protocol number %d", _keyExchangeProtocol);
_helloHashEnabled = Manager::instance().getConfigBool (IP2IP_PROFILE, ZRTP_HELLO_HASH);
} else {
srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE);
keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE);
_debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), keyExchangeProtocol);
helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH);
_srtpEnabled = Manager::instance().getConfigBool (accountId, SRTP_ENABLE);
_keyExchangeProtocol = Manager::instance().getConfigInt (accountId, SRTP_KEY_EXCHANGE);
_debug ("Registered account %s profile selected with key exchange protocol number %d", accountId.c_str(), _keyExchangeProtocol);
_helloHashEnabled = Manager::instance().getConfigBool (accountId, ZRTP_HELLO_HASH);
}
}
_debug ("Srtp enable: %d ", srtpEnabled);
void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
{
ost::MutexLock m (_audioRtpThreadMutex);
if (srtpEnabled) {
_debug ("Srtp enable: %d ", _srtpEnabled);
if (_srtpEnabled) {
std::string zidFilename (Manager::instance().getConfigString (SIGNALISATION, ZRTP_ZIDFILE));
switch (keyExchangeProtocol) {
switch (_keyExchangeProtocol) {
case Zrtp:
_rtpSession = new AudioZrtpSession (&Manager::instance(), ca, zidFilename);
_rtpSessionType = Zrtp;
if (helloHashEnabled) {
if (_helloHashEnabled) {
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
// not even available at that point.
ca->getLocalSDP()->set_zrtp_hash (static_cast<AudioZrtpSession *> (_rtpSession)->getHelloHash());
......
......@@ -61,6 +61,8 @@ namespace sfl {
AudioRtpFactory(SIPCall * ca);
~AudioRtpFactory();
void initAudioRtpConfig(SIPCall *ca);
/**
* Lazy instantiation method. Create a new RTP session of a given
* type according to the content of the configuration file.
......@@ -108,7 +110,22 @@ namespace sfl {
/**
* @param Set internal audio rtp session type (Symmetric, Zrtp, Sdes)
*/
inline RtpMethod setAudioRtpType(RtpMethod type) { _rtpSessionType = type; }
inline void setAudioRtpType(RtpMethod type) { _rtpSessionType = type; }
/**
* Manually set the srtpEnable option (usefull for RTP fallback)
*/
void setSrtpEnabled(bool enable){ _srtpEnabled = enable; }
/**
* Manually set the keyExchangeProtocol parameter (usefull for RTP fallback)
*/
void setKeyExchangeProtocol(int proto){ _keyExchangeProtocol = proto; }
/**
* Manually set the setHelloHashEnabled parameter (usefull for RTP fallback)
*/
void setHelloHashEnabled(bool enable){ _helloHashEnabled = enable; }
/**
* Get the current AudioZrtpSession. Throws an AudioRtpFactoryException
......@@ -127,6 +144,18 @@ namespace sfl {
void * _rtpSession;
RtpMethod _rtpSessionType;
ost::Mutex _audioRtpThreadMutex;
// Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig
bool _srtpEnabled;
// Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig
int _keyExchangeProtocol;
// Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig
bool _helloHashEnabled;
};
}
#endif // __AUDIO_RTP_FACTORY_H__
......@@ -757,6 +757,7 @@ SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl)
try {
_debug ("Creating new rtp session in newOutgoingCall");
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioRtpSession (call);
} catch (...) {
_debug ("Failed to create rtp thread from newOutGoingCall");
......@@ -1060,6 +1061,7 @@ SIPVoIPLink::offhold (const CallID& id)
}
try {
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioRtpSession (call);
} catch (...) {
_debug ("! SIP Failure: Unable to create RTP Session (%s:%d)", __FILE__, __LINE__);
......@@ -1569,6 +1571,7 @@ bool SIPVoIPLink::new_ip_to_ip_call (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()->initAudioRtpSession (call);
} catch (...) {
_debug ("! SIP Failure: Unable to create RTP Session in SIPVoIPLink::new_ip_to_ip_call (%s:%d)", __FILE__, __LINE__);
......@@ -3266,8 +3269,9 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status)
// @TODO if SRTPONLY, CallFail
// if RTPFALLBACK, change RTP session
_debug("Did not found any crypto or negociation failed but Sdes enabled");
call->getAudioRtp()->stop();
call->getAudioRtp()->setAudioRtpType(sfl::Symmetric);
call->getAudioRtp()->setSrtpEnabled(false);
call->getAudioRtp()->initAudioRtpSession(call);
}
......@@ -3661,6 +3665,7 @@ mod_on_rx_request (pjsip_rx_data *rdata)
call->getLocalSDP()->set_ip_address (addrSdp);
try {
call->getAudioRtp()->initAudioRtpConfig (call);
call->getAudioRtp()->initAudioRtpSession (call);
} catch (...) {
_debug ("Failed to create rtp thread from answer");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment