diff --git a/sflphone-gtk/src/configwindow.c b/sflphone-gtk/src/configwindow.c index b977faeb4498899886a7aa36b3917fad3bfe0873..09e8df54137bc47dc5bbe0e80429151148407562 100644 --- a/sflphone-gtk/src/configwindow.c +++ b/sflphone-gtk/src/configwindow.c @@ -27,6 +27,7 @@ #include <mainwindow.h> #include <stdlib.h> +#include <stdio.h> #include <gtk/gtk.h> @@ -48,6 +49,9 @@ GtkWidget *deleteButton; GtkWidget *defaultButton; GtkWidget *restoreButton; +GtkWidget *outputDeviceComboBox; +GtkWidget *inputDeviceComboBox; + GtkWidget *moveUpButton; GtkWidget *moveDownButton; @@ -133,7 +137,7 @@ config_window_fill_codec_list() } /** - * TODO + * Fill store with audio managers */ void config_window_fill_audio_manager_list() @@ -158,13 +162,14 @@ config_window_fill_audio_manager_list() } /** - * TODO + * Fill output audio device store */ void config_window_fill_output_audio_device_list() { GtkTreeIter iter; gchar** list; + gchar** details; gchar* audioDevice; gtk_list_store_clear(outputAudioDeviceManagerStore); @@ -177,19 +182,56 @@ config_window_fill_output_audio_device_list() for(audioDevice = list[c]; audioDevice != NULL; audioDevice = list[c]) { c++; + int index = atoi(audioDevice); + details = dbus_get_audio_device_details(index); gtk_list_store_append(outputAudioDeviceManagerStore, &iter); - gtk_list_store_set(outputAudioDeviceManagerStore, &iter, 0 , audioDevice, -1); + gtk_list_store_set(outputAudioDeviceManagerStore, &iter, 0, details[0], 1, index, -1); } } /** - * TODO + * Select active output audio device + */ +void +select_active_output_audio_device() +{ + 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]); + model = gtk_combo_box_get_model(GTK_COMBO_BOX(outputDeviceComboBox)); + + // 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(outputDeviceComboBox), &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(outputDeviceComboBox), 0); +} + +/** + * Fill input audio device store */ void config_window_fill_input_audio_device_list() { GtkTreeIter iter; gchar** list; + gchar** details; gchar* audioDevice; gtk_list_store_clear(inputAudioDeviceManagerStore); @@ -202,36 +244,101 @@ config_window_fill_input_audio_device_list() for(audioDevice = list[c]; audioDevice != NULL; audioDevice = list[c]) { c++; + int index = atoi(audioDevice); + details = dbus_get_audio_device_details(index); gtk_list_store_append(inputAudioDeviceManagerStore, &iter); - gtk_list_store_set(inputAudioDeviceManagerStore, &iter, 0 , audioDevice, -1); + gtk_list_store_set(inputAudioDeviceManagerStore, &iter, 0, details[0], 1, index, -1); } } /** - * TODO + * Select active input audio device + */ +void +select_active_input_audio_device() +{ + GtkTreeModel* model; + GtkTreeIter iter; + gchar** devices; + int currentDeviceIndex; + int deviceIndex; + + // Select active input device on server + devices = dbus_get_current_audio_devices_index(); + currentDeviceIndex = atoi(devices[1]); + model = gtk_combo_box_get_model(GTK_COMBO_BOX(inputDeviceComboBox)); + + // 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(inputDeviceComboBox), &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(inputDeviceComboBox), 0); +} + +/** + * Select the audio manager by calling the server + * Not yet used because audio manager is by default ALSA */ static void select_audio_manager(GtkWidget* widget, gpointer data) { - dbus_set_audio_manager("ALSA"); + //dbus_set_audio_manager(""); } /** - * + * Set the audio output device on the server with its index */ static void -select_audio_output_device(GtkWidget* widget, gpointer data) +select_audio_output_device(GtkComboBox* comboBox, gpointer data) { - dbus_set_audio_output_device(8); + 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_output_device(deviceIndex); + } } /** - * + * Set the audio input device on the server with its index */ static void -select_audio_input_device(GtkWidget* widget, gpointer data) +select_audio_input_device(GtkComboBox* comboBox, gpointer data) { - dbus_set_audio_input_device(11); + 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_input_device(deviceIndex); + } } /** @@ -240,14 +347,13 @@ select_audio_input_device(GtkWidget* widget, gpointer data) static void detect_all_audio_settings() { - // TODO Remember selected entry for each list - // Update lists - config_window_fill_audio_manager_list(); - config_window_fill_output_audio_device_list(); - config_window_fill_input_audio_device_list(); +// config_window_fill_output_audio_device_list(); +// config_window_fill_input_audio_device_list(); - // Reselect entries or set to default + // Select active device in combo box +// select_active_output_audio_device(); +// select_active_input_audio_device(); } /** @@ -812,19 +918,19 @@ create_audio_tab () gtk_table_attach(GTK_TABLE(deviceTable), titleLabel, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_widget_show(titleLabel); // Set choices of output devices - outputAudioDeviceManagerStore = gtk_list_store_new(1, G_TYPE_STRING); - config_window_fill_output_audio_device_list(); - comboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputAudioDeviceManagerStore)); - gtk_combo_box_set_active(GTK_COMBO_BOX(comboBox), 0); - gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), comboBox); - g_signal_connect(G_OBJECT(comboBox), "changed", G_CALLBACK(select_audio_output_device), comboBox); + outputAudioDeviceManagerStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); +// config_window_fill_output_audio_device_list(); + outputDeviceComboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(outputAudioDeviceManagerStore)); +// select_active_output_audio_device(); + gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), outputDeviceComboBox); + g_signal_connect(G_OBJECT(outputDeviceComboBox), "changed", G_CALLBACK(select_audio_output_device), outputDeviceComboBox); // Set rendering renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(comboBox), renderer, TRUE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(comboBox), renderer, "text", 0, NULL); - gtk_table_attach(GTK_TABLE(deviceTable), comboBox, 2, 3, 1, 2, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); - gtk_widget_show(comboBox); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(outputDeviceComboBox), renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(outputDeviceComboBox), renderer, "text", 0, NULL); + gtk_table_attach(GTK_TABLE(deviceTable), outputDeviceComboBox, 2, 3, 1, 2, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); + gtk_widget_show(outputDeviceComboBox); // Device : Input device // Create title label @@ -833,19 +939,19 @@ create_audio_tab () gtk_table_attach(GTK_TABLE(deviceTable), titleLabel, 1, 2, 2, 3, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); gtk_widget_show(titleLabel); // Set choices of output devices - inputAudioDeviceManagerStore = gtk_list_store_new(1, G_TYPE_STRING); - config_window_fill_input_audio_device_list(); - comboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputAudioDeviceManagerStore)); - gtk_combo_box_set_active(GTK_COMBO_BOX(comboBox), 0); - gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), comboBox); - g_signal_connect(G_OBJECT(comboBox), "changed", G_CALLBACK(select_audio_input_device), comboBox); + inputAudioDeviceManagerStore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT); +// config_window_fill_input_audio_device_list(); + inputDeviceComboBox = gtk_combo_box_new_with_model(GTK_TREE_MODEL(inputAudioDeviceManagerStore)); +// select_active_input_audio_device(); + gtk_label_set_mnemonic_widget(GTK_LABEL(titleLabel), inputDeviceComboBox); + g_signal_connect(G_OBJECT(inputDeviceComboBox), "changed", G_CALLBACK(select_audio_input_device), inputDeviceComboBox); // Set rendering renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(comboBox), renderer, TRUE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(comboBox), renderer, "text", 0, NULL); - gtk_table_attach(GTK_TABLE(deviceTable), comboBox, 2, 3, 2, 3, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); - gtk_widget_show(comboBox); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(inputDeviceComboBox), renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(inputDeviceComboBox), renderer, "text", 0, NULL); + gtk_table_attach(GTK_TABLE(deviceTable), inputDeviceComboBox, 2, 3, 2, 3, GTK_FILL | GTK_EXPAND, GTK_SHRINK, 0, 0); + gtk_widget_show(inputDeviceComboBox); // Create detect button refreshButton = gtk_button_new_with_label("Detect all"); diff --git a/sflphone-gtk/src/configwindow.h b/sflphone-gtk/src/configwindow.h index 3597e5cbc370999af6305b89b11b9e3e5ad4b0bc..f22909a2fcd64b003e4fe2ae454402746e1fc22c 100644 --- a/sflphone-gtk/src/configwindow.h +++ b/sflphone-gtk/src/configwindow.h @@ -28,10 +28,11 @@ */ void config_window_fill_account_list(); void config_window_fill_codec_list(); -void show_config_window(); void config_window_fill_audio_manager_list(); void config_window_fill_output_audio_device_list(); +void select_active_output_audio_device(); void config_window_fill_input_audio_device_list(); +void select_active_input_audio_device(); void default_account(GtkWidget *widget, gpointer data); void bold_if_default_account(GtkTreeViewColumn *col, GtkCellRenderer *rend, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data); void default_codecs(GtkWidget* widget, gpointer data); diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index 2b53fae28b1189aced9bf18dddb1d7271389fc5b..667b6eee5e113f966244b145b0cf0cfd06557e45 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -76,27 +76,19 @@ class AudioLayer { * Get the sample rate of audiolayer * accessor only */ + int getIndexIn() { return _indexIn; } + int getIndexOut() { return _indexOut; } unsigned int getSampleRate() { return _sampleRate; } unsigned int getFrameSize() { return _frameSize; } int getDeviceCount(); - - - - - - // NOW void selectPreferedApi(PaHostApiTypeId apiTypeID, int& outputDeviceIndex, int& inputDeviceIndex); std::vector<std::string> getAudioDeviceList(PaHostApiTypeId apiTypeID, int ioDeviceMask); -// void setOutputAudioDevice(int index); -// std::vector<std::string> getInputAudioDeviceList(); -// void setInputAudioDevice(int index); -// std::vector<AudioDevice*> getAudioDevicesInfo(); - - + + AudioDevice* getAudioDeviceInfo(int index, int ioDeviceMask); enum IODEVICE {InputDevice=0x01, OutputDevice=0x02 }; diff --git a/src/managerimpl.cpp b/src/managerimpl.cpp index 3152c81bbe754a3c6d157a846bfb40992223881b..ecad7b08801cb0c6a88960f65e3d89f4f75ffac8 100644 --- a/src/managerimpl.cpp +++ b/src/managerimpl.cpp @@ -1214,7 +1214,7 @@ ManagerImpl::getAudioManagerList(void) std::vector<std::string> v; _debug("Get audio manager list"); - // Return only ALSA for now, pulseAudio maybe later + // Return only ALSA for now v.push_back("ALSA"); return v; } @@ -1246,7 +1246,8 @@ void ManagerImpl::setAudioOutputDevice(const int index) { _debug("Set audio output device"); - printf("%l audio output set\n", index); + _audiodriver->openDevice(_audiodriver->getIndexIn(), index, _audiodriver->getSampleRate(), _audiodriver->getFrameSize()); + printf("%d audio output set\n", index); } /** @@ -1265,9 +1266,9 @@ ManagerImpl::getAudioInputDeviceList(void) void ManagerImpl::setAudioInputDevice(const int index) { - // TODO _debug("Set audio input device"); - printf("%l audio input set\n", index); + _audiodriver->openDevice(index, _audiodriver->getIndexOut(), _audiodriver->getSampleRate(), _audiodriver->getFrameSize()); + printf("%d audio input set\n", index); } /** @@ -1276,12 +1277,14 @@ ManagerImpl::setAudioInputDevice(const int index) std::vector<std::string> ManagerImpl::getCurrentAudioDevicesIndex() { - // TODO _debug("Get current audio devices index"); std::vector<std::string> v; - v.push_back("6"); - v.push_back("12"); + char index[10]; + sprintf(index, "%d", _audiodriver->getIndexOut()); + v.push_back(index); + sprintf(index, "%d", _audiodriver->getIndexIn()); + v.push_back(index); return v; } @@ -1292,15 +1295,24 @@ ManagerImpl::getCurrentAudioDevicesIndex() std::vector<std::string> ManagerImpl::getAudioDeviceDetails(const int index) { - // TODO _debug("Get audio input device list"); std::vector<std::string> v; - - v.push_back("default"); - v.push_back("128"); - v.push_back("128"); - v.push_back("44100"); - + + try + { + portaudio::System& sys = portaudio::System::instance(); + portaudio::Device& device = sys.deviceByIndex(index); + + char answer[10]; + v.push_back(device.name()); + sprintf(answer, "%d", device.maxInputChannels()); + v.push_back(answer); + sprintf(answer, "%d", device.maxOutputChannels()); + v.push_back(answer); + sprintf(answer, "%d", device.defaultSampleRate()); + v.push_back(answer); + } + catch (...) {} return v; }