Commit 0171ee72 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6629 : clean AudioLayer

Don't store a pointer to ManagerImpl
Store a reference to audio preferences
Remove unused noisesuppression state
parent 1f8534ff
......@@ -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);
......
......@@ -50,9 +50,8 @@ class AlsaLayer : public AudioLayer
public:
/**
* Constructor
* @param manager An instance of managerimpl
*/
AlsaLayer (ManagerImpl* manager);
AlsaLayer ();
/**
* Destructor
......
......@@ -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)
{}
......
......@@ -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:
/**
......
......@@ -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) {
......
......@@ -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.
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment