changeset 1448:7b3290336f3b

merge
author Cristi Magherusan <majeru@atheme-project.org>
date Mon, 06 Aug 2007 02:52:19 +0300
parents 776dd8fc2b38 (current diff) 90d4c120fbca (diff)
children e92d0f4d2793
files src/daap/daap.c src/daap/xmms2-daap/daap_conn.c src/daap/xmms2-daap/daap_conn.h src/daap/xmms2-daap/daap_mdns_avahi.c src/daap/xmms2-daap/daap_mdns_dnssd.c src/daap/xmms2-daap/daap_mdns_dummy.c
diffstat 8 files changed, 127 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/daap/daap.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/daap.c	Mon Aug 06 02:52:19 2007 +0300
@@ -20,30 +20,110 @@
 
 #include <audacious/vfs.h>
 #include <audacious/plugin.h>
+#include <audacious/discovery.h>
 /*
 #include <audacious/configdb.h>
 #include <libmowgli/mowgli.h>
 #include <curl/curl.h>
 */
 #include <glib.h>
-#include <daap/client.h>
+#include "daap_mdns_browse.h"
+#include "daap_cmd.h"
+
+gboolean daap_initialized=FALSE;
+
+GMutex * mutex_init = NULL; 
+
+GMutex * mutex_discovery = NULL; 
+
+GList * daap_servers = NULL;
+
+guint request_id=0;
+
+GList * daap_get_server_playlist(gchar * host, gint port  )
+{
+return NULL;
+
+}
 
 
+GList * daap_discovery_get_devices_impl(void)
+{   
+    discovery_device_t * current_device=NULL;
+    GList * returned_devices=NULL;
+    GSList * daap_found_devices=NULL,
+          * current_server=NULL;
+
+    if(mutex_discovery==NULL)
+        return NULL;
+
+    g_mutex_lock(mutex_discovery);
+
+    daap_found_devices  = daap_mdns_get_server_list ();
+    current_server=daap_found_devices;
+    for (current_server = daap_found_devices; current_server; current_server = g_slist_next (current_server)) 
+    {
+        current_device = g_new0(discovery_device_t,1);
+        daap_mdns_server_t *serv=current_server->data;
+        current_device->device_name = 
+            g_strdup_printf("%s(%s)",
+                    serv->server_name,
+                    serv->mdns_hostname
+                    );
+
+        current_device->device_address = 
+            g_strdup_printf(
+                    "%s:%d",
+                    serv->address,
+                    serv->port
+                    );
+        current_device->device_playlist=
+            daap_get_server_playlist(
+                    serv->mdns_hostname,
+                    serv->port
+                    );
+        returned_devices = g_list_prepend(returned_devices,current_device); 
+#if DEBUG
+        g_print("DAAP: Found device %s at address %s\n", current_device->device_name ,current_device->device_address );
+#endif
+    }
+    g_slist_free(daap_found_devices);
+    g_mutex_unlock(mutex_discovery);
+    return g_list_reverse(returned_devices);
+}
 
 
 
 
-DAAP_SClientHost *libopendaap_host;
-
-
 VFSFile * daap_vfs_fopen_impl(const gchar * path, const gchar * mode)
 {
-    VFSFile *file;
+    VFSFile *file=NULL;
+    if(!mutex_init)
+        return NULL;
+
+    g_mutex_lock(mutex_init); /* locking for init */
+    if(!daap_initialized)
+    {
+        if( !daap_mdns_initialize ())
+        {
+#ifdef DEBUG    /*this isn't a fatal error, we can try again later*/
+            g_print("Error while initializing DAAP !!!\n");
+#endif          
+            g_mutex_unlock(mutex_init);
+            return NULL;
+        }
+        else
+            daap_initialized=TRUE;
+
+    }
+    if(daap_initialized)
+        daap_discovery_get_devices_impl();
+    g_mutex_unlock(mutex_init);  /*init ended*/
+
     file = g_new0(VFSFile, 1);
-    /* connectiong daap*/
+//    GList * l = 
 
-
-    return file;
+        return file;
 }
 
 gint daap_vfs_fclose_impl(VFSFile * file)
@@ -120,10 +200,15 @@
 };
 
 static void init(void)
-{       
+{   
+    mutex_init = g_mutex_new();        
+    mutex_discovery = g_mutex_new();        
     vfs_register_transport(&daap_const);
 }
 static void cleanup(void)
 {
+    g_mutex_free (mutex_init);
+    g_mutex_free (mutex_discovery);
+    daap_mdns_destroy ();
 }
 DECLARE_PLUGIN(daap, init, cleanup, NULL, NULL, NULL, NULL, NULL, NULL)
--- a/src/daap/xmms2-daap/daap_conn.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/xmms2-daap/daap_conn.c	Mon Aug 06 02:52:19 2007 +0300
@@ -121,7 +121,7 @@
         FD_SET (sockfd, &fds);
 
 		sret = select (sockfd + 1, NULL, &fds, NULL, &tmout);
-		if (sret == 0 || sret == SOCKET_ERROR) {
+		if (sret <= 0 ) {
 			g_io_channel_unref (sock_chan);
 			return NULL;
 		}
--- a/src/daap/xmms2-daap/daap_conn.h	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/xmms2-daap/daap_conn.h	Mon Aug 06 02:52:19 2007 +0300
@@ -35,7 +35,7 @@
 #define CONTENT_LENGTH "Content-Length: "
 #define CONTENT_TYPE "Content-Type: "
 /* TODO does this work ok? */
-#define USER_AGENT VERSION
+#define USER_AGENT "Audacious"
 /*#define USER_AGENT "iTunes/4.6 (Windows; N)"*/
 
 GIOChannel *
--- a/src/daap/xmms2-daap/daap_mdns_avahi.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/xmms2-daap/daap_mdns_avahi.c	Mon Aug 06 02:52:19 2007 +0300
@@ -13,7 +13,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  */
-
+#ifdef DAAP_MDNS_AVAHI
 #include "daap_mdns_browse.h"
 
 #include <string.h>
@@ -264,4 +264,5 @@
 {
 	/* FIXME: deinit avahi */
 }
+#endif
 
--- a/src/daap/xmms2-daap/daap_mdns_dnssd.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/xmms2-daap/daap_mdns_dnssd.c	Mon Aug 06 02:52:19 2007 +0300
@@ -12,6 +12,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  */
+#ifdef DAAP_MDNS_DNSSD
 
 #include <glib.h>
 #include <dns_sd.h>
@@ -182,7 +183,7 @@
 		err = DNSServiceResolve (&ud2->client, 0, kDNSServiceInterfaceIndexAny,
 		                         server->mdnsname,
 		                         "_daap._tcp", "local",
-		                         resolve_reply, ud2);
+		                         (DNSServiceResolveReply)resolve_reply, ud2);
 
 		if (err != kDNSServiceErr_NoError) {
 			g_warning ("Couldn't do ServiceResolv");
@@ -332,7 +333,7 @@
 	                        service, 0, browse_reply, ud);
 
 	if (err != kDNSServiceErr_NoError) {
-		g_warning ("Couldn't setup mDNS poller");
+		g_warning ("Couldn't setup mDNS poller, error = %d",err);
 		return FALSE;
 	}
 
@@ -415,4 +416,4 @@
 	g_mdns->mutex = g_mutex_new ();
 	return g_mdns_browse (g_mdns, "_daap._tcp", NULL, NULL);
 }
-
+#endif
--- a/src/daap/xmms2-daap/daap_mdns_dummy.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/daap/xmms2-daap/daap_mdns_dummy.c	Mon Aug 06 02:52:19 2007 +0300
@@ -12,7 +12,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  */
-
+#ifdef AVAHI_MDNS_DUMMY
 #include <glib.h>
 
 #include "daap_mdns_browse.h"
@@ -33,4 +33,4 @@
 daap_mdns_destroy ()
 {
 }
-
+#endif
--- a/src/vtx/vtx.c	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/vtx/vtx.c	Mon Aug 06 02:52:19 2007 +0300
@@ -22,6 +22,7 @@
 #include <audacious/output.h>
 #include <audacious/util.h>
 #include <audacious/titlestring.h>
+#include <audacious/configdb.h>
 #include <audacious/vfs.h>
 #include <audacious/strings.h>
 #include <audacious/i18n.h>
@@ -56,6 +57,19 @@
 
 static gchar *vtx_fmts[] = { "vtx", NULL };
 
+void
+vtx_init(void)
+{
+        ConfigDb *db;
+        db = bmp_cfg_db_open();
+
+        bmp_cfg_db_get_int(db, NULL, "src_rate", &freq);
+        if (freq < 4000 || freq > 192000)
+                freq = 44100;
+
+        bmp_cfg_db_close(db);
+}
+
 int
 vtx_is_our_fd (char *filename, VFSFile *fp)
 {
@@ -169,6 +183,9 @@
 	{
 	  playback->output->buffer_free ();
 	  playback->output->buffer_free ();
+	  while (playback->output->buffer_playing())
+	    g_usleep(10000);
+	  playback->playing = 0;
 	}
     
       /* jump to time in seek_to (in seconds) */
@@ -179,10 +196,7 @@
 	  seek_to = -1;
 	}
     }
-
-  /* close sound and release vtx file must be done in vtx_stop() */
-  g_thread_exit (NULL);
-
+  ayemu_vtx_free (&vtx);
   return NULL;
 }
 
@@ -229,7 +243,8 @@
       bmp_title_input_free(ti);
 
       playback->playing = TRUE;
-      play_thread = g_thread_create (play_loop, playback, TRUE, NULL);
+      play_thread = g_thread_self();
+      play_loop(playback);
     }
 }
 
@@ -292,8 +307,8 @@
 InputPlugin vtx_ip = {
 	NULL,			/* FILLED BY XMMS */
 	NULL,			/* FILLED BY XMMS */
-	"VTX Audio Plugin",		/* Plugin description */
-	NULL,			/* Initialization */
+	"VTX Audio Plugin",	/* Plugin description */
+	vtx_init,		/* Initialization */
 	vtx_about,		/* Show aboutbox */
 	vtx_config,		/* Show/edit configuration */
 	vtx_is_our_file,	/* Check file, return 1 if the plugin can handle this file */
--- a/src/vtx/vtx.h	Sun Aug 05 00:26:21 2007 +0300
+++ b/src/vtx/vtx.h	Mon Aug 06 02:52:19 2007 +0300
@@ -13,6 +13,7 @@
 
 #include "audacious/plugin.h"
 
+void vtx_init(void);
 void vtx_about(void);
 void vtx_config(void);
 void vtx_file_info(char *filename);