Commit 89852b37 authored by Emmanuel Milou's avatar Emmanuel Milou
parents 2a618dd6 647e0645
...@@ -84,8 +84,6 @@ libsflphone_la_SOURCES = conference.cpp \ ...@@ -84,8 +84,6 @@ libsflphone_la_SOURCES = conference.cpp \
logger.cpp \ logger.cpp \
numbercleaner.cpp \ numbercleaner.cpp \
fileutils.cpp \ fileutils.cpp \
scoped_lock.cpp \
scoped_lock.h \
sflthread.cpp \ sflthread.cpp \
sflthread.h \ sflthread.h \
conference.h \ conference.h \
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "audiolayer.h" #include "audiolayer.h"
#include "audio/dcblocker.h" #include "audio/dcblocker.h"
#include "manager.h" #include "manager.h"
#include "scoped_lock.h"
AudioLayer::AudioLayer() AudioLayer::AudioLayer()
: captureGain_(1.0) : captureGain_(1.0)
...@@ -47,31 +46,25 @@ AudioLayer::AudioLayer() ...@@ -47,31 +46,25 @@ AudioLayer::AudioLayer()
, converter_(sampleRate_) , converter_(sampleRate_)
, lastNotificationTime_(0) , lastNotificationTime_(0)
{ {
pthread_mutex_init(&mutex_, NULL);
urgentRingBuffer_.createReadPointer(MainBuffer::DEFAULT_ID); urgentRingBuffer_.createReadPointer(MainBuffer::DEFAULT_ID);
} }
AudioLayer::~AudioLayer()
{
pthread_mutex_destroy(&mutex_);
}
void AudioLayer::flushMain() void AudioLayer::flushMain()
{ {
sfl::ScopedLock guard(mutex_); std::lock_guard<std::mutex> lock(mutex_);
// should pass call id // should pass call id
Manager::instance().getMainBuffer().flushAllBuffers(); Manager::instance().getMainBuffer().flushAllBuffers();
} }
void AudioLayer::flushUrgent() void AudioLayer::flushUrgent()
{ {
sfl::ScopedLock guard(mutex_); std::lock_guard<std::mutex> lock(mutex_);
urgentRingBuffer_.flushAll(); urgentRingBuffer_.flushAll();
} }
void AudioLayer::putUrgent(AudioBuffer& buffer) void AudioLayer::putUrgent(AudioBuffer& buffer)
{ {
sfl::ScopedLock guard(mutex_); std::lock_guard<std::mutex> lock(mutex_);
urgentRingBuffer_.put(buffer); urgentRingBuffer_.put(buffer);
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#ifndef AUDIO_LAYER_H_ #ifndef AUDIO_LAYER_H_
#define AUDIO_LAYER_H_ #define AUDIO_LAYER_H_
#include <pthread.h> #include <mutex>
#include <sys/time.h> #include <sys/time.h>
#include <vector> #include <vector>
#include "ringbuffer.h" #include "ringbuffer.h"
...@@ -80,7 +80,7 @@ class AudioLayer { ...@@ -80,7 +80,7 @@ class AudioLayer {
}; };
AudioLayer(); AudioLayer();
virtual ~AudioLayer(); virtual ~AudioLayer() = default;
virtual std::vector<std::string> getCaptureDeviceList() const = 0; virtual std::vector<std::string> getCaptureDeviceList() const = 0;
virtual std::vector<std::string> getPlaybackDeviceList() const = 0; virtual std::vector<std::string> getPlaybackDeviceList() const = 0;
...@@ -216,7 +216,7 @@ class AudioLayer { ...@@ -216,7 +216,7 @@ class AudioLayer {
/** /**
* Lock for the entire audio layer * Lock for the entire audio layer
*/ */
pthread_mutex_t mutex_; std::mutex mutex_;
/** /**
* Remove audio offset that can be introduced by certain cheap audio device * Remove audio offset that can be introduced by certain cheap audio device
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "sip/sipcall.h" #include "sip/sipcall.h"
#include "sip/sipaccount.h" #include "sip/sipaccount.h"
#include "sip/sdes_negotiator.h" #include "sip/sdes_negotiator.h"
#include "scoped_lock.h"
#include "logger.h" #include "logger.h"
namespace sfl { namespace sfl {
...@@ -55,14 +54,11 @@ AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL), ...@@ -55,14 +54,11 @@ AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL),
cachedRemoteMasterSalt_(MAX_MASTER_SALT_LENGTH), cachedRemoteMasterSalt_(MAX_MASTER_SALT_LENGTH),
remoteOfferIsSet_(false), ca_(ca), remoteOfferIsSet_(false), ca_(ca),
keyExchangeProtocol_(NONE) keyExchangeProtocol_(NONE)
{ {}
pthread_mutex_init(&audioRtpThreadMutex_, NULL);
}
AudioRtpFactory::~AudioRtpFactory() AudioRtpFactory::~AudioRtpFactory()
{ {
delete rtpSession_; delete rtpSession_;
pthread_mutex_destroy(&audioRtpThreadMutex_);
} }
void AudioRtpFactory::initConfig() void AudioRtpFactory::initConfig()
...@@ -105,7 +101,7 @@ void AudioRtpFactory::initConfig() ...@@ -105,7 +101,7 @@ void AudioRtpFactory::initConfig()
void AudioRtpFactory::initSession() void AudioRtpFactory::initSession()
{ {
ScopedLock m(audioRtpThreadMutex_); std::lock_guard<std::mutex> lock(audioRtpThreadMutex_);
if (srtpEnabled_) { if (srtpEnabled_) {
const std::string zidFilename(Manager::instance().voipPreferences.getZidFile()); const std::string zidFilename(Manager::instance().voipPreferences.getZidFile());
...@@ -151,7 +147,7 @@ void AudioRtpFactory::start(const std::vector<AudioCodec*> &audioCodecs) ...@@ -151,7 +147,7 @@ void AudioRtpFactory::start(const std::vector<AudioCodec*> &audioCodecs)
void AudioRtpFactory::stop() void AudioRtpFactory::stop()
{ {
ScopedLock mutex(audioRtpThreadMutex_); std::lock_guard<std::mutex> lock(audioRtpThreadMutex_);
delete rtpSession_; delete rtpSession_;
rtpSession_ = NULL; rtpSession_ = NULL;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
#include <ccrtp/CryptoContext.h> #include <ccrtp/CryptoContext.h>
#include <stdexcept> #include <stdexcept>
#include <tr1/array> #include <mutex>
#include <pthread.h>
#include "audio_rtp_session.h" #include "audio_rtp_session.h"
#include "audio_srtp_session.h" #include "audio_srtp_session.h"
#include "noncopyable.h" #include "noncopyable.h"
...@@ -159,7 +158,7 @@ class AudioRtpFactory { ...@@ -159,7 +158,7 @@ class AudioRtpFactory {
NON_COPYABLE(AudioRtpFactory); NON_COPYABLE(AudioRtpFactory);
enum KeyExchangeProtocol { NONE, SDES, ZRTP }; enum KeyExchangeProtocol { NONE, SDES, ZRTP };
AudioRtpSession *rtpSession_; AudioRtpSession *rtpSession_;
pthread_mutex_t audioRtpThreadMutex_; std::mutex audioRtpThreadMutex_;
// Field used when initializing audio rtp session // Field used when initializing audio rtp session
// May be set manually or from config using initAudioRtpConfig // May be set manually or from config using initAudioRtpConfig
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include "logger.h" #include "logger.h"
#include "sip/sipcall.h" #include "sip/sipcall.h"
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "scoped_lock.h"
#include "manager.h" #include "manager.h"
namespace sfl { namespace sfl {
...@@ -115,12 +114,7 @@ AudioRtpRecord::AudioRtpRecord() : ...@@ -115,12 +114,7 @@ AudioRtpRecord::AudioRtpRecord() :
, dtmfPayloadType_(101) // same as Asterisk , dtmfPayloadType_(101) // same as Asterisk
, dead_(false) , dead_(false)
, currentCodecIndex_(0) , currentCodecIndex_(0)
{ {}
pthread_mutex_init(&audioCodecMutex_, NULL);
#if HAVE_SPEEXDSP
pthread_mutex_init(&audioProcessMutex_, NULL);
#endif
}
// Call from processData* // Call from processData*
bool AudioRtpRecord::isDead() bool AudioRtpRecord::isDead()
...@@ -182,22 +176,17 @@ AudioRtpRecord::~AudioRtpRecord() ...@@ -182,22 +176,17 @@ AudioRtpRecord::~AudioRtpRecord()
delete converterDecode_; delete converterDecode_;
converterDecode_ = 0; converterDecode_ = 0;
{ {
ScopedLock lock(audioCodecMutex_); std::lock_guard<std::mutex> lock(audioCodecMutex_);
deleteCodecs(); deleteCodecs();
} }
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
{ {
ScopedLock lock(audioProcessMutex_); std::lock_guard<std::mutex> lock(audioProcessMutex_);
delete noiseSuppressDecode_; delete noiseSuppressDecode_;
noiseSuppressDecode_ = 0; noiseSuppressDecode_ = 0;
delete noiseSuppressEncode_; delete noiseSuppressEncode_;
noiseSuppressEncode_ = 0; noiseSuppressEncode_ = 0;
} }
#endif
pthread_mutex_destroy(&audioCodecMutex_);
#if HAVE_SPEEXDSP
pthread_mutex_destroy(&audioProcessMutex_);
#endif #endif
} }
...@@ -217,7 +206,7 @@ std::string ...@@ -217,7 +206,7 @@ std::string
AudioRtpRecordHandler::getCurrentAudioCodecNames() AudioRtpRecordHandler::getCurrentAudioCodecNames()
{ {
std::string result; std::string result;
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
{ {
std::string sep = ""; std::string sep = "";
...@@ -234,7 +223,7 @@ AudioRtpRecordHandler::getCurrentAudioCodecNames() ...@@ -234,7 +223,7 @@ AudioRtpRecordHandler::getCurrentAudioCodecNames()
void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs) void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs)
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
audioRtpRecord_.deleteCodecs(); audioRtpRecord_.deleteCodecs();
// Set various codec info to reduce indirection // Set various codec info to reduce indirection
...@@ -268,7 +257,7 @@ void AudioRtpRecordHandler::initBuffers() ...@@ -268,7 +257,7 @@ void AudioRtpRecordHandler::initBuffers()
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
void AudioRtpRecordHandler::initNoiseSuppress() void AudioRtpRecordHandler::initNoiseSuppress()
{ {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
delete audioRtpRecord_.noiseSuppressEncode_; delete audioRtpRecord_.noiseSuppressEncode_;
audioRtpRecord_.noiseSuppressEncode_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate()); audioRtpRecord_.noiseSuppressEncode_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate());
delete audioRtpRecord_.noiseSuppressDecode_; delete audioRtpRecord_.noiseSuppressDecode_;
...@@ -334,7 +323,7 @@ int AudioRtpRecordHandler::processDataEncode() ...@@ -334,7 +323,7 @@ int AudioRtpRecordHandler::processDataEncode()
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
if (Manager::instance().audioPreference.getNoiseReduce()) { if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressEncode_, 0, "Noise suppressor already destroyed"); RETURN_IF_NULL(audioRtpRecord_.noiseSuppressEncode_, 0, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize()); audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize());
} }
...@@ -346,7 +335,7 @@ int AudioRtpRecordHandler::processDataEncode() ...@@ -346,7 +335,7 @@ int AudioRtpRecordHandler::processDataEncode()
#endif #endif
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed"); RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed");
unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data(); unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data();
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize()); return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize());
...@@ -378,7 +367,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si ...@@ -378,7 +367,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
size = std::min(size, audioRtpRecord_.decData_.frames()); size = std::min(size, audioRtpRecord_.decData_.frames());
{ {
ScopedLock lock(audioRtpRecord_.audioCodecMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed"); RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), "Audio codecs already destroyed");
// Return the size of data in samples // Return the size of data in samples
audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size); audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size);
...@@ -392,7 +381,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si ...@@ -392,7 +381,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
if (Manager::instance().audioPreference.getNoiseReduce()) { if (Manager::instance().audioPreference.getNoiseReduce()) {
ScopedLock lock(audioRtpRecord_.audioProcessMutex_); std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
RETURN_IF_NULL(audioRtpRecord_.noiseSuppressDecode_, "Noise suppressor already destroyed"); RETURN_IF_NULL(audioRtpRecord_.noiseSuppressDecode_, "Noise suppressor already destroyed");
audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize()); audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize());
} }
......
...@@ -42,7 +42,7 @@ using std::ptrdiff_t; ...@@ -42,7 +42,7 @@ using std::ptrdiff_t;
#include <ccrtp/rtp.h> #include <ccrtp/rtp.h>
#include <tr1/array> #include <tr1/array>
#include <list> #include <list>
#include <pthread.h> #include <mutex>
#include "noncopyable.h" #include "noncopyable.h"
#include "audio/codecs/audiocodec.h" #include "audio/codecs/audiocodec.h"
...@@ -89,7 +89,7 @@ class AudioRtpRecord { ...@@ -89,7 +89,7 @@ class AudioRtpRecord {
private: private:
std::vector<AudioCodec*> audioCodecs_; std::vector<AudioCodec*> audioCodecs_;
pthread_mutex_t audioCodecMutex_; std::mutex audioCodecMutex_;
// these will have the same value unless we are sending // these will have the same value unless we are sending
// a different codec than we are receiving (asymmetric RTP) // a different codec than we are receiving (asymmetric RTP)
int encoderPayloadType_; int encoderPayloadType_;
...@@ -107,7 +107,7 @@ class AudioRtpRecord { ...@@ -107,7 +107,7 @@ class AudioRtpRecord {
#if HAVE_SPEEXDSP #if HAVE_SPEEXDSP
NoiseSuppress *noiseSuppressEncode_; NoiseSuppress *noiseSuppressEncode_;
NoiseSuppress *noiseSuppressDecode_; NoiseSuppress *noiseSuppressDecode_;
pthread_mutex_t audioProcessMutex_; std::mutex audioProcessMutex_;
#endif #endif
unsigned int dtmfPayloadType_; unsigned int dtmfPayloadType_;
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include "manager.h" #include "manager.h"
#include "audio/mainbuffer.h" #include "audio/mainbuffer.h"
#include "history/historyitem.h" #include "history/historyitem.h"
#include "scoped_lock.h"
Call::Call(const std::string& id, Call::CallType type, const std::string &accountID) Call::Call(const std::string& id, Call::CallType type, const std::string &accountID)
: callMutex_() : callMutex_()
...@@ -51,40 +50,37 @@ Call::Call(const std::string& id, Call::CallType type, const std::string &accoun ...@@ -51,40 +50,37 @@ Call::Call(const std::string& id, Call::CallType type, const std::string &accoun
, timestamp_start_(0) , timestamp_start_(0)
, timestamp_stop_(0) , timestamp_stop_(0)
{ {
pthread_mutex_init(&callMutex_, NULL);
time(&timestamp_start_); time(&timestamp_start_);
} }
Call::~Call() Call::~Call()
{ {}
pthread_mutex_destroy(&callMutex_);
}
void void
Call::setConnectionState(ConnectionState state) Call::setConnectionState(ConnectionState state)
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
connectionState_ = state; connectionState_ = state;
} }
Call::ConnectionState Call::ConnectionState
Call::getConnectionState() Call::getConnectionState()
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
return connectionState_; return connectionState_;
} }
void void
Call::setState(CallState state) Call::setState(CallState state)
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
callState_ = state; callState_ = state;
} }
Call::CallState Call::CallState
Call::getState() Call::getState()
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
return callState_; return callState_;
} }
...@@ -129,21 +125,21 @@ Call::getStateStr() ...@@ -129,21 +125,21 @@ Call::getStateStr()
std::string std::string
Call::getLocalIp() Call::getLocalIp()
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
return localIPAddress_; return localIPAddress_;
} }
unsigned int unsigned int
Call::getLocalAudioPort() Call::getLocalAudioPort()
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
return localAudioPort_; return localAudioPort_;
} }
unsigned int unsigned int
Call::getLocalVideoPort() Call::getLocalVideoPort()
{ {
sfl::ScopedLock m(callMutex_); std::lock_guard<std::mutex> lock(callMutex_);
return localVideoPort_; return localVideoPort_;
} }
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include <sstream> #include <sstream>
#include <map> #include <map>
#include <pthread.h> #include <mutex>
#include "audio/recordable.h" #include "audio/recordable.h"
/* /*
...@@ -233,7 +233,7 @@ class Call : public Recordable { ...@@ -233,7 +233,7 @@ class Call : public Recordable {
private: private:
std::string getTypeStr() const; std::string getTypeStr() const;
/** Protect every attribute that can be changed by two threads */ /** Protect every attribute that can be changed by two threads */
pthread_mutex_t callMutex_; std::mutex callMutex_;
// Informations about call socket / audio // Informations about call socket / audio
......
...@@ -37,28 +37,19 @@ ...@@ -37,28 +37,19 @@
#include <sys/stat.h> // for mkdir #include <sys/stat.h> // for mkdir
#include <ctime> #include <ctime>
#include <cstring> #include <cstring>
#include "scoped_lock.h"
#include "fileutils.h" #include "fileutils.h"
#include "logger.h" #include "logger.h"
#include "call.h" #include "call.h"
namespace sfl { namespace sfl {
History::History() : historyItemsMutex_(), items_(), path_() {}
using std::map; using std::map;
using std::string; using std::string;
using std::vector; using std::vector;
History::History() : historyItemsMutex_(), items_(), path_("")
{
pthread_mutex_init(&historyItemsMutex_, NULL);
}
History::~History()
{
pthread_mutex_destroy(&historyItemsMutex_);
}
bool History::load(int limit) bool History::load(int limit)
{ {
ensurePath(); ensurePath();
...@@ -79,7 +70,7 @@ bool History::load(int limit) ...@@ -79,7 +70,7 @@ bool History::load(int limit)
bool History::save() bool