Skip to content
Snippets Groups Projects
Commit 83f9a6ff authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews
Browse files

iax: make IAX lock global

Refs #51555

Change-Id: I7b4583a4e6b63a83f69947eec1e674cd9ba580ec
parent 1f9ea697
No related branches found
No related tags found
No related merge requests found
...@@ -48,11 +48,11 @@ ...@@ -48,11 +48,11 @@
AccountMap IAXVoIPLink::iaxAccountMap_; AccountMap IAXVoIPLink::iaxAccountMap_;
IAXCallMap IAXVoIPLink::iaxCallMap_; IAXCallMap IAXVoIPLink::iaxCallMap_;
std::mutex IAXVoIPLink::iaxCallMapMutex_; std::mutex IAXVoIPLink::iaxCallMapMutex_;
std::mutex IAXVoIPLink::mutexIAX = {};
IAXVoIPLink::IAXVoIPLink(const std::string& accountID) : IAXVoIPLink::IAXVoIPLink(const std::string& accountID) :
regSession_(NULL) regSession_(NULL)
, nextRefreshStamp_(0) , nextRefreshStamp_(0)
, mutexIAX_()
, rawBuffer_(RAW_BUFFER_SIZE, AudioFormat::MONO) , rawBuffer_(RAW_BUFFER_SIZE, AudioFormat::MONO)
, resampledData_(RAW_BUFFER_SIZE * 4, AudioFormat::MONO) , resampledData_(RAW_BUFFER_SIZE * 4, AudioFormat::MONO)
, encodedData_() , encodedData_()
...@@ -103,7 +103,7 @@ IAXVoIPLink::terminate() ...@@ -103,7 +103,7 @@ IAXVoIPLink::terminate()
for (auto & item : iaxCallMap_) { for (auto & item : iaxCallMap_) {
auto& call = item.second; auto& call = item.second;
if (call) { if (call) {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_hangup(call->session, const_cast<char*>("Dumped Call")); iax_hangup(call->session, const_cast<char*>("Dumped Call"));
call.reset(); call.reset();
} }
...@@ -121,7 +121,7 @@ IAXVoIPLink::getEvent() ...@@ -121,7 +121,7 @@ IAXVoIPLink::getEvent()
iax_event *event = NULL; iax_event *event = NULL;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
event = iax_get_event(0); event = iax_get_event(0);
} }
...@@ -129,7 +129,7 @@ IAXVoIPLink::getEvent() ...@@ -129,7 +129,7 @@ IAXVoIPLink::getEvent()
// If we received an 'ACK', libiax2 tells apps to ignore them. // If we received an 'ACK', libiax2 tells apps to ignore them.
if (event->etype == IAX_EVENT_NULL) { if (event->etype == IAX_EVENT_NULL) {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_event_free(event); iax_event_free(event);
event = iax_get_event(0); event = iax_get_event(0);
continue; continue;
...@@ -148,7 +148,7 @@ IAXVoIPLink::getEvent() ...@@ -148,7 +148,7 @@ IAXVoIPLink::getEvent()
} }
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_event_free(event); iax_event_free(event);
event = iax_get_event(0); event = iax_get_event(0);
} }
...@@ -237,7 +237,7 @@ IAXVoIPLink::sendAudioFromMic() ...@@ -237,7 +237,7 @@ IAXVoIPLink::sendAudioFromMic()
compSize = audioCodec->encode(in->getData(), encodedData_, RAW_BUFFER_SIZE); compSize = audioCodec->encode(in->getData(), encodedData_, RAW_BUFFER_SIZE);
if (currentCall->session and samples > 0) { if (currentCall->session and samples > 0) {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
if (iax_send_voice(currentCall->session, currentCall->format, encodedData_, compSize, outSamples) == -1) if (iax_send_voice(currentCall->session, currentCall->format, encodedData_, compSize, outSamples) == -1)
ERROR("IAX: Error sending voice data."); ERROR("IAX: Error sending voice data.");
...@@ -266,7 +266,7 @@ IAXVoIPLink::sendRegister(Account& a) ...@@ -266,7 +266,7 @@ IAXVoIPLink::sendRegister(Account& a)
if (account.getUsername().empty()) if (account.getUsername().empty())
throw VoipLinkException("Account username is empty"); throw VoipLinkException("Account username is empty");
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
if (regSession_) if (regSession_)
iax_destroy(regSession_); iax_destroy(regSession_);
...@@ -284,7 +284,7 @@ void ...@@ -284,7 +284,7 @@ void
IAXVoIPLink::sendUnregister(Account& a, std::function<void(bool)> cb) IAXVoIPLink::sendUnregister(Account& a, std::function<void(bool)> cb)
{ {
if (regSession_) { if (regSession_) {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_destroy(regSession_); iax_destroy(regSession_);
regSession_ = NULL; regSession_ = NULL;
} }
...@@ -320,7 +320,7 @@ IAXVoIPLink::answer(Call *call) ...@@ -320,7 +320,7 @@ IAXVoIPLink::answer(Call *call)
Manager::instance().addStream(call->getCallId()); Manager::instance().addStream(call->getCallId());
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
call->answer(); call->answer();
} }
...@@ -342,7 +342,7 @@ IAXVoIPLink::hangup(const std::string& id, int reason UNUSED) ...@@ -342,7 +342,7 @@ IAXVoIPLink::hangup(const std::string& id, int reason UNUSED)
throw VoipLinkException("Could not find call"); throw VoipLinkException("Could not find call");
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_hangup(call->session, (char*) "Dumped Call"); iax_hangup(call->session, (char*) "Dumped Call");
} }
call->session = NULL; call->session = NULL;
...@@ -382,7 +382,7 @@ IAXVoIPLink::onhold(const std::string& id) ...@@ -382,7 +382,7 @@ IAXVoIPLink::onhold(const std::string& id)
if (!call) if (!call)
throw VoipLinkException("Could not find call"); throw VoipLinkException("Could not find call");
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_quelch_moh(call->session, true); iax_quelch_moh(call->session, true);
} }
call->setState(Call::HOLD); call->setState(Call::HOLD);
...@@ -402,7 +402,7 @@ IAXVoIPLink::offhold(const std::string& id) ...@@ -402,7 +402,7 @@ IAXVoIPLink::offhold(const std::string& id)
throw VoipLinkException("Could not find call"); throw VoipLinkException("Could not find call");
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_unquelch(call->session); iax_unquelch(call->session);
} }
...@@ -424,7 +424,7 @@ IAXVoIPLink::transfer(const std::string& id, const std::string& to) ...@@ -424,7 +424,7 @@ IAXVoIPLink::transfer(const std::string& id, const std::string& to)
if (!call) if (!call)
return; return;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_transfer(call->session, callto); iax_transfer(call->session, callto);
} }
} }
...@@ -445,7 +445,7 @@ IAXVoIPLink::refuse(const std::string& id) ...@@ -445,7 +445,7 @@ IAXVoIPLink::refuse(const std::string& id)
if (!call) if (!call)
return; return;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_reject(call->session, (char*) "Call rejected manually."); iax_reject(call->session, (char*) "Call rejected manually.");
} }
} }
...@@ -462,7 +462,7 @@ IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code) ...@@ -462,7 +462,7 @@ IAXVoIPLink::carryingDTMFdigits(const std::string& id, char code)
return; return;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_send_dtmf(call->session, code); iax_send_dtmf(call->session, code);
} }
} }
...@@ -479,7 +479,7 @@ IAXVoIPLink::sendTextMessage(const std::string& callID, ...@@ -479,7 +479,7 @@ IAXVoIPLink::sendTextMessage(const std::string& callID,
return; return;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
sfl::InstantMessaging::send_iax_message(call->session, callID, message.c_str()); sfl::InstantMessaging::send_iax_message(call->session, callID, message.c_str());
} }
} }
...@@ -526,7 +526,7 @@ IAXVoIPLink::getIaxCall(const std::string& id) ...@@ -526,7 +526,7 @@ IAXVoIPLink::getIaxCall(const std::string& id)
void void
IAXVoIPLink::iaxOutgoingInvite(IAXCall* call) IAXVoIPLink::iaxOutgoingInvite(IAXCall* call)
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
call->session = iax_session_new(); call->session = iax_session_new();
...@@ -764,7 +764,7 @@ void IAXVoIPLink::iaxHandleRegReply(iax_event* event) ...@@ -764,7 +764,7 @@ void IAXVoIPLink::iaxHandleRegReply(iax_event* event)
return; return;
{ {
std::lock_guard<std::mutex> lock(mutexIAX_); std::lock_guard<std::mutex> lock(mutexIAX);
iax_destroy(regSession_); iax_destroy(regSession_);
regSession_ = NULL; regSession_ = NULL;
} }
......
...@@ -199,6 +199,10 @@ class IAXVoIPLink : public VoIPLink { ...@@ -199,6 +199,10 @@ class IAXVoIPLink : public VoIPLink {
static std::shared_ptr<IAXCall> getIaxCall(const std::string& id); static std::shared_ptr<IAXCall> getIaxCall(const std::string& id);
static void removeIaxCall(const std::string &id); static void removeIaxCall(const std::string &id);
/** Mutex for iax_ calls, since we're the only one dealing with the incorporated
* iax_stuff inside this class. */
static std::mutex mutexIAX;
private: private:
NON_COPYABLE(IAXVoIPLink); NON_COPYABLE(IAXVoIPLink);
...@@ -286,10 +290,6 @@ class IAXVoIPLink : public VoIPLink { ...@@ -286,10 +290,6 @@ class IAXVoIPLink : public VoIPLink {
* to force a registration. */ * to force a registration. */
int nextRefreshStamp_; int nextRefreshStamp_;
/** Mutex for iax_ calls, since we're the only one dealing with the incorporated
* iax_stuff inside this class. */
std::mutex mutexIAX_;
/** encoder/decoder/resampler buffers */ /** encoder/decoder/resampler buffers */
AudioBuffer rawBuffer_; AudioBuffer rawBuffer_;
AudioBuffer resampledData_; AudioBuffer resampledData_;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment