Mercurial > audlegacy-plugins
annotate src/bluetooth/bluetooth.c @ 2870:c3df7556d85a
restoring the default ocm device at cleanup
| author | Paula Stanciu <paula.stanciu@gmail.com> |
|---|---|
| date | Thu, 07 Aug 2008 12:33:57 +0300 |
| parents | 9e9293b87392 |
| children | 455e6e37feae |
| 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" |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
27 #include <audacious/plugin.h> |
| 2644 | 28 #define DEBUG 1 |
| 29 static gboolean plugin_active = FALSE,exiting=FALSE; | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
30 GList * current_device = NULL; |
| 2728 | 31 gint config = 0; |
| 32 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
|
33 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
|
34 static gchar *current_address=NULL; |
|
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
35 static GThread *connect_th; |
| 2644 | 36 void bluetooth_init ( void ); |
| 37 void bluetooth_cleanup ( void ); | |
| 38 void bt_cfg(void); | |
| 39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 void discover_devices(void); |
| 2728 | 46 void disconnect_dbus_signals(void); |
| 2857 | 47 static void show_restart_dialog(void); |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
48 static void remove_bonding(); |
| 2644 | 49 GeneralPlugin bluetooth_gp = |
| 50 { | |
|
2649
d891ba4be5a5
fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2648
diff
changeset
|
51 .description = "Bluetooth audio support", |
| 2644 | 52 .init = bluetooth_init, |
| 53 .about = bt_about, | |
| 54 .configure = bt_cfg, | |
| 55 .cleanup = bluetooth_cleanup | |
| 56 }; | |
| 57 GeneralPlugin *bluetooth_gplist[] = { &bluetooth_gp, NULL }; | |
| 58 DECLARE_PLUGIN(bluetooth_gp, NULL, NULL, NULL, NULL, NULL, bluetooth_gplist, NULL, NULL) | |
| 2728 | 59 |
| 2644 | 60 void bluetooth_init ( void ) |
| 61 { | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
62 audio_devices = NULL; |
|
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
63 bus = NULL; |
|
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
64 obj = NULL; |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
65 discover_devices(); |
| 2644 | 66 } |
| 67 | |
| 68 void bluetooth_cleanup ( void ) | |
| 69 { | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
70 printf("bluetooth: exit\n"); |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
71 if (config ==1 ) |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
72 { |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
73 close_window(); |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
74 config =0; |
|
2649
d891ba4be5a5
fixed crash when prefs window was closed while scanning
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2648
diff
changeset
|
75 } |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
76 remove_bonding(); |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
77 if(discover_finish == 2) { |
|
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
78 dbus_g_connection_flush (bus); |
| 2734 | 79 dbus_g_connection_unref(bus); |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
80 disconnect_dbus_signals(); |
| 2644 | 81 |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
82 } |
|
2870
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
83 /* 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
|
84 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
|
85 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
|
86 aud_cfg_db_close(cfgfile); |
|
c3df7556d85a
restoring the default ocm device at cleanup
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2868
diff
changeset
|
87 |
| 2734 | 88 } |
|
2732
1a27c497e526
indentation and some small bug fixing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2728
diff
changeset
|
89 |
| 2734 | 90 void bt_about( void ) |
| 91 { | |
| 92 printf("about call\n"); | |
| 93 } | |
| 2728 | 94 |
| 2734 | 95 void bt_cfg(void) |
| 96 { | |
| 97 printf("bt_cfg\n"); | |
| 98 config =1; | |
| 99 if(discover_finish == 2){ | |
| 100 if (devices_no == 0){ | |
| 101 printf("no devs!\n"); | |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
102 show_scan(0); |
| 2734 | 103 show_no_devices(); |
| 104 }else | |
| 105 results_ui(); | |
| 2728 | 106 } |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
107 else show_scan(0); |
| 2734 | 108 printf("end of bt_cfg\n"); |
| 109 } | |
| 2728 | 110 |
| 2734 | 111 void disconnect_dbus_signals() |
| 112 { | |
| 113 dbus_g_proxy_disconnect_signal(obj, "RemoteDeviceFound", G_CALLBACK(remote_device_found), bus); | |
| 114 dbus_g_proxy_disconnect_signal(obj, "DiscoveryStarted", G_CALLBACK(discovery_started), bus); | |
| 115 dbus_g_proxy_disconnect_signal(obj, "DiscoveryCompleted", G_CALLBACK(discovery_completed), bus); | |
| 116 dbus_g_proxy_disconnect_signal(obj, "RemoteNameUpdated", G_CALLBACK(remote_name_updated), NULL); | |
| 2644 | 117 |
| 2734 | 118 } |
| 2644 | 119 |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
120 void clean_devices_list() |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
121 { |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
122 g_list_free(audio_devices); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
123 dbus_g_connection_flush (bus); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
124 dbus_g_connection_unref(bus); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
125 audio_devices = NULL; |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
126 //g_list_free(current_device); |
|
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
127 } |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
128 static void remove_bonding() |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
129 { |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
130 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); |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
131 dbus_g_proxy_call(obj,"RemoveBonding",NULL,G_TYPE_STRING,"00:0D:3C:B1:1C:7A",G_TYPE_INVALID,G_TYPE_INVALID); |
| 2644 | 132 |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
133 } |
| 2734 | 134 void refresh_call(void) |
| 135 { | |
| 136 printf("refresh function called\n"); | |
| 137 disconnect_dbus_signals(); | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
138 clean_devices_list(); |
| 2734 | 139 if(discover_finish == 0 ||discover_finish== 2){ |
| 140 discover_finish = 0; | |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
141 |
| 2734 | 142 discover_devices(); |
|
2756
d3d71539d675
rescan functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2734
diff
changeset
|
143 close_window(); |
|
2847
671cdfc2d62d
Basic pairing interface
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2846
diff
changeset
|
144 show_scan(0); |
| 2728 | 145 } |
| 2734 | 146 else |
| 147 printf("Scanning please wait!\n"); | |
| 148 } | |
| 2644 | 149 |
|
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
150 gpointer connect_call_th(void) |
| 2734 | 151 { |
| 2841 | 152 |
| 153 //I will have to enable the audio service if necessary | |
|
2838
22a2ffe86750
added passkey agent and basic pairing functionality
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2756
diff
changeset
|
154 |
|
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
155 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); |
| 2841 | 156 run_agents(); |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
157 dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
158 |
|
2845
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
159 } |
|
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
160 void connect_call(void) |
|
d0cbf303869b
removed interface freeze while pairing
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2842
diff
changeset
|
161 { |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
162 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
|
163 connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
164 close_call(); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
165 close_window(); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
166 show_scan(1); |
| 2734 | 167 } |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
168 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
169 |
| 2854 | 170 void play_call() |
| 171 { | |
| 172 | |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
173 FILE *file; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
174 FILE *temp_file; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
175 gint prev=0; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
176 char line[128]; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
177 gchar *home; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
178 gchar *device_line; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
179 gchar *file_name=""; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
180 gchar *temp_file_name; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
181 int ret = EOF+1; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
182 home = g_get_home_dir(); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
183 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
|
184 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
|
185 file = fopen(file_name,"r"); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
186 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
|
187 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
|
188 if ( file != NULL ) |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
189 { |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
190 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
|
191 { |
|
2858
528d19a2ea3d
fixed .asoundrc bug - writeing multiple pcm bluetooth device
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2857
diff
changeset
|
192 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
|
193 fputs(line,temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
194 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
|
195 fputs(line,temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
196 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
|
197 fputs(device_line,temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
198 prev = 1; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
199 } else |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
200 fputs(line,temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
201 } |
| 2854 | 202 |
|
2855
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
203 fclose (file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
204 } |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
205 if(!prev){ |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
206 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
|
207 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
|
208 fputs(device_line,temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
209 fputs("}\n",temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
210 prev = 0; |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
211 } |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
212 |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
213 fclose(temp_file); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
214 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
|
215 printf("rename error : %d",err); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
216 perror("zz"); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
217 g_free(device_line); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
218 g_free(file_name); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
219 g_free(temp_file_name); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
220 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
|
221 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
|
222 aud_cfg_db_close(cfgfile); |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
223 |
|
162766a69f12
bluetooth audio support - working after restarting the player
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2854
diff
changeset
|
224 printf("play callback\n"); |
| 2857 | 225 close_window(); |
|
2868
9e9293b87392
playing without restart
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2867
diff
changeset
|
226 aud_output_plugin_cleanup(); |
|
9e9293b87392
playing without restart
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2867
diff
changeset
|
227 audacious_drct_stop(); |
|
9e9293b87392
playing without restart
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2867
diff
changeset
|
228 audacious_drct_play(); |
| 2854 | 229 |
| 230 | |
| 231 } | |
| 2857 | 232 static void show_restart_dialog() |
| 233 { | |
|
2867
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
234 static GtkWidget *window = NULL; |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
235 GtkWidget *dialog; |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
236 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
|
237 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
|
238 GTK_MESSAGE_INFO, |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
239 GTK_BUTTONS_OK, |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
240 "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
|
241 gtk_dialog_run (GTK_DIALOG (dialog)); |
|
dc22e3d2e56e
fixed bonding an allready bonded device bug
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2858
diff
changeset
|
242 gtk_widget_destroy (dialog); |
| 2857 | 243 } |
| 2854 | 244 |
| 2734 | 245 static void remote_device_found(DBusGProxy *object, char *address, const unsigned int class, const int rssi, gpointer user_data) |
| 246 { | |
| 247 int found_in_list=FALSE; | |
| 248 g_static_mutex_lock(&mutex); | |
| 249 current_device = audio_devices; | |
| 250 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
|
251 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
252 while(current_device != NULL) |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
253 { |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
254 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
|
255 { |
| 2734 | 256 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
|
257 break; |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
258 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
259 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
|
260 } |
| 2734 | 261 if(!found_in_list) |
| 262 { | |
| 263 DeviceData *dev= g_new0(DeviceData, 1); | |
| 264 dev->class = class; | |
| 265 dev->address = g_strdup(address); | |
| 266 dev->name = NULL; | |
| 267 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
|
268 } |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
269 } |
| 2734 | 270 g_static_mutex_unlock(&mutex); |
| 271 } | |
| 272 | |
| 273 static void discovery_started(DBusGProxy *object, gpointer user_data) | |
| 274 { | |
| 275 g_print("Signal: DiscoveryStarted()\n"); | |
| 276 discover_finish = 1; | |
| 277 } | |
| 278 | |
| 279 static void remote_name_updated(DBusGProxy *object, const char *address, char *name, gpointer user_data) | |
| 280 { | |
| 281 g_static_mutex_lock(&mutex); | |
| 282 current_device=audio_devices; | |
| 283 while(current_device != NULL) | |
| 284 { | |
| 285 if(g_str_equal(address,((DeviceData*)(current_device->data))->address)) | |
| 286 { | |
| 287 ((DeviceData*)(current_device->data))->name=g_strdup(name); | |
| 288 break; | |
| 289 } | |
| 290 current_device=g_list_next(current_device); | |
| 291 } | |
| 292 g_static_mutex_unlock(&mutex); | |
| 293 } | |
| 294 | |
| 295 static void print_results() | |
| 296 { | |
| 297 int i=0; | |
| 298 g_print("Final Scan results:\n"); | |
| 299 devices_no = g_list_length(audio_devices); | |
| 300 g_print("Number of audio devices: %d \n",devices_no); | |
| 301 if(devices_no==0 ) { | |
| 302 if(config ==1) show_no_devices(); | |
| 303 } else { | |
| 304 current_device=audio_devices; | |
| 305 while(current_device != NULL) | |
| 306 { | |
| 307 g_print("Device %d: Name: %s, Class: 0x%x, Address: %s\n",++i, | |
| 308 ((DeviceData*)(current_device->data))-> name, | |
| 309 ((DeviceData*)(current_device->data))-> class, | |
| 310 ((DeviceData*)(current_device->data))-> address); | |
| 311 current_device=g_list_next(current_device); | |
| 312 } | |
| 313 destroy_scan_window(); | |
| 314 if(config==1) { | |
| 315 destroy_scan_window(); | |
| 316 results_ui(); | |
| 317 } | |
| 318 // refresh_tree(); | |
| 319 } | |
| 320 } | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
321 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
322 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
323 |
| 2734 | 324 static void discovery_completed(DBusGProxy *object, gpointer user_data) |
| 325 { | |
| 326 g_print("Signal: DiscoveryCompleted()\n"); | |
| 327 discover_finish =2; | |
| 328 print_results(); | |
| 329 } | |
|
2646
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
330 |
|
7fbff3287a56
added device discovery in the plugin's prefs window
Paula Stanciu <paula.stanciu@gmail.com>
parents:
2644
diff
changeset
|
331 |
| 2728 | 332 |
| 2734 | 333 void discover_devices(void) |
| 334 { | |
| 335 GError *error = NULL; | |
| 336 // g_type_init(); | |
| 337 g_log_set_always_fatal (G_LOG_LEVEL_WARNING); | |
| 338 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | |
| 339 if (error != NULL) | |
| 340 { | |
| 341 g_printerr("Connecting to system bus failed: %s\n", error->message); | |
| 342 g_error_free(error); | |
| 343 } | |
| 344 obj = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci0", "org.bluez.Adapter"); | |
| 345 printf("bluetooth plugin - start discovery \n"); | |
| 346 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
|
347 |
| 2734 | 348 dbus_g_proxy_add_signal(obj, "RemoteDeviceFound", G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INT, G_TYPE_INVALID); |
| 349 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
|
350 |
| 2734 | 351 dbus_g_proxy_add_signal(obj, "DiscoveryStarted", G_TYPE_INVALID); |
| 352 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
|
353 |
| 2734 | 354 dbus_g_proxy_add_signal(obj, "DiscoveryCompleted", G_TYPE_INVALID); |
| 355 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
|
356 |
| 2734 | 357 dbus_g_object_register_marshaller(marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); |
| 2728 | 358 |
| 2734 | 359 dbus_g_proxy_add_signal(obj, "RemoteNameUpdated", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); |
| 360 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
|
361 |
| 2734 | 362 dbus_g_proxy_call(obj, "DiscoverDevices", &error, G_TYPE_INVALID, G_TYPE_INVALID); |
| 363 if (error != NULL) | |
| 364 { | |
| 365 g_printerr("Failed to discover devices: %s\n", error->message); | |
| 366 g_error_free(error); | |
| 367 } | |
| 2728 | 368 |
| 2734 | 369 } |
