From 8e4e63eb7e98072a68a1ce38b4697ec6cc106e72 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Fri, 19 Aug 2011 14:48:45 -0400
Subject: [PATCH] * #6692: more forward declarations, AudioThread->AlsaThread

---
 daemon/src/audio/alsa/alsalayer.cpp        | 45 ++++++++++--
 daemon/src/audio/alsa/alsalayer.h          |  8 +--
 daemon/src/audio/audiolayer.cpp            | 41 +++++++++--
 daemon/src/audio/audiolayer.h              | 46 +++----------
 daemon/src/audio/audioprocessing.cpp       |  3 +-
 daemon/src/audio/audioprocessing.h         |  4 +-
 daemon/src/audio/echosuppress.cpp          |  8 +--
 daemon/src/audio/echosuppress.h            | 79 +++++++++++-----------
 daemon/src/audio/pulseaudio/pulselayer.cpp |  3 +-
 daemon/src/audio/speexechocancel.cpp       |  2 +
 daemon/src/audio/speexechocancel.h         | 12 ++--
 daemon/src/eventthread.cpp                 | 20 ------
 daemon/src/eventthread.h                   | 20 ------
 13 files changed, 145 insertions(+), 146 deletions(-)

diff --git a/daemon/src/audio/alsa/alsalayer.cpp b/daemon/src/audio/alsa/alsalayer.cpp
index 3e0e90412d..7616e9bed1 100644
--- a/daemon/src/audio/alsa/alsalayer.cpp
+++ b/daemon/src/audio/alsa/alsalayer.cpp
@@ -30,9 +30,47 @@
  */
 
 #include "alsalayer.h"
-
+#include "audio/dcblocker.h"
+#include "audio/audioprocessing.h"
+#include "eventthread.h"
+#include "audio/samplerateconverter.h"
 #include "managerimpl.h"
 
+class AlsaThread : public ost::Thread
+{
+    public:
+        AlsaThread (AlsaLayer *alsa);
+
+        ~AlsaThread () {
+            terminate();
+        }
+
+        virtual void run (void);
+
+    private:
+        AlsaThread (const AlsaThread& at);
+        AlsaThread& operator= (const AlsaThread& at);
+
+        AlsaLayer* _alsa;
+};
+
+AlsaThread::AlsaThread (AlsaLayer *alsa)
+    : Thread(), _alsa (alsa)
+{
+    setCancel (cancelDeferred);
+}
+
+/**
+ * Reimplementation of run()
+ */
+void AlsaThread::run (void)
+{
+    while (!testCancel()) {
+        _alsa->audioCallback();
+        Thread::sleep (20);
+    }
+}
+
 // Constructor
 AlsaLayer::AlsaLayer (ManagerImpl* manager)
     : AudioLayer (manager, ALSA)
@@ -179,7 +217,7 @@ AlsaLayer::startStream (void)
     if (audioThread_ == NULL) {
         try {
             _debug ("Audio: Start Audio Thread");
-            audioThread_ = new AudioThread (this);
+            audioThread_ = new AlsaThread (this);
             audioThread_->start();
         } catch (...) {
             _debugException ("Fail to start audio thread");
@@ -659,7 +697,7 @@ AlsaLayer::handle_xrun_playback (snd_pcm_t *handle)
 std::string
 AlsaLayer::buildDeviceTopo (const std::string &plugin, int card, int subdevice)
 {
-    std::stringstream ss,ss1;
+    std::stringstream ss, ss1;
     std::string pcm(plugin);
 
     if (pcm == PCM_DEFAULT)
@@ -923,4 +961,3 @@ void AlsaLayer::audioCallback (void)
 
     free (in);
 }
-
diff --git a/daemon/src/audio/alsa/alsalayer.h b/daemon/src/audio/alsa/alsalayer.h
index e1e321edf0..a1b7c161ec 100644
--- a/daemon/src/audio/alsa/alsalayer.h
+++ b/daemon/src/audio/alsa/alsalayer.h
@@ -33,14 +33,12 @@
 #define _ALSA_LAYER_H
 
 #include "audio/audiolayer.h"
-#include "audio/samplerateconverter.h"
-#include "eventthread.h"
 #include <alsa/asoundlib.h>
 
-// #include <fstream>
-
+class SamplerateConverter;
 class RingBuffer;
 class ManagerImpl;
+class AlsaThread;
 
 /**
  * @file  AlsaLayer.h
@@ -280,7 +278,7 @@ class AlsaLayer : public AudioLayer
         bool is_capture_open_;
         bool trigger_request_;
 
-        AudioThread* audioThread_;
+        AlsaThread* audioThread_;
 
         /** Sample rate converter object */
         SamplerateConverter* converter_;
diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp
index 330a7858fa..973f0272e1 100644
--- a/daemon/src/audio/audiolayer.cpp
+++ b/daemon/src/audio/audiolayer.cpp
@@ -30,28 +30,58 @@
  */
 
 #include "audiolayer.h"
+#include "audioprocessing.h"
+#include "audio/dcblocker.h"
 #include "manager.h"
+#include <cc++/numbers.h>
+
+AudioLayer::AudioLayer (ManagerImpl* manager , int type)
+    : _layerType (type)
+    , _isStarted(false)
+    , _manager (manager)
+    , _urgentRingBuffer (SIZEBUF, Call::DEFAULT_ID)
+    , _mainBuffer(0)
+    , _recorder(0)
+    , _indexIn (0)
+    , _indexOut (0)
+    , _indexRing(0)
+    , _audioSampleRate (0)
+    , _frameSize (0)
+    , _inChannel (1)
+    , _outChannel (1)
+    , _errorMessage (0)
+    , _mutex ()
+    , _dcblocker(0)
+    , _audiofilter(0)
+    , _noisesuppressstate(false)
+    , _countNotificationTime(0)
+      , _time (new ost::Time)
+{}
+
+
+AudioLayer::~AudioLayer ()
+{
+    delete _time;
+    delete _audiofilter;
+    delete _dcblocker;
+}
 
 void AudioLayer::flushMain (void)
 {
     ost::MutexLock guard (_mutex);
-
     // should pass call id
     getMainBuffer()->flushAllBuffers();
 }
 
-
 void AudioLayer::flushUrgent (void)
 {
     ost::MutexLock guard (_mutex);
     _urgentRingBuffer.flushAll();
 }
 
-
 void AudioLayer::putUrgent (void* buffer, int toCopy)
 {
     ost::MutexLock guard (_mutex);
-
     _urgentRingBuffer.Put (buffer, toCopy);
 }
 
@@ -62,9 +92,8 @@ void AudioLayer::notifyincomingCall()
         _countNotificationTime += _time->getSecond();
         int countTimeModulo = _countNotificationTime % 5000;
 
-        if ( (countTimeModulo - _countNotificationTime) < 0) {
+        if ((countTimeModulo - _countNotificationTime) < 0)
             Manager::instance().notificationIncomingCall();
-        }
 
         _countNotificationTime = countTimeModulo;
     }
diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h
index 5d0888e3d4..010e6b3516 100644
--- a/daemon/src/audio/audiolayer.h
+++ b/daemon/src/audio/audiolayer.h
@@ -34,17 +34,9 @@
 #ifndef _AUDIO_LAYER_H
 #define _AUDIO_LAYER_H
 
-#include <cc++/numbers.h> // for ost::Time
 #include <cc++/thread.h> // for ost::Mutex
 
-#include "global.h"
-#include "audiodevice.h"
 #include "ringbuffer.h"
-#include "mainbuffer.h"
-#include "dcblocker.h"
-#include "speexechocancel.h"
-#include "echocancel.h"
-
 
 /**
  * @file  audiolayer.h
@@ -52,12 +44,16 @@
  */
 
 class ManagerImpl;
+class DcBlocker;
+class MainBuffer;
+class AudioProcessing;
+namespace ost {
+    class Time;
+}
 
 class AudioLayer
 {
-
     private:
-
         //copy constructor
         AudioLayer (const AudioLayer& rh);
 
@@ -69,38 +65,12 @@ class AudioLayer
          * Constructor
          * @param manager An instance of managerimpl
          */
-        AudioLayer (ManagerImpl* manager , int type)
-            : _layerType (type)
-        	, _isStarted(false)
-            , _manager (manager)
-            , _urgentRingBuffer (SIZEBUF, Call::DEFAULT_ID)
-            , _mainBuffer(0)
-            , _recorder(0)
-            , _indexIn (0)
-            , _indexOut (0)
-            , _indexRing(0)
-            , _audioSampleRate (0)
-            , _frameSize (0)
-            , _inChannel (1)
-            , _outChannel (1)
-            , _errorMessage (0)
-            , _mutex ()
-            , _dcblocker(0)
-            , _audiofilter(0)
-            , _noisesuppressstate(false)
-        	, _countNotificationTime(0)
-            , _time (new ost::Time) {
-
-        }
+        AudioLayer (ManagerImpl* manager , int type);
 
         /**
          * Destructor
          */
-        virtual ~AudioLayer (void) {
-            delete _time;
-            delete _audiofilter;
-            delete _dcblocker;
-        }
+        virtual ~AudioLayer (void);
 
         virtual bool closeLayer (void) = 0;
 
diff --git a/daemon/src/audio/audioprocessing.cpp b/daemon/src/audio/audioprocessing.cpp
index f7aba723f5..a728c99442 100644
--- a/daemon/src/audio/audioprocessing.cpp
+++ b/daemon/src/audio/audioprocessing.cpp
@@ -30,8 +30,7 @@
 
 
 #include "audioprocessing.h"
-
-
+#include "audio/algorithm.h"
 
 AudioProcessing::AudioProcessing (Algorithm *_algo) : _algorithm (_algo) {}
 
diff --git a/daemon/src/audio/audioprocessing.h b/daemon/src/audio/audioprocessing.h
index 195549a4d6..7f5a8de046 100644
--- a/daemon/src/audio/audioprocessing.h
+++ b/daemon/src/audio/audioprocessing.h
@@ -32,7 +32,9 @@
 #ifndef AUDIOPROCESSING_H
 #define AUDIOPROCESSING_H
 
-#include "algorithm.h"
+#include "global.h"
+
+class Algorithm;
 
 /**
  * Process audio buffers using specified at instantiation which may be
diff --git a/daemon/src/audio/echosuppress.cpp b/daemon/src/audio/echosuppress.cpp
index 4ea3826263..542598e732 100644
--- a/daemon/src/audio/echosuppress.cpp
+++ b/daemon/src/audio/echosuppress.cpp
@@ -10,7 +10,7 @@
 
 #define ECHO_CANCEL_MEM_SIZE 1000
 
-EchoSuppress::EchoSuppress(pj_pool_t *pool)
+EchoSuppress::EchoSuppress(pj_pool_t * /*pool*/)
 {
 
     /*
@@ -45,7 +45,7 @@ void EchoSuppress::reset()
 
 }
 
-void EchoSuppress::putData (SFLDataFormat *inputData, int nbBytes)
+void EchoSuppress::putData (SFLDataFormat * /*inputData*/, int /*nbBytes*/)
 {
     /*
     pj_status_t status;
@@ -58,7 +58,7 @@ void EchoSuppress::putData (SFLDataFormat *inputData, int nbBytes)
     */
 }
 
-int EchoSuppress::getData(SFLDataFormat *outputData)
+int EchoSuppress::getData(SFLDataFormat * /*outputData*/)
 {
     /*
     pj_status_t status;
@@ -73,4 +73,4 @@ int EchoSuppress::getData(SFLDataFormat *outputData)
 
 void EchoSuppress::process (SFLDataFormat *data UNUSED, int nbBytes UNUSED) {}
 
-int EchoSuppress::process (SFLDataFormat *inputData, SFLDataFormat *outputData, int nbBytes) { return 0; }
+int EchoSuppress::process (SFLDataFormat * /*inputData*/, SFLDataFormat * /*outputData*/, int /*nbBytes*/) { return 0; }
diff --git a/daemon/src/audio/echosuppress.h b/daemon/src/audio/echosuppress.h
index a60c7152e7..3df72f13a4 100644
--- a/daemon/src/audio/echosuppress.h
+++ b/daemon/src/audio/echosuppress.h
@@ -12,45 +12,46 @@
 #include "pj/pool.h"
 
 #include "audioprocessing.h"
-
-class EchoSuppress: public Algorithm {
-public:
-    EchoSuppress(pj_pool_t *pool);
-
-    virtual ~EchoSuppress();
-
-    virtual void reset (void);
-
-    /**
-     * Add speaker data into internal buffer
-     * \param inputData containing far-end voice data to be sent to speakers
-     */
-    virtual void putData (SFLDataFormat *, int);
-
-    virtual int getData(SFLDataFormat *);
-
-    /**
-     * Unused
-     */
-    virtual void process (SFLDataFormat *, int);
-
-    /**
-     * Perform echo cancellation using internal buffers
-     * \param inputData containing mixed echo and voice data
-     * \param outputData containing
-     */
-    virtual int process (SFLDataFormat *, SFLDataFormat *, int);
-private:
-
-    /**
-     * Memory pool for echo cancellation
-     */
-    pj_pool_t *echoCancelPool;
-
-    /**
-     * The internal state of the echo canceller
-     */
-    pjmedia_echo_state *echoState;
+#include "audio/algorithm.h"
+
+class EchoSuppress : public Algorithm {
+    public:
+        EchoSuppress(pj_pool_t *pool);
+
+        virtual ~EchoSuppress();
+
+        virtual void reset (void);
+
+        /**
+         * Add speaker data into internal buffer
+         * \param inputData containing far-end voice data to be sent to speakers
+         */
+        virtual void putData (SFLDataFormat *, int);
+
+        virtual int getData(SFLDataFormat *);
+
+        /**
+         * Unused
+         */
+        virtual void process (SFLDataFormat *, int);
+
+        /**
+         * Perform echo cancellation using internal buffers
+         * \param inputData containing mixed echo and voice data
+         * \param outputData containing
+         */
+        virtual int process (SFLDataFormat *, SFLDataFormat *, int);
+    private:
+
+        /**
+         * Memory pool for echo cancellation
+         */
+        pj_pool_t *echoCancelPool;
+
+        /**
+         * The internal state of the echo canceller
+         */
+        pjmedia_echo_state *echoState;
 };
 
 #endif /* ECHOSUPPRESS_H_ */
diff --git a/daemon/src/audio/pulseaudio/pulselayer.cpp b/daemon/src/audio/pulseaudio/pulselayer.cpp
index a3ec233bbc..e1b391aa89 100644
--- a/daemon/src/audio/pulseaudio/pulselayer.cpp
+++ b/daemon/src/audio/pulseaudio/pulselayer.cpp
@@ -30,6 +30,7 @@
  */
 
 #include "pulselayer.h"
+#include "audio/audioprocessing.h"
 #include "managerimpl.h"
 
 static void playback_callback (pa_stream* s, size_t bytes, void* userdata)
@@ -392,7 +393,7 @@ void 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));
+    AudioLayer::_audiofilter = new AudioProcessing (_dcblocker);
 }
 
 
diff --git a/daemon/src/audio/speexechocancel.cpp b/daemon/src/audio/speexechocancel.cpp
index 130f04f3cf..f80513c093 100644
--- a/daemon/src/audio/speexechocancel.cpp
+++ b/daemon/src/audio/speexechocancel.cpp
@@ -21,6 +21,8 @@
 #include <limits.h>
 
 #include "speexechocancel.h"
+#include <speex/speex_echo.h>
+#include <speex/speex_preprocess.h>
 #include "manager.h"
 
 // number of samples (20 ms)
diff --git a/daemon/src/audio/speexechocancel.h b/daemon/src/audio/speexechocancel.h
index 74e9bbf00a..209e4e1a97 100644
--- a/daemon/src/audio/speexechocancel.h
+++ b/daemon/src/audio/speexechocancel.h
@@ -20,19 +20,19 @@
 #ifndef SPEEXECHOCANCEL_H
 #define SPEEXECHOCANCEL_H
 
-#include "audioprocessing.h"
-#include <speex/speex_echo.h>
-#include "speex/speex_preprocess.h"
+#include "audio/algorithm.h"
 
-#include "ringbuffer.h"
+class RingBuffer;
+class SpeexEchoState_;
+typedef SpeexEchoState_ SpeexEchoState;
+class SpeexPreprocessState_;
+typedef SpeexPreprocessState_ SpeexPreprocessState;
 
 class SpeexEchoCancel : public Algorithm
 {
-
     public:
 
         SpeexEchoCancel();
-
         ~SpeexEchoCancel();
 
         virtual void reset (void);
diff --git a/daemon/src/eventthread.cpp b/daemon/src/eventthread.cpp
index edd744e3b6..d80c4423c8 100644
--- a/daemon/src/eventthread.cpp
+++ b/daemon/src/eventthread.cpp
@@ -30,7 +30,6 @@
 
 #include "eventthread.h"
 #include "voiplink.h"
-#include "audio/alsa/alsalayer.h"
 
 /********************************** Voiplink thread *************************************/
 EventThread::EventThread (VoIPLink *link)
@@ -51,22 +50,3 @@ void EventThread::run (void)
     }
 }
 
-/********************************************************************************************/
-
-AudioThread::AudioThread (AlsaLayer *alsa)
-    : Thread(), _alsa (alsa)
-{
-    setCancel (cancelDeferred);
-}
-
-/**
- * Reimplementation of run()
- */
-void AudioThread::run (void)
-{
-    while (!testCancel()) {
-        _alsa->audioCallback();
-        Thread::sleep (20);
-    }
-}
-
diff --git a/daemon/src/eventthread.h b/daemon/src/eventthread.h
index e18906a486..3553f59f61 100644
--- a/daemon/src/eventthread.h
+++ b/daemon/src/eventthread.h
@@ -35,7 +35,6 @@
 
 
 class VoIPLink;
-class AlsaLayer;
 
 /**
  * @file eventthread.h
@@ -65,23 +64,4 @@ class EventThread : public ost::Thread
         VoIPLink*	_linkthread;
 };
 
-class AudioThread : public ost::Thread
-{
-
-    public:
-        AudioThread (AlsaLayer *alsa);
-
-        ~AudioThread (void) {
-            terminate();
-        }
-
-        virtual void run (void);
-
-    private:
-        AudioThread (const AudioThread& at);
-        AudioThread& operator= (const AudioThread& at);
-
-        AlsaLayer* _alsa;
-};
-
 #endif // __EVENT_THREAD_H__
-- 
GitLab