# HG changeset patch # User Paula Stanciu # Date 1217620420 -10800 # Node ID 162766a69f128908ec49fd8b8cb4abe0dcd67119 # Parent 43557eb3180fd7fab31bc34d6d2f8a010b255812# Parent 7a000caead2891026bfbeb5ec727163dd259c0c1 bluetooth audio support - working after restarting the player diff -r 43557eb3180f -r 162766a69f12 src/bluetooth/bluetooth.c --- a/src/bluetooth/bluetooth.c Wed Jul 30 17:49:43 2008 +0300 +++ b/src/bluetooth/bluetooth.c Fri Aug 01 22:53:40 2008 +0300 @@ -16,18 +16,21 @@ * along with this program. If not, see . */ +#include +#include +#include #include "bluetooth.h" #include "marshal.h" #include "gui.h" #include "scan_gui.h" #include "agent.h" -#include "../alsa/alsa.h" #define DEBUG 1 static gboolean plugin_active = FALSE,exiting=FALSE; GList * current_device = NULL; gint config = 0; gint devices_no = 0; GStaticMutex mutex = G_STATIC_MUTEX_INIT; +static gchar *current_address=NULL; static GThread *connect_th; void bluetooth_init ( void ); void bluetooth_cleanup ( void ); @@ -64,7 +67,8 @@ void bluetooth_cleanup ( void ) { printf("bluetooth: exit\n"); - if (config ==1 ){ + if (config ==1 ) + { close_window(); config =0; } @@ -106,7 +110,8 @@ } -void clean_devices_list(){ +void clean_devices_list() +{ g_list_free(audio_devices); dbus_g_connection_flush (bus); dbus_g_connection_unref(bus); @@ -137,36 +142,76 @@ 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); run_agents(); - dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,((DeviceData*)(selected_dev->data))->address,G_TYPE_INVALID,G_TYPE_INVALID); - + dbus_g_proxy_call(obj,"CreateBonding",NULL,G_TYPE_STRING,current_address,G_TYPE_INVALID,G_TYPE_INVALID); + } void connect_call(void) { - connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; - close_call(); - close_window(); - show_scan(1); + current_address = g_strdup(((DeviceData*)(selected_dev->data))->address); + connect_th = g_thread_create((GThreadFunc)connect_call_th,NULL,TRUE,NULL) ; + close_call(); + close_window(); + show_scan(1); } void play_call() { -// static GFile *asoundrc; - - - - mcs_handle_t *cfgfile = aud_cfg_db_open(); - aud_cfg_db_set_int(cfgfile, ALSA_CFGID, "buffer_time", 500); - aud_cfg_db_set_int(cfgfile, ALSA_CFGID, "period_time", 100); - aud_cfg_db_set_string(cfgfile,ALSA_CFGID,"pcm_device", "bt"); - aud_cfg_db_set_int(cfgfile, ALSA_CFGID, "mixer_card", 0); - aud_cfg_db_set_string(cfgfile,ALSA_CFGID,"mixer_device", "PCM"); - aud_cfg_db_set_int(cfgfile, ALSA_CFGID, "volume_left", 100); - aud_cfg_db_set_int(cfgfile, ALSA_CFGID, "volume_right", 100); - aud_cfg_db_close(cfgfile); + FILE *file; + FILE *temp_file; + gint prev=0; + char line[128]; + gchar *home; + gchar *device_line; + gchar *file_name=""; + gchar *temp_file_name; + int ret = EOF+1; + home = g_get_home_dir(); + file_name = g_strconcat(home,"/.asoundrc",NULL); + temp_file_name = g_strconcat(home,"/temp_bt",NULL); + file = fopen(file_name,"r"); + temp_file = fopen(temp_file_name,"w"); + /* hardcoded address TO REMOVE after testing */ + // current_address = "00:0D:3C:B1:1C:7A"; + device_line = g_strdup_printf("device %s\n",current_address); + if ( file != NULL ) + { + while ( fgets ( line, sizeof line, file ) != NULL ) + { + if(!(strcmp(line,"pcm.audacious_bt {\n"))){ + fputs(line,temp_file); + fgets ( line, sizeof line, file ); /* type bluetooth */ + fputs(line,temp_file); + fgets ( line, sizeof line, file ); /* device MAC */ + fputs(device_line,temp_file); + prev = 1; + } else + fputs(line,temp_file); + } - printf("play callback\n"); + fclose (file); + } + if(!prev){ + fputs("pcm.audacious_bt{\n",temp_file); + fputs("type bluetooth\n",temp_file); + fputs(device_line,temp_file); + fputs("}\n",temp_file); + prev = 0; + } + + fclose(temp_file); + int err = rename(temp_file_name,file_name); + printf("rename error : %d",err); + perror("zz"); + g_free(device_line); + g_free(file_name); + g_free(temp_file_name); + mcs_handle_t *cfgfile = aud_cfg_db_open(); + aud_cfg_db_set_string(cfgfile,"ALSA","pcm_device", "audacious_bt"); + aud_cfg_db_close(cfgfile); + + printf("play callback\n"); }