From b19b940da0031301bae6f8a45d6e8e043247aeeb Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Tue, 18 Dec 2012 18:08:20 -0500
Subject: [PATCH] * #18668: manager: fix audiolayer synchronization

---
 daemon/src/audio/audiolayer.cpp |  2 --
 daemon/src/iax/iaxvoiplink.cpp  |  4 ++--
 daemon/src/managerimpl.cpp      |  6 ++++++
 daemon/src/managerimpl.h        | 10 ++--------
 daemon/src/sip/sipvoiplink.cpp  |  4 +---
 5 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp
index cb1374b3d6..ca0342e2e8 100644
--- a/daemon/src/audio/audiolayer.cpp
+++ b/daemon/src/audio/audiolayer.cpp
@@ -107,9 +107,7 @@ void AudioLayer::notifyIncomingCall()
     tone.getNext(buf, nbSample);
 
     /* Put the data in the urgent ring buffer */
-    Manager::instance().audioLayerMutexLock();
     flushUrgent();
     putUrgent(buf, sizeof buf);
-    Manager::instance().audioLayerMutexUnlock();
 }
 
diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp
index bb94a4d535..840dee2598 100644
--- a/daemon/src/iax/iaxvoiplink.cpp
+++ b/daemon/src/iax/iaxvoiplink.cpp
@@ -364,7 +364,7 @@ IAXVoIPLink::offhold(const std::string& id)
         iax_unquelch(call->session);
     }
 
-    Manager::instance().getAudioDriver()->startStream();
+    Manager::instance().startAudioDriverStream();
     call->setState(Call::ACTIVE);
 }
 
@@ -570,7 +570,7 @@ IAXVoIPLink::iaxHandleCallEvent(iax_event* event, IAXCall* call)
 
             Manager::instance().peerAnsweredCall(id);
 
-            Manager::instance().getAudioDriver()->startStream();
+            Manager::instance().startAudioDriverStream();
             Manager::instance().getMainBuffer().flushAllBuffers();
 
             break;
diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp
index fa3557a063..6a7dab9715 100644
--- a/daemon/src/managerimpl.cpp
+++ b/daemon/src/managerimpl.cpp
@@ -2874,3 +2874,9 @@ void ManagerImpl::clearHistory()
 {
     history_.clear();
 }
+
+void ManagerImpl::startAudioDriverStream()
+{
+    ost::MutexLock lock(audioLayerMutex_);
+    audiodriver_->startStream();
+}
diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h
index f52a3433ca..7b3e9e71fc 100644
--- a/daemon/src/managerimpl.h
+++ b/daemon/src/managerimpl.h
@@ -151,6 +151,8 @@ class ManagerImpl {
             return audiodriver_;
         }
 
+        void startAudioDriverStream();
+
         /**
          * Functions which occur with a user's action
          * Place a new call
@@ -795,14 +797,6 @@ class ManagerImpl {
 
         void initAudioDriver();
 
-        void audioLayerMutexLock() {
-            audioLayerMutex_.enterMutex();
-        }
-
-        void audioLayerMutexUnlock() {
-            audioLayerMutex_.leaveMutex();
-        }
-
         /**
          * Load the accounts order set by the user from the sflphonedrc config file
          * @return std::vector<std::string> A vector containing the account ID's
diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp
index c2dcc535c6..cc4d1fcf4d 100644
--- a/daemon/src/sip/sipvoiplink.cpp
+++ b/daemon/src/sip/sipvoiplink.cpp
@@ -1805,9 +1805,7 @@ void sdp_media_update_cb(pjsip_inv_session *inv, pj_status_t status)
         return;
 
     try {
-        Manager::instance().audioLayerMutexLock();
-        Manager::instance().getAudioDriver()->startStream();
-        Manager::instance().audioLayerMutexUnlock();
+        Manager::instance().startAudioDriverStream();
 
         std::vector<AudioCodec*> audioCodecs;
         for (std::vector<sfl::AudioCodec*>::const_iterator i = sessionMedia.begin(); i != sessionMedia.end(); ++i) {
-- 
GitLab