Commit 89852b37 authored by Emmanuel Milou's avatar Emmanuel Milou
parents 2a618dd6 647e0645
......@@ -84,8 +84,6 @@ libsflphone_la_SOURCES = conference.cpp \
logger.cpp \
numbercleaner.cpp \
fileutils.cpp \
scoped_lock.cpp \
scoped_lock.h \
sflthread.cpp \
sflthread.h \
conference.h \
......
......@@ -33,7 +33,6 @@
#include "audiolayer.h"
#include "audio/dcblocker.h"
#include "manager.h"
#include "scoped_lock.h"
AudioLayer::AudioLayer()
: captureGain_(1.0)
......@@ -47,31 +46,25 @@ AudioLayer::AudioLayer()
, converter_(sampleRate_)
, lastNotificationTime_(0)
{
pthread_mutex_init(&mutex_, NULL);
urgentRingBuffer_.createReadPointer(MainBuffer::DEFAULT_ID);
}
AudioLayer::~AudioLayer()
{
pthread_mutex_destroy(&mutex_);
}
void AudioLayer::flushMain()
{
sfl::ScopedLock guard(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
// should pass call id
Manager::instance().getMainBuffer().flushAllBuffers();
}
void AudioLayer::flushUrgent()
{
sfl::ScopedLock guard(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
urgentRingBuffer_.flushAll();
}
void AudioLayer::putUrgent(AudioBuffer& buffer)
{
sfl::ScopedLock guard(mutex_);
std::lock_guard<std::mutex> lock(mutex_);
urgentRingBuffer_.put(buffer);
}
......
......@@ -34,7 +34,7 @@
#ifndef AUDIO_LAYER_H_
#define AUDIO_LAYER_H_
#include <pthread.h>
#include <mutex>
#include <sys/time.h>
#include <vector>
#include "ringbuffer.h"
......@@ -80,7 +80,7 @@ class AudioLayer {
};
AudioLayer();
virtual ~AudioLayer();
virtual ~AudioLayer() = default;
virtual std::vector<std::string> getCaptureDeviceList() const = 0;
virtual std::vector<std::string> getPlaybackDeviceList() const = 0;
......@@ -216,7 +216,7 @@ class AudioLayer {
/**
* 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
......
......@@ -42,7 +42,6 @@
#include "sip/sipcall.h"
#include "sip/sipaccount.h"
#include "sip/sdes_negotiator.h"
#include "scoped_lock.h"
#include "logger.h"
namespace sfl {
......@@ -55,14 +54,11 @@ AudioRtpFactory::AudioRtpFactory(SIPCall *ca) : rtpSession_(NULL),
cachedRemoteMasterSalt_(MAX_MASTER_SALT_LENGTH),
remoteOfferIsSet_(false), ca_(ca),
keyExchangeProtocol_(NONE)
{
pthread_mutex_init(&audioRtpThreadMutex_, NULL);
}
{}
AudioRtpFactory::~AudioRtpFactory()
{
delete rtpSession_;
pthread_mutex_destroy(&audioRtpThreadMutex_);
}
void AudioRtpFactory::initConfig()
......@@ -105,7 +101,7 @@ void AudioRtpFactory::initConfig()
void AudioRtpFactory::initSession()
{
ScopedLock m(audioRtpThreadMutex_);
std::lock_guard<std::mutex> lock(audioRtpThreadMutex_);
if (srtpEnabled_) {
const std::string zidFilename(Manager::instance().voipPreferences.getZidFile());
......@@ -151,7 +147,7 @@ void AudioRtpFactory::start(const std::vector<AudioCodec*> &audioCodecs)
void AudioRtpFactory::stop()
{
ScopedLock mutex(audioRtpThreadMutex_);
std::lock_guard<std::mutex> lock(audioRtpThreadMutex_);
delete rtpSession_;
rtpSession_ = NULL;
......
......@@ -33,8 +33,7 @@
#include <ccrtp/CryptoContext.h>
#include <stdexcept>
#include <tr1/array>
#include <pthread.h>
#include <mutex>
#include "audio_rtp_session.h"
#include "audio_srtp_session.h"
#include "noncopyable.h"
......@@ -159,7 +158,7 @@ class AudioRtpFactory {
NON_COPYABLE(AudioRtpFactory);
enum KeyExchangeProtocol { NONE, SDES, ZRTP };
AudioRtpSession *rtpSession_;
pthread_mutex_t audioRtpThreadMutex_;
std::mutex audioRtpThreadMutex_;
// Field used when initializing audio rtp session
// May be set manually or from config using initAudioRtpConfig
......
......@@ -38,7 +38,6 @@
#include "logger.h"
#include "sip/sipcall.h"
#include "audio/audiolayer.h"
#include "scoped_lock.h"
#include "manager.h"
namespace sfl {
......@@ -115,12 +114,7 @@ AudioRtpRecord::AudioRtpRecord() :
, dtmfPayloadType_(101) // same as Asterisk
, dead_(false)
, currentCodecIndex_(0)
{
pthread_mutex_init(&audioCodecMutex_, NULL);
#if HAVE_SPEEXDSP
pthread_mutex_init(&audioProcessMutex_, NULL);
#endif
}
{}
// Call from processData*
bool AudioRtpRecord::isDead()
......@@ -182,22 +176,17 @@ AudioRtpRecord::~AudioRtpRecord()
delete converterDecode_;
converterDecode_ = 0;
{
ScopedLock lock(audioCodecMutex_);
std::lock_guard<std::mutex> lock(audioCodecMutex_);
deleteCodecs();
}
#if HAVE_SPEEXDSP
{
ScopedLock lock(audioProcessMutex_);
std::lock_guard<std::mutex> lock(audioProcessMutex_);
delete noiseSuppressDecode_;
noiseSuppressDecode_ = 0;
delete noiseSuppressEncode_;
noiseSuppressEncode_ = 0;
}
#endif
pthread_mutex_destroy(&audioCodecMutex_);
#if HAVE_SPEEXDSP
pthread_mutex_destroy(&audioProcessMutex_);
#endif
}
......@@ -217,7 +206,7 @@ std::string
AudioRtpRecordHandler::getCurrentAudioCodecNames()
{
std::string result;
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
{
std::string sep = "";
......@@ -234,7 +223,7 @@ AudioRtpRecordHandler::getCurrentAudioCodecNames()
void AudioRtpRecordHandler::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs)
{
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
audioRtpRecord_.deleteCodecs();
// Set various codec info to reduce indirection
......@@ -268,7 +257,7 @@ void AudioRtpRecordHandler::initBuffers()
#if HAVE_SPEEXDSP
void AudioRtpRecordHandler::initNoiseSuppress()
{
ScopedLock lock(audioRtpRecord_.audioProcessMutex_);
std::lock_guard<std::mutex> lock(audioRtpRecord_.audioProcessMutex_);
delete audioRtpRecord_.noiseSuppressEncode_;
audioRtpRecord_.noiseSuppressEncode_ = new NoiseSuppress(getCodecFrameSize(), getCodecSampleRate());
delete audioRtpRecord_.noiseSuppressDecode_;
......@@ -334,7 +323,7 @@ int AudioRtpRecordHandler::processDataEncode()
#if HAVE_SPEEXDSP
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");
audioRtpRecord_.noiseSuppressEncode_->process(micData, getCodecFrameSize());
}
......@@ -346,7 +335,7 @@ int AudioRtpRecordHandler::processDataEncode()
#endif
{
ScopedLock lock(audioRtpRecord_.audioCodecMutex_);
std::lock_guard<std::mutex> lock(audioRtpRecord_.audioCodecMutex_);
RETURN_IF_NULL(audioRtpRecord_.getCurrentCodec(), 0, "Audio codec already destroyed");
unsigned char *micDataEncoded = audioRtpRecord_.encodedData_.data();
return audioRtpRecord_.getCurrentCodec()->encode(micDataEncoded, out->getData(), getCodecFrameSize());
......@@ -378,7 +367,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
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 the size of data in samples
audioRtpRecord_.getCurrentCodec()->decode(audioRtpRecord_.decData_.getData(), spkrData, size);
......@@ -392,7 +381,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
#if HAVE_SPEEXDSP
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");
audioRtpRecord_.noiseSuppressDecode_->process(audioRtpRecord_.decData_, getCodecFrameSize());
}
......
......@@ -42,7 +42,7 @@ using std::ptrdiff_t;
#include <ccrtp/rtp.h>
#include <tr1/array>
#include <list>
#include <pthread.h>
#include <mutex>
#include "noncopyable.h"
#include "audio/codecs/audiocodec.h"
......@@ -89,7 +89,7 @@ class AudioRtpRecord {
private:
std::vector<AudioCodec*> audioCodecs_;
pthread_mutex_t audioCodecMutex_;
std::mutex audioCodecMutex_;
// these will have the same value unless we are sending
// a different codec than we are receiving (asymmetric RTP)
int encoderPayloadType_;
......@@ -107,7 +107,7 @@ class AudioRtpRecord {
#if HAVE_SPEEXDSP
NoiseSuppress *noiseSuppressEncode_;
NoiseSuppress *noiseSuppressDecode_;
pthread_mutex_t audioProcessMutex_;
std::mutex audioProcessMutex_;
#endif
unsigned int dtmfPayloadType_;
......
......@@ -32,7 +32,6 @@
#include "manager.h"
#include "audio/mainbuffer.h"
#include "history/historyitem.h"
#include "scoped_lock.h"
Call::Call(const std::string& id, Call::CallType type, const std::string &accountID)
: callMutex_()
......@@ -51,40 +50,37 @@ Call::Call(const std::string& id, Call::CallType type, const std::string &accoun
, timestamp_start_(0)
, timestamp_stop_(0)
{
pthread_mutex_init(&callMutex_, NULL);
time(&timestamp_start_);
}
Call::~Call()
{
pthread_mutex_destroy(&callMutex_);
}
{}
void
Call::setConnectionState(ConnectionState state)
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
connectionState_ = state;
}
Call::ConnectionState
Call::getConnectionState()
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
return connectionState_;
}
void
Call::setState(CallState state)
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
callState_ = state;
}
Call::CallState
Call::getState()
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
return callState_;
}
......@@ -129,21 +125,21 @@ Call::getStateStr()
std::string
Call::getLocalIp()
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
return localIPAddress_;
}
unsigned int
Call::getLocalAudioPort()
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
return localAudioPort_;
}
unsigned int
Call::getLocalVideoPort()
{
sfl::ScopedLock m(callMutex_);
std::lock_guard<std::mutex> lock(callMutex_);
return localVideoPort_;
}
......
......@@ -34,7 +34,7 @@
#include <sstream>
#include <map>
#include <pthread.h>
#include <mutex>
#include "audio/recordable.h"
/*
......@@ -233,7 +233,7 @@ class Call : public Recordable {
private:
std::string getTypeStr() const;
/** Protect every attribute that can be changed by two threads */
pthread_mutex_t callMutex_;
std::mutex callMutex_;
// Informations about call socket / audio
......
......@@ -37,28 +37,19 @@
#include <sys/stat.h> // for mkdir
#include <ctime>
#include <cstring>
#include "scoped_lock.h"
#include "fileutils.h"
#include "logger.h"
#include "call.h"
namespace sfl {
History::History() : historyItemsMutex_(), items_(), path_() {}
using std::map;
using std::string;
using std::vector;
History::History() : historyItemsMutex_(), items_(), path_("")
{
pthread_mutex_init(&historyItemsMutex_, NULL);
}
History::~History()
{
pthread_mutex_destroy(&historyItemsMutex_);
}
bool History::load(int limit)
{
ensurePath();
......@@ -79,7 +70,7 @@ bool History::load(int limit)
bool History::save()
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
DEBUG("Saving history in XDG directory: %s", path_.c_str());
ensurePath();
std::sort(items_.begin(), items_.end());
......@@ -93,7 +84,7 @@ bool History::save()
void History::addEntry(const HistoryItem &item, int oldest)
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
if (item.hasPeerNumber() and item.youngerThan(oldest))
items_.push_back(item);
}
......@@ -126,7 +117,7 @@ void History::ensurePath()
vector<map<string, string> > History::getSerialized()
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
vector<map<string, string> > result;
for (const auto &item : items_)
result.push_back(item.toMap());
......@@ -152,20 +143,20 @@ void History::addCall(Call *call, int limit)
void History::clear()
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
items_.clear();
}
bool History::empty()
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
return items_.empty();
}
size_t History::numberOfItems()
{
sfl::ScopedLock lock(historyItemsMutex_);
std::lock_guard<std::mutex> lock(historyItemsMutex_);
return items_.size();
}
......
......@@ -34,7 +34,7 @@
#define HISTORY_
#include "historyitem.h"
#include <pthread.h>
#include <mutex>
#include <vector>
class Call;
......@@ -45,8 +45,6 @@ class History {
public:
History();
~History();
/** Load history from file */
bool load(int limit);
......@@ -69,7 +67,7 @@ class History {
void setPath(const std::string &path);
private:
/* Mutex to protect the history items */
pthread_mutex_t historyItemsMutex_;
std::mutex historyItemsMutex_;
/* If no path has been set, this will initialize path to a
* system-dependent location */
......
......@@ -43,28 +43,24 @@
#include "audio/audiolayer.h"
#include "audio/samplerateconverter.h"
#include "array_size.h"
#include "scoped_lock.h"
#include "map_utils.h"
AccountMap IAXVoIPLink::iaxAccountMap_;
IAXCallMap IAXVoIPLink::iaxCallMap_;
// has same effect as pthread_mutex_init with default args, but for a statically
// allocated mutex
pthread_mutex_t IAXVoIPLink::iaxCallMapMutex_ = PTHREAD_MUTEX_INITIALIZER;
std::mutex IAXVoIPLink::iaxCallMapMutex_;
IAXVoIPLink::IAXVoIPLink(const std::string& accountID) :
regSession_(NULL)
, nextRefreshStamp_(0)
, mutexIAX_()
, decData_(DEC_BUFFER_SIZE)
, resampledData_(DEC_BUFFER_SIZE*4)
, resampledData_(DEC_BUFFER_SIZE * 4)
, encodedData_()
, converter_(44100)
, initDone_(false)
, accountID_(accountID)
, evThread_(this)
{
pthread_mutex_init(&mutexIAX_, NULL);
srand(time(NULL)); // to get random number for RANDOM_PORT
}
......@@ -78,7 +74,6 @@ IAXVoIPLink::~IAXVoIPLink()
// This is our last account
if (iaxAccountMap_.size() == 1)
clearIaxCallMap();
pthread_mutex_destroy(&mutexIAX_);
}
void
......@@ -103,13 +98,13 @@ IAXVoIPLink::terminate()
if (!initDone_)
return;
sfl::ScopedLock m(iaxCallMapMutex_);
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
for (auto &item : iaxCallMap_) {
for (auto & item : iaxCallMap_) {
IAXCall *call = static_cast<IAXCall*>(item.second);
if (call) {
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
iax_hangup(call->session, const_cast<char*>("Dumped Call"));
delete call;
}
......@@ -126,7 +121,7 @@ IAXVoIPLink::getEvent()
iax_event *event = NULL;
{
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
event = iax_get_event(0);
}
......@@ -134,7 +129,7 @@ IAXVoIPLink::getEvent()
// If we received an 'ACK', libiax2 tells apps to ignore them.
if (event->etype == IAX_EVENT_NULL) {
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
iax_event_free(event);
event = iax_get_event(0);
continue;
......@@ -153,7 +148,7 @@ IAXVoIPLink::getEvent()
}
{
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
iax_event_free(event);
event = iax_get_event(0);
}
......@@ -173,7 +168,7 @@ std::vector<std::string>
IAXVoIPLink::getCallIDs()
{
std::vector<std::string> v;
sfl::ScopedLock m(iaxCallMapMutex_);
std::lock_guard<std::mutex> lock(iaxCallMapMutex_);
map_utils::vectorFromMapKeys(iaxCallMap_, v);
return v;
......@@ -182,7 +177,7 @@ IAXVoIPLink::getCallIDs()
void
IAXVoIPLink::sendAudioFromMic()
{
for (const auto &item : iaxCallMap_) {
for (const auto & item : iaxCallMap_) {
IAXCall *currentCall = static_cast<IAXCall*>(item.second);
if (!currentCall or currentCall->getState() != Call::ACTIVE)
......@@ -228,7 +223,7 @@ IAXVoIPLink::sendAudioFromMic()
compSize = audioCodec->encode(encodedData_, in->getData(), DEC_BUFFER_SIZE);
if (currentCall->session and samples > 0) {
sfl::ScopedLock m(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
if (iax_send_voice(currentCall->session, currentCall->format, encodedData_, compSize, outSamples) == -1)
ERROR("IAX: Error sending voice data.");
......@@ -254,7 +249,7 @@ IAXVoIPLink::sendRegister(Account *a)
if (account->getUsername().empty())
throw VoipLinkException("Account username is empty");
sfl::ScopedLock m(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
if (regSession_)
iax_destroy(regSession_);
......@@ -272,7 +267,7 @@ void
IAXVoIPLink::sendUnregister(Account *a)
{
if (regSession_) {
sfl::ScopedLock m(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
iax_destroy(regSession_);
regSession_ = NULL;
}
......@@ -305,7 +300,7 @@ IAXVoIPLink::answer(Call *call)
Manager::instance().addStream(call->getCallId());
{
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
call->answer();
}
......@@ -326,7 +321,7 @@ IAXVoIPLink::hangup(const std::string& id, int reason UNUSED)
Manager::instance().getMainBuffer().unBindAll(call->getCallId());
{
sfl::ScopedLock lock(mutexIAX_);
std::lock_guard<std::mutex> lock(mutexIAX_);
iax_hangup(call->session, (char*) "Dumped Call");
}