From ae7f07303b8d2c130b77cd4f42737d9a1c1af29a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?=
 <rafael.carre@savoirfairelinux.com>
Date: Mon, 8 Aug 2011 16:48:41 -0400
Subject: [PATCH] audiolayer : cleanup

---
 sflphone-common/src/audio/alsa/alsalayer.cpp  | 22 +++++++------------
 sflphone-common/src/audio/alsa/alsalayer.h    |  2 +-
 sflphone-common/src/audio/audiolayer.h        |  5 +++--
 .../src/audio/pulseaudio/pulselayer.cpp       | 15 ++-----------
 .../src/audio/pulseaudio/pulselayer.h         |  2 +-
 sflphone-common/test/audiolayertest.cpp       |  2 +-
 6 files changed, 16 insertions(+), 32 deletions(-)

diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp
index 55dcf4f424..c13d56450e 100644
--- a/sflphone-common/src/audio/alsa/alsalayer.cpp
+++ b/sflphone-common/src/audio/alsa/alsalayer.cpp
@@ -68,10 +68,7 @@ AlsaLayer::~AlsaLayer (void)
     _debug ("Audio: Destroy of ALSA layer");
     closeLayer();
 
-    if (_converter) {
-        delete _converter;
-        _converter = NULL;
-    }
+    delete _converter;
 }
 
 bool
@@ -103,7 +100,7 @@ AlsaLayer::closeLayer()
     return true;
 }
 
-bool
+void
 AlsaLayer::openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize, int stream , std::string plugin)
 {
     /* Close the devices before open it */
@@ -136,8 +133,6 @@ AlsaLayer::openDevice (int indexIn, int indexOut, int indexRing, int sampleRate,
 
     AudioLayer::_dcblocker = new DcBlocker();
     AudioLayer::_audiofilter = new AudioProcessing (static_cast<Algorithm *> (_dcblocker));
-
-    return true;
 }
 
 void
@@ -801,14 +796,13 @@ AlsaLayer::soundCardIndexExist (int card , int stream)
     ss << card ;
     name.append (ss.str());
 
-    if (snd_ctl_open (&handle, name.c_str(), 0) == 0) {
-        snd_pcm_info_set_stream (pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
+    if (snd_ctl_open (&handle, name.c_str(), 0) != 0)
+		return false;
 
-        if (snd_ctl_pcm_info (handle , pcminfo) < 0) return false;
-        else
-            return true;
-    } else
-        return false;
+    snd_pcm_info_set_stream (pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
+	bool ret =  snd_ctl_pcm_info (handle , pcminfo) >= 0;
+	snd_ctl_close(handle);
+	return ret;
 }
 
 int
diff --git a/sflphone-common/src/audio/alsa/alsalayer.h b/sflphone-common/src/audio/alsa/alsalayer.h
index 2845d36e6b..c317700327 100644
--- a/sflphone-common/src/audio/alsa/alsalayer.h
+++ b/sflphone-common/src/audio/alsa/alsalayer.h
@@ -79,7 +79,7 @@ class AlsaLayer : public AudioLayer
          *			  SFL_PCM_BOTH
          * @param plugin	  The alsa plugin ( dmix , default , front , surround , ...)
          */
-        bool openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize, int stream, std::string plugin);
+        void openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize, int stream, std::string plugin);
 
         /**
          * Start the capture stream and prepare the playback stream.
diff --git a/sflphone-common/src/audio/audiolayer.h b/sflphone-common/src/audio/audiolayer.h
index f2108f319c..77e7261056 100644
--- a/sflphone-common/src/audio/audiolayer.h
+++ b/sflphone-common/src/audio/audiolayer.h
@@ -93,7 +93,8 @@ class AudioLayer
          */
         virtual ~AudioLayer (void) {
             delete _time;
-            _time = NULL;
+            delete _dcblocker;
+            delete _audiofilter;
         }
 
         virtual bool closeLayer (void) = 0;
@@ -111,7 +112,7 @@ class AudioLayer
          *			  SFL_PCM_BOTH
          * @param plugin	  The alsa plugin ( dmix , default , front , surround , ...)
          */
-        virtual bool openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize, int stream , std::string plugin) = 0;
+        virtual void openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize, int stream , std::string plugin) = 0;
 
         /**
          * Start the capture stream and prepare the playback stream.
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
index dcdf68fbc5..08c2e6db98 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
@@ -252,16 +252,7 @@ PulseLayer::~PulseLayer (void)
 {
     closeLayer ();
 
-    if (_converter) {
-        delete _converter;
-        _converter = NULL;
-    }
-
-    delete AudioLayer::_dcblocker;
-    AudioLayer::_dcblocker = NULL;
-
-    delete AudioLayer::_audiofilter;
-    AudioLayer::_audiofilter = NULL;
+    delete _converter;
 }
 
 void
@@ -402,7 +393,7 @@ void PulseLayer::context_state_callback (pa_context* c, void* user_data)
     }
 }
 
-bool PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int indexRing UNUSED, int sampleRate, int frameSize , int stream UNUSED, std::string plugin UNUSED)
+void PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int indexRing UNUSED, int sampleRate, int frameSize , int stream UNUSED, std::string plugin UNUSED)
 {
     _debug ("Audio: Open device sampling rate %d, frame size %d", _audioSampleRate, _frameSize);
 
@@ -417,8 +408,6 @@ bool PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int indexR
     // Instantiate the algorithm
     AudioLayer::_dcblocker = new DcBlocker();
     AudioLayer::_audiofilter = new AudioProcessing (static_cast<Algorithm *> (_dcblocker));
-
-    return true;
 }
 
 
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.h b/sflphone-common/src/audio/pulseaudio/pulselayer.h
index 7d4500731b..7b89c1f12d 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.h
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.h
@@ -77,7 +77,7 @@ class PulseLayer : public AudioLayer
          *			  SFL_PCM_BOTH
          * @param plugin	  The alsa plugin ( dmix , default , front , surround , ...)
          */
-        bool openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize , int stream, std::string plugin) ;
+        void openDevice (int indexIn, int indexOut, int indexRing, int sampleRate, int frameSize , int stream, std::string plugin) ;
 
         DeviceList* getSinkList (void) {
             return &_sinkList;
diff --git a/sflphone-common/test/audiolayertest.cpp b/sflphone-common/test/audiolayertest.cpp
index 0298f042cb..2984f0fe6e 100644
--- a/sflphone-common/test/audiolayertest.cpp
+++ b/sflphone-common/test/audiolayertest.cpp
@@ -119,7 +119,7 @@ void AudioLayerTest::testPulseConnect()
     _pulselayer->setErrorMessage (-1);
 
     try {
-        CPPUNIT_ASSERT (_pulselayer->openDevice (numCardIn, numCardOut, numCardRing, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin) == true);
+        _pulselayer->openDevice (numCardIn, numCardOut, numCardRing, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin);
     } catch (...) {
         _debug ("Exception occured wile opening device! ");
     }
-- 
GitLab