From 574f17232cf373b5cd49c6bdde4e97a786711706 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Thu, 13 Jun 2013 10:17:30 -0400
Subject: [PATCH] * #23661: remove audio stream if no calls remain

This went away in 638727aced3812eb01a4ff44e73f4726f9b512a1
---
 daemon/src/managerimpl.cpp | 22 ++++++++++++++++------
 daemon/src/managerimpl.h   |  3 +++
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp
index 08554b8e8b..0b20dd3189 100644
--- a/daemon/src/managerimpl.cpp
+++ b/daemon/src/managerimpl.cpp
@@ -395,6 +395,15 @@ bool ManagerImpl::answerCall(const std::string& call_id)
     return result;
 }
 
+void ManagerImpl::checkAudio()
+{
+    if (getCallList().empty()) {
+        sfl::ScopedLock lock(audioLayerMutex_);
+        if (audiodriver_)
+            audiodriver_->stopStream();
+    }
+}
+
 //THREAD=Main
 bool ManagerImpl::hangupCall(const std::string& callId)
 {
@@ -435,6 +444,7 @@ bool ManagerImpl::hangupCall(const std::string& callId)
             if (call) {
                 history_.addCall(call, preferences.getHistoryLimit());
                 SIPVoIPLink::instance()->hangup(callId, 0);
+                checkAudio();
                 saveHistory();
             }
         } catch (const VoipLinkException &e) {
@@ -447,6 +457,7 @@ bool ManagerImpl::hangupCall(const std::string& callId)
             history_.addCall(call, preferences.getHistoryLimit());
             VoIPLink *link = getAccountLink(call->getAccountId());
             link->hangup(callId, 0);
+            checkAudio();
             saveHistory();
         }
     }
@@ -656,6 +667,8 @@ bool ManagerImpl::refuseCall(const std::string& id)
             return false;
 
         getAccountLink(accountid)->refuse(id);
+
+        checkAudio();
     }
 
     removeWaitingCall(id);
@@ -1672,13 +1685,8 @@ void ManagerImpl::peerHungupCall(const std::string& call_id)
     dbus_.getCallManager()->callStateChanged(call_id, "HUNGUP");
 
     removeWaitingCall(call_id);
+    checkAudio();
     removeStream(call_id);
-
-    if (getCallList().empty()) {
-        DEBUG("Stop audio stream, there are no calls remaining");
-        sfl::ScopedLock lock(audioLayerMutex_);
-        audiodriver_->stopStream();
-    }
 }
 
 //THREAD=VoIP
@@ -1692,6 +1700,7 @@ void ManagerImpl::callBusy(const std::string& id)
         unsetCurrentCall();
     }
 
+    checkAudio();
     removeWaitingCall(id);
 }
 
@@ -1711,6 +1720,7 @@ void ManagerImpl::callFailure(const std::string& call_id)
         removeParticipant(call_id);
     }
 
+    checkAudio();
     removeWaitingCall(call_id);
 }
 
diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h
index 6159442154..f06c6b3666 100644
--- a/daemon/src/managerimpl.h
+++ b/daemon/src/managerimpl.h
@@ -1050,6 +1050,9 @@ class ManagerImpl {
          */
         AccountMap getAllAccounts() const;
 
+        void
+        checkAudio();
+
         /**
           * To handle the persistent history
           * TODO: move this to ConfigurationManager
-- 
GitLab