diff --git a/daemon/src/audio/alsa/alsalayer.cpp b/daemon/src/audio/alsa/alsalayer.cpp index 3e0e90412daa01cc3e10cc0321fcba736e610b22..7616e9bed143dc7fb6dbc2e53851ed47926fc3c9 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 e1e321edf092d683f1073943d3b2518cef82e2e7..a1b7c161ec3339214035a4ab1abd44217a49f9f4 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 330a7858fa9ce4c0d1378191d3612315bab3c2dc..973f0272e13dc78783a83f19dda6e0feafcaee5c 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 5d0888e3d4d5e1e904ae99a4e0a4089937279a48..010e6b3516220c437cb367fadbd5db9aeee3418e 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 f7aba723f50b2bab92d9082c534256696a9e0421..a728c9944283d6c1a402683072c30f7b13a88adb 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 195549a4d60b43c12d977f2dc7f3255492a3cff4..7f5a8de0465895ac0243b9d48935c36e79971b14 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 4ea38262632489c03f2aaf38c83b82259dd4a192..542598e732d7a0e57e5f2aa3b3eda5ece7ac13d8 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 a60c7152e7d2a7dfcdb9660e37373f19416073f9..3df72f13a446877532877a47a616321072fde247 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 a3ec233bbcc847b9f5affa50107c106374aad643..e1b391aa899d120bf246948068925acc6cbd955d 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 130f04f3cf988ea60a43a1724d23aadd1e867183..f80513c093da04c01667ca88a6b7ae23528592cf 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 74e9bbf00a0f07785443d253096118b8abddc3eb..209e4e1a97af3efad8b56ad7e71cb4f127740c2c 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 edd744e3b644115ed578f5fbdba008f2fa351726..d80c4423c891cbdb628361cf7bb3bcbf46b2194e 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 e18906a4861619640f48b566f64196e3184049fd..3553f59f61a4952223d7f1f6a1ecbdc5f0ea1e4e 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__