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

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

parent c1b8adde
......@@ -73,8 +73,7 @@ void AlsaThread::run (void)
// Constructor
AlsaLayer::AlsaLayer ()
: AudioLayer (ALSA)
, indexIn_ (audioPref.getCardin())
: indexIn_ (audioPref.getCardin())
, indexOut_ (audioPref.getCardout())
, indexRing_ (audioPref.getCardring())
, playbackHandle_ (NULL)
......
......@@ -34,14 +34,13 @@
#include "audio/dcblocker.h"
#include "manager.h"
AudioLayer::AudioLayer (int type)
AudioLayer::AudioLayer ()
: isStarted_ (false)
, urgentRingBuffer_ (SIZEBUF, Call::DEFAULT_ID)
, audioSampleRate_(Manager::instance().getMainBuffer()->getInternalSamplingRate())
, mutex_ ()
, audioPref(Manager::instance().audioPreference)
, converter_ (new SamplerateConverter(audioSampleRate_))
, layerType_ (type)
, lastNotificationTime_ (0)
{
urgentRingBuffer_.createReadPointer();
......
......@@ -66,7 +66,7 @@ class AudioLayer
/**
* Constructor
*/
AudioLayer (int type);
AudioLayer ();
/**
* Destructor
......@@ -111,15 +111,6 @@ class AudioLayer
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.
*
......@@ -172,9 +163,6 @@ class AudioLayer
private:
const int layerType_;
/**
* 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
PulseLayer::PulseLayer ()
: AudioLayer (PULSEAUDIO)
, playback_(0)
: playback_(0)
, record_(0)
, ringtone_(0)
, mic_buffer_(NULL)
......
......@@ -226,7 +226,7 @@
<method name="getAudioManager" tp:name-for-bindings="getAudioManager">
<tp:docstring>
</tp:docstring>
<arg type="i" name="api" direction="out">
<arg type="s" name="api" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
......@@ -235,7 +235,7 @@
<method name="setAudioManager" tp:name-for-bindings="setAudioManager">
<tp:docstring>
</tp:docstring>
<arg type="i" name="api" direction="in">
<arg type="s" name="api" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
......
......@@ -361,12 +361,12 @@ void ConfigurationManager::setHistoryLimit (const int32_t& days)
Manager::instance().setHistoryLimit (days);
}
void ConfigurationManager::setAudioManager (const int32_t& api)
void ConfigurationManager::setAudioManager (const std::string& api)
{
Manager::instance().setAudioManager (api);
}
int32_t ConfigurationManager::getAudioManager (void)
std::string ConfigurationManager::getAudioManager (void)
{
return Manager::instance().getAudioManager();
}
......
......@@ -94,8 +94,8 @@ class ConfigurationManager
void setEchoCancelDelay(const int32_t& length);
int getEchoCancelDelay(void);
int32_t getAudioManager (void);
void setAudioManager (const int32_t& api);
std::string getAudioManager (void);
void setAudioManager (const std::string& api);
int32_t isIax2Enabled (void);
std::string getRecordPath (void);
......
......@@ -119,9 +119,8 @@ static const SOUND_FORMAT INT32 = 0x8;
#define PULSEAUDIO_NOT_RUNNING 0x0100 /** Pulseaudio is not running */
#define CODECS_NOT_LOADED 0x1000 /** Codecs not found */
#define ALSA 0
#define PULSEAUDIO 1
#define PULSEAUDIO_API_STR "pulseaudio"
#define ALSA_API_STR "alsa"
#define UNUSED __attribute__((__unused__))
#define DEFAULT_SIP_PORT 5060
......
......@@ -2262,7 +2262,7 @@ void ManagerImpl::setMailNotify (void)
saveConfig();
}
void ManagerImpl::setAudioManager (int32_t api)
void ManagerImpl::setAudioManager (const std::string &api)
{
audioLayerMutexLock();
......@@ -2271,9 +2271,7 @@ void ManagerImpl::setAudioManager (int32_t api)
return;
}
int layerType = _audiodriver->getLayerType();
if (layerType == api) {
if (api == preferences.getAudioApi()) {
_debug ("Manager: Audio manager chosen already in use. No changes made. ");
audioLayerMutexUnlock();
return;
......@@ -2281,14 +2279,12 @@ void ManagerImpl::setAudioManager (int32_t api)
audioLayerMutexUnlock();
preferences.setAudioApi(api);
switchAudioManager();
saveConfig();
}
int32_t ManagerImpl::getAudioManager (void) const
std::string ManagerImpl::getAudioManager (void) const
{
return preferences.getAudioApi();
}
......@@ -2392,10 +2388,10 @@ void ManagerImpl::initAudioDriver (void)
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;
} else {
preferences.setAudioApi (ALSA);
else {
preferences.setAudioApi(ALSA_API_STR);
_audiodriver = new AlsaLayer;
}
......@@ -2407,14 +2403,16 @@ void ManagerImpl::switchAudioManager (void)
audioLayerMutexLock();
bool wasStarted = _audiodriver->isStarted();
int newType = (_audiodriver->getLayerType() == PULSEAUDIO) ? ALSA : PULSEAUDIO;
delete _audiodriver;
if (newType == ALSA)
if (preferences.getAudioApi() == PULSEAUDIO_API_STR) {
_audiodriver = new AlsaLayer;
else
_audiodriver = new PulseLayer();
preferences.setAudioApi(ALSA_API_STR);
}
else {
_audiodriver = new PulseLayer;
preferences.setAudioApi(PULSEAUDIO_API_STR);
}
if (wasStarted)
_audiodriver->startStream();
......@@ -2442,13 +2440,12 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
else
_debug ("Manager: Audio sampling rate changed: %d -> %d", currentSamplerate, samplerate);
int type = _audiodriver->getLayerType();
bool wasActive = _audiodriver->isStarted();
_mainBuffer.setInternalSamplingRate(samplerate);
delete _audiodriver;
if (type == PULSEAUDIO)
if (preferences.getAudioApi() == PULSEAUDIO_API_STR)
_audiodriver = new PulseLayer;
else
_audiodriver = new AlsaLayer;
......
......@@ -726,15 +726,15 @@ class ManagerImpl
/**
* Get the audio manager
* @return int The audio manager
* 0 ALSA
* 1 PULSEAUDIO
* "alsa"
* "pulseaudio"
*/
int32_t getAudioManager (void) const;
std::string getAudioManager (void) const;
/**
* Set the audio manager
*/
void setAudioManager (int32_t api);
void setAudioManager (const std::string &api);
void switchAudioManager (void);
......
......@@ -44,7 +44,7 @@ namespace {
} // end anonymous namespace
Preferences::Preferences() : _accountOrder ("")
, _audioApi (1) // 1 is pulseaudio, 0 alsa
, _audioApi (PULSEAUDIO_API_STR)
, _historyLimit (30)
, _historyMaxCalls (20)
, _notifyMails (false)
......@@ -66,8 +66,7 @@ void Preferences::serialize (Conf::YamlEmitter *emiter)
Conf::MappingNode preferencemap (NULL);
Conf::ScalarNode order (_accountOrder);
std::string audioapistr = (_audioApi == 1) ? "pulseaudio" : "alsa";
Conf::ScalarNode audioapi (audioapistr);
Conf::ScalarNode audioapi (_audioApi);
std::stringstream histlimitstr;
histlimitstr << _historyLimit;
Conf::ScalarNode historyLimit (histlimitstr.str());
......@@ -109,10 +108,8 @@ void Preferences::unserialize (Conf::MappingNode *map)
}
map->getValue (orderKey, &_accountOrder);
std::string audioApi;
map->getValue (audioApiKey, &audioApi);
map->getValue (audioApiKey, &_audioApi);
// 1 is pulseaudio, 0 is alsa
_audioApi = (audioApi == "pulseaudio") ? 1 : 0;
map->getValue (historyLimitKey, &_historyLimit);
map->getValue (historyMaxCallsKey, &_historyMaxCalls);
map->getValue (notifyMailsKey, &_notifyMails);
......
......@@ -121,10 +121,10 @@ class Preferences : public Serializable
_accountOrder = ord;
}
int getAudioApi (void) const {
std::string getAudioApi (void) const {
return _audioApi;
}
void setAudioApi (int api) {
void setAudioApi (const std::string &api) {
_audioApi = api;
}
......@@ -196,7 +196,7 @@ class Preferences : public Serializable
// account order
std::string _accountOrder;
int _audioApi;
std::string _audioApi;
int _historyLimit;
int _historyMaxCalls;
bool _notifyMails;
......
......@@ -67,20 +67,18 @@ void AudioLayerTest::testAudioLayerSwitch()
{
_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++) {
_debug ("iter - %i",i);
_debug ("iter - %i", i);
Manager::instance().switchAudioManager();
if (previous_layer == ALSA) {
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == PULSEAUDIO);
} else {
CPPUNIT_ASSERT (Manager::instance().getAudioDriver()->getLayerType() == ALSA);
}
previous_layer = Manager::instance().getAudioDriver()->getLayerType();
if (wasAlsa)
CPPUNIT_ASSERT (dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
else
CPPUNIT_ASSERT (dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
wasAlsa = dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()) != 0;
usleep (100000);
}
}
......@@ -89,7 +87,7 @@ void AudioLayerTest::testPulseConnect()
{
_debug ("-------------------- AudioLayerTest::testPulseConnect --------------------\n");
if (Manager::instance().getAudioDriver()->getLayerType() == ALSA) {
if (dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver())) {
Manager::instance().switchAudioManager();
usleep (100000);
}
......@@ -97,7 +95,7 @@ void AudioLayerTest::testPulseConnect()
ManagerImpl* manager;
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 @@
#include "configurationtest.h"
#include "constants.h"
#include "audio/alsa/alsalayer.h"
#include "audio/pulseaudio/pulselayer.h"
using std::cout;
using std::endl;
......@@ -79,10 +81,10 @@ 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)
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), ALSA);
else if (Manager::instance().preferences.getAudioApi() == PULSEAUDIO)
CPPUNIT_ASSERT_EQUAL (Manager::instance().getAudioDriver()->getLayerType(), PULSEAUDIO);
if (Manager::instance().preferences.getAudioApi() == "alsa")
CPPUNIT_ASSERT (!dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
else if (Manager::instance().preferences.getAudioApi() == "pulseaudio")
CPPUNIT_ASSERT (!dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
else
CPPUNIT_FAIL ("Wrong audio layer type");
}
......
......@@ -177,18 +177,10 @@ is_iax_enabled (void)
void
select_dtmf_type (void)
{
DEBUG ("DTMF selection changed\n");
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (overrtp))) {
// dbus_set_audio_manager( ALSA );
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (overrtp)))
DEBUG ("Selected DTMF over RTP");
} else {
// dbus_set_audio_manager( PULSEAUDIO );
else
DEBUG ("Selected DTMF over SIP");
}
}
static GPtrArray* getNewCredential (void)
......
......@@ -194,7 +194,7 @@ preferences_dialog_fill_ringtone_audio_device_list()
void
select_active_output_audio_device()
{
if (SHOW_ALSA_CONF) {
if (must_show_alsa_conf()) {
GtkTreeModel* model;
GtkTreeIter iter;
......@@ -234,7 +234,7 @@ select_active_output_audio_device()
void
select_active_ringtone_audio_device()
{
if (SHOW_ALSA_CONF) {
if (must_show_alsa_conf()) {
GtkTreeModel* model;
GtkTreeIter iter;
......@@ -299,7 +299,7 @@ preferences_dialog_fill_input_audio_device_list()
void
select_active_input_audio_device()
{
if (SHOW_ALSA_CONF) {
if (must_show_alsa_conf()) {
GtkTreeModel* model;
GtkTreeIter iter;
......@@ -718,15 +718,15 @@ GtkWidget* audiocodecs_box (account_t *a)
void
select_audio_manager (void)
{
if (!SHOW_ALSA_CONF && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (ALSA);
if (!must_show_alsa_conf() && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (ALSA_API_STR);
alsabox = alsa_box();
gtk_container_add (GTK_CONTAINER (alsa_conf) , alsabox);
gtk_widget_show (alsa_conf);
gtk_widget_set_sensitive (GTK_WIDGET (alsa_conf), TRUE);
gtk_action_set_sensitive (GTK_ACTION (volumeToggle), TRUE);
} else if (SHOW_ALSA_CONF && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (PULSEAUDIO);
} else if (must_show_alsa_conf() && gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (pulse))) {
dbus_set_audio_manager (PULSEAUDIO_API_STR);
gtk_container_remove (GTK_CONTAINER (alsa_conf) , alsabox);
gtk_widget_hide (alsa_conf);
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (volumeToggle))) {
......@@ -954,12 +954,12 @@ GtkWidget* create_audio_configuration()
gnome_main_section_new_with_table (_ ("Sound Manager"), &frame, &table, 1, 4);
gtk_box_pack_start (GTK_BOX (ret), frame, FALSE, FALSE, 0);
int audio_manager = dbus_get_audio_manager();
gchar *audio_manager = dbus_get_audio_manager();
gboolean pulse_audio = FALSE;
if (audio_manager == PULSEAUDIO) {
if (g_strcmp0(audio_manager, PULSEAUDIO_API_STR) == 0)
pulse_audio = TRUE;
}
g_free(audio_manager);
pulse = gtk_radio_button_new_with_mnemonic (NULL , _ ("_Pulseaudio"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pulse), pulse_audio);
......@@ -975,7 +975,7 @@ GtkWidget* create_audio_configuration()
gtk_box_pack_start (GTK_BOX (ret), alsa_conf, FALSE, FALSE, 0);
gtk_widget_show (alsa_conf);
if (SHOW_ALSA_CONF) {
if (must_show_alsa_conf()) {
// Box for the ALSA configuration
alsabox = alsa_box();
gtk_container_add (GTK_CONTAINER (alsa_conf) , alsabox);
......@@ -1033,37 +1033,27 @@ GtkWidget* create_audio_configuration()
enableEchoCancel = gtk_check_button_new_with_mnemonic(_("_Echo Cancellation"));
state = dbus_get_echo_cancel_state();
echoCancelActive = FALSE;
if (g_strcmp0(state, "enabled") == 0) {
if (g_strcmp0(state, "enabled") == 0)
echoCancelActive = TRUE;
}
else {
else
echoCancelActive = FALSE;
}
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(enableEchoCancel), echoCancelActive);
g_signal_connect(G_OBJECT(enableEchoCancel), "clicked", active_echo_cancel, NULL);
gtk_table_attach(GTK_TABLE(table), enableEchoCancel, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
/*
gint value = dbus_get_echo_cancel_tail_length();
echoTailLength = gtk_hscale_new_with_range(100, 500, 5);
gtk_range_set_value(GTK_RANGE(echoTailLength), (gdouble)value);
gtk_table_attach(GTK_TABLE(table), echoTailLength, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(echoTailLength), "value-changed", G_CALLBACK(echo_tail_length_changed), NULL);
value = dbus_get_echo_cancel_delay();
echoDelay = gtk_hscale_new_with_range(0, 500, 5);
gtk_range_set_value(GTK_RANGE(echoDelay), (gdouble)value);
gtk_table_attach(GTK_TABLE(table), echoDelay, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(echoDelay), "value-changed", G_CALLBACK(echo_delay_changed), NULL);
*/
gtk_widget_show_all (ret);
if (!pulse_audio) {
if (!pulse_audio)
gtk_widget_show (alsa_conf);
} else {
else
gtk_widget_hide (alsa_conf);
}
return ret;
}
/** Show/Hide the alsa configuration panel */
gboolean must_show_alsa_conf()
{
return g_strcmp0(dbus_get_audio_manager(), ALSA_API_STR) == 0;
}
......@@ -42,5 +42,6 @@ GtkWidget* audiocodecs_box();
GtkWidget* ringtone_box();
gboolean get_api();
gboolean must_show_alsa_conf ();
#endif // __AUDIO_CONF_H
......@@ -226,7 +226,7 @@
<method name="getAudioManager" tp:name-for-bindings="getAudioManager">
<tp:docstring>
</tp:docstring>
<arg type="i" name="api" direction="out">
<arg type="s" name="api" direction="out">
<tp:docstring>
</tp:docstring>
</arg>
......@@ -235,7 +235,7 @@
<method name="setAudioManager" tp:name-for-bindings="setAudioManager">
<tp:docstring>
</tp:docstring>
<arg type="i" name="api" direction="in">
<arg type="s" name="api" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
......
......@@ -1734,7 +1734,7 @@ dbus_get_history_limit (void)
}
void
dbus_set_audio_manager (int api)
dbus_set_audio_manager (const gchar *api)
{
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_audio_manager (
......@@ -1744,10 +1744,10 @@ dbus_set_audio_manager (int api)
g_error_free (error);
}
int
gchar *
dbus_get_audio_manager (void)
{
int api;
gchar *api;
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_get_audio_manager (
configurationManagerProxy, &api, &error);
......
......@@ -338,17 +338,17 @@ void dbus_set_history_limit (const guint days);
/**
* ConfigurationManager - Returns the selected audio manager
* @return int 0 ALSA
* 1 PULSEAUDIO
* @return "alsa"
* or "pulseaudio"
*/
int dbus_get_audio_manager (void);
gchar *dbus_get_audio_manager (void);
/**
* ConfigurationManager - Set the audio manager
* @param api 0 ALSA
* 1 PULSEAUDIO
* @param api "alsa"
* "pulseaudio"
*/
void dbus_set_audio_manager (int api);
void dbus_set_audio_manager (const gchar *api);
/**
* ConfigurationManager - Start a tone when a new call is open and no numbers have been dialed
......
......@@ -43,6 +43,7 @@
#include <widget/gtkscrollbook.h>
#include <widget/minidialog.h>
#include "uimanager.h"
#include "config/audioconf.h"
#include <sys/stat.h>
#include <gtk/gtk.h>
......
......@@ -135,6 +135,9 @@
/** Error codecs not loaded */
#define CODECS_NOT_LOADED 0x1000
#define PULSEAUDIO_API_STR "pulseaudio"
#define ALSA_API_STR "alsa"
/** Tone to play when no voice mails */
#define TONE_WITHOUT_MESSAGE 0
/** Tone to play when voice mails */
......@@ -143,14 +146,8 @@
#define MINIMIZED TRUE
/** Behaviour of the main window on incoming calls */
#define __POPUP_WINDOW (eel_gconf_get_integer (POPUP_ON_CALL))
/** Show/Hide the alsa configuration panel */
#define SHOW_ALSA_CONF ( dbus_get_audio_manager() == ALSA )
/** Show/Hide the volume controls */
#define SHOW_VOLUME (eel_gconf_get_integer (SHOW_VOLUME_CONTROLS) && SHOW_ALSA_CONF)
/** Audio Managers */
#define ALSA 0
#define PULSEAUDIO 1
#define SHOW_VOLUME (eel_gconf_get_integer (SHOW_VOLUME_CONTROLS) && must_show_alsa_conf())
/** DTMF type */
#define OVERRTP "overrtp"
......
......@@ -44,6 +44,7 @@
#include <eel-gconf-extensions.h>
#include "config/audioconf.h"
#include "uimanager.h"
#include "statusicon.h"
......@@ -1767,7 +1768,7 @@ create_menus (GtkUIManager *ui_manager)
// Set the toggle buttons
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Dialpad")), eel_gconf_get_boolean (CONF_SHOW_DIALPAD));
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (volumeToggle), (gboolean) SHOW_VOLUME);
gtk_action_set_sensitive (GTK_ACTION (volumeToggle), SHOW_ALSA_CONF);
gtk_action_set_sensitive (GTK_ACTION (volumeToggle), must_show_alsa_conf());
gtk_action_set_sensitive (GTK_ACTION (gtk_ui_manager_get_action (ui_manager, "/MenuBar/ViewMenu/Toolbar")), FALSE);
......
Markdown is supported
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