Commit 73a54bf0 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #6852: audiolayer creation depends only on preference.audioApi

parent c1b8adde
...@@ -73,8 +73,7 @@ void AlsaThread::run (void) ...@@ -73,8 +73,7 @@ void AlsaThread::run (void)
// Constructor // Constructor
AlsaLayer::AlsaLayer () AlsaLayer::AlsaLayer ()
: AudioLayer (ALSA) : indexIn_ (audioPref.getCardin())
, indexIn_ (audioPref.getCardin())
, indexOut_ (audioPref.getCardout()) , indexOut_ (audioPref.getCardout())
, indexRing_ (audioPref.getCardring()) , indexRing_ (audioPref.getCardring())
, playbackHandle_ (NULL) , playbackHandle_ (NULL)
......
...@@ -34,14 +34,13 @@ ...@@ -34,14 +34,13 @@
#include "audio/dcblocker.h" #include "audio/dcblocker.h"
#include "manager.h" #include "manager.h"
AudioLayer::AudioLayer (int type) AudioLayer::AudioLayer ()
: isStarted_ (false) : isStarted_ (false)
, urgentRingBuffer_ (SIZEBUF, Call::DEFAULT_ID) , urgentRingBuffer_ (SIZEBUF, Call::DEFAULT_ID)
, audioSampleRate_(Manager::instance().getMainBuffer()->getInternalSamplingRate()) , audioSampleRate_(Manager::instance().getMainBuffer()->getInternalSamplingRate())
, mutex_ () , mutex_ ()
, audioPref(Manager::instance().audioPreference) , audioPref(Manager::instance().audioPreference)
, converter_ (new SamplerateConverter(audioSampleRate_)) , converter_ (new SamplerateConverter(audioSampleRate_))
, layerType_ (type)
, lastNotificationTime_ (0) , lastNotificationTime_ (0)
{ {
urgentRingBuffer_.createReadPointer(); urgentRingBuffer_.createReadPointer();
......
...@@ -66,7 +66,7 @@ class AudioLayer ...@@ -66,7 +66,7 @@ class AudioLayer
/** /**
* Constructor * Constructor
*/ */
AudioLayer (int type); AudioLayer ();
/** /**
* Destructor * Destructor
...@@ -111,15 +111,6 @@ class AudioLayer ...@@ -111,15 +111,6 @@ class AudioLayer
return audioSampleRate_; return audioSampleRate_;
} }
/**
* Get the layer type for this instance (either Alsa or PulseAudio)
* @return unsigned int The layer type
*
*/
int getLayerType (void) const {
return layerType_;
}
/** /**
* Get a pointer to the application MainBuffer class. * Get a pointer to the application MainBuffer class.
* *
...@@ -172,9 +163,6 @@ class AudioLayer ...@@ -172,9 +163,6 @@ class AudioLayer
private: private:
const int layerType_;
/** /**
* Time of the last incoming call notification * Time of the last incoming call notification
*/ */
......
...@@ -193,8 +193,7 @@ void context_changed_callback (pa_context* c, pa_subscription_event_type_t t, ui ...@@ -193,8 +193,7 @@ void context_changed_callback (pa_context* c, pa_subscription_event_type_t t, ui
PulseLayer::PulseLayer () PulseLayer::PulseLayer ()
: AudioLayer (PULSEAUDIO) : playback_(0)
, playback_(0)
, record_(0) , record_(0)
, ringtone_(0) , ringtone_(0)
, mic_buffer_(NULL) , mic_buffer_(NULL)
......
...@@ -226,7 +226,7 @@ ...@@ -226,7 +226,7 @@
<method name="getAudioManager" tp:name-for-bindings="getAudioManager"> <method name="getAudioManager" tp:name-for-bindings="getAudioManager">
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
<arg type="i" name="api" direction="out"> <arg type="s" name="api" direction="out">
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
</arg> </arg>
...@@ -235,7 +235,7 @@ ...@@ -235,7 +235,7 @@
<method name="setAudioManager" tp:name-for-bindings="setAudioManager"> <method name="setAudioManager" tp:name-for-bindings="setAudioManager">
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
<arg type="i" name="api" direction="in"> <arg type="s" name="api" direction="in">
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
</arg> </arg>
......
...@@ -361,12 +361,12 @@ void ConfigurationManager::setHistoryLimit (const int32_t& days) ...@@ -361,12 +361,12 @@ void ConfigurationManager::setHistoryLimit (const int32_t& days)
Manager::instance().setHistoryLimit (days); Manager::instance().setHistoryLimit (days);
} }
void ConfigurationManager::setAudioManager (const int32_t& api) void ConfigurationManager::setAudioManager (const std::string& api)
{ {
Manager::instance().setAudioManager (api); Manager::instance().setAudioManager (api);
} }
int32_t ConfigurationManager::getAudioManager (void) std::string ConfigurationManager::getAudioManager (void)
{ {
return Manager::instance().getAudioManager(); return Manager::instance().getAudioManager();
} }
......
...@@ -94,8 +94,8 @@ class ConfigurationManager ...@@ -94,8 +94,8 @@ class ConfigurationManager
void setEchoCancelDelay(const int32_t& length); void setEchoCancelDelay(const int32_t& length);
int getEchoCancelDelay(void); int getEchoCancelDelay(void);
int32_t getAudioManager (void); std::string getAudioManager (void);
void setAudioManager (const int32_t& api); void setAudioManager (const std::string& api);
int32_t isIax2Enabled (void); int32_t isIax2Enabled (void);
std::string getRecordPath (void); std::string getRecordPath (void);
......
...@@ -119,9 +119,8 @@ static const SOUND_FORMAT INT32 = 0x8; ...@@ -119,9 +119,8 @@ static const SOUND_FORMAT INT32 = 0x8;
#define PULSEAUDIO_NOT_RUNNING 0x0100 /** Pulseaudio is not running */ #define PULSEAUDIO_NOT_RUNNING 0x0100 /** Pulseaudio is not running */
#define CODECS_NOT_LOADED 0x1000 /** Codecs not found */ #define CODECS_NOT_LOADED 0x1000 /** Codecs not found */
#define ALSA 0 #define PULSEAUDIO_API_STR "pulseaudio"
#define PULSEAUDIO 1 #define ALSA_API_STR "alsa"
#define UNUSED __attribute__((__unused__)) #define UNUSED __attribute__((__unused__))
#define DEFAULT_SIP_PORT 5060 #define DEFAULT_SIP_PORT 5060
......
...@@ -2262,7 +2262,7 @@ void ManagerImpl::setMailNotify (void) ...@@ -2262,7 +2262,7 @@ void ManagerImpl::setMailNotify (void)
saveConfig(); saveConfig();
} }
void ManagerImpl::setAudioManager (int32_t api) void ManagerImpl::setAudioManager (const std::string &api)
{ {
audioLayerMutexLock(); audioLayerMutexLock();
...@@ -2271,9 +2271,7 @@ void ManagerImpl::setAudioManager (int32_t api) ...@@ -2271,9 +2271,7 @@ void ManagerImpl::setAudioManager (int32_t api)
return; return;
} }
int layerType = _audiodriver->getLayerType(); if (api == preferences.getAudioApi()) {
if (layerType == api) {
_debug ("Manager: Audio manager chosen already in use. No changes made. "); _debug ("Manager: Audio manager chosen already in use. No changes made. ");
audioLayerMutexUnlock(); audioLayerMutexUnlock();
return; return;
...@@ -2281,14 +2279,12 @@ void ManagerImpl::setAudioManager (int32_t api) ...@@ -2281,14 +2279,12 @@ void ManagerImpl::setAudioManager (int32_t api)
audioLayerMutexUnlock(); audioLayerMutexUnlock();
preferences.setAudioApi(api);
switchAudioManager(); switchAudioManager();
saveConfig(); saveConfig();
} }
int32_t ManagerImpl::getAudioManager (void) const std::string ManagerImpl::getAudioManager (void) const
{ {
return preferences.getAudioApi(); return preferences.getAudioApi();
} }
...@@ -2392,10 +2388,10 @@ void ManagerImpl::initAudioDriver (void) ...@@ -2392,10 +2388,10 @@ void ManagerImpl::initAudioDriver (void)
audioPreference.setCardring (ALSA_DFT_CARD_ID); audioPreference.setCardring (ALSA_DFT_CARD_ID);
} }
if (preferences.getAudioApi() == PULSEAUDIO && system("ps -C pulseaudio") == 0) { if (preferences.getAudioApi() == PULSEAUDIO_API_STR and system("ps -C pulseaudio") == 0)
_audiodriver = new PulseLayer; _audiodriver = new PulseLayer;
} else { else {
preferences.setAudioApi (ALSA); preferences.setAudioApi(ALSA_API_STR);
_audiodriver = new AlsaLayer; _audiodriver = new AlsaLayer;
} }
...@@ -2407,14 +2403,16 @@ void ManagerImpl::switchAudioManager (void) ...@@ -2407,14 +2403,16 @@ void ManagerImpl::switchAudioManager (void)
audioLayerMutexLock(); audioLayerMutexLock();
bool wasStarted = _audiodriver->isStarted(); bool wasStarted = _audiodriver->isStarted();
int newType = (_audiodriver->getLayerType() == PULSEAUDIO) ? ALSA : PULSEAUDIO;
delete _audiodriver; delete _audiodriver;
if (newType == ALSA) if (preferences.getAudioApi() == PULSEAUDIO_API_STR) {
_audiodriver = new AlsaLayer; _audiodriver = new AlsaLayer;
else preferences.setAudioApi(ALSA_API_STR);
_audiodriver = new PulseLayer(); }
else {
_audiodriver = new PulseLayer;
preferences.setAudioApi(PULSEAUDIO_API_STR);
}
if (wasStarted) if (wasStarted)
_audiodriver->startStream(); _audiodriver->startStream();
...@@ -2442,13 +2440,12 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate) ...@@ -2442,13 +2440,12 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
else else
_debug ("Manager: Audio sampling rate changed: %d -> %d", currentSamplerate, samplerate); _debug ("Manager: Audio sampling rate changed: %d -> %d", currentSamplerate, samplerate);
int type = _audiodriver->getLayerType();
bool wasActive = _audiodriver->isStarted(); bool wasActive = _audiodriver->isStarted();
_mainBuffer.setInternalSamplingRate(samplerate); _mainBuffer.setInternalSamplingRate(samplerate);
delete _audiodriver; delete _audiodriver;
if (type == PULSEAUDIO) if (preferences.getAudioApi() == PULSEAUDIO_API_STR)
_audiodriver = new PulseLayer; _audiodriver = new PulseLayer;
else else
_audiodriver = new AlsaLayer; _audiodriver = new AlsaLayer;
......
...@@ -726,15 +726,15 @@ class ManagerImpl ...@@ -726,15 +726,15 @@ class ManagerImpl
/** /**
* Get the audio manager * Get the audio manager
* @return int The audio manager * @return int The audio manager
* 0 ALSA * "alsa"
* 1 PULSEAUDIO * "pulseaudio"
*/ */
int32_t getAudioManager (void) const; std::string getAudioManager (void) const;
/** /**
* Set the audio manager * Set the audio manager
*/ */
void setAudioManager (int32_t api); void setAudioManager (const std::string &api);
void switchAudioManager (void); void switchAudioManager (void);
......
...@@ -44,7 +44,7 @@ namespace { ...@@ -44,7 +44,7 @@ namespace {
} // end anonymous namespace } // end anonymous namespace
Preferences::Preferences() : _accountOrder ("") Preferences::Preferences() : _accountOrder ("")
, _audioApi (1) // 1 is pulseaudio, 0 alsa , _audioApi (PULSEAUDIO_API_STR)
, _historyLimit (30) , _historyLimit (30)
, _historyMaxCalls (20) , _historyMaxCalls (20)
, _notifyMails (false) , _notifyMails (false)
...@@ -66,8 +66,7 @@ void Preferences::serialize (Conf::YamlEmitter *emiter) ...@@ -66,8 +66,7 @@ void Preferences::serialize (Conf::YamlEmitter *emiter)
Conf::MappingNode preferencemap (NULL); Conf::MappingNode preferencemap (NULL);
Conf::ScalarNode order (_accountOrder); Conf::ScalarNode order (_accountOrder);
std::string audioapistr = (_audioApi == 1) ? "pulseaudio" : "alsa"; Conf::ScalarNode audioapi (_audioApi);
Conf::ScalarNode audioapi (audioapistr);
std::stringstream histlimitstr; std::stringstream histlimitstr;
histlimitstr << _historyLimit; histlimitstr << _historyLimit;
Conf::ScalarNode historyLimit (histlimitstr.str()); Conf::ScalarNode historyLimit (histlimitstr.str());
...@@ -109,10 +108,8 @@ void Preferences::unserialize (Conf::MappingNode *map) ...@@ -109,10 +108,8 @@ void Preferences::unserialize (Conf::MappingNode *map)
} }
map->getValue (orderKey, &_accountOrder); map->getValue (orderKey, &_accountOrder);
std::string audioApi; map->getValue (audioApiKey, &_audioApi);
map->getValue (audioApiKey, &audioApi);
// 1 is pulseaudio, 0 is alsa // 1 is pulseaudio, 0 is alsa
_audioApi = (audioApi == "pulseaudio") ? 1 : 0;
map->getValue (historyLimitKey, &_historyLimit); map->getValue (historyLimitKey, &_historyLimit);
map->getValue (historyMaxCallsKey, &_historyMaxCalls); map->getValue (historyMaxCallsKey, &_historyMaxCalls);
map->getValue (notifyMailsKey, &_notifyMails); map->getValue (notifyMailsKey, &_notifyMails);
......
...@@ -121,10 +121,10 @@ class Preferences : public Serializable ...@@ -121,10 +121,10 @@ class Preferences : public Serializable
_accountOrder = ord; _accountOrder = ord;
} }
int getAudioApi (void) const { std::string getAudioApi (void) const {
return _audioApi; return _audioApi;
} }
void setAudioApi (int api) { void setAudioApi (const std::string &api) {
_audioApi = api; _audioApi = api;
} }
...@@ -196,7 +196,7 @@ class Preferences : public Serializable ...@@ -196,7 +196,7 @@ class Preferences : public Serializable
// account order // account order
std::string _accountOrder; std::string _accountOrder;
int _audioApi; std::string _audioApi;
int _historyLimit; int _historyLimit;
int _historyMaxCalls; int _historyMaxCalls;
bool _notifyMails; bool _notifyMails;
......
...@@ -67,20 +67,18 @@ void AudioLayerTest::testAudioLayerSwitch() ...@@ -67,20 +67,18 @@ void AudioLayerTest::testAudioLayerSwitch()
{ {
_debug ("-------------------- AudioLayerTest::testAudioLayerSwitch --------------------\n"); _debug ("-------------------- AudioLayerTest::testAudioLayerSwitch --------------------\n");
int previous_layer = Manager::instance().getAudioDriver()->getLayerType(); bool wasAlsa = dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()) != 0;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
_debug ("iter - %i",i); _debug ("iter - %i", i);
Manager::instance().switchAudioManager(); Manager::instance().switchAudioManager();
if (previous_layer == ALSA) { if (wasAlsa)
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == PULSEAUDIO); CPPUNIT_ASSERT (dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
} else { else
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == ALSA); CPPUNIT_ASSERT (dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
}
previous_layer = Manager::instance().getAudioDriver()->getLayerType();
wasAlsa = dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()) != 0;
usleep (100000); usleep (100000);
} }
} }
...@@ -89,7 +87,7 @@ void AudioLayerTest::testPulseConnect() ...@@ -89,7 +87,7 @@ void AudioLayerTest::testPulseConnect()
{ {
_debug ("-------------------- AudioLayerTest::testPulseConnect --------------------\n"); _debug ("-------------------- AudioLayerTest::testPulseConnect --------------------\n");
if (Manager::instance().getAudioDriver()->getLayerType() == ALSA) { if (dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver())) {
Manager::instance().switchAudioManager(); Manager::instance().switchAudioManager();
usleep (100000); usleep (100000);
} }
...@@ -97,7 +95,7 @@ void AudioLayerTest::testPulseConnect() ...@@ -97,7 +95,7 @@ void AudioLayerTest::testPulseConnect()
ManagerImpl* manager; ManagerImpl* manager;
manager = &Manager::instance(); manager = &Manager::instance();
_pulselayer = (PulseLayer*) Manager::instance().getAudioDriver(); _pulselayer = dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver());
CPPUNIT_ASSERT (_pulselayer->getLayerType() == PULSEAUDIO); CPPUNIT_ASSERT (_pulselayer);
} }
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "configurationtest.h" #include "configurationtest.h"
#include "constants.h" #include "constants.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
using std::cout; using std::cout;
using std::endl; using std::endl;
...@@ -79,10 +81,10 @@ void ConfigurationTest::testInitAudioDriver() ...@@ -79,10 +81,10 @@ void ConfigurationTest::testInitAudioDriver()
CPPUNIT_FAIL ("Error while loading audio layer"); CPPUNIT_FAIL ("Error while loading audio layer");
// Check if it has been created with the right type // Check if it has been created with the right type
if (Manager::instance().preferences.getAudioApi() == ALSA) if (Manager::instance().preferences.getAudioApi() == "alsa")
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), ALSA); CPPUNIT_ASSERT (!dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
else if (Manager::instance().preferences.getAudioApi() == PULSEAUDIO) else if (Manager::instance().preferences.getAudioApi() == "pulseaudio")
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), PULSEAUDIO); CPPUNIT_ASSERT (!dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
else else
CPPUNIT_FAIL ("Wrong audio layer type"); CPPUNIT_FAIL ("Wrong audio layer type");
} }
......
...@@ -177,18 +177,10 @@ is_iax_enabled (void) ...@@ -177,18 +177,10 @@ is_iax_enabled (void)
void void
select_dtmf_type (void) select_dtmf_type (void)
{ {
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (overrtp)))
DEBUG ("DTMF selection changed\n");
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (overrtp))) {
// dbus_set_audio_manager( ALSA );
DEBUG ("Selected DTMF over RTP"); DEBUG ("Selected DTMF over RTP");
} else { else
// dbus_set_audio_manager( PULSEAUDIO );
DEBUG ("Selected DTMF over SIP"); DEBUG ("Selected DTMF over SIP");
}
} }
static GPtrArray* getNewCredential (void) static GPtrArray* getNewCredential (void)
......
...@@ -194,7 +194,7 @@ preferences_dialog_fill_ringtone_audio_device_list() ...@@ -194,7 +194,7 @@ preferences_dialog_fill_ringtone_audio_device_list()
void void
select_active_output_audio_device() select_active_output_audio_device()
{ {
if (SHOW_ALSA_CONF) { if (must_show_alsa_conf()) {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
...@@ -234,7 +234,7 @@ select_active_output_audio_device() ...@@ -234,7 +234,7 @@ select_active_output_audio_device()
void void
select_active_ringtone_audio_device() select_active_ringtone_audio_device()
{ {
if (SHOW_ALSA_CONF) { if (must_show_alsa_conf()) {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
...@@ -299,7 +299,7 @@ preferences_dialog_fill_input_audio_device_list() ...@@ -299,7 +299,7 @@ preferences_dialog_fill_input_audio_device_list()
void void
select_active_input_audio_device() select_active_input_audio_device()
{ {
if (SHOW_ALSA_CONF) { if (must_show_alsa_conf()) {
GtkTreeModel* model; GtkTreeModel* model;
GtkTreeIter iter; GtkTreeIter iter;
...@@ -718,15 +718,15 @@ GtkWidget* audiocodecs_box (account_t *a) ...@@ -718,15 +718,15 @@ GtkWidget* audiocodecs_box (account_t *a)
void void
select_audio_manager (void) select_audio_manager (void)
{ {
if (!SHOW_ALSA_CONF && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) { if (!must_show_alsa_conf() && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (ALSA); dbus_set_audio_manager (ALSA_API_STR);
alsabox = alsa_box(); alsabox = alsa_box();
gtk_container_add (GTK_CONTAINER (alsa_conf) , alsabox); gtk_container_add (GTK_CONTAINER (alsa_conf) , alsabox);
gtk_widget_show (alsa_conf); gtk_widget_show (alsa_conf);
gtk_widget_set_sensitive (GTK_WIDGET (alsa_conf), TRUE); gtk_widget_set_sensitive (GTK_WIDGET (alsa_conf), TRUE);
gtk_action_set_sensitive (GTK_ACTION (volumeToggle), TRUE); gtk_action_set_sensitive (GTK_ACTION (volumeToggle), TRUE);
} else if (SHOW_ALSA_CONF && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) { } else if (must_show_alsa_conf() && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (PULSEAUDIO