From 0171ee72ede3e769d4de398c6e5fed206cf1ad6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= <rafael.carre@savoirfairelinux.com> Date: Mon, 29 Aug 2011 15:23:22 -0400 Subject: [PATCH] * #6629 : clean AudioLayer Don't store a pointer to ManagerImpl Store a reference to audio preferences Remove unused noisesuppression state --- daemon/src/audio/alsa/alsalayer.cpp | 16 +++++++-------- daemon/src/audio/alsa/alsalayer.h | 3 +-- daemon/src/audio/audiolayer.cpp | 5 ++--- daemon/src/audio/audiolayer.h | 24 +++------------------- daemon/src/audio/pulseaudio/pulselayer.cpp | 22 +++++++++----------- daemon/src/audio/pulseaudio/pulselayer.h | 2 +- daemon/src/managerimpl.cpp | 21 ++++++------------- 7 files changed, 30 insertions(+), 63 deletions(-) diff --git a/daemon/src/audio/alsa/alsalayer.cpp b/daemon/src/audio/alsa/alsalayer.cpp index 3393b6e1f8..e1798b4c82 100644 --- a/daemon/src/audio/alsa/alsalayer.cpp +++ b/daemon/src/audio/alsa/alsalayer.cpp @@ -72,8 +72,8 @@ void AlsaThread::run (void) } // Constructor -AlsaLayer::AlsaLayer (ManagerImpl* manager) - : AudioLayer (manager, ALSA) +AlsaLayer::AlsaLayer () + : AudioLayer (ALSA) , playbackHandle_ (NULL) , ringtoneHandle_ (NULL) , captureHandle_ (NULL) @@ -94,9 +94,7 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager) _debug ("Audio: Build ALSA layer"); urgentRingBuffer_.createReadPointer(); - audioPlugin_ = manager_->audioPreference.getPlugin(); - - noiseSuppressState_ = true; + audioPlugin_ = audioPref.getPlugin(); } // Destructor @@ -807,10 +805,10 @@ void AlsaLayer::audioCallback (void) notifyincomingCall(); - unsigned short spkrVolume = manager_->getSpkrVolume(); + unsigned short spkrVolume = Manager::instance().getSpkrVolume(); - AudioLoop *tone = manager_->getTelephoneTone(); - AudioLoop *file_tone = manager_->getTelephoneFile(); + AudioLoop *tone = Manager::instance().getTelephoneTone(); + AudioLoop *file_tone = Manager::instance().getTelephoneFile(); // AvailForGet tell the number of chars inside the buffer // framePerBuffer are the number of data for one channel (left) @@ -926,7 +924,7 @@ void AlsaLayer::audioCallback (void) free(in); return; } - adjustVolume (in, toPutSamples, manager_->getSpkrVolume()); + adjustVolume (in, toPutSamples, Manager::instance().getSpkrVolume()); if (resample) { int outSamples = toPutSamples * ((double) audioSampleRate_ / mainBufferSampleRate); diff --git a/daemon/src/audio/alsa/alsalayer.h b/daemon/src/audio/alsa/alsalayer.h index 46c5c92edb..57c8a51404 100644 --- a/daemon/src/audio/alsa/alsalayer.h +++ b/daemon/src/audio/alsa/alsalayer.h @@ -50,9 +50,8 @@ class AlsaLayer : public AudioLayer public: /** * Constructor - * @param manager An instance of managerimpl */ - AlsaLayer (ManagerImpl* manager); + AlsaLayer (); /** * Destructor diff --git a/daemon/src/audio/audiolayer.cpp b/daemon/src/audio/audiolayer.cpp index d628c67b2b..55346ad821 100644 --- a/daemon/src/audio/audiolayer.cpp +++ b/daemon/src/audio/audiolayer.cpp @@ -35,10 +35,9 @@ #include "audio/dcblocker.h" #include "manager.h" -AudioLayer::AudioLayer (ManagerImpl* manager , int type) +AudioLayer::AudioLayer (int type) : layerType_ (type) , isStarted_ (false) - , manager_ (manager) , urgentRingBuffer_ (SIZEBUF, Call::DEFAULT_ID) , recorder_ (0) , indexIn_ (0) @@ -52,7 +51,7 @@ AudioLayer::AudioLayer (ManagerImpl* manager , int type) , mutex_ () , dcblocker_ (0) , audiofilter_ (0) - , noiseSuppressState_ (false) + , audioPref(Manager::instance().audioPreference) , lastNotificationTime_ (0) {} diff --git a/daemon/src/audio/audiolayer.h b/daemon/src/audio/audiolayer.h index 8a29050b03..45b52d81e7 100644 --- a/daemon/src/audio/audiolayer.h +++ b/daemon/src/audio/audiolayer.h @@ -64,9 +64,8 @@ class AudioLayer public: /** * Constructor - * @param manager An instance of managerimpl */ - AudioLayer (ManagerImpl* manager , int type); + AudioLayer (int type); /** * Destructor @@ -197,7 +196,7 @@ class AudioLayer * @return MainBuffer* a pointer to the MainBuffer instance */ MainBuffer* getMainBuffer (void) const { - return manager_->getMainBuffer(); + return Manager::instance().getMainBuffer(); } /** @@ -214,20 +213,6 @@ class AudioLayer return recorder_; } - /** - * Set the noise suppressor state - * @param state true if noise suppressor active, false elsewhere - */ - void setNoiseSuppressState (bool state) { noiseSuppressState_ = state; } - - /** - * Get the noise suppressor state - * @return true if noise suppressor activated - */ - bool getNoiseSuppressState (void) const { - return noiseSuppressState_; - } - /** * Get the mutex lock for the entire audio layer */ @@ -256,9 +241,6 @@ class AudioLayer */ bool isStarted_; - /** Augment coupling, reduce indirect access */ - ManagerImpl* manager_; - /** * Urgent ring buffer used for ringtones */ @@ -317,7 +299,7 @@ class AudioLayer DcBlocker *dcblocker_; AudioProcessing *audiofilter_; - bool noiseSuppressState_; + AudioPreference &audioPref; private: /** diff --git a/daemon/src/audio/pulseaudio/pulselayer.cpp b/daemon/src/audio/pulseaudio/pulselayer.cpp index da0d04fa45..90fb23dfff 100644 --- a/daemon/src/audio/pulseaudio/pulselayer.cpp +++ b/daemon/src/audio/pulseaudio/pulselayer.cpp @@ -218,8 +218,8 @@ void playback_overflow_callback (pa_stream* s UNUSED, void* userdata UNUSED) } // end anonymous namespace -PulseLayer::PulseLayer (ManagerImpl* manager) - : AudioLayer (manager , PULSEAUDIO) +PulseLayer::PulseLayer () + : AudioLayer (PULSEAUDIO) , context_(0) , mainloop_(0) , playback_(0) @@ -229,8 +229,6 @@ PulseLayer::PulseLayer (ManagerImpl* manager) { urgentRingBuffer_.createReadPointer(); - noiseSuppressState_ = true; - openLayer(); } @@ -428,9 +426,9 @@ void PulseLayer::createStreams (pa_context* c) playback_ = new AudioStream (c, mainloop_, PLAYBACK_STREAM_NAME, PLAYBACK_STREAM, audioSampleRate_); - std::string playbackDevice(manager_->audioPreference.getDevicePlayback()); - std::string recordDevice(manager_->audioPreference.getDeviceRecord()); - std::string ringtoneDevice(manager_->audioPreference.getDeviceRingtone()); + std::string playbackDevice(audioPref.getDevicePlayback()); + std::string recordDevice(audioPref.getDeviceRecord()); + std::string ringtoneDevice(audioPref.getDeviceRingtone()); _debug ("Audio: Device for playback: %s", playbackDevice.c_str()); _debug ("Audio: Device for record: %s", recordDevice.c_str()); @@ -493,7 +491,7 @@ void PulseLayer::closeCaptureStream (void) if (name && strlen (name)) { _debug ("Audio: record device to be stored in config: %s", name); - manager_->audioPreference.setDeviceRecord (name); + audioPref.setDeviceRecord (name); } } @@ -511,7 +509,7 @@ void PulseLayer::closePlaybackStream (void) if (name && strlen (name)) { _debug ("Audio: playback device to be stored in config: %s", name); - manager_->audioPreference.setDevicePlayback (name); + audioPref.setDevicePlayback (name); } } @@ -525,7 +523,7 @@ void PulseLayer::closePlaybackStream (void) if (name && strlen (name)) { _debug ("Audio: ringtone device to be stored in config: %s", name); - manager_->audioPreference.setDeviceRingtone (name); + audioPref.setDeviceRingtone (name); } } @@ -646,7 +644,7 @@ void PulseLayer::writeToSpeaker (void) return; } - AudioLoop *toneToPlay = manager_->getTelephoneTone(); + AudioLoop *toneToPlay = Manager::instance().getTelephoneTone(); if (toneToPlay) { if (playback_->getStreamState() == PA_STREAM_READY) { SFLDataFormat *out = (SFLDataFormat*) pa_xmalloc (writeableSizeBytes); @@ -744,7 +742,7 @@ end: void PulseLayer::ringtoneToSpeaker (void) { - AudioLoop* fileToPlay = manager_->getTelephoneFile(); + AudioLoop* fileToPlay = Manager::instance().getTelephoneFile(); int writableSize = pa_stream_writable_size (ringtone_->pulseStream()); if (fileToPlay) { diff --git a/daemon/src/audio/pulseaudio/pulselayer.h b/daemon/src/audio/pulseaudio/pulselayer.h index 353f166866..878cf9bfee 100644 --- a/daemon/src/audio/pulseaudio/pulselayer.h +++ b/daemon/src/audio/pulseaudio/pulselayer.h @@ -54,7 +54,7 @@ typedef std::list<std::string> DeviceList; class PulseLayer : public AudioLayer { public: - PulseLayer (ManagerImpl* manager); + PulseLayer (); ~PulseLayer (void); /** * Check if no devices are opened, otherwise close them. diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index e057f04cd1..eea8003efb 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -2431,18 +2431,9 @@ std::string ManagerImpl::getNoiseSuppressState (void) const void ManagerImpl::setNoiseSuppressState (const std::string &state) { - _debug ("Manager: Set noise suppress state: %s", state.c_str()); - bool isEnabled = (state == "enabled"); audioPreference.setNoiseReduce (isEnabled); - - audioLayerMutexLock(); - - if (_audiodriver) - _audiodriver->setNoiseSuppressState (isEnabled); - - audioLayerMutexUnlock(); } std::string ManagerImpl::getEchoCancelState() const @@ -2484,10 +2475,10 @@ void ManagerImpl::initAudioDriver (void) audioLayerMutexLock(); if (preferences.getAudioApi() == PULSEAUDIO && system("ps -C pulseaudio") == 0) { - _audiodriver = new PulseLayer (this); + _audiodriver = new PulseLayer; } else { preferences.setAudioApi (ALSA); - _audiodriver = new AlsaLayer (this); + _audiodriver = new AlsaLayer; } int error = _audiodriver->getErrorMessage(); @@ -2585,9 +2576,9 @@ void ManagerImpl::switchAudioManager (void) delete _audiodriver; if (type == PULSEAUDIO) - _audiodriver = new PulseLayer (this); + _audiodriver = new PulseLayer(); else - _audiodriver = new AlsaLayer (this); + _audiodriver = new AlsaLayer(); _audiodriver->openDevice (numCardIn, numCardOut, numCardRing, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin); @@ -2641,9 +2632,9 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate) delete _audiodriver; if (type == PULSEAUDIO) - _audiodriver = new PulseLayer (this); + _audiodriver = new PulseLayer; else - _audiodriver = new AlsaLayer (this); + _audiodriver = new AlsaLayer; _audiodriver->openDevice (numCardIn, numCardOut, numCardRing, samplerate, framesize, SFL_PCM_BOTH, alsaPlugin); -- GitLab