Commit 6281f08d authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#1962] Fix alsa device choosing (capture, playback, ringtone)

parent 1acdc884
......@@ -354,7 +354,7 @@ select_output_audio_plugin (GtkComboBox* widget, gpointer data UNUSED)
model = gtk_combo_box_get_model (widget);
gtk_combo_box_get_active_iter (widget, &iter);
gtk_tree_model_get (model, &iter, 0, &pluginName, -1);
dbus_set_output_audio_plugin (pluginName);
dbus_set_audio_plugin (pluginName);
//update_combo_box( pluginName);
}
}
......@@ -439,6 +439,31 @@ select_audio_input_device (GtkComboBox* comboBox, gpointer data UNUSED)
}
}
/**
+ * Set the audio ringtone device on the server with its index
+ */
static void
select_audio_ringtone_device (GtkComboBox *comboBox, gpointer data UNUSED)
{
GtkTreeModel *model;
GtkTreeIter iter;
int comboBoxIndex;
int deviceIndex;
comboBoxIndex = gtk_combo_box_get_active (comboBox);
if (comboBoxIndex >= 0) {
model = gtk_combo_box_get_model (comboBox);
gtk_combo_box_get_active_iter (comboBox, &iter);
gtk_tree_model_get (model, &iter, 1, &deviceIndex, -1);
dbus_set_audio_ringtone_device (deviceIndex);
}
}
/**
* Toggle move buttons on if a codec is selected, off elsewise
*/
......@@ -844,6 +869,27 @@ GtkWidget* alsa_box()
gtk_label_set_mnemonic_widget (GTK_LABEL (item), input);
g_signal_connect (G_OBJECT (input), "changed", G_CALLBACK (select_audio_input_device), input);
DEBUG ("Audio: Configuration rintgtone");
item = gtk_label_new (_ ("Ringtone"));
gtk_misc_set_alignment (GTK_MISC (item), 0, 0.5);
gtk_table_attach (GTK_TABLE (table), item, 1, 2, 4, 5, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (item);
// set choices of ringtone devices
ringtonelist = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
preferences_dialog_fill_ringtone_audio_device_list();
ringtone = gtk_combo_box_new_with_model (GTK_TREE_MODEL (ringtonelist));
select_active_ringtone_audio_device();
gtk_label_set_mnemonic_widget (GTK_LABEL (item), output);
g_signal_connect (G_OBJECT (ringtone), "changed", G_CALLBACK (select_audio_ringtone_device), output);
// Set rendering
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (ringtone), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (ringtone), renderer, "text", 0, NULL);
gtk_table_attach (GTK_TABLE (table), ringtone, 2, 3, 4, 5, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0);
gtk_widget_show (ringtone);
// Set rendering
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (input), renderer, TRUE);
......
......@@ -456,16 +456,7 @@
</arg>
</method>
<method name="setInputAudioPlugin" tp:name-for-bindings="setInputAudioPlugin">
<tp:docstring>
</tp:docstring>
<arg type="s" name="audioPlugin" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setOutputAudioPlugin" tp:name-for-bindings="setOutputAudioPlugin">
<method name="setAudioPlugin" tp:name-for-bindings="setAudioPlugin">
<tp:docstring>
</tp:docstring>
<arg type="s" name="audioPlugin" direction="in">
......
......@@ -1255,27 +1255,14 @@ dbus_get_audio_plugin_list()
}
void
dbus_set_input_audio_plugin (gchar* audioPlugin)
dbus_set_audio_plugin (gchar* audioPlugin)
{
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_input_audio_plugin (
org_sflphone_SFLphone_ConfigurationManager_set_audio_plugin (
configurationManagerProxy, audioPlugin, &error);
if (error) {
ERROR ("Failed to call set_input_audio_plugin() on ConfigurationManager: %s", error->message);
g_error_free (error);
}
}
void
dbus_set_output_audio_plugin (gchar* audioPlugin)
{
GError* error = NULL;
org_sflphone_SFLphone_ConfigurationManager_set_output_audio_plugin (
configurationManagerProxy, audioPlugin, &error);
if (error) {
ERROR ("Failed to call set_output_audio_plugin() on ConfigurationManager: %s", error->message);
ERROR ("Failed to call set_audio_plugin() on ConfigurationManager: %s", error->message);
g_error_free (error);
}
}
......
......@@ -41,8 +41,8 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager)
, _PlaybackHandle (NULL)
, _RingtoneHandle (NULL)
, _CaptureHandle (NULL)
, _periodSize()
, _audioPlugin()
, _periodSize (160)
, _audioPlugin ("default")
, IDSoundCards()
, _is_prepared_playback (false)
, _is_prepared_capture (false)
......@@ -60,6 +60,8 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager)
// _audioThread = NULL;
_urgentRingBuffer.createReadPointer();
_audioPlugin = AudioLayer::_manager->audioPreference.getPlugin();
AudioLayer::_echocancelstate = true;
AudioLayer::_noisesuppressstate = true;
}
......
......@@ -515,8 +515,8 @@ bool PulseLayer::createStreams (pa_context* c)
std::string ringtoneDevice = _manager->audioPreference.getDeviceRingtone();
_debug ("Audio: Device stored in config for playback: %s", playbackDevice.c_str());
_debug ("Audio: Device stored in config for ringtone: %s", recordDevice.c_str());
_debug ("Audio: Device stored in config for record: %s", ringtoneDevice.c_str());
_debug ("Audio: Device stored in config for record: %s", recordDevice.c_str());
_debug ("Audio: Device stored in config for ringtone: %s", ringtoneDevice.c_str());
PulseLayerType * playbackParam = new PulseLayerType();
playbackParam->context = c;
......
......@@ -456,16 +456,7 @@
</arg>
</method>
<method name="setInputAudioPlugin" tp:name-for-bindings="setInputAudioPlugin">
<tp:docstring>
</tp:docstring>
<arg type="s" name="audioPlugin" direction="in">
<tp:docstring>
</tp:docstring>
</arg>
</method>
<method name="setOutputAudioPlugin" tp:name-for-bindings="setOutputAudioPlugin">
<method name="setAudioPlugin" tp:name-for-bindings="setAudioPlugin">
<tp:docstring>
</tp:docstring>
<arg type="s" name="audioPlugin" direction="in">
......
......@@ -501,14 +501,11 @@ std::vector<std::string> ConfigurationManager::getAudioPluginList()
}
void ConfigurationManager::setInputAudioPlugin (const std::string& audioPlugin)
void ConfigurationManager::setAudioPlugin (const std::string& audioPlugin)
{
return Manager::instance().setInputAudioPlugin (audioPlugin);
}
_debug ("ConfigurationManager: Set audio plugin %s", audioPlugin.c_str());
void ConfigurationManager::setOutputAudioPlugin (const std::string& audioPlugin)
{
return Manager::instance().setOutputAudioPlugin (audioPlugin);
return Manager::instance().setAudioPlugin (audioPlugin);
}
std::vector<std::string> ConfigurationManager::getAudioOutputDeviceList()
......@@ -548,6 +545,8 @@ int32_t ConfigurationManager::getAudioDeviceIndex (const std::string& name)
std::string ConfigurationManager::getCurrentAudioOutputPlugin (void)
{
_debug ("ConfigurationManager: Get audio plugin %s", Manager::instance().getCurrentAudioOutputPlugin().c_str());
return Manager::instance().getCurrentAudioOutputPlugin();
}
......
......@@ -80,8 +80,7 @@ class ConfigurationManager
void setActiveCodecList (const std::vector< std::string >& list, const std::string& accountID);
std::vector< std::string > getAudioPluginList();
void setInputAudioPlugin (const std::string& audioPlugin);
void setOutputAudioPlugin (const std::string& audioPlugin);
void setAudioPlugin (const std::string& audioPlugin);
std::vector< std::string > getAudioOutputDeviceList();
void setAudioOutputDevice (const int32_t& index);
void setAudioInputDevice (const int32_t& index);
......
......@@ -2312,65 +2312,25 @@ std::string ManagerImpl::getCurrentCodecName (const CallID& id)
/**
* Set input audio plugin
*/
void ManagerImpl::setInputAudioPlugin (const std::string& audioPlugin)
void ManagerImpl::setAudioPlugin (const std::string& audioPlugin)
{
int layer = _audiodriver -> getLayerType();
audioPreference.setPlugin (audioPlugin);
if (CHECK_INTERFACE (layer , ALSA)) {
_debug ("Set input audio plugin");
_audiodriver -> setErrorMessage (-1);
_audiodriver -> openDevice (_audiodriver->getIndexIn(), _audiodriver->getIndexOut(),
_audiodriver->getIndexRing(), _audiodriver -> getSampleRate(),
_audiodriver -> getFrameSize(), SFL_PCM_CAPTURE, audioPlugin);
_audiodriver -> getFrameSize(), SFL_PCM_BOTH, audioPlugin);
if (_audiodriver -> getErrorMessage() != -1)
notifyErrClient (_audiodriver -> getErrorMessage());
} else {
}
}
/**
* Set output audio plugin
*/
void ManagerImpl::setOutputAudioPlugin (const std::string& audioPlugin)
{
int res;
_debug ("Manager: Set output audio plugin");
_audiodriver -> setErrorMessage (-1);
res = _audiodriver -> openDevice (_audiodriver->getIndexIn(), _audiodriver->getIndexOut(),
_audiodriver->getIndexRing(), _audiodriver -> getSampleRate(),
_audiodriver -> getFrameSize(), SFL_PCM_BOTH, audioPlugin);
if (_audiodriver -> getErrorMessage() != -1)
notifyErrClient (_audiodriver -> getErrorMessage());
// set config
if (res)
audioPreference.setPlugin (audioPlugin);
//setConig(AUDIO, ALSA_PLUGIN, audioPlugin);
}
/**
* Get list of supported audio output device
*/
std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void)
{
_debug ("Manager: Get audio output device list");
AlsaLayer *layer;
std::vector<std::string> devices;
layer = dynamic_cast<AlsaLayer*> (getAudioDriver());
if (layer)
devices = layer -> getSoundCardsInfo (SFL_PCM_PLAYBACK);
return devices;
}
/**
* Set audio output device
*/
......@@ -2424,6 +2384,24 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
}
/**
* Get list of supported audio output device
*/
std::vector<std::string> ManagerImpl::getAudioOutputDeviceList (void)
{
_debug ("Manager: Get audio output device list");
AlsaLayer *layer;
std::vector<std::string> devices;
layer = dynamic_cast<AlsaLayer*> (getAudioDriver());
if (layer)
devices = layer -> getSoundCardsInfo (SFL_PCM_PLAYBACK);
return devices;
}
/**
* Get list of supported audio input device
*/
......@@ -2615,9 +2593,8 @@ void ManagerImpl::setAudioManager (const int32_t& api)
{
int type;
std::string alsaPlugin;
_debug ("Setting audio manager ");
_debug ("Manager: Setting audio manager ");
if (!_audiodriver)
return;
......@@ -2625,7 +2602,7 @@ void ManagerImpl::setAudioManager (const int32_t& api)
type = _audiodriver->getLayerType();
if (type == api) {
_debug ("Audio manager chosen already in use. No changes made. ");
_debug ("Manager: Audio manager chosen already in use. No changes made. ");
return;
}
......@@ -2645,7 +2622,7 @@ int32_t ManagerImpl::getAudioManager (void)
void ManagerImpl::notifyErrClient (const int32_t& errCode)
{
if (_dbus) {
_debug ("NOTIFY ERR NUMBER %i" , errCode);
_debug ("Manager: NOTIFY ERR NUMBER %i" , errCode);
_dbus -> getConfigurationManager() -> errorAlert (errCode);
}
}
......@@ -2654,7 +2631,7 @@ int ManagerImpl::getAudioDeviceIndex (const std::string name)
{
AlsaLayer *alsalayer;
_debug ("Get audio device index");
_debug ("Manager: Get audio device index");
alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver());
......@@ -2668,14 +2645,14 @@ std::string ManagerImpl::getCurrentAudioOutputPlugin (void)
{
AlsaLayer *alsalayer;
_debug ("Get alsa plugin");
_debug ("Manager: Get alsa plugin");
alsalayer = dynamic_cast<AlsaLayer *> (getAudioDriver());
if (alsalayer)
return alsalayer -> getAudioPlugin();
else
return audioPreference.getPlugin();
// if (alsalayer)
// return alsalayer -> getAudioPlugin();
// else
return audioPreference.getPlugin();
}
......
......@@ -568,13 +568,14 @@ class ManagerImpl
* Set input audio plugin
* @param audioPlugin The audio plugin
*/
void setInputAudioPlugin (const std::string& audioPlugin);
void setAudioPlugin (const std::string& audioPlugin);
/**
* Set output audio plugin
* @param audioPlugin The audio plugin
*/
void setOutputAudioPlugin (const std::string& audioPlugin);
* Set audio device
* @param index The index of the soundcard
* @param the type of stream, either SFL_PCM_PLAYBACK, SFL_PCM_CAPTURE, SFL_PCM_RINGTONE
*/
void setAudioDevice (const int index, const int streamType);
/**
* Get list of supported audio output device
......@@ -582,13 +583,6 @@ class ManagerImpl
*/
std::vector<std::string> getAudioOutputDeviceList (void);
/**
* Set audio device
* @param index The index of the soundcard
* @param the type of stream, either SFL_PCM_PLAYBACK, SFL_PCM_CAPTURE, SFL_PCM_RINGTONE
*/
void setAudioDevice (const int index, const int streamType);
/**
* Get list of supported audio input device
* @return std::vector<std::string> A list of the audio devices supporting capture
......@@ -596,7 +590,7 @@ class ManagerImpl
std::vector<std::string> getAudioInputDeviceList (void);
/**
* Get string array representing integer indexes of output and input device
* Get string array representing integer indexes of output, input, and ringtone device
* @return std::vector<std::string> A list of the current audio devices
*/
std::vector<std::string> getCurrentAudioDevicesIndex();
......
......@@ -569,97 +569,123 @@ void AudioPreference::unserialize (Conf::MappingNode *map)
if (!map)
return;
Conf::MappingNode *alsamap = NULL;
Conf::MappingNode *pulsemap = NULL;
Conf::ScalarNode *val = NULL;
val = (Conf::ScalarNode *) (map->getValue (cardinKey));
val = (Conf::ScalarNode *) (map->getValue (recordpathKey));
if (val) {
_cardin = atoi (val->getValue().data());
_recordpath = val->getValue();
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (cardoutKey));
val = (Conf::ScalarNode *) (map->getValue (volumemicKey));
if (val) {
_cardout = atoi (val->getValue().data());
_volumemic = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (cardringKey));
val = (Conf::ScalarNode *) (map->getValue (volumespkrKey));
if (val) {
_cardring = atoi (val->getValue().data());
_volumespkr = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (framesizeKey));
val = (Conf::ScalarNode *) (map->getValue (noiseReduceKey));
if (val) {
_framesize = atoi (val->getValue().data());
_noisereduce = (val->getValue() == "true");
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (smplrateKey));
val = (Conf::ScalarNode *) (map->getValue (echocancelKey));
if (val) {
_smplrate = atoi (val->getValue().data());
_echocancel = (val->getValue() == "true");
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (devicePlaybackKey));
alsamap = (Conf::MappingNode *) (map->getValue ("alsa"));
if (val) {
_devicePlayback = val->getValue();
val = NULL;
}
// did found alsa
if (alsamap) {
val = (Conf::ScalarNode *) (map->getValue (deviceRecordKey));
val = (Conf::ScalarNode *) (alsamap->getValue (cardinKey));
if (val) {
_deviceRecord = val->getValue();
val = NULL;
}
if (val) {
_cardin = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (deviceRingtoneKey));
val = (Conf::ScalarNode *) (alsamap->getValue (cardoutKey));
if (val) {
_deviceRingtone = val->getValue();
val = NULL;
}
if (val) {
_cardout = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (recordpathKey));
val = (Conf::ScalarNode *) (alsamap->getValue (cardringKey));
if (val) {
_recordpath = val->getValue();
val = NULL;
}
if (val) {
_cardring = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (volumemicKey));
val = (Conf::ScalarNode *) (alsamap->getValue (framesizeKey));
if (val) {
_volumemic = atoi (val->getValue().data());
val = NULL;
}
if (val) {
_framesize = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (volumespkrKey));
val = (Conf::ScalarNode *) (alsamap->getValue (smplrateKey));
if (val) {
_volumespkr = atoi (val->getValue().data());
val = NULL;
}
if (val) {
_smplrate = atoi (val->getValue().data());
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (noiseReduceKey));
val = (Conf::ScalarNode *) (alsamap->getValue (pluginKey));
if (val) {
_plugin = val->getValue();
val = NULL;
}
if (val) {
_noisereduce = (val->getValue() == "true");
val = NULL;
}
val = (Conf::ScalarNode *) (map->getValue (echocancelKey));
if (val) {
_echocancel = (val->getValue() == "true");
val = NULL;
pulsemap = (Conf::MappingNode *) (map->getValue ("pulse"));
if (pulsemap) {
val = (Conf::ScalarNode *) (pulsemap->getValue (devicePlaybackKey));
if (val) {
_devicePlayback = val->getValue();
val = NULL;
}
val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRecordKey));
if (val) {
_deviceRecord = val->getValue();
val = NULL;
}
val = (Conf::ScalarNode *) (pulsemap->getValue (deviceRingtoneKey));
if (val) {
_deviceRingtone = val->getValue();
val = NULL;
}
}
}
......
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