changeset 2855:162766a69f12

bluetooth audio support - working after restarting the player
author Paula Stanciu <paula.stanciu@gmail.com>
date Fri, 01 Aug 2008 22:53:40 +0300
parents 43557eb3180f (current diff) 7a000caead28 (diff)
children 59ff744e1e23
files src/bluetooth/bluetooth.c
diffstat 1 files changed, 68 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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 <http://www.gnu.org/licenses>.
  */
 
+#include <glib/gstdio.h>
+#include <errno.h>
+#include <string.h>
 #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");
 
 
 }