changeset 26157:1aed9a92b657

Implement *_remove_output_window and *_remove_output_windows.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Mon, 02 Feb 2009 09:58:14 +0000
parents 1199abde956b
children bb8d4ff8276a 218f052b9bf5
files libpurple/media.c libpurple/media.h pidgin/gtkmedia.c
diffstat 3 files changed, 87 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Mon Feb 02 05:38:29 2009 +0000
+++ b/libpurple/media.c	Mon Feb 02 09:58:14 2009 +0000
@@ -2374,4 +2374,87 @@
 	return FALSE;
 }
 
+static void
+dummy_block_cb(GstPad *pad, gboolean blocked, gpointer user_data)
+{
+}
+
+gboolean
+purple_media_remove_output_window(PurpleMedia *media, const gchar *session_id,
+		const gchar *participant)
+{	
+	GstElement *parent, *fakesink, *sink;
+	GstPad *pad, *peer;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE);
+
+	if (session_id != NULL && participant == NULL) {
+		PurpleMediaSession *session;
+		session = purple_media_get_session(media, session_id);
+
+		if (session == NULL)
+			return FALSE;
+
+		sink = session->sink;
+	} else if (session_id != NULL && participant != NULL) {
+		PurpleMediaStream *stream;
+		stream = purple_media_get_stream(media,
+				session_id, participant);
+
+		if (stream == NULL)
+			return FALSE;
+
+		sink = stream->sink;
+	} else
+		return FALSE;
+
+	if (!GST_IS_ELEMENT(sink))
+		return FALSE;
+
+	/* Remove sink */
+	parent = GST_ELEMENT(gst_element_get_parent(sink));
+	pad = gst_element_get_static_pad(sink, "ghostsink");
+
+	if (pad == NULL) {
+		/* It's already a fakesink */
+		gst_object_unref(parent);
+		return FALSE;
+	}
+
+	peer = gst_pad_get_peer(pad);
+	gst_object_unref(pad);
+	gst_pad_set_blocked_async(peer, TRUE, dummy_block_cb, NULL);
+	gst_element_set_state(sink, GST_STATE_NULL);
+	gst_bin_remove(GST_BIN(parent), sink);
+
+	/* Add fakesink */
+	fakesink = gst_element_factory_make("fakesink", NULL);
+	gst_bin_add(GST_BIN(parent), fakesink);
+	gst_element_sync_state_with_parent(fakesink);
+	gst_object_unref(parent);
+	pad = gst_element_get_static_pad(fakesink, "sink");
+	gst_pad_link(peer, pad);
+	gst_object_unref(pad);
+	gst_pad_set_blocked_async(peer, FALSE, dummy_block_cb, NULL);
+	gst_object_unref(peer);
+	return TRUE;
+}
+
+void
+purple_media_remove_output_windows(PurpleMedia *media)
+{
+	GList *iter = media->priv->streams;
+	for (; iter; iter = g_list_next(iter)) {
+		PurpleMediaStream *stream = iter->data;
+		purple_media_remove_output_window(media,
+				stream->session->id, stream->participant);
+	}
+
+	iter = purple_media_get_session_names(media);
+	for (; iter; iter = g_list_delete_link(iter, iter)) {
+		gchar *session_name = iter->data;
+		purple_media_remove_output_window(media, session_name, NULL);
+	}
+}
+
 #endif  /* USE_VV */
--- a/libpurple/media.h	Mon Feb 02 05:38:29 2009 +0000
+++ b/libpurple/media.h	Mon Feb 02 09:58:14 2009 +0000
@@ -642,6 +642,9 @@
 gboolean purple_media_set_output_window(PurpleMedia *media,
 		const gchar *session_id, const gchar *participant,
 		gulong window_id);
+gboolean purple_media_remove_output_window(PurpleMedia *media,
+		const gchar *session_id, const gchar *participant);
+void purple_media_remove_output_windows(PurpleMedia *media);
 
 #ifdef __cplusplus
 }
--- a/pidgin/gtkmedia.c	Mon Feb 02 05:38:29 2009 +0000
+++ b/pidgin/gtkmedia.c	Mon Feb 02 09:58:14 2009 +0000
@@ -285,20 +285,7 @@
 	purple_debug_info("gtkmedia", "pidgin_media_dispose\n");
 
 	if (gtkmedia->priv->media) {
-		GstElement *videosendbin = NULL, *videorecvbin = NULL;
-
-		purple_media_get_elements(gtkmedia->priv->media, NULL, NULL,
-					  &videosendbin, &videorecvbin);
-
-		if (videorecvbin) {
-			gst_element_set_locked_state(videorecvbin, TRUE);
-			gst_element_set_state(videorecvbin, GST_STATE_NULL);
-		}
-		if (videosendbin) {
-			gst_element_set_locked_state(videosendbin, TRUE);
-			gst_element_set_state(videosendbin, GST_STATE_NULL);
-		}
-
+		purple_media_remove_output_windows(gtkmedia->priv->media);
 		pidgin_media_disconnect_levels(gtkmedia->priv->media, gtkmedia);
 		g_object_unref(gtkmedia->priv->media);
 		gtkmedia->priv->media = NULL;