changeset 26155:39c1b30b26e2

Simplify handling prepare-xwindow-id signal. Reduce thread unsafety.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Mon, 02 Feb 2009 04:01:34 +0000
parents 4cbf594b2f17
children 1199abde956b
files libpurple/media.c
diffstat 1 files changed, 32 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Mon Feb 02 03:01:24 2009 +0000
+++ b/libpurple/media.c	Mon Feb 02 04:01:34 2009 +0000
@@ -2177,9 +2177,8 @@
 
 typedef struct
 {
-	PurpleMedia *media;
-	gchar *session_id;
-	gchar *participant;
+	gchar *name;
+	gulong window_id;
 	gulong handler_id;
 } PurpleMediaXOverlayData;
 
@@ -2187,9 +2186,6 @@
 window_id_cb(GstBus *bus, GstMessage *msg, PurpleMediaXOverlayData *data)
 {
 	gchar *name;
-	gchar *cmpname;
-	gulong window_id;
-	gboolean set = FALSE;
 
 	if (GST_MESSAGE_TYPE(msg) != GST_MESSAGE_ELEMENT ||
 			!gst_structure_has_name(msg->structure,
@@ -2198,49 +2194,17 @@
 
 	name = gst_object_get_name(GST_MESSAGE_SRC(msg));
 
-	if (data->participant == NULL) {
-		cmpname = g_strdup_printf("session-sink_%s",
-				data->session_id);
-		if (!strncmp(name, cmpname, strlen(cmpname))) {
-			PurpleMediaSession *session =
-					purple_media_get_session(
-					data->media, data->session_id);
-			if (session != NULL) {
-				window_id = session->window_id;
-				set = TRUE;
-			}
-		}
-	} else {
-		cmpname = g_strdup_printf("stream-sink_%s_%s",
-				data->session_id, data->participant);
-
-		if (!strncmp(name, cmpname, strlen(cmpname))) {
-			PurpleMediaStream *stream =
-					purple_media_get_stream(
-					data->media, data->session_id,
-					data->participant);
-			if (stream != NULL) {
-				window_id = stream->window_id;
-				set = TRUE;
-			}
-		}
-	}
-	g_free(cmpname);
-	g_free(name);
-
-	if (set == TRUE) {
-		GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(
-				purple_media_get_pipeline(data->media)));
+	if (!strncmp(name, data->name, strlen(data->name))) {
 		g_signal_handler_disconnect(bus, data->handler_id);
-		gst_object_unref(bus);
 
 		gst_x_overlay_set_xwindow_id(GST_X_OVERLAY(
-				GST_MESSAGE_SRC(msg)), window_id);
+				GST_MESSAGE_SRC(msg)), data->window_id);
 
-		g_free(data->session_id);
-		g_free(data->participant);
+		g_free(data->name);
 		g_free(data);
 	}
+
+	g_free(name);
 		
 	return;
 }
@@ -2262,25 +2226,12 @@
 		session->window_id = window_id;
 
 		if (session->sink == NULL) {
+			PurpleMediaXOverlayData *data;
 			GstBus *bus;
 			GstElement *tee, *bin, *queue, *sink;
 			GstPad *request_pad, *sinkpad, *ghostpad;
 			gchar *name;
 
-			/* Create callback for prepared-xwindow-id signal */
-			PurpleMediaXOverlayData *data =
-					g_new0(PurpleMediaXOverlayData, 1);
-			data->media = media;
-			data->session_id = g_strdup(session_id);
-			data->participant = g_strdup(participant);
-
-			bus = gst_pipeline_get_bus(GST_PIPELINE(
-					purple_media_get_pipeline(media)));
-			data->handler_id = g_signal_connect(bus,
-					"sync-message::element",
-					G_CALLBACK(window_id_cb), data);
-			gst_object_unref(bus);
-
 			/* Create sink */
 			tee = gst_bin_get_by_name(GST_BIN(session->src),
 					"purplevideosrctee");
@@ -2292,7 +2243,6 @@
 					"session-sink_%s", session_id);
 			sink = gst_element_factory_make(
 					"autovideosink", name);
-			g_free(name);
 
 			gst_bin_add_many(GST_BIN(bin), queue, sink, NULL);
 			gst_element_link(queue, sink);
@@ -2302,6 +2252,18 @@
 			gst_object_unref(sinkpad);
 			gst_element_add_pad(bin, ghostpad);
 
+			/* Connect callback for prepared-xwindow-id signal */
+			data = g_new0(PurpleMediaXOverlayData, 1);
+			data->name = name;
+			data->window_id = window_id;
+
+			bus = gst_pipeline_get_bus(GST_PIPELINE(
+					purple_media_get_pipeline(media)));
+			data->handler_id = g_signal_connect(bus,
+					"sync-message::element",
+					G_CALLBACK(window_id_cb), data);
+			gst_object_unref(bus);
+
 			gst_element_set_state(bin, GST_STATE_PLAYING);
 
 			request_pad = gst_element_get_request_pad(
@@ -2370,18 +2332,6 @@
 			}
 		}
 
-		data = g_new0(PurpleMediaXOverlayData, 1);
-		data->media = media;
-		data->session_id = g_strdup(session_id);
-		data->participant = g_strdup(participant);
-
-		bus = gst_pipeline_get_bus(GST_PIPELINE(
-				purple_media_get_pipeline(media)));
-		data->handler_id = g_signal_connect(bus,
-				"sync-message::element",
-				G_CALLBACK(window_id_cb), data);
-		gst_object_unref(bus);
-
 		bin = gst_bin_new(NULL);
 
 		if (stream->sink != NULL)
@@ -2391,13 +2341,24 @@
 		name = g_strdup_printf("stream-sink_%s_%s",
 				session_id, participant);
 		sink = gst_element_factory_make("autovideosink", name);
-		g_free(name);
 
 		gst_bin_add(GST_BIN(bin), sink);
 		pad = gst_element_get_static_pad(sink, "sink");
 		ghostpad = gst_ghost_pad_new("ghostsink", pad);
 		gst_element_add_pad(bin, ghostpad);
 
+		/* Connect callback for prepared-xwindow-id signal */
+		data = g_new0(PurpleMediaXOverlayData, 1);
+		data->name = name;
+		data->window_id = window_id;
+
+		bus = gst_pipeline_get_bus(GST_PIPELINE(
+				purple_media_get_pipeline(media)));
+		data->handler_id = g_signal_connect(bus,
+				"sync-message::element",
+				G_CALLBACK(window_id_cb), data);
+		gst_object_unref(bus);
+
 		if (stream->sink != NULL) {
 			gst_element_set_state(bin, GST_STATE_PLAYING);
 			gst_pad_link(peer, ghostpad);