Commit 1f8534ff authored by Rafaël Carré's avatar Rafaël Carré
Browse files

* #6629 : don't store mainbuffer inside audiolayer

we're using one unique mainbuffer instance inside managerimpl
remove use of setErrorMessage(-1)
simplify audiodriver creation
parent fc906287
......@@ -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)
......
......@@ -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)
*/
......
......@@ -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);
......
......@@ -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(); }
/**
......
......@@ -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 (...) {
......
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