From 1620098ad462c6c0f654910dac5394711bd05e6a Mon Sep 17 00:00:00 2001
From: yanmorin <yanmorin>
Date: Fri, 28 Oct 2005 21:48:08 +0000
Subject: [PATCH] Added debugging messages to detect the stop bugs when you
 play a tone

---
 src/audio/audiolayer.cpp         |  5 +++--
 src/audio/audiortp.cpp           |  4 +++-
 src/gui/server/request.cpp       |  2 ++
 src/gui/server/tcpsessionio.cpp  |  4 ++++
 src/gui/server/tcpstreampool.cpp | 11 ++++++++---
 src/gui/server/tcpstreampool.h   |  2 +-
 src/managerimpl.cpp              | 26 +++++++++++++++-----------
 7 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/audio/audiolayer.cpp b/src/audio/audiolayer.cpp
index 18ca6f32c6..2e9650a560 100644
--- a/src/audio/audiolayer.cpp
+++ b/src/audio/audiolayer.cpp
@@ -103,6 +103,7 @@ AudioLayer::startStream(void)
 {
   ost::MutexLock guard(_mutex);
   if (_stream && !_stream->isActive()) {
+    _debug("starting stream...\n");
     _stream->start();
   }
 }
@@ -113,6 +114,7 @@ AudioLayer::stopStream(void)
   ost::MutexLock guard(_mutex);
   try {
     if (_stream && !_stream->isStopped()) {
+      _debug("stopping stream...\n");
       _stream->stop();
       _mainSndRingBuffer.flush();
       _urgentRingBuffer.flush();
@@ -163,8 +165,7 @@ AudioLayer::flushMain()
 void
 AudioLayer::putUrgent(void* buffer, int toCopy)
 {
-  ost::MutexLock guard(_mutex);
-  int a = _mainSndRingBuffer.AvailForPut();
+  int a = _urgentRingBuffer.AvailForPut();
   if ( a >= toCopy ) {
     _urgentRingBuffer.Put(buffer, toCopy);
   } else {
diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp
index 3395ae8d9e..6a65a1ffe2 100644
--- a/src/audio/audiortp.cpp
+++ b/src/audio/audiortp.cpp
@@ -181,7 +181,6 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m
   }
 
   // Get bytes from micRingBuffer to data_from_mic
-  Manager::instance().getAudioDriver()->startStream();
   Manager::instance().getAudioDriver()->micRingBuffer().Get(data_from_mic_stereo, bytesAvail, 100);
   // control volume and stereo->mono
   // the j is in int16 RTP_FRAMES2SEND
@@ -192,6 +191,7 @@ AudioRtpRTX::sendSessionFromMic (unsigned char* data_to_send, int16* data_from_m
   }
   if ( bytesAvail != maxBytesToGet ) {
     // fill end with 0...
+    _debug("Padding mic: %d bytes\n", (maxBytesToGet-bytesAvail)/2);
     bzero(data_from_mic_mono + (bytesAvail/4), (maxBytesToGet-bytesAvail)/2);
   }
 
@@ -258,6 +258,8 @@ AudioRtpRTX::receiveSessionForSpkr (int16* data_for_speakers_stereo, int16* data
   Manager::instance().getAudioDriver()->putMain(data_for_speakers_stereo, expandedSize*2);
   //}
 	
+  Manager::instance().getAudioDriver()->startStream();
+
 	// Notify (with a beep) an incoming call when there is already a call 
 	countTime += time->getSecond();
 	if (Manager::instance().incomingCallWaiting() > 0) {
diff --git a/src/gui/server/request.cpp b/src/gui/server/request.cpp
index 2775dabc92..b872dceff4 100644
--- a/src/gui/server/request.cpp
+++ b/src/gui/server/request.cpp
@@ -204,6 +204,7 @@ RequestVersion::execute()
 ResponseMessage
 RequestQuit::execute()
 {
+  GUIServer::instance().hangupAll();
   GUIServer::instance().stopTone();
   GUIServer::instance().quit();
   return message("200", "Quitting");
@@ -212,6 +213,7 @@ RequestQuit::execute()
 ResponseMessage
 RequestStop::execute()
 {
+  GUIServer::instance().hangupAll();
   GUIServer::instance().stopTone();
   GUIServer::instance().stop();
   return message("200", "Stopping server");
diff --git a/src/gui/server/tcpsessionio.cpp b/src/gui/server/tcpsessionio.cpp
index c2de67c099..eae54d1bbb 100644
--- a/src/gui/server/tcpsessionio.cpp
+++ b/src/gui/server/tcpsessionio.cpp
@@ -17,6 +17,7 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 #include "tcpsessionio.h"
+#include <cstdio>
 
 const int TCPSessionIO::PORT = 3999;
 const char * const TCPSessionIO::IP = "127.0.0.1";
@@ -37,8 +38,11 @@ TCPSessionIO::TCPSessionIO() : SessionIO()
 
 TCPSessionIO::~TCPSessionIO()
 {
+  fprintf(stderr, "TCPSessionIO: delete clientStream\n");
   delete _clientStream; _clientStream = NULL;
+  fprintf(stderr, "TCPSessionIO: delete serverSocket\n");
   delete _serverSocket; _serverSocket = NULL;
+  fprintf(stderr, "TCPSessionIO: end\n");
 }
 
 bool
diff --git a/src/gui/server/tcpstreampool.cpp b/src/gui/server/tcpstreampool.cpp
index 172443c87e..b3fd595468 100644
--- a/src/gui/server/tcpstreampool.cpp
+++ b/src/gui/server/tcpstreampool.cpp
@@ -23,9 +23,14 @@
 
 TCPStreamPool::~TCPStreamPool() 
 {
+  _debug("TCPStreamPool terminate\n");
   terminate();
+  _debug("terminate done\n");
+
+
   std::string output;
-  while (good() && _outputPool.pop(output, WAITING_TIME))  {
+  while (_outputPool.pop(output, WAITING_TIME))  {
+    _debug("TCPStreamPool send %s\n", output.c_str());
     //_debug("sending last message...\n");
     *this << output << std::endl;
   }
@@ -40,7 +45,7 @@ TCPStreamPool::run() {
   while(!testCancel() && good()) {
     while (isPending(ost::TCPSocket::pendingInput, WAITING_TIME)) {
       std::getline(*this, input);
-      //_debug("TCPStreamPool getline %s\n", input.c_str());
+      _debug("TCPStreamPool getline %s\n", input.c_str());
       if (input != null && input[0]!=cr13) {
         _inputPool.push(input);
       }
@@ -48,7 +53,7 @@ TCPStreamPool::run() {
       if (testCancel() || !good()) {break;}
     }
     if (good() && _outputPool.pop(output, WAITING_TIME)) {
-      //_debug("TCPStreamPool send %s\n", output.c_str());
+      _debug("TCPStreamPool send %s\n", output.c_str());
       *this << output << std::endl;
     }
   }
diff --git a/src/gui/server/tcpstreampool.h b/src/gui/server/tcpstreampool.h
index 3c7420ee0f..75145ff466 100644
--- a/src/gui/server/tcpstreampool.h
+++ b/src/gui/server/tcpstreampool.h
@@ -41,7 +41,7 @@ class TCPStreamPool : public ost::TCPSession
 public:
   TCPStreamPool(ost::TCPSocket& server) : ost::TCPSession(server) 
   {
-    setCancel(cancelDeferred);
+    setCancel(cancelImmediate);
   }
   TCPStreamPool::~TCPStreamPool();
 
diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp
index 84f6917c34..bebae80cab 100644
--- a/src/managerimpl.cpp
+++ b/src/managerimpl.cpp
@@ -881,13 +881,17 @@ ManagerImpl::stopTone() {
   _debug("TONE: stop tone...\n");
   _toneMutex.enterMutex();
   _telephoneTone->setCurrentTone(Tone::TONE_NULL);
+  _toneMutex.leaveMutex();
+  _debug("TONE: tone stopped\n");
+
   // for ringing tone..
+  _toneMutex.enterMutex();
   if ( _toneType != ZT_TONE_NULL ) {
     _toneType = ZT_TONE_NULL;
     _tone->stopTone();
   }
   _toneMutex.leaveMutex();
-  _debug("TONE: tone stopped\n");
+  _debug("TONE: leave stop tone function\n");
 }
 
 /**
@@ -963,19 +967,19 @@ ManagerImpl::getTelephoneTone()
 void
 ManagerImpl::ringtone() 
 {
-  std::string ringchoice = getConfigString(AUDIO, RING_CHOICE);
+  //std::string ringchoice = getConfigString(AUDIO, RING_CHOICE);
   // if there is no / inside the path
-  if ( ringchoice.find(DIR_SEPARATOR_CH) == std::string::npos ) {
+  //if ( ringchoice.find(DIR_SEPARATOR_CH) == std::string::npos ) {
     // check inside global share directory
-    ringchoice = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + DIR_SEPARATOR_STR + ringchoice; 
-  }
-  _toneMutex.enterMutex(); 
-  _toneType = ZT_TONE_FILE;
-  int play = _tone->playRingtone(ringchoice.c_str());
-  _toneMutex.leaveMutex();
-  if (play!=1) {
+  //  ringchoice = std::string(PROGSHAREDIR) + DIR_SEPARATOR_STR + RINGDIR + DIR_SEPARATOR_STR + ringchoice; 
+  //}
+  //_toneMutex.enterMutex(); 
+  //_toneType = ZT_TONE_FILE;
+  //int play = _tone->playRingtone(ringchoice.c_str());
+  //_toneMutex.leaveMutex();
+  //if (play!=1) {
     ringback();
-  }
+  //}
 }
 
 /**
-- 
GitLab