changeset 1451:31a21423999f

merge
author Cristi Magherusan <majeru@atheme-project.org>
date Wed, 08 Aug 2007 22:08:39 +0300
parents 69bff388b0f8 (diff) e11d83ce8d16 (current diff)
children d43075afd1db
files
diffstat 12 files changed, 124 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/daap/Makefile	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/Makefile	Wed Aug 08 22:08:39 2007 +0300
@@ -7,7 +7,15 @@
 
 LIBDIR = $(plugindir)/$(TRANSPORT_PLUGIN_DIR)
 
-LIBADD += ./xmms2-daap/xmms2-daap.a $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) 
+#For the moment i'm hardcoding it but it will be configurable
+#MDNS_LIBS=-ldns_sd
+MDNS_LIBS=-lavahi-glib -lavahi-common -lavahi-client
+#MDNS_LIBS= 
+
+
+
+
+LIBADD += ./xmms2-daap/xmms2-daap.a $(GTK_LIBS) $(GLIB_LIBS) $(PANGO_LIBS) $(MDNS_LIBS)
 
 SOURCES = daap.c
 
--- a/src/daap/daap.c	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/daap.c	Wed Aug 08 22:08:39 2007 +0300
@@ -20,30 +20,115 @@
 
 #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 "xmms2-daap/daap_mdns_browse.h"
+#include "xmms2-daap/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);
+    g_print ("caut\n");
+    daap_found_devices  = daap_mdns_get_server_list ();
+    current_server=daap_found_devices;
+    g_print ("entering for\n");
+    for (; current_server; current_server = g_slist_next (current_server)) 
+    {
+     g_print ("in for\n");
+
+        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 1
+        g_print("DAAP: Found device %s at address %s\n", current_device->device_name ,current_device->device_address );
+#endif
+    }
+    g_print("am iesit\n");
+    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 +205,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/Makefile	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/Makefile	Wed Aug 08 22:08:39 2007 +0300
@@ -14,11 +14,14 @@
 
 #		 daap_xform.c 
 LIBADD = $(GLIB_LIBS) 
- 
 
-CFLAGS = $(GLIB_CFLAGS)  -I/usr/include   -std=c99 -Wall # -H -v
+#For the moment i'm hardcoding it but it will be configurable
+#MDNS_IMPL=DAAP_MDNS_DNSSD
+MDNS_IMPL=DAAP_MDNS_AVAHI
+#MDNS_IMPL=DAAP_MDNS_DUMMY 
 
-#CFLAGS += $(PICFLAGS) $(ARCH_DEFINES) $(CURL_CFLAGS) -c -I../../../intl -I../../.. -I/usr/include -Wall   -std=c99 -H -v
+CFLAGS = $(GLIB_CFLAGS) $(PICFLAGS) -std=c99 -Wall -D_POSIX_SOURCE -D$(MDNS_IMPL) 
+
 OBJECTS=${SOURCES:.c=.o}
 
 include ../../../mk/objective.mk
--- a/src/daap/xmms2-daap/daap_conn.c	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/daap_conn.c	Wed Aug 08 22:08:39 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	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/daap_conn.h	Wed Aug 08 22:08:39 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	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/daap_mdns_avahi.c	Wed Aug 08 22:08:39 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	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/daap_mdns_dnssd.c	Wed Aug 08 22:08:39 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	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/daap/xmms2-daap/daap_mdns_dummy.c	Wed Aug 08 22:08:39 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/flacng/flacng.h	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/flacng/flacng.h	Wed Aug 08 22:08:39 2007 +0300
@@ -79,7 +79,6 @@
 
 
 typedef struct callback_info {
-    GMutex* mutex;
     gint32* output_buffer;
     gint32* write_pointer;
     guint buffer_free;
--- a/src/flacng/plugin.c	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/flacng/plugin.c	Wed Aug 08 22:08:39 2007 +0300
@@ -180,11 +180,8 @@
 
     _DEBUG("Testing fd for file: %s", filename);
 
-    INFO_LOCK(test_info);
-
     if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _DEBUG("File not handled by this plugin!");
-        INFO_UNLOCK(test_info);
         _LEAVE FALSE;
     }
 
@@ -193,7 +190,6 @@
      */
     if (FALSE == test_info->metadata_changed) {
         _DEBUG("No metadata found in stream");
-        INFO_UNLOCK(test_info);
         _LEAVE FALSE;
     }
 
@@ -211,7 +207,6 @@
     if (MAX_SUPPORTED_CHANNELS < test_info->stream.channels) {
         _ERROR("This number of channels (%d) is currently not supported, stream not handled by this plugin",
             test_info->stream.channels);
-        INFO_UNLOCK(test_info);
         _LEAVE FALSE;
     }
 
@@ -220,7 +215,6 @@
         (8 != test_info->stream.bits_per_sample)) {
         _ERROR("This number of bits (%d) is currently not supported, stream not handled by this plugin",
             test_info->stream.bits_per_sample);
-        INFO_UNLOCK(test_info);
         _LEAVE FALSE;
     }
 
@@ -231,7 +225,6 @@
     _DEBUG("Accepting file %s", filename);
 
     reset_info(test_info, FALSE);
-    INFO_UNLOCK(test_info);
 
     _LEAVE TRUE;
 }
@@ -654,14 +647,11 @@
         _LEAVE;
     }
 
-    INFO_LOCK(test_info);
-
     if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _ERROR("Could not read file info!");
         *length = -1;
         *title = g_strdup("");
         reset_info(test_info, TRUE);
-        INFO_UNLOCK(test_info);
         _LEAVE;
     }
 
@@ -680,7 +670,6 @@
     *title = get_title(filename, test_info);
 
     reset_info(test_info, TRUE);
-    INFO_UNLOCK(test_info);
 
     _LEAVE;
 }
@@ -703,19 +692,15 @@
         _LEAVE NULL;
     }
 
-    INFO_LOCK(test_info);
-
     if (FALSE == read_metadata(fd, test_decoder, test_info)) {
         _ERROR("Could not read metadata tuple for file <%s>", filename);
         reset_info(test_info, TRUE);
-        INFO_UNLOCK(test_info);
         _LEAVE NULL;
     }
 
     tuple = get_tuple(filename, test_info);
 
     reset_info(test_info, TRUE);
-    INFO_UNLOCK(test_info);
 
     _LEAVE tuple;
 }
--- a/src/flacng/tools.c	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/flacng/tools.c	Wed Aug 08 22:08:39 2007 +0300
@@ -66,8 +66,6 @@
     info->replaygain.album_peak = NULL;
     reset_info(info, FALSE);
 
-    info->mutex = g_mutex_new();
-
     _DEBUG("Playback buffer allocated for %d samples, %d bytes", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE);
 
     _LEAVE info;
--- a/src/flacng/tools.h	Wed Aug 08 20:25:13 2007 +0200
+++ b/src/flacng/tools.h	Wed Aug 08 22:08:39 2007 +0300
@@ -23,21 +23,6 @@
 #include <FLAC/all.h>
 #include "flacng.h"
 #include "flac_compat.h"
-#include "debug.h"
-
-#define INFO_LOCK(__info) \
-    do { \
-        _DEBUG("Trying to lock info %s", (__info)->name); \
-        g_mutex_lock((__info)->mutex); \
-        _DEBUG("Locked info %s", (__info)->name); \
-    } while(0)
-
-#define INFO_UNLOCK(__info) \
-    do { \
-        _DEBUG("Unlocking info %s", (__info)->name); \
-        g_mutex_unlock((__info)->mutex); \
-        _DEBUG("Unlocked info %s", (__info)->name); \
-    } while(0)
 
 callback_info* init_callback_info(gchar* name);
 void reset_info(callback_info* info, gboolean close_fd);