From f8bc445a28ed8698e9dab9c4efb744a3ece4e660 Mon Sep 17 00:00:00 2001
From: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
Date: Fri, 25 Feb 2011 22:20:07 -0500
Subject: [PATCH] [#5211] Move mainbuffer unbind call in rtp final method

---
 .../src/audio/audiortp/AudioRtpFactory.cpp          |  2 +-
 .../src/audio/audiortp/AudioRtpSession.cpp          | 10 +++++-----
 .../src/audio/audiortp/AudioRtpSession.h            |  4 +++-
 sflphone-common/src/audio/pulseaudio/pulselayer.cpp | 11 -----------
 sflphone-common/src/global.h                        |  2 +-
 sflphone-common/src/sip/sipcall.cpp                 |  4 ++--
 sflphone-common/src/sip/sipvoiplink.cpp             | 13 +++++++------
 7 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
index ab02df4ecc..84d44d91ea 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp
@@ -203,7 +203,7 @@ void AudioRtpFactory::stop (void)
                 break;
 
             case Symmetric:
-                static_cast<AudioSrtpSession *> (_rtpSession)->stopRtpThread();
+                static_cast<AudioRtpSession *> (_rtpSession)->stopRtpThread();
                 break;
 
             case Zrtp:
diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
index a61a6165ee..954e406c7e 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
+++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.cpp
@@ -81,13 +81,15 @@ AudioRtpSession::~AudioRtpSession()
         _debugException ("AudioRtpSession: Thread destructor didn't terminate correctly");
         throw;
     }
-
-    Manager::instance().getMainBuffer()->unBindAll (_audioRtpRecord._callId);
 }
 
 void AudioRtpSession::final()
 {
-    delete this;
+    _debug ("AudioRtpSession: Finalize AudioRtpSession instance");
+
+    Manager::instance().getMainBuffer()->unBindAll (_audioRtpRecord._callId);
+
+    delete static_cast<AudioRtpSession *> (this);
 }
 
 void AudioRtpSession::setSessionTimeouts (void)
@@ -403,8 +405,6 @@ void AudioRtpSession::run ()
 
     _debug ("AudioRtpSession: Left main loop for call %s", _audioRtpRecord._callId.c_str());
 
-    Thread::exit();
-
 }
 
 }
diff --git a/sflphone-common/src/audio/audiortp/AudioRtpSession.h b/sflphone-common/src/audio/audiortp/AudioRtpSession.h
index 6e495d29f8..7461d7027b 100644
--- a/sflphone-common/src/audio/audiortp/AudioRtpSession.h
+++ b/sflphone-common/src/audio/audiortp/AudioRtpSession.h
@@ -71,6 +71,8 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
 
         virtual void final ();
 
+        void terminateRtpSession();
+
         // Thread associated method
         virtual void run ();
 
@@ -137,7 +139,7 @@ class AudioRtpSession : protected ost::Thread, public ost::TimerPort, public Aud
         // optional in ost::thread, then
         // it amounts to the same as doing
         // start() with no semaphore at all.
-        ost::Semaphore * _mainloopSemaphore;
+        ost::Semaphore *_mainloopSemaphore;
 
         // Main destination address for this rtp session.
         // Stored in case or reINVITE, which may require to forget
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
index c360756ee2..6aa3b226e1 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
@@ -249,10 +249,6 @@ PulseLayer::PulseLayer (ManagerImpl* manager)
 
     byteCounter = 0;
 
-
-    // captureFile = new ofstream ("probeCaptureFile", ofstream::binary);
-    // spkrFile = new ofstream ("probeSpkrFile", ofstream::binary);
-
     openLayer();
 }
 
@@ -271,13 +267,6 @@ PulseLayer::~PulseLayer (void)
 
     delete AudioLayer::_audiofilter;
     AudioLayer::_audiofilter = NULL;
-
-
-    // captureFile->close();
-    // spkrFile->close();
-
-    // delete captureFile;
-    // delete spkrFile;
 }
 
 void
diff --git a/sflphone-common/src/global.h b/sflphone-common/src/global.h
index f69f1898ac..d69aea955e 100644
--- a/sflphone-common/src/global.h
+++ b/sflphone-common/src/global.h
@@ -44,7 +44,7 @@
 #include <vector>
 #include "logger.h"
 
-#define SFLPHONED_VERSION "0.9.8"		/** Version number */
+#define SFLPHONED_VERSION "0.9.12"		/** Version number */
 
 #define HOMEDIR					(getenv ("HOME"))				/** Home directory */
 #define XDG_DATA_HOME			(getenv ("XDG_DATA_HOME"))
diff --git a/sflphone-common/src/sip/sipcall.cpp b/sflphone-common/src/sip/sipcall.cpp
index 8e88ee7edd..17476ad1e4 100644
--- a/sflphone-common/src/sip/sipcall.cpp
+++ b/sflphone-common/src/sip/sipcall.cpp
@@ -65,8 +65,8 @@ SIPCall::~SIPCall()
     delete _local_sdp;
     _local_sdp = NULL;
 
-    _error ("SDP: pool capacity %d", pj_pool_get_capacity (_pool));
-    _error ("SDP: pool size %d", pj_pool_get_used_size (_pool));
+    _debug ("SDP: pool capacity %d", pj_pool_get_capacity (_pool));
+    _debug ("SDP: pool size %d", pj_pool_get_used_size (_pool));
 
     // Release memory allocated for SDP only once
     pj_pool_release (_pool);
diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index b727efac33..31aac9ac76 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -473,7 +473,6 @@ int SIPVoIPLink::sendRegister (AccountID id)
     int expire_value;
 
     pj_status_t status;
-    pj_str_t useragent;
     pjsip_tx_data *tdata;
     pjsip_host_info destination;
 
@@ -636,7 +635,9 @@ int SIPVoIPLink::sendRegister (AccountID id)
     // Add User-Agent Header
     pj_list_init (&hdr_list);
 
-    useragent = pj_str ( (char*) get_useragent_name (id).c_str());
+    const char *useragent_name = get_useragent_name (id).c_str();
+    pj_str_t useragent = pj_str ( (char *) useragent_name);
+    // pj_str_t useragent = pj_str ( (char *) "SFLphone"); // { (char *) "SFLphone",  8};
 
     h = pjsip_generic_string_hdr_create (_pool, &STR_USER_AGENT, &useragent);
 
@@ -771,8 +772,8 @@ SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) throw
 
     _debug ("UserAgent: New outgoing call %s to %s", id.c_str(), toUrl.c_str());
 
-    _error ("UserAgent: pool capacity %d", pj_pool_get_capacity (_pool));
-    _error ("UserAgent: pool size %d", pj_pool_get_used_size (_pool));
+    _debug ("UserAgent: pool capacity %d", pj_pool_get_capacity (_pool));
+    _debug ("UserAgent: pool size %d", pj_pool_get_used_size (_pool));
 
     SIPCall* call = new SIPCall (id, Call::Outgoing, _cp);
 
@@ -864,8 +865,8 @@ SIPVoIPLink::answer (const CallID& id)
 
     SIPCall *call = getSIPCall (id);
 
-    _error ("UserAgent: pool capacity %d", pj_pool_get_capacity (_pool));
-    _error ("UserAgent: pool size %d", pj_pool_get_used_size (_pool));
+    _debug ("UserAgent: pool capacity %d", pj_pool_get_capacity (_pool));
+    _debug ("UserAgent: pool size %d", pj_pool_get_used_size (_pool));
 
 
     if (call==0) {
-- 
GitLab