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