Mercurial > audlegacy-plugins
changeset 2647:5808b64d3f68
branch merge
author | Paula Stanciu <paula.stanciu@gmail.com> |
---|---|
date | Sun, 25 May 2008 21:29:48 +0300 |
parents | 7fbff3287a56 (diff) 45ef6d7c0174 (current diff) |
children | 6cc858a726b8 |
files | src/alsa/init.c |
diffstat | 6 files changed, 505 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Sun May 25 20:03:48 2008 +0300 +++ b/configure.ac Sun May 25 21:29:48 2008 +0300 @@ -1372,6 +1372,26 @@ AC_SUBST(MTP_LIBS) AC_SUBST(MTP_CFLAGS) +dnl *** Bluetooth audio suport + +AC_ARG_ENABLE(bluetooth, +[ --disable-bluetooth disable bluetooth audio support. (default=enabled)], +[have_bluetooth=$enableval], +[have_bluetooth=yes]) + +if test "x$have_bluetooth" = "xyes"; then + have_bluetooth=yes + PKG_CHECK_MODULES(BLUEZ, [bluez >= 2.22], + [GENERAL_PLUGINS="$GENERAL_PLUGINS bluetooth" ], [have_bluetooth="no"]) + BLUEZ_LIBS=`pkg-config --libs bluez` + BLUEZ_CFLAGS=`pkg-config --cflags bluez` +else + have_bluetooth=no + AC_MSG_RESULT([*** bluetooth audio suport plugin disabled by request ***]) +fi +AC_SUBST(BLUEZ_LIBS) +AC_SUBST(BLUEZ_CFLAGS) + dnl *** libparanormal checks AC_ARG_ENABLE(paranormal, @@ -1687,6 +1707,7 @@ echo " LIRC: $have_lirc" echo " AudioScrobbler Client: $scrobbler" echo " Upload to MTP device: $have_mtp_up" +echo " Bluetooth audio suport: $have_bluetooth" echo " MacOS Dock Album Art plugin: $have_dockalbumart" echo echo " Effect"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/Makefile Sun May 25 21:29:48 2008 +0300 @@ -0,0 +1,11 @@ +PLUGIN = bluetooth${PLUGIN_SUFFIX} + +SRCS = bluetooth.c gui.c marshal.c +include ../../buildsys.mk +include ../../extra.mk + +plugindir := ${plugindir}/${GENERAL_PLUGIN_DIR} + +CFLAGS += ${PLUGIN_CFLAGS} +CPPFLAGS += ${PLUGIN_CPPFLAGS} ${BEEP_DEFINES} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${GTK_CFLAGS} ${GLIB_CFLAGS} ${PANGO_CFLAGS} -I../../intl -I../.. ${BLUEZ_CFLAGS} +LIBS += ${GTK_LIBS} ${GLIB_LIBS} ${PANGO_LIBS} ${BLUEZ_LIBS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/bluetooth.c Sun May 25 21:29:48 2008 +0300 @@ -0,0 +1,189 @@ +#include <dbus/dbus.h> +#include <dbus/dbus-glib.h> +#include <glib-object.h> +#include <stdio.h> +#include "bluetooth.h" +#include "marshal.h" +#include "gui.h" + +#define DEBUG 1 +static gboolean plugin_active = FALSE,exiting=FALSE; +GList * current_device = NULL; +DBusGConnection * bus = NULL; +gint discover_finish =0; +GStaticMutex mutex = G_STATIC_MUTEX_INIT; + +void bluetooth_init ( void ); +void bluetooth_cleanup ( void ); +void bt_cfg(void); +void bt_about(void); +static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data); +static void discovery_started(DBusGProxy *object, gpointer user_data); +static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data); +static void print_results(void); +static void discovery_completed(DBusGProxy *object, gpointer user_data); +void discover_devices(void); + + + +GeneralPlugin bluetooth_gp = +{ + .description = "Bluetooth audio suport", + .init = bluetooth_init, + .about = bt_about, + .configure = bt_cfg, + .cleanup = bluetooth_cleanup +}; +GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL }; +DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL) +void bluetooth_init ( void ) +{ + audio_devices = NULL; + discover_devices(); +} + +void bluetooth_cleanup ( void ) +{ + printf("bluetooth: exit\n"); + dbus_g_connection_flush (bus); + dbus_g_connection_unref(bus); + +} +/*void bt_cfg( void ) + { + + } + */ +void bt_about( void ) +{ + +} + + +void refresh_call(void){ + discover_devices() + printf("refresh function called\n"); +} + +void connect_call(void){ + printf("connect function \n"); +} + + +static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) +{ + int found_in_list=FALSE; + g_static_mutex_lock(&mutex); + current_device = audio_devices; + if((class & 0x200404)==0x200404) + { + + while(current_device != NULL) + { + if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) + { + found_in_list = TRUE; + break; + } + current_device=g_list_next(current_device); + } + if(!found_in_list) + { + DeviceData *dev= g_new0(DeviceData, 1); + dev->class = class; + dev->address = g_strdup(address); + dev->name = NULL; + audio_devices=g_list_prepend(audio_devices, dev); + + } + } + g_static_mutex_unlock(&mutex); +} + +static void discovery_started(DBusGProxy *object, gpointer user_data) +{ + g_print("Signal: DiscoveryStarted()\n"); +} + +static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data) +{ + g_static_mutex_lock(&mutex); + current_device=audio_devices; + while(current_device != NULL) + { + if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) + { + ((DeviceData*)(current_device->data))->name=g_strdup(name); + break; + } + current_device=g_list_next(current_device); + } + g_static_mutex_unlock(&mutex); +} +static void print_results() +{ + int i=0; + g_print("Final Scan results:\n"); + g_print("Number of audio devices: %d \n",g_list_length(audio_devices)); + current_device=audio_devices; + while(current_device != NULL) + { + g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, + ((DeviceData*)(current_device->data))-> name, + ((DeviceData*)(current_device->data))-> class, + ((DeviceData*)(current_device->data))-> address); + + current_device=g_list_next(current_device); + } + + refresh_tree(); +} + +static void discovery_completed(DBusGProxy *object, gpointer user_data) +{ + g_print("Signal: DiscoveryCompleted()\n"); + print_results(); + + +} + + +void discover_devices(void){ + GError *error = NULL; + DBusGProxy * obj = NULL; + g_type_init(); + g_log_set_always_fatal (G_LOG_LEVEL_WARNING); + + bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (error != NULL) + { + g_printerr("Connecting to system bus failed: %s\n", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } + obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); + + dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_INT, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL); + + dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL); + + dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL); + + dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL); + + dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID); + if (error != NULL) + { + g_printerr("Failed to discover devices: %s\n", error->message); + g_error_free(error); + exit(EXIT_FAILURE); + } + // / dbus_g_connection_flush (bus); + // dbus_g_connection_unref(bus); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/bluetooth.h Sun May 25 21:29:48 2008 +0300 @@ -0,0 +1,22 @@ +#include <config.h> + +#include <glib.h> +#include <sys/types.h> +#include <audacious/plugin.h> +#include <audacious/ui_plugin_menu.h> +#include <audacious/i18n.h> +#include <gtk/gtk.h> +#include <audacious/util.h> +#include "gui.h" +typedef struct { + guint class; + gchar* address; + gchar* name; +}DeviceData; + + + +void refresh_call(void); +void connect_call(void); +GList * audio_devices; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/bluetooth/gui.c Sun May 25 21:29:48 2008 +0300 @@ -0,0 +1,259 @@ +#include "gui.h" +#include "bluetooth.h" + +static GtkWidget *window = NULL; +static GtkTreeModel *model; +GtkWidget *mainbox; +GtkWidget *hbox_top; +GtkWidget *hbox_bottom; +GtkWidget *box_about; +GtkWidget *box_about_left; +GtkWidget *box_about_right; +GtkWidget *headset_frame; +GtkWidget *about_frame; +GtkWidget *refresh; +GtkWidget *connect_button; +GtkWidget *close_button; +GtkWidget *treeview; +GtkWidget *label_p; +GtkWidget *label_c; +GtkWidget *label_a; +GtkWidget *label_prod; +GtkWidget *label_class; +GtkWidget *label_address; +GList * dev = NULL; +enum{ + COLUMN_PRODUCER, + NUM_COLUMNS +}; +static DeviceData test_data[]= +{ + {0,"00:00:00:00:00","Scanning"} +}; + + +static GtkTreeModel * create_model(void) +{ + GtkListStore *store; + GtkTreeIter iter; + gint i=0; + /* create list store */ + store = gtk_list_store_new(NUM_COLUMNS, + G_TYPE_STRING); + + /* add data to the list store */ + for(i = 0;i<G_N_ELEMENTS(test_data);i++) + { + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter, + COLUMN_PRODUCER, test_data[i].name,-1); + } + + return GTK_TREE_MODEL(store); +} +static GtkTreeModel * rebuild_model(void) +{ + + GtkListStore *store; + GtkTreeIter iter; + gint i=0; + gint dev_no=0; + GList *dev; + gchar *temp; + /* create list store */ + store = gtk_list_store_new(NUM_COLUMNS, + G_TYPE_STRING); + + /*add inf to test_data from audio_devices */ + dev_no = g_list_length(audio_devices); + dev = audio_devices; + while(dev != NULL) + { + test_data[i].name = ((DeviceData*)(dev->data))-> name; + test_data[i].class = ((DeviceData*)(dev->data))-> class; + test_data[i].address = ((DeviceData*)(dev->data))-> address; + i++; + dev=g_list_next(dev); + } + if (dev_no == 0) + { + test_data[0].name = "No devices found!"; + test_data[0].class = 0; + test_data[0].address = "00:00:00:00:00"; + } + + /* add data to the list store */ + for(i = 0;i<G_N_ELEMENTS(test_data);i++) + { + gtk_list_store_append(store,&iter); + gtk_list_store_set(store,&iter, + COLUMN_PRODUCER, test_data[i].name,-1); + } + //set the labels + temp = g_strdup_printf("0x%x",test_data[0].class); + gtk_label_set_text(GTK_LABEL(label_prod),test_data[0].name); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),test_data[0].address); + + return GTK_TREE_MODEL(store); + +} + + +void refresh_tree() +{ + model = rebuild_model(); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),GTK_TREE_MODEL(model)); +} + + +static void add_columns(GtkTreeView *treeview) +{ + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + // GtkTreeModel *model = gtk_tree_view_get_model (treeview); + + /* column for producer */ + renderer = gtk_cell_renderer_text_new (); + column = gtk_tree_view_column_new_with_attributes ("Producer", + renderer, + "text", + COLUMN_PRODUCER, + NULL); + gtk_tree_view_column_set_sort_column_id (column,COLUMN_PRODUCER); + gtk_tree_view_append_column (treeview, column); + +} + +void close_call(void){ + printf("close callback \n"); + gtk_widget_destroy (window); + window = NULL; +} +void select_row(GtkWidget *treeview){ + + GtkTreeIter iter; + gint sel; + gchar *temp; + printf("select\n"); + GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(treeview)); + if(gtk_tree_selection_get_selected (selection, NULL,&iter)){ + GtkTreePath *path; + path = gtk_tree_model_get_path (model, &iter); + sel = gtk_tree_path_get_indices (path)[0]; + printf("i=%d\n",sel); + temp = g_strdup_printf("0x%x",test_data[sel].class); + gtk_label_set_text(GTK_LABEL(label_prod),test_data[sel].name); + gtk_label_set_text(GTK_LABEL(label_class),temp); + gtk_label_set_text(GTK_LABEL(label_address),test_data[sel].address); + gtk_tree_path_free (path); + g_free(temp); + + } + + + +} +void bt_cfg() +{ + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy",G_CALLBACK (gtk_widget_destroyed), &window); + + mainbox = gtk_vbox_new(FALSE,4); + gtk_container_set_border_width (GTK_CONTAINER (mainbox), 4); + gtk_container_add (GTK_CONTAINER (window), mainbox); + + hbox_top = gtk_hbox_new(FALSE,4); + gtk_container_set_border_width (GTK_CONTAINER(hbox_top), 4); + gtk_container_add (GTK_CONTAINER (mainbox), hbox_top); + + hbox_bottom = gtk_hbox_new(FALSE,4); + gtk_container_set_border_width (GTK_CONTAINER (hbox_bottom), 4); + gtk_container_add (GTK_CONTAINER (mainbox), hbox_bottom); + + headset_frame = gtk_frame_new("Available Headsets"); + gtk_container_add (GTK_CONTAINER (hbox_top), headset_frame); + + about_frame = gtk_frame_new("Current Headset"); + gtk_container_add(GTK_CONTAINER(hbox_top),about_frame); + + refresh = gtk_button_new_with_mnemonic ("_Refresh"); + g_signal_connect (refresh, "clicked",G_CALLBACK (refresh_call), NULL); + gtk_container_add(GTK_CONTAINER(hbox_bottom),refresh); + + connect_button = gtk_button_new_with_mnemonic("_Connect"); + g_signal_connect(connect_button,"clicked",G_CALLBACK (connect_call), NULL); + gtk_container_add(GTK_CONTAINER(hbox_bottom),connect_button); + + close_button = gtk_button_new_with_mnemonic("_Close"); + g_signal_connect(close_button,"clicked",G_CALLBACK (close_call),NULL); + gtk_container_add(GTK_CONTAINER(hbox_bottom),close_button); + /* create tree model */ + model = create_model (); + + /* create tree view */ + treeview = gtk_tree_view_new_with_model (model); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE); + gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),GTK_SELECTION_SINGLE); + g_object_unref (model); + gtk_container_add (GTK_CONTAINER (headset_frame), treeview); + /* add columns to the tree view */ + add_columns (GTK_TREE_VIEW (treeview)); + + g_signal_connect(treeview,"cursor-changed",G_CALLBACK(select_row),treeview); + + + box_about = gtk_hbox_new(FALSE,4); + gtk_container_set_border_width (GTK_CONTAINER (box_about), 4); + gtk_container_add (GTK_CONTAINER (about_frame), box_about); + + /*about box left - vbox */ + + box_about_left = gtk_vbox_new(FALSE,4); + gtk_container_set_border_width (GTK_CONTAINER (box_about_left), 4); + gtk_container_add (GTK_CONTAINER (box_about), box_about_left); + + /*about box right - vbox */ + box_about_right = gtk_vbox_new(TRUE,4); + gtk_container_set_border_width (GTK_CONTAINER (box_about_right), 4); + gtk_container_add (GTK_CONTAINER (box_about), box_about_right); + + /* Left labels */ + label_p = gtk_label_new("Name:"); + gtk_container_add(GTK_CONTAINER(box_about_left),label_p); + + label_c = gtk_label_new("Class"); + gtk_container_add(GTK_CONTAINER(box_about_left),label_c); + + + label_a = gtk_label_new("Address:"); + gtk_container_add(GTK_CONTAINER(box_about_left),label_a); + + + /*right labels */ + label_prod = gtk_label_new("Scanning"); + gtk_container_add(GTK_CONTAINER(box_about_right),label_prod); + + label_class = gtk_label_new(" "); + gtk_container_add(GTK_CONTAINER(box_about_right),label_class); + + + label_address = gtk_label_new(" "); + gtk_container_add(GTK_CONTAINER(box_about_right),label_address); + + gtk_window_set_default_size (GTK_WINDOW (window), 480, 180); + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show_all (window); + else + { + gtk_widget_destroy (window); + window = NULL; + } + // return window; + } + // return window; +} +