Commit be6905d9 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #7131: cleanup, remove underscore prefix vars

parent d2f15f8d
...@@ -42,17 +42,17 @@ ...@@ -42,17 +42,17 @@
namespace sfl { namespace sfl {
AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : _rtpSession(NULL), remoteContext(NULL), localContext(NULL), ca_(ca) AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL), remoteContext_(NULL), localContext_(NULL), ca_(ca)
{} {}
AudioRtpFactory::~AudioRtpFactory() AudioRtpFactory::~AudioRtpFactory()
{ {
delete _rtpSession; delete rtpSession_;
} }
void AudioRtpFactory::initAudioRtpConfig() void AudioRtpFactory::initAudioRtpConfig()
{ {
if (_rtpSession != NULL) if (rtpSession_ != NULL)
stop(); stop();
std::string accountId(Manager::instance().getAccountFromCall(ca_->getCallId())); std::string accountId(Manager::instance().getAccountFromCall(ca_->getCallId()));
...@@ -60,150 +60,136 @@ void AudioRtpFactory::initAudioRtpConfig() ...@@ -60,150 +60,136 @@ void AudioRtpFactory::initAudioRtpConfig()
SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(accountId)); SIPAccount *account = dynamic_cast<SIPAccount *>(Manager::instance().getAccount(accountId));
if (account) { if (account) {
_srtpEnabled = account->getSrtpEnabled(); srtpEnabled_ = account->getSrtpEnabled();
std::string key(account->getSrtpKeyExchange()); std::string key(account->getSrtpKeyExchange());
if (key == "sdes") if (key == "sdes")
_keyExchangeProtocol = Sdes; keyExchangeProtocol_ = Sdes;
else if (key == "zrtp") else if (key == "zrtp")
_keyExchangeProtocol = Zrtp; keyExchangeProtocol_ = Zrtp;
else else
_keyExchangeProtocol = Symmetric; keyExchangeProtocol_ = Symmetric;
_helloHashEnabled = account->getZrtpHelloHash(); helloHashEnabled_ = account->getZrtpHelloHash();
} else { } else {
_srtpEnabled = false; srtpEnabled_ = false;
_keyExchangeProtocol = Symmetric; keyExchangeProtocol_ = Symmetric;
_helloHashEnabled = false; helloHashEnabled_ = false;
} }
} }
void AudioRtpFactory::initAudioSymmetricRtpSession() void AudioRtpFactory::initAudioSymmetricRtpSession()
{ {
ost::MutexLock m(_audioRtpThreadMutex); ost::MutexLock m(audioRtpThreadMutex_);
if (_srtpEnabled) { if (srtpEnabled_) {
std::string zidFilename(Manager::instance().voipPreferences.getZidFile()); std::string zidFilename(Manager::instance().voipPreferences.getZidFile());
switch (_keyExchangeProtocol) { switch (keyExchangeProtocol_) {
case Zrtp: case Zrtp:
_rtpSession = new AudioZrtpSession(ca_, zidFilename); rtpSession_ = new AudioZrtpSession(ca_, zidFilename);
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's
if (_helloHashEnabled) { // not even available at that point.
// TODO: be careful with that. The hello hash is computed asynchronously. Maybe it's if (helloHashEnabled_)
// not even available at that point. ca_->getLocalSDP()->setZrtpHash(static_cast<AudioZrtpSession *>(rtpSession_)->getHelloHash());
ca_->getLocalSDP()->setZrtpHash(static_cast<AudioZrtpSession *>(_rtpSession)->getHelloHash());
}
break; break;
case Sdes: case Sdes:
_rtpSession = new AudioSrtpSession(ca_); rtpSession_ = new AudioSrtpSession(ca_);
break; break;
default: default:
throw UnsupportedRtpSessionType("Unsupported Rtp Session Exception Type!"); throw UnsupportedRtpSessionType("Unsupported Rtp Session Exception Type!");
} }
} else { } else
_rtpSession = new AudioSymmetricRtpSession(ca_); rtpSession_ = new AudioSymmetricRtpSession(ca_);
}
} }
void AudioRtpFactory::start(AudioCodec* audiocodec) void AudioRtpFactory::start(AudioCodec* audiocodec)
{ {
if (_rtpSession == NULL) { if (rtpSession_ == NULL)
throw AudioRtpFactoryException("AudioRtpFactory: Error: RTP session was null when trying to start audio thread"); throw AudioRtpFactoryException("AudioRtpFactory: Error: RTP session was null when trying to start audio thread");
}
if (_rtpSession->getAudioRtpType() == Sdes) { if (rtpSession_->getAudioRtpType() == Sdes)
if (localContext && remoteContext) { if (localContext_ and remoteContext_)
static_cast<AudioSrtpSession *>(_rtpSession)->restoreCryptoContext(localContext, remoteContext); static_cast<AudioSrtpSession *>(rtpSession_)->restoreCryptoContext(localContext_, remoteContext_);
}
}
if (_rtpSession->startRtpThread(audiocodec) != 0) { if (rtpSession_->startRtpThread(audiocodec) != 0)
throw AudioRtpFactoryException("AudioRtpFactory: Error: Failed to start AudioZrtpSession thread"); throw AudioRtpFactoryException("AudioRtpFactory: Error: Failed to start AudioZrtpSession thread");
}
} }
void AudioRtpFactory::stop(void) void AudioRtpFactory::stop()
{ {
ost::MutexLock mutex(_audioRtpThreadMutex); ost::MutexLock mutex(audioRtpThreadMutex_);
if (_rtpSession == NULL) if (rtpSession_ == NULL)
return; return;
if (_rtpSession->getAudioRtpType() == Sdes) { if (rtpSession_->getAudioRtpType() == Sdes) {
localContext = static_cast<AudioSrtpSession *>(_rtpSession)->_localCryptoCtx; localContext_ = static_cast<AudioSrtpSession*>(rtpSession_)->localCryptoCtx_;
remoteContext = static_cast<AudioSrtpSession *>(_rtpSession)->_remoteCryptoCtx; remoteContext_ = static_cast<AudioSrtpSession*>(rtpSession_)->remoteCryptoCtx_;
} }
delete _rtpSession; delete rtpSession_;
_rtpSession = NULL; rtpSession_ = NULL;
} }
int AudioRtpFactory::getSessionMedia() int AudioRtpFactory::getSessionMedia()
{ {
if (_rtpSession == NULL) { if (rtpSession_ == NULL)
throw AudioRtpFactoryException("AudioRtpFactory: Error: RTP session was null when trying to get session media type"); throw AudioRtpFactoryException("AudioRtpFactory: Error: RTP session was null when trying to get session media type");
}
return _rtpSession->getCodecPayloadType(); return rtpSession_->getCodecPayloadType();
} }
void AudioRtpFactory::updateSessionMedia(AudioCodec *audiocodec) void AudioRtpFactory::updateSessionMedia(AudioCodec *audiocodec)
{ {
if (_rtpSession == NULL) { if (rtpSession_ == NULL)
throw AudioRtpFactoryException("AudioRtpFactory: Error: _rtpSession was null when trying to update IP address"); throw AudioRtpFactoryException("AudioRtpFactory: Error: rtpSession_ was null when trying to update IP address");
}
_rtpSession->updateSessionMedia(audiocodec); rtpSession_->updateSessionMedia(audiocodec);
} }
void AudioRtpFactory::updateDestinationIpAddress(void) void AudioRtpFactory::updateDestinationIpAddress()
{ {
if (_rtpSession) if (rtpSession_)
_rtpSession->updateDestinationIpAddress(); rtpSession_->updateDestinationIpAddress();
} }
sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession() sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession()
{ {
if (_rtpSession->getAudioRtpType() == Zrtp) { if (rtpSession_->getAudioRtpType() == Zrtp)
return static_cast<AudioZrtpSession *>(_rtpSession); return static_cast<AudioZrtpSession *>(rtpSession_);
} else { else
throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in getAudioZrtpSession"); throw AudioRtpFactoryException("RTP: Error: rtpSession_ is NULL in getAudioZrtpSession");
}
} }
void sfl::AudioRtpFactory::initLocalCryptoInfo() void sfl::AudioRtpFactory::initLocalCryptoInfo()
{ {
if (_rtpSession && _rtpSession->getAudioRtpType() == Sdes) { if (rtpSession_ && rtpSession_->getAudioRtpType() == Sdes) {
static_cast<AudioSrtpSession *>(_rtpSession)->initLocalCryptoInfo(); static_cast<AudioSrtpSession *>(rtpSession_)->initLocalCryptoInfo();
ca_->getLocalSDP()->setLocalSdpCrypto(static_cast<AudioSrtpSession *>(rtpSession_)->getLocalCryptoInfo());
ca_->getLocalSDP()->setLocalSdpCrypto(static_cast<AudioSrtpSession *>(_rtpSession)->getLocalCryptoInfo());
} }
} }
void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego)
{ {
if (_rtpSession && _rtpSession->getAudioRtpType() == Sdes) { if (rtpSession_ && rtpSession_->getAudioRtpType() == Sdes)
static_cast<AudioSrtpSession *>(_rtpSession)->setRemoteCryptoInfo(nego); static_cast<AudioSrtpSession *>(rtpSession_)->setRemoteCryptoInfo(nego);
} else { else
throw AudioRtpFactoryException("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo"); throw AudioRtpFactoryException("RTP: Error: rtpSession_ is NULL in setRemoteCryptoInfo");
}
} }
void AudioRtpFactory::setDtmfPayloadType(unsigned int payloadType) void AudioRtpFactory::setDtmfPayloadType(unsigned int payloadType)
{ {
if (_rtpSession) if (rtpSession_)
_rtpSession->setDtmfPayloadType(payloadType); rtpSession_->setDtmfPayloadType(payloadType);
} }
void AudioRtpFactory::sendDtmfDigit(int digit) void AudioRtpFactory::sendDtmfDigit(int digit)
{ {
_rtpSession->putDtmfEvent(digit); rtpSession_->putDtmfEvent(digit);
} }
} }
...@@ -99,17 +99,17 @@ class AudioRtpFactory { ...@@ -99,17 +99,17 @@ class AudioRtpFactory {
* Update current RTP destination address with one stored in call * Update current RTP destination address with one stored in call
* @param None * @param None
*/ */
void updateDestinationIpAddress(void); void updateDestinationIpAddress();
bool isSdesEnabled(void) const { bool isSdesEnabled() const {
return _srtpEnabled && _keyExchangeProtocol == sfl::Sdes; return srtpEnabled_ and keyExchangeProtocol_ == sfl::Sdes;
} }
/** /**
* Manually set the srtpEnable option (usefull for RTP fallback) * Manually set the srtpEnable option (usefull for RTP fallback)
*/ */
void setSrtpEnabled(bool enable) { void setSrtpEnabled(bool enable) {
_srtpEnabled = enable; srtpEnabled_ = enable;
} }
/** /**
...@@ -138,26 +138,26 @@ class AudioRtpFactory { ...@@ -138,26 +138,26 @@ class AudioRtpFactory {
void sendDtmfDigit(int digit); void sendDtmfDigit(int digit);
private: private:
AudioRtpSession *_rtpSession; AudioRtpSession *rtpSession_;
ost::Mutex _audioRtpThreadMutex; ost::Mutex audioRtpThreadMutex_;
// Field used when initializinga udio rtp session // Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig // May be set manually or from config using initAudioRtpConfig
bool _srtpEnabled; bool srtpEnabled_;
// Field used when initializinga udio rtp session // Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig // May be set manually or from config using initAudioRtpConfig
RtpMethod _keyExchangeProtocol; RtpMethod keyExchangeProtocol_;
// Field used when initializinga udio rtp session // Field used when initializinga udio rtp session
// May be set manually or from config using initAudioRtpConfig // May be set manually or from config using initAudioRtpConfig
bool _helloHashEnabled; bool helloHashEnabled_;
/** Remote srtp crypto context to be set into incoming data queue. */ /** Remote srtp crypto context to be set into incoming data queue. */
ost::CryptoContext *remoteContext; ost::CryptoContext *remoteContext_;
/** Local srtp crypto context to be set into outgoing data queue. */ /** Local srtp crypto context to be set into outgoing data queue. */
ost::CryptoContext *localContext; ost::CryptoContext *localContext_;
SIPCall *ca_; SIPCall *ca_;
}; };
......
...@@ -38,76 +38,66 @@ namespace sfl { ...@@ -38,76 +38,66 @@ namespace sfl {
static const SFLDataFormat initFadeinFactor = 32000; static const SFLDataFormat initFadeinFactor = 32000;
AudioRtpRecord::AudioRtpRecord() : _audioCodec(NULL) AudioRtpRecord::AudioRtpRecord() : audioCodec_(NULL)
, _hasDynamicPayloadType(false) , hasDynamicPayloadType_(false)
, _converter(NULL) , converter_(NULL)
, _codecSampleRate(0) , codecSampleRate_(0)
, _codecFrameSize(0) , codecFrameSize_(0)
, _micAmplFactor(initFadeinFactor) , micAmplFactor_(initFadeinFactor)
, _noiseSuppress(NULL) , noiseSuppress_(NULL)
, _callId("") , callId_("")
, _dtmfPayloadType(101) // same as Asterisk , dtmfPayloadType_(101) // same as Asterisk
{ {}
}
AudioRtpRecord::~AudioRtpRecord() AudioRtpRecord::~AudioRtpRecord()
{ {
delete _converter; delete converter_;
delete _audioCodec; delete audioCodec_;
delete _noiseSuppress; delete noiseSuppress_;
} }
AudioRtpRecordHandler::AudioRtpRecordHandler(SIPCall *ca) : _audioRtpRecord(), id_(ca->getCallId()), echoCanceller(ca->getMemoryPool()), gainController(8000, -10.0) AudioRtpRecordHandler::AudioRtpRecordHandler(SIPCall *ca) : audioRtpRecord_(), id_(ca->getCallId()), echoCanceller(ca->getMemoryPool()), gainController(8000, -10.0)
{ {}
}
AudioRtpRecordHandler::~AudioRtpRecordHandler() {} AudioRtpRecordHandler::~AudioRtpRecordHandler() {}
void AudioRtpRecordHandler::setRtpMedia(AudioCodec* audioCodec) void AudioRtpRecordHandler::setRtpMedia(AudioCodec* audioCodec)
{ {
_audioRtpRecord.audioCodecMutex.enter(); ost::MutexLock lock(audioRtpRecord_.audioCodecMutex_);
delete _audioRtpRecord._audioCodec; delete audioRtpRecord_.audioCodec_;
// Set varios codec info to reduce indirection // Set varios codec info to reduce indirection
_audioRtpRecord._audioCodec = audioCodec; audioRtpRecord_.audioCodec_ = audioCodec;
_audioRtpRecord._codecPayloadType = audioCodec->getPayloadType(); audioRtpRecord_.codecPayloadType_ = audioCodec->getPayloadType();
_audioRtpRecord._codecSampleRate = audioCodec->getClockRate(); audioRtpRecord_.codecSampleRate_ = audioCodec->getClockRate();
_audioRtpRecord._codecFrameSize = audioCodec->getFrameSize(); audioRtpRecord_.codecFrameSize_ = audioCodec->getFrameSize();
_audioRtpRecord._hasDynamicPayloadType = audioCodec->hasDynamicPayload(); audioRtpRecord_.hasDynamicPayloadType_ = audioCodec->hasDynamicPayload();
_audioRtpRecord.audioCodecMutex.leave();
} }
void AudioRtpRecordHandler::initBuffers() void AudioRtpRecordHandler::initBuffers()
{ {
// Set sampling rate, main buffer choose the highest one // Set sampling rate, main buffer choose the highest one
Manager::instance().audioSamplingRateChanged(_audioRtpRecord._codecSampleRate); Manager::instance().audioSamplingRateChanged(audioRtpRecord_.codecSampleRate_);
// initialize SampleRate converter using AudioLayer's sampling rate // initialize SampleRate converter using AudioLayer's sampling rate
// (internal buffers initialized with maximal sampling rate and frame size) // (internal buffers initialized with maximal sampling rate and frame size)
delete _audioRtpRecord._converter; delete audioRtpRecord_.converter_;
_audioRtpRecord._converter = new SamplerateConverter(getCodecSampleRate()); audioRtpRecord_.converter_ = new SamplerateConverter(getCodecSampleRate());
} }
void AudioRtpRecordHandler::initNoiseSuppress() void AudioRtpRecordHandler::initNoiseSuppress()
{ {
_audioRtpRecord.audioProcessMutex.enter(); ost::MutexLock lock(audioRtpRecord_.audioProcessMutex_);
delete audioRtpRecord_.noiseSuppress_;
delete _audioRtpRecord._noiseSuppress; audioRtpRecord_.noiseSuppress_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate());
_audioRtpRecord._noiseSuppress = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate());
_audioRtpRecord.audioProcessMutex.leave();
} }
void AudioRtpRecordHandler::putDtmfEvent(int digit) void AudioRtpRecordHandler::putDtmfEvent(int digit)
{ {
_audioRtpRecord._dtmfQueue.push_back(digit); audioRtpRecord_.dtmfQueue_.push_back(digit);
} }
#ifdef DUMP_PROCESS_DATA_ENCODE #ifdef DUMP_PROCESS_DATA_ENCODE
...@@ -116,9 +106,9 @@ std::ofstream teststream("test_process_data_encode.raw"); ...@@ -116,9 +106,9 @@ std::ofstream teststream("test_process_data_encode.raw");
int AudioRtpRecordHandler::processDataEncode(void) int AudioRtpRecordHandler::processDataEncode(void)
{ {
SFLDataFormat *micData = _audioRtpRecord.decData; SFLDataFormat *micData = audioRtpRecord_.decData_;
unsigned char *micDataEncoded = _audioRtpRecord.encodedData; unsigned char *micDataEncoded = audioRtpRecord_.encodedData_;
SFLDataFormat *micDataConverted = _audioRtpRecord.resampledData; SFLDataFormat *micDataConverted = audioRtpRecord_.resampledData_;
int codecSampleRate = getCodecSampleRate(); int codecSampleRate = getCodecSampleRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate(); int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
...@@ -129,9 +119,8 @@ int AudioRtpRecordHandler::processDataEncode(void) ...@@ -129,9 +119,8 @@ int AudioRtpRecordHandler::processDataEncode(void)
int samplesToGet = resampleFactor * getCodecFrameSize(); int samplesToGet = resampleFactor * getCodecFrameSize();
int bytesToGet = samplesToGet * sizeof(SFLDataFormat); int bytesToGet = samplesToGet * sizeof(SFLDataFormat);
if (Manager::instance().getMainBuffer()->availForGet(id_) < bytesToGet) { if (Manager::instance().getMainBuffer()->availForGet(id_) < bytesToGet)
return 0; return 0;
}
int bytes = Manager::instance().getMainBuffer()->getData(micData, bytesToGet, id_); int bytes = Manager::instance().getMainBuffer()->getData(micData, bytesToGet, id_);
...@@ -142,7 +131,7 @@ int AudioRtpRecordHandler::processDataEncode(void) ...@@ -142,7 +131,7 @@ int AudioRtpRecordHandler::processDataEncode(void)
int samples = bytesToGet / sizeof(SFLDataFormat); int samples = bytesToGet / sizeof(SFLDataFormat);
fadeIn(micData, samples, &_audioRtpRecord._micAmplFactor); fadeIn(micData, samples, &audioRtpRecord_.micAmplFactor_);
if (Manager::instance().getEchoCancelState()) if (Manager::instance().getEchoCancelState())
echoCanceller.getData(micData); echoCanceller.getData(micData);
...@@ -155,18 +144,19 @@ int AudioRtpRecordHandler::processDataEncode(void) ...@@ -155,18 +144,19 @@ int AudioRtpRecordHandler::processDataEncode(void)
if (codecSampleRate != mainBufferSampleRate) { if (codecSampleRate != mainBufferSampleRate) {
out = micDataConverted; out = micDataConverted;
_audioRtpRecord._converter->resample(micData, micDataConverted, codecSampleRate, mainBufferSampleRate, samplesToGet); audioRtpRecord_.converter_->resample(micData, micDataConverted, codecSampleRate, mainBufferSampleRate, samplesToGet);
} }
if (Manager::instance().audioPreference.getNoiseReduce()) { if (Manager::instance().audioPreference.getNoiseReduce()) {
_audioRtpRecord.audioProcessMutex.enter(); ost::MutexLock lock(audioRtpRecord_.audioProcessMutex_);
_audioRtpRecord._noiseSuppress->process(micData, getCodecFrameSize()); audioRtpRecord_.noiseSuppress_->process(micData, getCodecFrameSize());
_audioRtpRecord.audioProcessMutex.leave();
} }
_audioRtpRecord.audioCodecMutex.enter(); int compSize;
int compSize = _audioRtpRecord._audioCodec->encode(micDataEncoded, out, getCodecFrameSize()); {
_audioRtpRecord.audioCodecMutex.leave(); ost::MutexLock lock(audioRtpRecord_.audioCodecMutex_);
compSize = audioRtpRecord_.audioCodec_->encode(micDataEncoded, out, getCodecFrameSize());
}
return compSize; return compSize;
} }
...@@ -178,19 +168,19 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, unsigned ...@@ -178,19 +168,19 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, unsigned
int codecSampleRate = getCodecSampleRate(); int codecSampleRate = getCodecSampleRate();
SFLDataFormat *spkrDataDecoded = _audioRtpRecord.decData; SFLDataFormat *spkrDataDecoded = audioRtpRecord_.decData_;
SFLDataFormat *spkrDataConverted = _audioRtpRecord.resampledData; SFLDataFormat *spkrDataConverted = audioRtpRecord_.resampledData_;