Commit aac05d43 authored by Emmanuel Milou's avatar Emmanuel Milou
Browse files

Switching audio layer from the GTK implemented

You can switch from ALSA to Pulseaudio from the config window

If pulseaudio is selected, the alsa configuration panel gets hidden
parent 515e7df7
......@@ -30,6 +30,9 @@ GtkWidget *plugin;
GtkWidget *codecMoveUpButton;
GtkWidget *codecMoveDownButton;
GtkWidget *codecTreeView; // View used instead of store to get access to selection
GtkWidget *pulse;
GtkWidget *alsabox;
GtkWidget *alsa_conf;
// Codec properties ID
enum {
......@@ -105,13 +108,13 @@ config_window_fill_output_audio_plugin_list()
void
config_window_fill_output_audio_device_list()
{
/*
GtkTreeIter iter;
gchar** list;
gchar** audioDevice;
int index;
gtk_list_store_clear(outputlist);
GtkTreeIter iter;
gchar** list;
gchar** audioDevice;
int index;
gtk_list_store_clear(outputlist);
// Call dbus to retreive list
list = dbus_get_audio_output_device_list();
......@@ -120,12 +123,12 @@ config_window_fill_output_audio_device_list()
int c = 0;
for(audioDevice = list; *list ; list++)
{
index = dbus_get_audio_device_index( *list );
gtk_list_store_append(outputlist, &iter);
gtk_list_store_set(outputlist, &iter, 0, *list, 1, index, -1);
c++;
index = dbus_get_audio_device_index( *list );
gtk_list_store_append(outputlist, &iter);
gtk_list_store_set(outputlist, &iter, 0, *list, 1, index, -1);
c++;
}
*/
}
/**
......@@ -134,35 +137,35 @@ config_window_fill_output_audio_device_list()
void
select_active_output_audio_device()
{
/*
GtkTreeModel* model;
GtkTreeIter iter;
gchar** devices;
int currentDeviceIndex;
int deviceIndex;
GtkTreeModel* model;
GtkTreeIter iter;
gchar** devices;
int currentDeviceIndex;
int deviceIndex;
// Select active output device on server
devices = dbus_get_current_audio_devices_index();
currentDeviceIndex = atoi(devices[0]);
//devices = dbus_get_current_audio_devices_index();
currentDeviceIndex = 0;//atoi(devices[0]);
printf(_("audio device index for output = %d\n"), currentDeviceIndex);
model = gtk_combo_box_get_model(GTK_COMBO_BOX(output));
// Find the currently set output device
gtk_tree_model_get_iter_first(model, &iter);
do {
gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
if(deviceIndex == currentDeviceIndex)
{
// Set current iteration the active one
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(output), &iter);
return;
}
gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
if(deviceIndex == currentDeviceIndex)
{
// Set current iteration the active one
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(output), &iter);
return;
}
} while(gtk_tree_model_iter_next(model, &iter));
// No index was found, select first one
g_print("Warning : No active output device found");
gtk_combo_box_set_active(GTK_COMBO_BOX(output), 0);
*/
}
/**
......@@ -171,12 +174,12 @@ select_active_output_audio_device()
void
config_window_fill_input_audio_device_list()
{
/*
GtkTreeIter iter;
gchar** list;
gchar** audioDevice;
int index ;
gtk_list_store_clear(inputAudioDeviceManagerStore);
GtkTreeIter iter;
gchar** list;
gchar** audioDevice;
int index ;
gtk_list_store_clear(inputlist);
// Call dbus to retreive list
list = dbus_get_audio_input_device_list();
......@@ -185,12 +188,13 @@ config_window_fill_input_audio_device_list()
//int c = 0;
for(audioDevice = list; *list; list++)
{
index = dbus_get_audio_device_index( *list );
gtk_list_store_append(inputAudioDeviceManagerStore, &iter);
gtk_list_store_set(inputAudioDeviceManagerStore, &iter, 0, *list, 1, index, -1);
//c++;
g_print("dbasbasdfbzfb\n");
index = dbus_get_audio_device_index( *list );
gtk_list_store_append(inputlist, &iter);
gtk_list_store_set(inputlist, &iter, 0, *list, 1, index, -1);
//c++;
}
*/
}
/**
......@@ -199,12 +203,12 @@ config_window_fill_input_audio_device_list()
void
select_active_input_audio_device()
{
/*
GtkTreeModel* model;
GtkTreeIter iter;
gchar** devices;
int currentDeviceIndex;
int deviceIndex;
GtkTreeModel* model;
GtkTreeIter iter;
gchar** devices;
int currentDeviceIndex;
int deviceIndex;
// Select active input device on server
devices = dbus_get_current_audio_devices_index();
......@@ -214,19 +218,19 @@ select_active_input_audio_device()
// Find the currently set input device
gtk_tree_model_get_iter_first(model, &iter);
do {
gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
if(deviceIndex == currentDeviceIndex)
{
// Set current iteration the active one
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(input), &iter);
return;
}
gtk_tree_model_get(model, &iter, 1, &deviceIndex, -1);
if(deviceIndex == currentDeviceIndex)
{
// Set current iteration the active one
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(input), &iter);
return;
}
} while(gtk_tree_model_iter_next(model, &iter));
// No index was found, select first one
g_print("Warning : No active input device found");
gtk_combo_box_set_active(GTK_COMBO_BOX(input), 0);
*/
}
/**
......@@ -593,21 +597,37 @@ GtkWidget* codecs_box()
return ret;
}
void
select_audio_manager( void )
{
if( !SHOW_ALSA_CONF && !gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pulse) ) )
{
alsabox = alsa_box();
gtk_container_add( GTK_CONTAINER(alsa_conf ) , alsabox);
gtk_widget_show( alsa_conf );
}
else if( SHOW_ALSA_CONF && gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pulse) ))
{
gtk_container_remove( GTK_CONTAINER(alsa_conf) , alsabox );
}
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pulse) )? dbus_set_audio_manager( PULSEAUDIO ):dbus_set_audio_manager( ALSA );
}
GtkWidget* api_box()
{
GtkWidget *ret;
GtkWidget *alsa;
GtkWidget *pulse;
ret = gtk_hbox_new(FALSE, 10);
gtk_widget_show( ret );
pulse = gtk_radio_button_new_with_mnemonic( NULL , _("Pulseaudio"));
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(pulse), TRUE );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(pulse), !SHOW_ALSA_CONF );
gtk_box_pack_start( GTK_BOX(ret) , pulse , TRUE , TRUE , 1);
alsa = gtk_radio_button_new_with_mnemonic_from_widget(GTK_RADIO_BUTTON(pulse), _("ALSA"));
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(alsa), FALSE );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(alsa), SHOW_ALSA_CONF );
gtk_box_pack_end( GTK_BOX(ret) , alsa , TRUE , TRUE , 1);
g_signal_connect(G_OBJECT(alsa), "clicked", G_CALLBACK(select_audio_manager), NULL);
gtk_widget_show_all(ret);
......@@ -639,7 +659,7 @@ GtkWidget* alsa_box()
plugin = gtk_combo_box_new_with_model(GTK_TREE_MODEL(pluginlist));
//select_active_output_audio_plugin();
gtk_label_set_mnemonic_widget(GTK_LABEL(item), plugin);
//g_signal_connect(G_OBJECT(plugin), "changed", G_CALLBACK(select_output_audio_plugin), plugin);
g_signal_connect(G_OBJECT(plugin), "changed", G_CALLBACK(select_output_audio_plugin), plugin);
// Set rendering
renderer = gtk_cell_renderer_text_new();
......@@ -660,7 +680,7 @@ GtkWidget* alsa_box()
output = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputlist));
//select_active_output_audio_device();
gtk_label_set_mnemonic_widget(GTK_LABEL(item), output);
//g_signal_connect(G_OBJECT(output), "changed", G_CALLBACK(select_audio_output_device), output);
g_signal_connect(G_OBJECT(output), "changed", G_CALLBACK(select_audio_output_device), output);
// Set rendering
renderer = gtk_cell_renderer_text_new();
......@@ -681,7 +701,7 @@ GtkWidget* alsa_box()
input = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputlist));
//select_active_input_audio_device();
gtk_label_set_mnemonic_widget(GTK_LABEL(item), input);
//g_signal_connect(G_OBJECT(input), "changed", G_CALLBACK(select_audio_input_device), input);
g_signal_connect(G_OBJECT(input), "changed", G_CALLBACK(select_audio_input_device), input);
// Set rendering
renderer = gtk_cell_renderer_text_new();
......@@ -730,7 +750,6 @@ GtkWidget* create_audio_configuration()
GtkWidget *ret;
// Main frames
GtkWidget *sound_conf;
GtkWidget *alsa_conf;
GtkWidget *codecs_conf;
GtkWidget *ringtones_conf;
// Sub boxes
......@@ -750,8 +769,11 @@ GtkWidget* create_audio_configuration()
alsa_conf = gtk_frame_new(_("ALSA configuration"));
gtk_box_pack_start(GTK_BOX(ret), alsa_conf, FALSE, FALSE, 0);
gtk_widget_show( alsa_conf );
box = alsa_box();
gtk_container_add( GTK_CONTAINER(alsa_conf) , box );
if( SHOW_ALSA_CONF )
{
alsabox = alsa_box();
gtk_container_add( GTK_CONTAINER(alsa_conf) , alsabox );
}
// Box for the codecs
codecs_conf = gtk_frame_new(_("Codecs"));
......@@ -771,9 +793,3 @@ GtkWidget* create_audio_configuration()
return ret;
}
gboolean get_api()
{
return gtk_widget_get_active()
}
......@@ -578,6 +578,81 @@ static
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_get_audio_manager (DBusGProxy *proxy, gint* OUT_api, GError **error)
{
return dbus_g_proxy_call (proxy, "getAudioManager", error, G_TYPE_INVALID, G_TYPE_INT, OUT_api, G_TYPE_INVALID);
}
typedef void (*org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_reply) (DBusGProxy *proxy, gint OUT_api, GError *error, gpointer userdata);
static void
org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
{
DBusGAsyncData *data = (DBusGAsyncData*) user_data;
GError *error = NULL;
gint OUT_api;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INT, &OUT_api, G_TYPE_INVALID);
(*(org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_reply)data->cb) (proxy, OUT_api, error, data->userdata);
return;
}
static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_async (DBusGProxy *proxy, org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_reply callback, gpointer userdata)
{
DBusGAsyncData *stuff;
stuff = g_new (DBusGAsyncData, 1);
stuff->cb = G_CALLBACK (callback);
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "getAudioManager", org_sflphone_SFLphone_ConfigurationManager_get_audio_manager_async_callback, stuff, g_free, G_TYPE_INVALID);
}
static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_set_audio_manager (DBusGProxy *proxy, const gint IN_api, GError **error)
{
return dbus_g_proxy_call (proxy, "setAudioManager", error, G_TYPE_INT, IN_api, G_TYPE_INVALID, G_TYPE_INVALID);
}
typedef void (*org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_reply) (DBusGProxy *proxy, GError *error, gpointer userdata);
static void
org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_async_callback (DBusGProxy *proxy, DBusGProxyCall *call, void *user_data)
{
DBusGAsyncData *data = (DBusGAsyncData*) user_data;
GError *error = NULL;
dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID);
(*(org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_reply)data->cb) (proxy, error, data->userdata);
return;
}
static
#ifdef G_HAVE_INLINE
inline
#endif
DBusGProxyCall*
org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_async (DBusGProxy *proxy, const gint IN_api, org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_reply callback, gpointer userdata)
{
DBusGAsyncData *stuff;
stuff = g_new (DBusGAsyncData, 1);
stuff->cb = G_CALLBACK (callback);
stuff->userdata = userdata;
return dbus_g_proxy_begin_call (proxy, "setAudioManager", org_sflphone_SFLphone_ConfigurationManager_set_audio_manager_async_callback, stuff, g_free, G_TYPE_INT, IN_api, G_TYPE_INVALID);
}
static
#ifdef G_HAVE_INLINE
inline
#endif
gboolean
org_sflphone_SFLphone_ConfigurationManager_get_codec_list (DBusGProxy *proxy, char *** OUT_list, GError **error)
{
......
......@@ -1419,3 +1419,40 @@ dbus_get_mail_notify( void )
return level;
}
void
dbus_set_audio_manager( int api )
{
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_audio_manager(
configurationManagerProxy,
api,
&error);
if(error)
{
g_error_free(error);
}
else
g_print("Called dbus_set_audio_manager\n");
}
int
dbus_get_audio_manager( void )
{
g_print("Before dbus_get_mail_notif_level()\n");
int api;
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_get_audio_manager(
configurationManagerProxy,
&api,
&error);
if(error)
{
g_print("Error calling dbus_get_audio_manager\n");
g_error_free(error);
}
else
g_print("Called dbus_get_audio_manager\n");
return api;
}
......@@ -352,6 +352,20 @@ void dbus_switch_popup_mode( void );
*/
int dbus_popup_mode( void );
/**
* ConfigurationManager - Returns the selected audio manager
* @return int 0 ALSA
* 1 PULSEAUDIO
*/
int dbus_get_audio_manager( void );
/**
* ConfigurationManager - Set the audio manager
* @param api 0 ALSA
* 1 PULSEAUDIO
*/
void dbus_set_audio_manager( int api );
/**
* ConfigurationManager - Configure the notification level
* @return int 0 disable
......
......@@ -76,6 +76,12 @@
#define SHOW_VOLUME ( dbus_get_volume_controls() )
/** Show/Hide the dialpad */
#define SHOW_SEARCHBAR ( dbus_get_searchbar() )
/** Show/Hide the alsa configuration panel */
#define SHOW_ALSA_CONF ( dbus_get_audio_manager() == ALSA )
/** Audio Managers */
#define ALSA 0
#define PULSEAUDIO 1
/** Notification levels */
#define __NOTIF_LEVEL_MIN 0
......
......@@ -40,6 +40,14 @@ AlsaLayer::~AlsaLayer (void)
deviceClosed = true;
}
void
AlsaLayer::closeLayer()
{
_debugAlsa("Close ALSA streams\n");
closeCaptureStream();
closePlaybackStream();
deviceClosed = true;
}
bool
AlsaLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, int stream , std::string plugin)
......
......@@ -46,6 +46,8 @@ class AlsaLayer : public AudioLayer {
*/
~AlsaLayer(void);
void closeLayer( void );
/**
* Check if no devices are opened, otherwise close them.
* Then open the specified devices by calling the private functions open_device
......
......@@ -68,6 +68,8 @@ class AudioLayer {
*/
~AudioLayer(void){}
virtual void closeLayer( void ) = 0;
/**
* Check if no devices are opened, otherwise close them.
* Then open the specified devices by calling the private functions open_device
......
......@@ -376,13 +376,12 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
toAudioLayer = _dataAudioLayer;
#endif
// int layer = audiolayer->getLayerType();
// _debug(" interface %i\n" , layer);
//#if CHECK_INTERFACE( layer , ALSA )
// audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat), true);
//#else
audiolayer->putMain( toAudioLayer, nbSample * sizeof(SFLDataFormat) );
//#endif
int layer = audiolayer->getLayerType();
//_debug(" interface %i - ALSA = %i\n" , layer, ALSA);
if( CHECK_INTERFACE( layer, ALSA ) )
audiolayer->playSamples(toAudioLayer, nbSample * sizeof(SFLDataFormat), true);
else
audiolayer->putMain( toAudioLayer, nbSample * sizeof(SFLDataFormat) );
// Notify (with a beep) an incoming call when there is already a call
countTime += time->getSecond();
if (Manager::instance().incomingCallWaiting() > 0) {
......
......@@ -37,6 +37,15 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc )
AudioStream::~AudioStream()
{
_debug("Destroy audio streams\n");
pa_stream_disconnect( pulseStream() );
}
void
AudioStream::disconnect( void )
{
_debug("Destroy audio streams\n");
pa_stream_disconnect( pulseStream() );
}
void
......
......@@ -42,6 +42,7 @@ class AudioStream {
int putMain( void* buffer , int toCopy );
int putUrgent( void* buffer , int toCopy );
void disconnect();
pa_stream* pulseStream(){ return _audiostream; }
private:
......
......@@ -38,11 +38,20 @@ int framesPerBuffer = 2048;
// Destructor
PulseLayer::~PulseLayer (void)
{
_debug(" Destroy pulselayer\n");
delete playback;
delete record;
pa_context_disconnect(context);
}
void
PulseLayer::closeLayer( void )
{
playback->disconnect();
record->disconnect();
pa_context_disconnect( context );
}
void
PulseLayer::connectPulseServer( void )
{
......
......@@ -31,6 +31,8 @@ class PulseLayer : public AudioLayer {
PulseLayer(ManagerImpl* manager);
~PulseLayer(void);
void closeLayer( void );
/**
* Check if no devices are opened, otherwise close them.
* Then open the specified devices by calling the private functions open_device
......
......@@ -35,6 +35,8 @@ public:
register_method(ConfigurationManager, ringtoneEnabled, _ringtoneEnabled_stub);
register_method(ConfigurationManager, getRingtoneChoice, _getRingtoneChoice_stub);
register_method(ConfigurationManager, setRingtoneChoice, _setRingtoneChoice_stub);
register_method(ConfigurationManager, getAudioManager, _getAudioManager_stub);
register_method(ConfigurationManager, setAudioManager, _setAudioManager_stub);
register_method(ConfigurationManager, getCodecList, _getCodecList_stub);
register_method(ConfigurationManager, getCodecDetails, _getCodecDetails_stub);
register_method(ConfigurationManager, getActiveCodecList, _getActiveCodecList_stub);
......@@ -148,6 +150,16 @@ public:
{ "tone", "s", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getAudioManager_args[] =
{
{ "api", "i", false },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument setAudioManager_args[] =
{
{ "api", "i", true },
{ 0, 0, 0 }
};
static ::DBus::IntrospectedArgument getCodecList_args[] =
{
{ "list", "as", false },
......@@ -334,6 +346,8 @@ public:
{ "ringtoneEnabled", ringtoneEnabled_args },
{ "getRingtoneChoice", getRingtoneChoice_args },
{ "setRingtoneChoice", setRingtoneChoice_args },
{ "getAudioManager", getAudioManager_args },
{ "setAudioManager", setAudioManager_args },
{ "getCodecList", getCodecList_args },
{ "getCodecDetails", getCodecDetails_args },
{ "getActiveCodecList", getActiveCodecList_args },
......@@ -415,6 +429,8 @@ public:
virtual void ringtoneEnabled( ) = 0;
virtual ::DBus::String getRingtoneChoice( ) = 0;
virtual void setRingtoneChoice( const ::DBus::String& tone ) = 0;
virtual ::DBus::Int32 getAudioManager( ) = 0;
virtual void setAudioManager( const ::DBus::Int32& api ) = 0;
virtual std::vector< ::DBus::String > getCodecList( ) = 0;
virtual std::vector< ::DBus::String > getCodecDetails( const ::DBus::Int32& payload ) = 0;
virtual std::vector< ::DBus::String > getActiveCodecList( ) = 0;
......@@ -622,6 +638,25 @@ private:
::DBus::ReturnMessage reply(call);
return reply;
}
::DBus::Message _getAudioManager_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::Int32 argout1 = getAudioManager();
::DBus::ReturnMessage reply(call);
::DBus::MessageIter wi = reply.writer();
wi << argout1;
return reply;
}
::DBus::Message _setAudioManager_stub( const ::DBus::CallMessage& call )
{
::DBus::MessageIter ri = call.reader();
::DBus::Int32 argin1; ri >> argin1;
setAudioManager(argin1);
::DBus::ReturnMessage reply(call);
return reply;
}