Index: rb-player-gst.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/player/rb-player-gst.c,v
retrieving revision 1.46
diff -u -r1.46 rb-player-gst.c
--- rb-player-gst.c	8 Sep 2005 21:45:05 -0000	1.46
+++ rb-player-gst.c	2 Oct 2005 22:26:26 -0000
@@ -28,6 +28,8 @@
 #include <math.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
+
 #include <libgnome/gnome-i18n.h>
 #include <libgnomevfs/gnome-vfs-ops.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
@@ -50,6 +52,7 @@
 	char *uri;
 
 	GstElement *playbin;
+	GstElement *server_thread;
 
 	gboolean can_signal_direct_error;
 	GError *error;
@@ -193,6 +196,9 @@
 		gst_element_set_state (mp->priv->playbin,
 				       GST_STATE_NULL);
 		
+		gst_element_set_state (mp->priv->server_thread,
+				       GST_STATE_NULL);
+				       
 		rb_player_gst_free_playbin (mp);
 	}
 
@@ -209,6 +215,12 @@
 	
 	gst_object_unref (GST_OBJECT (player->priv->playbin));
 	player->priv->playbin = NULL;
+	
+	if (player->priv->server_thread == NULL)
+		return;
+
+	gst_object_unref (GST_OBJECT (player->priv->server_thread));
+	player->priv->server_thread = NULL;
 }
 
 static void
@@ -286,6 +298,7 @@
 						 (GSourceFunc) emit_signal_idle,
 						 signal,
 						 destroy_idle_signal);
+//	gst_element_set_state (mp->priv->server_thread, GST_STATE_PAUSED);
 }
 
 static void
@@ -411,16 +424,28 @@
 	mp->priv->idle_buffering_id = g_idle_add ((GSourceFunc) emit_signal_idle, signal);
 }
 
+static GstCaps *
+get_tee_sink_caps (GstPad *pad)
+{
+	/* XXX who frees this? */
+	return gst_caps_new_simple ("audio/x-raw-int",
+			"rate", GST_TYPE_INT_RANGE, 44100, G_MAXINT,
+			NULL);
+}
+
+
 static gboolean
 rb_player_construct (RBPlayer *mp, GError **error)
 {
 	char *element_name = NULL;
-	GstElement *sink;
+	GstElement *gconf, *bin, *tee, *nowplaying, *tcpserver, *queue;
+	GstPad *tee_sink;
 
 	/* playbin */
 	rb_debug ("constructing element \"playbin\"");
 	mp->priv->playbin = gst_element_factory_make ("playbin", "playbin");
 	if (mp->priv->playbin == NULL) {
+		element_name = "playbin";
 		goto missing_element;
 	}
 	g_signal_connect_object (G_OBJECT (mp->priv->playbin),
@@ -440,18 +465,86 @@
 					 G_CALLBACK (error_cb),
 					 mp, 0);
 
-	/* Output sink */
-	sink = gst_gconf_get_default_audio_sink ();
-	if (sink == NULL) {
-		g_set_error (error,
-			     RB_PLAYER_ERROR,
-			     RB_PLAYER_ERROR_NO_AUDIO,
-			     _("Could not create audio output element; check your settings"));
-		rb_player_gst_free_playbin (mp);
-		return FALSE;
+	bin = gst_bin_new ("bin");
+	if (bin == NULL) {
+		element_name = "bin";
+		goto missing_element;
 	}
-
-	g_object_set (G_OBJECT (mp->priv->playbin), "audio-sink", sink, NULL);
+	
+	tee = gst_element_factory_make ("tee", "tee");
+	if (tee == NULL) {
+		element_name = "tee";
+		goto missing_element;
+	}
+	
+	nowplaying = gst_element_factory_make ("nowplaying", "nowplaying");
+	if (nowplaying == NULL) {
+		rb_debug ("No gst element nowplaying, not using it..");
+	}
+	
+	tcpserver = gst_element_factory_make ("tcpserversink", "tcpserversink");
+	if (tcpserver == NULL) {
+		element_name = "tcpserversink";
+		goto missing_element;
+	}
+	unlink("/tmp/rb-buddymusic");
+	g_object_set (G_OBJECT (tcpserver), 
+		"socket-type", 1,
+		"address", "/tmp/rb-buddymusic",
+		"protocol", 1,
+		"sync-method", 0,
+		"timeout", 60*GST_SECOND,
+		"recover-policy", 0,
+		NULL);
+	
+	queue = gst_element_factory_make ("queue", "queue");
+	if (queue == NULL) {
+		element_name = "queue";
+		goto missing_element;
+	}
+	
+	mp->priv->server_thread = gst_thread_new ("serverthread");
+	if (mp->priv->server_thread == NULL) {
+		element_name = "thread";
+		goto missing_element;
+	}
+	
+	gconf = gst_gconf_get_default_audio_sink ();
+	if (gconf == NULL) {
+		element_name = "gconfaudiosink";
+		goto missing_element;
+	}
+	
+	gst_bin_add (GST_BIN (bin), tee);
+	gst_bin_add (GST_BIN (bin), queue);
+	gst_bin_add (GST_BIN (bin), gconf);
+
+	gst_element_link (tee, gconf);
+	gst_element_link (tee, queue);		
+
+	tee_sink = gst_element_get_pad (tee, "sink");
+	gst_pad_set_getcaps_function (tee_sink, (GstPadGetCapsFunction)get_tee_sink_caps);
+	gst_element_add_ghost_pad (bin, tee_sink, "sink");
+
+	/* Setup tcpserver thread */
+	if (nowplaying != NULL) {
+		gst_bin_add (GST_BIN (mp->priv->server_thread), nowplaying);
+	}
+	gst_bin_add (GST_BIN (mp->priv->server_thread), tcpserver);
+	
+	if (nowplaying != NULL)
+	{	
+		gst_element_link (queue, nowplaying);
+		gst_element_link (nowplaying, tcpserver);
+	}
+	else
+	{
+		gst_element_link (queue, tcpserver);
+	}
+	
+	gst_element_set_state (mp->priv->server_thread, GST_STATE_PLAYING);
+	
+	g_object_set (G_OBJECT (mp->priv->playbin), "audio-sink", bin, NULL);
 	g_signal_connect_object (G_OBJECT (mp->priv->playbin), "eos",
 				 G_CALLBACK (eos_cb), mp, 0);
 
@@ -515,12 +608,16 @@
 	if (mp->priv->playing) {
  		rb_debug ("PLAYING pipeline");
  		if (gst_element_set_state (mp->priv->playbin,
+ 					   GST_STATE_PLAYING) == GST_STATE_FAILURE ||
+ 			gst_element_set_state (mp->priv->server_thread,
  					   GST_STATE_PLAYING) == GST_STATE_FAILURE) {
  			return FALSE;
 		}
 	} else {
 		rb_debug ("PAUSING pipeline");
 		if (gst_element_set_state (mp->priv->playbin,
+					   GST_STATE_PAUSED) == GST_STATE_FAILURE ||
+			gst_element_set_state (mp->priv->server_thread,
 					   GST_STATE_PAUSED) == GST_STATE_FAILURE) {
 			return FALSE;
 		}
@@ -768,7 +865,8 @@
 	g_return_if_fail (mp->priv->playbin != NULL);
 
 	gst_element_set_state (mp->priv->playbin, GST_STATE_PAUSED);
-
+	gst_element_set_state (mp->priv->server_thread, GST_STATE_PAUSED);
+	
 #ifdef WITH_DAAP_SUPPORT
 	/* FIXME?
 	 * This is sorta hack/sorta best way to do it.
@@ -792,7 +890,10 @@
 	}
 #endif
 	if (mp->priv->playing)
+	{
 		gst_element_set_state (mp->priv->playbin, GST_STATE_PLAYING);
+		gst_element_set_state (mp->priv->server_thread, GST_STATE_PLAYING);
+	}
 }
 
 long
