diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp index 1a2c00aa4f0687c604a1fe3abfb585677bf97a8b..d628c67b2b3436eac03958015e3d626645242a63 100644 --- a/daemon/src/audio/audiolayer.cpp +++ b/daemon/src/audio/audiolayer.cpp @@ -40,7 +40,6 @@ AudioLayer::AudioLayer (ManagerImpl* manager , int type) , isStarted_ (false) , manager_ (manager) , urgentRingBuffer_ (SIZEBUF, Call::DEFAULT_ID) - , mainBuffer_ (0) , recorder_ (0) , indexIn_ (0) , indexOut_ (0) diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h index 4df3af3bcd9d9c01f9c66fd3a76bd9dcf830a783..8a29050b03eb4d081cdd3f3a5e0bffe3042e0b97 100644 --- a/daemon/src/audio/audiolayer.h +++ b/daemon/src/audio/audiolayer.h @@ -37,6 +37,7 @@ #include <cc++/thread.h> // for ost::Mutex #include <sys/time.h> +#include "manager.h" #include "ringbuffer.h" /** @@ -44,7 +45,6 @@ * @brief Main sound class. Manages the data transfers between the application and the hardware. */ -class ManagerImpl; class DcBlocker; class MainBuffer; class AudioProcessing; @@ -197,14 +197,7 @@ class AudioLayer * @return MainBuffer* a pointer to the MainBuffer instance */ MainBuffer* getMainBuffer (void) const { - return mainBuffer_; - } - - /** - * Set the mainbuffer once the audiolayer is created - */ - void setMainBuffer (MainBuffer* mainbuffer) { - mainBuffer_ = mainbuffer; + return manager_->getMainBuffer(); } /** @@ -271,15 +264,6 @@ class AudioLayer */ RingBuffer urgentRingBuffer_; - /** - * Instance of the MainBuffer for the whole application - * - * In order to send signal to other parts of the application, one must pass through the mainbuffer. - * Audio instances must be registered into the MainBuffer and bound together via the ManagerImpl. - * - */ - MainBuffer* mainBuffer_; - /** * A pointer to the recordable instance (may be a call or a conference) */ diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 885e34a3a6a336a3fe1bd832f7d6497e18b03a2d..e057f04cd1a088afe9f1c726e820c92603eb6041 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -2056,12 +2056,11 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin) if (CHECK_INTERFACE (layerType , ALSA)) { _debug ("Set input audio plugin"); - _audiodriver -> setErrorMessage (-1); _audiodriver -> openDevice (_audiodriver->getIndexIn(), _audiodriver->getIndexOut(), _audiodriver->getIndexRing(), _audiodriver -> getSampleRate(), _audiodriver -> getFrameSize(), SFL_PCM_BOTH, audioPlugin); - if (_audiodriver -> getErrorMessage() != -1) + if (_audiodriver -> getErrorMessage()) notifyErrClient (_audiodriver -> getErrorMessage()); } audioLayerMutexUnlock(); @@ -2081,8 +2080,6 @@ void ManagerImpl::setAudioDevice (const int index, int streamType) return; } - _audiodriver -> setErrorMessage (-1); - AlsaLayer *alsaLayer = dynamic_cast<AlsaLayer*>(_audiodriver); if (!alsaLayer) { _error("Cannot set audio output for non-alsa device"); @@ -2119,7 +2116,7 @@ void ManagerImpl::setAudioDevice (const int index, int streamType) _warn ("Unknown stream type"); } - if (_audiodriver -> getErrorMessage() != -1) + if (_audiodriver -> getErrorMessage()) notifyErrClient (_audiodriver -> getErrorMessage()); audioLayerMutexUnlock(); @@ -2482,44 +2479,22 @@ void ManagerImpl::setEchoCancelDelay(int delay) /** * Initialization: Main Thread */ -bool ManagerImpl::initAudioDriver (void) +void ManagerImpl::initAudioDriver (void) { - _debug ("Manager: AudioLayer Creation"); - audioLayerMutexLock(); - if (preferences.getAudioApi() == ALSA) { + if (preferences.getAudioApi() == PULSEAUDIO && system("ps -C pulseaudio") == 0) { + _audiodriver = new PulseLayer (this); + } else { + preferences.setAudioApi (ALSA); _audiodriver = new AlsaLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - } else if (preferences.getAudioApi() == PULSEAUDIO) { - if (system("ps -C pulseaudio") == 0) { - _audiodriver = new PulseLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - } else { - _audiodriver = new AlsaLayer (this); - preferences.setAudioApi (ALSA); - _audiodriver->setMainBuffer (&_mainBuffer); - } - } else - _debug ("Error - Audio API unknown"); - - if (_audiodriver == NULL) { - _debug ("Manager: Init audio driver error"); - audioLayerMutexUnlock(); - return false; - } else { - int error = _audiodriver->getErrorMessage(); - - if (error == -1) { - _debug ("Manager: Init audio driver: %d", error); - audioLayerMutexUnlock(); - return false; - } } - audioLayerMutexUnlock(); + int error = _audiodriver->getErrorMessage(); + if (error) + _error("Audio driver init: %d", error); - return true; + audioLayerMutexUnlock(); } /** @@ -2568,15 +2543,13 @@ void ManagerImpl::selectAudioDriver (void) } } - _audiodriver->setErrorMessage (-1); - /* Open the audio devices */ _audiodriver->openDevice (numCardIn, numCardOut, numCardRing, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin); /* Notify the error if there is one */ - if (_audiodriver-> getErrorMessage() != -1) + if (_audiodriver-> getErrorMessage()) notifyErrClient (_audiodriver -> getErrorMessage()); audioLayerMutexUnlock(); @@ -2611,32 +2584,15 @@ void ManagerImpl::switchAudioManager (void) _debug ("Manager: Deleting current layer... "); delete _audiodriver; - _audiodriver = NULL; - - switch (type) { - case ALSA: - _debug ("Manager: Creating Pulseaudio layer..."); - _audiodriver = new PulseLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; - - case PULSEAUDIO: - _debug ("Manager: Creating ALSA layer..."); - _audiodriver = new AlsaLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; - - default: - _warn ("Manager: Error: audio layer unknown"); - break; - } - - _audiodriver->setErrorMessage (-1); + if (type == PULSEAUDIO) + _audiodriver = new PulseLayer (this); + else + _audiodriver = new AlsaLayer (this); _audiodriver->openDevice (numCardIn, numCardOut, numCardRing, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin); - if (_audiodriver->getErrorMessage() != -1) + if (_audiodriver->getErrorMessage()) notifyErrClient (_audiodriver -> getErrorMessage()); _debug ("Manager: Current device: %d ", type); @@ -2684,34 +2640,15 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate) bool wasActive = _audiodriver->isStarted(); delete _audiodriver; - _audiodriver = 0; - - switch (type) { - - case PULSEAUDIO: - _debug ("Manager: Creating Pulseaudio layer..."); - _audiodriver = new PulseLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; - - case ALSA: - _debug ("Manager: Creating ALSA layer..."); - _audiodriver = new AlsaLayer (this); - _audiodriver->setMainBuffer (&_mainBuffer); - break; - - default: - _error ("Manager: Error: audio layer unknown"); - audioLayerMutexUnlock(); - return; - } - - _audiodriver->setErrorMessage (-1); + if (type == PULSEAUDIO) + _audiodriver = new PulseLayer (this); + else + _audiodriver = new AlsaLayer (this); _audiodriver->openDevice (numCardIn, numCardOut, numCardRing, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin); - if (_audiodriver -> getErrorMessage() != -1) + if (_audiodriver -> getErrorMessage()) notifyErrClient (_audiodriver -> getErrorMessage()); _debug ("Manager: Current device: %d ", type); diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 9650d04412f08fbac3df20f34b67b30cf30f3d13..81d246ee5c4a1fc379c9085a5e759773d1f5db11 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -933,19 +933,10 @@ class ManagerImpl */ bool isCurrentCall (const std::string& callId); - /* - * Initialize audiodriver - */ - bool initAudioDriver (void); + void initAudioDriver (void); - /** - * Enter the mutex for the audio layer - */ void audioLayerMutexLock(void) { _audiolayerMutex.enterMutex(); } - /** - * Leave the mutex for audio layer - */ void audioLayerMutexUnlock(void) { _audiolayerMutex.leaveMutex(); } /** diff --git a/daemon/test/audiolayertest.cpp b/daemon/test/audiolayertest.cpp index e7d50ea89d332067d7b6d3985251b215df5862f5..7e43246b4fe501f0085bf473b1873c3f44b7d211 100644 --- a/daemon/test/audiolayertest.cpp +++ b/daemon/test/audiolayertest.cpp @@ -117,8 +117,6 @@ void AudioLayerTest::testPulseConnect() CPPUNIT_ASSERT (_pulselayer->getPlaybackStream() == NULL); CPPUNIT_ASSERT (_pulselayer->getRecordStream() == NULL); - _pulselayer->setErrorMessage (-1); - try { _pulselayer->openDevice (numCardIn, numCardOut, numCardRing, sampleRate, frameSize, SFL_PCM_BOTH, alsaPlugin); } catch (...) {