pidgin.vv: 8a94ecf4: Simplify handling prepare-xwindow-id sig...

maiku at soc.pidgin.im maiku at soc.pidgin.im
Mon Feb 2 02:10:54 EST 2009


-----------------------------------------------------------------
Revision: 8a94ecf4760bc3dc342321fe81f9b44ee93b801d
Ancestor: fcbf98d1dd991f4fc777c5feafb88791a6edbc02
Author: maiku at soc.pidgin.im
Date: 2009-02-02T04:01:34
Branch: im.pidgin.pidgin.vv
URL: http://d.pidgin.im/viewmtn/revision/info/8a94ecf4760bc3dc342321fe81f9b44ee93b801d

Modified files:
        libpurple/media.c

ChangeLog: 

Simplify handling prepare-xwindow-id signal. Reduce thread unsafety.

-------------- next part --------------
============================================================
--- libpurple/media.c	1e28640bea1660137644841e3f6a50b496736f47
+++ libpurple/media.c	00921f7ff0f9e62ed8138a563176f05463228aa6
@@ -2177,9 +2177,8 @@ typedef struct
 
 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 *ms
 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 @@ window_id_cb(GstBus *bus, GstMessage *ms
 
 	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 @@ purple_media_set_output_window(PurpleMed
 		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 @@ purple_media_set_output_window(PurpleMed
 					"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 @@ purple_media_set_output_window(PurpleMed
 			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 @@ purple_media_set_output_window(PurpleMed
 			}
 		}
 
-		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 @@ purple_media_set_output_window(PurpleMed
 		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);


More information about the Commits mailing list