Commit d5e607c1 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6887: audiopreference creates audio layer

parent 5f455af2
......@@ -51,11 +51,11 @@ class AlsaThread : public ost::Thread
AlsaThread (const AlsaThread& at);
AlsaThread& operator= (const AlsaThread& at);
AlsaLayer* _alsa;
AlsaLayer* alsa_;
};
AlsaThread::AlsaThread (AlsaLayer *alsa)
: Thread(), _alsa (alsa)
: Thread(), alsa_(alsa)
{
setCancel (cancelDeferred);
}
......@@ -66,7 +66,7 @@ AlsaThread::AlsaThread (AlsaLayer *alsa)
void AlsaThread::run (void)
{
while (!testCancel()) {
_alsa->audioCallback();
alsa_->audioCallback();
Thread::sleep (20);
}
}
......@@ -481,21 +481,21 @@ AlsaLayer::getSoundCardsInfo (int stream)
bool
AlsaLayer::soundCardIndexExist (int card, int stream)
AlsaLayer::soundCardIndexExists(int card, int stream)
{
snd_ctl_t* handle;
snd_pcm_info_t *pcminfo;
snd_pcm_info_alloca (&pcminfo);
std::string name = "hw:";
snd_pcm_info_alloca(&pcminfo);
std::string name("hw:");
std::stringstream ss;
ss << card ;
name.append (ss.str());
ss << card;
name.append(ss.str());
if (snd_ctl_open (&handle, name.c_str(), 0) != 0)
if (snd_ctl_open(&handle, name.c_str(), 0) != 0)
return false;
snd_pcm_info_set_stream (pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
bool ret = snd_ctl_pcm_info (handle , pcminfo) >= 0;
snd_pcm_info_set_stream(pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
bool ret = snd_ctl_pcm_info(handle , pcminfo) >= 0;
snd_ctl_close(handle);
return ret;
}
......
......@@ -102,7 +102,7 @@ class AlsaLayer : public AudioLayer
* @return bool True if it exists and supports the mode
* false otherwise
*/
static bool soundCardIndexExist (int card , int stream);
static bool soundCardIndexExists(int card, int stream);
/**
* An index is associated with its string description
......
......@@ -1993,7 +1993,7 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin)
// Recreate audio driver with new settings
delete _audiodriver;
_audiodriver = preferences.createAudioLayer();
_audiodriver = audioPreference.createAudioLayer();
if (wasStarted)
_audiodriver->startStream();
......@@ -2032,7 +2032,7 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
// Recreate audio driver with new settings
delete _audiodriver;
_audiodriver = preferences.createAudioLayer();
_audiodriver = audioPreference.createAudioLayer();
if (wasStarted)
_audiodriver->startStream();
......@@ -2271,7 +2271,7 @@ void ManagerImpl::setAudioManager (const std::string &api)
return;
}
if (api == preferences.getAudioApi()) {
if (api == audioPreference.getAudioApi()) {
_debug ("Manager: Audio manager chosen already in use. No changes made. ");
audioLayerMutexUnlock();
return;
......@@ -2286,7 +2286,7 @@ void ManagerImpl::setAudioManager (const std::string &api)
std::string ManagerImpl::getAudioManager (void) const
{
return preferences.getAudioApi();
return audioPreference.getAudioApi();
}
......@@ -2364,31 +2364,7 @@ void ManagerImpl::setEchoCancelDelay(int delay)
void ManagerImpl::initAudioDriver (void)
{
audioLayerMutexLock();
/* Retrieve the global devices info from the user config */
int numCardIn = audioPreference.getCardin();
int numCardOut = audioPreference.getCardout();
int numCardRing = audioPreference.getCardring();
if (!AlsaLayer::soundCardIndexExist (numCardIn, SFL_PCM_CAPTURE)) {
_debug (" Card with index %d doesn't exist or cannot capture. Switch to 0.", numCardIn);
numCardIn = ALSA_DFT_CARD_ID;
audioPreference.setCardin (ALSA_DFT_CARD_ID);
}
if (!AlsaLayer::soundCardIndexExist (numCardOut, SFL_PCM_PLAYBACK)) {
_debug (" Card with index %d doesn't exist or cannot playback. Switch to 0.", numCardOut);
numCardOut = ALSA_DFT_CARD_ID;
audioPreference.setCardout (ALSA_DFT_CARD_ID);
}
if (!AlsaLayer::soundCardIndexExist (numCardRing, SFL_PCM_RINGTONE)) {
_debug (" Card with index %d doesn't exist or cannot ringtone. Switch to 0.", numCardRing);
numCardRing = ALSA_DFT_CARD_ID;
audioPreference.setCardring (ALSA_DFT_CARD_ID);
}
_audiodriver = preferences.createAudioLayer();
_audiodriver = audioPreference.createAudioLayer();
audioLayerMutexUnlock();
}
......@@ -2400,7 +2376,7 @@ void ManagerImpl::switchAudioManager (void)
bool wasStarted = _audiodriver->isStarted();
delete _audiodriver;
_audiodriver = preferences.switchAndCreateAudioLayer();
_audiodriver = audioPreference.switchAndCreateAudioLayer();
if (wasStarted)
_audiodriver->startStream();
......@@ -2433,7 +2409,7 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
_mainBuffer.setInternalSamplingRate(samplerate);
delete _audiodriver;
_audiodriver = preferences.createAudioLayer();
_audiodriver = audioPreference.createAudioLayer();
unsigned int sampleRate = _audiodriver->getSampleRate();
......
This diff is collapsed.
......@@ -108,9 +108,6 @@ class Preferences : public Serializable
Preferences();
AudioLayer *createAudioLayer();
AudioLayer *switchAndCreateAudioLayer();
virtual void serialize (Conf::YamlEmitter *emitter);
virtual void unserialize (Conf::MappingNode *map);
......@@ -123,13 +120,6 @@ class Preferences : public Serializable
_accountOrder = ord;
}
std::string getAudioApi (void) const {
return _audioApi;
}
void setAudioApi (const std::string &api) {
_audioApi = api;
}
int getHistoryLimit (void) const {
return _historyLimit;
}
......@@ -198,7 +188,6 @@ class Preferences : public Serializable
// account order
std::string _accountOrder;
std::string _audioApi;
int _historyLimit;
int _historyMaxCalls;
bool _notifyMails;
......@@ -402,6 +391,16 @@ class AudioPreference : public Serializable
{
public:
AudioPreference();
AudioLayer *createAudioLayer();
AudioLayer *switchAndCreateAudioLayer();
std::string getAudioApi (void) const {
return _audioApi;
}
void setAudioApi (const std::string &api) {
_audioApi = api;
}
virtual void serialize (Conf::YamlEmitter *emitter);
virtual void unserialize (Conf::MappingNode *map);
......@@ -530,6 +529,7 @@ class AudioPreference : public Serializable
}
private:
std::string _audioApi;
// alsa preference
int _cardin; // 0
......
......@@ -81,9 +81,9 @@ void ConfigurationTest::testInitAudioDriver()
CPPUNIT_FAIL ("Error while loading audio layer");
// Check if it has been created with the right type
if (Manager::instance().preferences.getAudioApi() == "alsa")
if (Manager::instance().audioPreference.getAudioApi() == "alsa")
CPPUNIT_ASSERT (!dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
else if (Manager::instance().preferences.getAudioApi() == "pulseaudio")
else if (Manager::instance().audioPreference.getAudioApi() == "pulseaudio")
CPPUNIT_ASSERT (!dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
else
CPPUNIT_FAIL ("Wrong audio layer type");
......
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