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

* #6852: Preferences now solely responsible for audiolayer creation.

parent 166dac9e
...@@ -1993,8 +1993,7 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin) ...@@ -1993,8 +1993,7 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin)
// Recreate audio driver with new settings // Recreate audio driver with new settings
delete _audiodriver; delete _audiodriver;
_audiodriver = new AlsaLayer; _audiodriver = preferences.createAudioLayer();
assert(preferences.getAudioApi() == ALSA_API_STR);
if (wasStarted) if (wasStarted)
_audiodriver->startStream(); _audiodriver->startStream();
...@@ -2033,8 +2032,7 @@ void ManagerImpl::setAudioDevice (const int index, int streamType) ...@@ -2033,8 +2032,7 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
// Recreate audio driver with new settings // Recreate audio driver with new settings
delete _audiodriver; delete _audiodriver;
_audiodriver = new AlsaLayer; _audiodriver = preferences.createAudioLayer();
assert(preferences.getAudioApi() == ALSA_API_STR);
if (wasStarted) if (wasStarted)
_audiodriver->startStream(); _audiodriver->startStream();
...@@ -2390,12 +2388,7 @@ void ManagerImpl::initAudioDriver (void) ...@@ -2390,12 +2388,7 @@ void ManagerImpl::initAudioDriver (void)
audioPreference.setCardring (ALSA_DFT_CARD_ID); audioPreference.setCardring (ALSA_DFT_CARD_ID);
} }
if (preferences.getAudioApi() == PULSEAUDIO_API_STR and system("ps -C pulseaudio") == 0) _audiodriver = preferences.createAudioLayer();
_audiodriver = new PulseLayer;
else {
preferences.setAudioApi(ALSA_API_STR);
_audiodriver = new AlsaLayer;
}
audioLayerMutexUnlock(); audioLayerMutexUnlock();
} }
...@@ -2407,14 +2400,7 @@ void ManagerImpl::switchAudioManager (void) ...@@ -2407,14 +2400,7 @@ void ManagerImpl::switchAudioManager (void)
bool wasStarted = _audiodriver->isStarted(); bool wasStarted = _audiodriver->isStarted();
delete _audiodriver; delete _audiodriver;
if (preferences.getAudioApi() == PULSEAUDIO_API_STR) { _audiodriver = preferences.switchAndCreateAudioLayer();
_audiodriver = new AlsaLayer;
preferences.setAudioApi(ALSA_API_STR);
}
else {
_audiodriver = new PulseLayer;
preferences.setAudioApi(PULSEAUDIO_API_STR);
}
if (wasStarted) if (wasStarted)
_audiodriver->startStream(); _audiodriver->startStream();
...@@ -2447,10 +2433,7 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate) ...@@ -2447,10 +2433,7 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
_mainBuffer.setInternalSamplingRate(samplerate); _mainBuffer.setInternalSamplingRate(samplerate);
delete _audiodriver; delete _audiodriver;
if (preferences.getAudioApi() == PULSEAUDIO_API_STR) _audiodriver = preferences.createAudioLayer();
_audiodriver = new PulseLayer;
else
_audiodriver = new AlsaLayer;
unsigned int sampleRate = _audiodriver->getSampleRate(); unsigned int sampleRate = _audiodriver->getSampleRate();
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
*/ */
#include "preferences.h" #include "preferences.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
#include <sstream> #include <sstream>
#include "global.h" #include "global.h"
#include <cassert> #include <cassert>
...@@ -58,8 +60,24 @@ Preferences::Preferences() : _accountOrder ("") ...@@ -58,8 +60,24 @@ Preferences::Preferences() : _accountOrder ("")
} }
Preferences::~Preferences() {} AudioLayer* Preferences::createAudioLayer()
{
if (_audioApi == PULSEAUDIO_API_STR and system("ps -C pulseaudio") == 0)
return new PulseLayer;
else {
_audioApi = ALSA_API_STR;
return new AlsaLayer;
}
}
AudioLayer* Preferences::switchAndCreateAudioLayer()
{
if (_audioApi == PULSEAUDIO_API_STR)
_audioApi = ALSA_API_STR;
else
_audioApi = PULSEAUDIO_API_STR;
return createAudioLayer();
}
void Preferences::serialize (Conf::YamlEmitter *emiter) void Preferences::serialize (Conf::YamlEmitter *emiter)
{ {
......
...@@ -97,6 +97,7 @@ const std::string popupShortKey ("popupWindow"); ...@@ -97,6 +97,7 @@ const std::string popupShortKey ("popupWindow");
const std::string toggleHoldShortKey ("toggleHold"); const std::string toggleHoldShortKey ("toggleHold");
const std::string togglePickupHangupShortKey ("togglePickupHangup"); const std::string togglePickupHangupShortKey ("togglePickupHangup");
class AudioLayer;
class Preferences : public Serializable class Preferences : public Serializable
{ {
...@@ -107,7 +108,8 @@ class Preferences : public Serializable ...@@ -107,7 +108,8 @@ class Preferences : public Serializable
Preferences(); Preferences();
~Preferences(); AudioLayer *createAudioLayer();
AudioLayer *switchAndCreateAudioLayer();
virtual void serialize (Conf::YamlEmitter *emitter); virtual void serialize (Conf::YamlEmitter *emitter);
......
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