Mercurial > audlegacy-plugins
annotate src/bluetooth/bluetooth.c @ 3189:ab6c7ebcd301
alsa-ng: Only support 16bit output for now. Someone else can debug this crap.
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 19 Jun 2009 09:14:22 -0500 |
parents | 3134a0987162 |
children |
rev | line source |
---|---|
2839 | 1 /* |
2 * Audacious Bluetooth headset suport plugin | |
3 * | |
4 * Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; under version 3 of the License. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 * GNU General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program. If not, see <http://www.gnu.org/licenses>. | |
17 */ | |
18 | |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
19 #include <glib/gstdio.h> |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
20 #include <errno.h> |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
21 #include <string.h> |
2644 | 22 #include "bluetooth.h" |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
23 #include "marshal.h" |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
24 #include "gui.h" |
2728 | 25 #include "scan_gui.h" |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
26 #include "agent.h" |
2971
3134a0987162
- changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
2930
diff
changeset
|
27 #include <audlegacy/plugin.h> |
2644 | 28 #define DEBUG 1 |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
29 GList * current_device = NULL; |
2728 | 30 gint config = 0; |
31 gint devices_no = 0; | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
32 GStaticMutex mutex = G_STATIC_MUTEX_INIT; |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
33 static gchar *current_address=NULL; |
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
34 static GThread *connect_th; |
2644 | 35 void bluetooth_init ( void ); |
36 void bluetooth_cleanup ( void ); | |
37 void bt_cfg(void); | |
38 void bt_about(void); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
39 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
40 static void discovery_started(DBusGProxy *object, gpointer user_data); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
41 static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
42 static void print_results(void); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
43 static void discovery_completed(DBusGProxy *object, gpointer user_data); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
44 void discover_devices(void); |
2728 | 45 void disconnect_dbus_signals(void); |
2871
455e6e37feae
removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2870
diff
changeset
|
46 /*static void show_restart_dialog(void); */ |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
47 static void remove_bonding(gchar* device); |
2644 | 48 GeneralPlugin bluetooth_gp = |
49 { | |
2649
d891ba4be5a5
fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2648
diff
changeset
|
50 .description = "Bluetooth audio support", |
2644 | 51 .init = bluetooth_init, |
52 .about = bt_about, | |
53 .configure = bt_cfg, | |
54 .cleanup = bluetooth_cleanup | |
55 }; | |
56 GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL }; | |
57 DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL) | |
2728 | 58 |
2644 | 59 void bluetooth_init ( void ) |
60 { | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
61 audio_devices = NULL; |
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
62 bus = NULL; |
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
63 obj = NULL; |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
64 gchar* bonded_addr="zz"; |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
65 discover_devices(); |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
66 mcs_handle_t *cfgfile ; |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
67 cfgfile = aud_cfg_db_open(); |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
68 if(!aud_cfg_db_get_string(cfgfile, "BLUETOOTH_PLUGIN", "bonded", |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
69 &bonded_addr)) |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
70 return; |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
71 if(bonded_addr!=NULL && g_strcmp0(bonded_addr,"no")!=0) |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
72 { |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
73 remove_bonding(bonded_addr); |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
74 } |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
75 aud_cfg_db_close(cfgfile); |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
76 |
2644 | 77 } |
78 | |
79 void bluetooth_cleanup ( void ) | |
80 { | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
81 printf("bluetooth: exit\n"); |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
82 if (config ==1 ) |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
83 { |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
84 close_window(); |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
85 config =0; |
2649
d891ba4be5a5
fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2648
diff
changeset
|
86 } |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
87 remove_bonding(bonded_dev); |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
88 if(discover_finish == 2) { |
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
89 dbus_g_connection_flush (bus); |
2734 | 90 dbus_g_connection_unref(bus); |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
91 disconnect_dbus_signals(); |
2644 | 92 |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
93 } |
2870
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
94 /* switching back to default pcm device at cleanup */ |
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
95 mcs_handle_t *cfgfile = aud_cfg_db_open(); |
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
96 aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "default"); |
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
97 aud_cfg_db_close(cfgfile); |
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
98 |
2734 | 99 } |
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
100 |
2734 | 101 void bt_about( void ) |
102 { | |
2930
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
103 static GtkWidget *dialog; |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
104 |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
105 dialog = audacious_info_dialog (_("Bluetooth headset support plugin"), |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
106 _("Bluetooth headset support\n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
107 "Copyright (c) 2008 Paula Stanciu paula.stanciu@gmail.com\n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
108 "This was a GSoC 2008 Project - Many thanks to my mentor Tony Vroon and the Audacious team\n \n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
109 "In order to use the AVRCP you need the uinput module loaded into the kernel\n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
110 "The headset keys will be recognized as normal mutimedia keys and \n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
111 "can be configured using the Audacious Global Hotkey plugin or ohter tools \n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
112 "provided by your window manager\n" |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
113 ), |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
114 _("OK"), TRUE, NULL, NULL); |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
115 |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
116 gtk_signal_connect(GTK_OBJECT(dialog), "destroy", |
acfa92d9ff5e
bluetooth headset plugin about box
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2916
diff
changeset
|
117 GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog); |
2882
15754379dbd5
fixed the remove bonding bug and made it thread safe
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2880
diff
changeset
|
118 |
2734 | 119 } |
2728 | 120 |
2734 | 121 void bt_cfg(void) |
122 { | |
123 printf("bt_cfg\n"); | |
124 config =1; | |
125 if(discover_finish == 2){ | |
126 if (devices_no == 0){ | |
127 printf("no devs!\n"); | |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
128 show_scan(0); |
2734 | 129 show_no_devices(); |
130 }else | |
131 results_ui(); | |
2728 | 132 } |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
133 else show_scan(0); |
2734 | 134 printf("end of bt_cfg\n"); |
135 } | |
2728 | 136 |
2734 | 137 void disconnect_dbus_signals() |
138 { | |
139 dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus); | |
140 dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus); | |
141 dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); | |
142 dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); | |
2644 | 143 |
2734 | 144 } |
2644 | 145 |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
146 void clean_devices_list() |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
147 { |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
148 g_list_free(audio_devices); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
149 dbus_g_connection_flush (bus); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
150 dbus_g_connection_unref(bus); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
151 audio_devices = NULL; |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
152 //g_list_free(current_device); |
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
153 } |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
154 static void remove_bonding(gchar *device) |
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
155 { |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
156 printf("remove_bonding call\n"); |
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
157 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); |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
158 dbus_g_proxy_call(obj,"RemoveBonding",NULL,G_TYPE_STRING,device,G_TYPE_INVALID,G_TYPE_INVALID); |
2644 | 159 |
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
160 } |
2734 | 161 void refresh_call(void) |
162 { | |
163 printf("refresh function called\n"); | |
164 disconnect_dbus_signals(); | |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
165 clean_devices_list(); |
2734 | 166 if(discover_finish == 0 ||discover_finish== 2){ |
167 discover_finish = 0; | |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
168 |
2734 | 169 discover_devices(); |
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
170 close_window(); |
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
171 show_scan(0); |
2728 | 172 } |
2734 | 173 else |
174 printf("Scanning please wait!\n"); | |
175 } | |
2644 | 176 |
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
177 gpointer connect_call_th(void) |
2734 | 178 { |
2841 | 179 //I will have to enable the audio service if necessary |
180 run_agents(); | |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
181 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); |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
182 dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
183 |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
184 return NULL; |
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
185 } |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
186 |
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
187 void connect_call(void) |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
188 { |
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
189 close_call(); |
2896
35773e919dba
removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2890
diff
changeset
|
190 close_window(); |
35773e919dba
removed unsed mutex - and a dupplicate function call
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2890
diff
changeset
|
191 show_scan(1); |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
192 current_address = g_strdup(((DeviceData*)(selected_dev->data))->address); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
193 connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; |
2854 | 194 } |
195 | |
196 | |
197 void play_call() | |
198 { | |
199 | |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
200 FILE *file; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
201 FILE *temp_file; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
202 gint prev=0; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
203 char line[128]; |
2871
455e6e37feae
removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2870
diff
changeset
|
204 const gchar *home; |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
205 gchar *device_line; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
206 gchar *file_name=""; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
207 gchar *temp_file_name; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
208 home = g_get_home_dir(); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
209 file_name = g_strconcat(home,"/.asoundrc",NULL); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
210 temp_file_name = g_strconcat(home,"/temp_bt",NULL); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
211 file = fopen(file_name,"r"); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
212 temp_file = fopen(temp_file_name,"w"); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
213 device_line = g_strdup_printf("device %s\n",current_address); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
214 if ( file != NULL ) |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
215 { |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
216 while ( fgets ( line, sizeof line, file ) != NULL ) |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
217 { |
2858
528d19a2ea3d
fixed .asoundrc bug - writeing multiple pcm bluetooth device
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2857
diff
changeset
|
218 if(!(strcmp(line,"pcm.audacious_bt{\n"))){ |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
219 fputs(line,temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
220 fgets ( line, sizeof line, file ); /* type bluetooth */ |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
221 fputs(line,temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
222 fgets ( line, sizeof line, file ); /* device MAC */ |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
223 fputs(device_line,temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
224 prev = 1; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
225 } else |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
226 fputs(line,temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
227 } |
2854 | 228 |
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
229 fclose (file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
230 } |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
231 if(!prev){ |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
232 fputs("pcm.audacious_bt{\n",temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
233 fputs("type bluetooth\n",temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
234 fputs(device_line,temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
235 fputs("}\n",temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
236 prev = 0; |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
237 } |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
238 |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
239 fclose(temp_file); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
240 int err = rename(temp_file_name,file_name); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
241 printf("rename error : %d",err); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
242 perror("zz"); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
243 g_free(device_line); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
244 g_free(file_name); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
245 g_free(temp_file_name); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
246 mcs_handle_t *cfgfile = aud_cfg_db_open(); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
247 aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "audacious_bt"); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
248 aud_cfg_db_close(cfgfile); |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
249 |
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
250 printf("play callback\n"); |
2857 | 251 close_window(); |
2868
9e9293b87392
playing without restart
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2867
diff
changeset
|
252 aud_output_plugin_cleanup(); |
2916
223822ba79f2
writing bonded device to the config file so it can be unbounded at start-up when
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2896
diff
changeset
|
253 // audacious_drct_stop(); |
2868
9e9293b87392
playing without restart
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2867
diff
changeset
|
254 audacious_drct_play(); |
2854 | 255 |
256 | |
257 } | |
2871
455e6e37feae
removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2870
diff
changeset
|
258 /*static void show_restart_dialog() |
2857 | 259 { |
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
260 static GtkWidget *window = NULL; |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
261 GtkWidget *dialog; |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
262 dialog = gtk_message_dialog_new (GTK_WINDOW (window), |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
263 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
264 GTK_MESSAGE_INFO, |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
265 GTK_BUTTONS_OK, |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
266 "Please restart the player to apply the bluetooth audio settings!"); |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
267 gtk_dialog_run (GTK_DIALOG (dialog)); |
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
268 gtk_widget_destroy (dialog); |
2857 | 269 } |
2871
455e6e37feae
removed the warnings
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2870
diff
changeset
|
270 */ |
2734 | 271 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) |
272 { | |
273 int found_in_list=FALSE; | |
274 g_static_mutex_lock(&mutex); | |
275 current_device = audio_devices; | |
276 if((class & 0x200404)==0x200404) | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
277 { |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
278 while(current_device != NULL) |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
279 { |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
280 if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
281 { |
2734 | 282 found_in_list = TRUE; |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
283 break; |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
284 } |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
285 current_device=g_list_next(current_device); |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
286 } |
2734 | 287 if(!found_in_list) |
288 { | |
289 DeviceData *dev= g_new0(DeviceData, 1); | |
290 dev->class = class; | |
291 dev->address = g_strdup(address); | |
292 dev->name = NULL; | |
293 audio_devices=g_list_prepend(audio_devices, dev); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
294 } |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
295 } |
2734 | 296 g_static_mutex_unlock(&mutex); |
297 } | |
298 | |
299 static void discovery_started(DBusGProxy *object, gpointer user_data) | |
300 { | |
301 g_print("Signal: DiscoveryStarted()\n"); | |
302 discover_finish = 1; | |
303 } | |
304 | |
305 static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data) | |
306 { | |
307 g_static_mutex_lock(&mutex); | |
308 current_device=audio_devices; | |
309 while(current_device != NULL) | |
310 { | |
311 if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) | |
312 { | |
313 ((DeviceData*)(current_device->data))->name=g_strdup(name); | |
314 break; | |
315 } | |
316 current_device=g_list_next(current_device); | |
317 } | |
318 g_static_mutex_unlock(&mutex); | |
319 } | |
320 | |
321 static void print_results() | |
322 { | |
323 int i=0; | |
324 g_print("Final Scan results:\n"); | |
325 devices_no = g_list_length(audio_devices); | |
326 g_print("Number of audio devices: %d \n",devices_no); | |
327 if(devices_no==0 ) { | |
328 if(config ==1) show_no_devices(); | |
329 } else { | |
330 current_device=audio_devices; | |
331 while(current_device != NULL) | |
332 { | |
333 g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, | |
334 ((DeviceData*)(current_device->data))-> name, | |
335 ((DeviceData*)(current_device->data))-> class, | |
336 ((DeviceData*)(current_device->data))-> address); | |
337 current_device=g_list_next(current_device); | |
338 } | |
339 destroy_scan_window(); | |
340 if(config==1) { | |
341 destroy_scan_window(); | |
342 results_ui(); | |
343 } | |
344 // refresh_tree(); | |
345 } | |
346 } | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
347 |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
348 |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
349 |
2734 | 350 static void discovery_completed(DBusGProxy *object, gpointer user_data) |
351 { | |
352 g_print("Signal: DiscoveryCompleted()\n"); | |
353 discover_finish =2; | |
354 print_results(); | |
355 } | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
356 |
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
357 |
2728 | 358 |
2734 | 359 void discover_devices(void) |
360 { | |
361 GError *error = NULL; | |
362 // g_type_init(); | |
363 g_log_set_always_fatal (G_LOG_LEVEL_WARNING); | |
364 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | |
365 if (error != NULL) | |
366 { | |
367 g_printerr("Connecting to system bus failed: %s\n", error->message); | |
368 g_error_free(error); | |
369 } | |
370 obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); | |
371 printf("bluetooth plugin - start discovery \n"); | |
372 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); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
373 |
2734 | 374 dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); |
375 dbus_g_proxy_connect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus, NULL); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
376 |
2734 | 377 dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID); |
378 dbus_g_proxy_connect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus, NULL); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
379 |
2734 | 380 dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID); |
381 dbus_g_proxy_connect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus, NULL); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
382 |
2734 | 383 dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); |
2728 | 384 |
2734 | 385 dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); |
386 dbus_g_proxy_connect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL, NULL); | |
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
387 |
2734 | 388 dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID); |
389 if (error != NULL) | |
390 { | |
391 g_printerr("Failed to discover devices: %s\n", error->message); | |
392 g_error_free(error); | |
393 } | |
2728 | 394 |
2734 | 395 } |