changeset 26027:94224a5563db

Prepare vv GUI earlier and create sinks when src-pad-added is triggered.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Thu, 06 Nov 2008 02:21:16 +0000
parents 431c59a6959d
children bcad7dc4b453
files libpurple/media.c pidgin/gtkmedia.c
diffstat 2 files changed, 56 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media.c	Thu Nov 06 01:32:58 2008 +0000
+++ b/libpurple/media.c	Thu Nov 06 02:21:16 2008 +0000
@@ -917,7 +917,7 @@
 
 	queue = gst_element_factory_make("queue", "purplelocalvideoqueue");
 	gst_bin_add(GST_BIN(*sendbin), queue);
-	/* The queue is linked later, when the local video is ready to be shown */
+	gst_element_link(tee, queue);
 
 	local_sink = gst_element_factory_make("autovideosink", "purplelocalvideosink");
 	gst_bin_add(GST_BIN(*sendbin), local_sink);
@@ -1034,9 +1034,16 @@
 purple_media_src_pad_added_cb(FsStream *stream, GstPad *srcpad,
 			      FsCodec *codec, PurpleMediaSession *session)
 {
-	GstPad *sinkpad = gst_element_get_static_pad(session->sink, "ghostsink");
+	PurpleMediaSessionType type = purple_media_from_fs(codec->media_type, FS_DIRECTION_RECV);
+	GstPad *sinkpad = NULL;
+	session->sink = purple_media_manager_get_element(purple_media_manager_get(), type);
+
+	gst_bin_add(GST_BIN(purple_media_get_pipeline(session->media)),
+		    session->sink);
+	sinkpad = gst_element_get_static_pad(session->sink, "ghostsink");
 	purple_debug_info("media", "connecting new src pad: %s\n", 
 			  gst_pad_link(srcpad, sinkpad) == GST_PAD_LINK_OK ? "success" : "failure");
+	gst_element_set_state(session->sink, GST_STATE_PLAYING);
 }
 
 static gchar *
--- a/pidgin/gtkmedia.c	Thu Nov 06 01:32:58 2008 +0000
+++ b/pidgin/gtkmedia.c	Thu Nov 06 02:21:16 2008 +0000
@@ -302,10 +302,13 @@
 static void
 pidgin_media_ready_cb(PurpleMedia *media, PidginMedia *gtkmedia)
 {
+	GstElement *pipeline = purple_media_get_pipeline(media);
+	GtkWidget *send_widget = NULL, *recv_widget = NULL;
 	GstElement *audiosendbin = NULL, *audiosendlevel = NULL;
-	GstElement *audiorecvbin = NULL, *audiorecvlevel = NULL;
 	GstElement *videosendbin = NULL;
-	GstElement *videorecvbin = NULL;
+	gboolean audiorecvbool = FALSE;
+	gboolean videorecvbool = FALSE;
+	GstBus *bus;
 
 	GList *sessions = purple_media_get_session_names(media);
 
@@ -317,10 +320,8 @@
 				purple_media_set_src(media, sessions->data, audiosendbin);
 				gst_element_set_state(audiosendbin, GST_STATE_PLAYING);
 			}
-			if (!audiorecvbin && (type & PURPLE_MEDIA_RECV_AUDIO)) {
-				purple_media_audio_init_recv(&audiorecvbin, &audiorecvlevel);
-				purple_media_set_sink(media, sessions->data, audiorecvbin);
-				gst_element_set_state(audiorecvbin, GST_STATE_READY);
+			if (!audiorecvbool && (type & PURPLE_MEDIA_RECV_AUDIO)) {
+				audiorecvbool = TRUE;
 			}
 		} else if (type & PURPLE_MEDIA_VIDEO) {
 			if (!videosendbin && (type & PURPLE_MEDIA_SEND_VIDEO)) {
@@ -328,48 +329,13 @@
 				purple_media_set_src(media, sessions->data, videosendbin);
 				gst_element_set_state(videosendbin, GST_STATE_PLAYING);
 			}
-			if (!videorecvbin && (type & PURPLE_MEDIA_RECV_VIDEO)) {
-				purple_media_video_init_recv(&videorecvbin);
-				purple_media_set_sink(media, sessions->data, videorecvbin);
-				gst_element_set_state(videorecvbin, GST_STATE_READY);
+			if (!videorecvbool && (type & PURPLE_MEDIA_RECV_VIDEO)) {
+				videorecvbool = TRUE;
 			}
 		}
 	}
 
-	if (audiosendlevel || audiorecvlevel) {
-		g_object_set(gtkmedia, "send-level", audiosendlevel,
-				       "recv-level", audiorecvlevel,
-				       NULL);
-	}
-}
-
-static void
-pidgin_media_wait_cb(PurpleMedia *media, PidginMedia *gtkmedia)
-{
-	pidgin_media_set_state(gtkmedia, PIDGIN_MEDIA_WAITING);
-}
-
-/* maybe we should have different callbacks for when we received the accept
-    and we accepted ourselves */
-static void
-pidgin_media_accept_cb(PurpleMedia *media, PidginMedia *gtkmedia)
-{
-	GtkWidget *send_widget = NULL, *recv_widget = NULL;
-
-	GstElement *pipeline = purple_media_get_pipeline(media);
-	GstElement *audiosendbin = NULL;
-	GstElement *audiorecvbin = NULL;
-	GstElement *videosendbin = NULL;
-	GstElement *videorecvbin = NULL;
-	GstBus *bus;
-
-	pidgin_media_emit_message(gtkmedia, _("Call in progress."));
-	pidgin_media_set_state(gtkmedia, PIDGIN_MEDIA_ACCEPTED);
-
-	purple_media_get_elements(media, &audiosendbin, &audiorecvbin,
-				  &videosendbin, &videorecvbin);
-
-	if (videorecvbin || audiorecvbin) {
+	if (videorecvbool || audiorecvbool) {
 		recv_widget = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE);
 		gtk_box_pack_start(GTK_BOX(gtkmedia->priv->display),
 				recv_widget, TRUE, TRUE, 0);
@@ -382,7 +348,7 @@
 		gtk_widget_show(send_widget);
 	}
 
-	if (videorecvbin) {
+	if (videorecvbool) {
 		GtkWidget *aspect;
 		GtkWidget *remote_video;
 
@@ -397,12 +363,10 @@
 		gtk_widget_show(aspect);
 
 		gtkmedia->priv->remote_video = remote_video;
-		gst_element_set_state(videorecvbin, GST_STATE_PLAYING);
 	}
 	if (videosendbin) {
 		GtkWidget *aspect;
 		GtkWidget *local_video;
-		GstElement *tee, *queue;
 
 		aspect = gtk_aspect_frame_new(NULL, 0.5, 0.5, 4.0/3.0, FALSE);
 		gtk_frame_set_shadow_type(GTK_FRAME(aspect), GTK_SHADOW_IN);
@@ -415,15 +379,9 @@
 		gtk_widget_show(aspect);
 
 		gtkmedia->priv->local_video = local_video;
-
-		tee = gst_bin_get_by_name(GST_BIN(videosendbin), "purplevideosrctee");
-		queue = gst_bin_get_by_name(GST_BIN(videosendbin), "purplelocalvideoqueue");
-		gst_element_link(tee, queue);
-		gst_object_unref(tee);
-		gst_object_unref(queue);
 	}
 
-	if (audiorecvbin) {
+	if (audiorecvbool) {
 		gtkmedia->priv->recv_progress = gtk_progress_bar_new();
 		gtk_widget_set_size_request(gtkmedia->priv->recv_progress, 10, 70);
 		gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(gtkmedia->priv->recv_progress),
@@ -431,7 +389,6 @@
 		gtk_box_pack_end(GTK_BOX(recv_widget),
 				   gtkmedia->priv->recv_progress, FALSE, FALSE, 0);
 		gtk_widget_show(gtkmedia->priv->recv_progress);
-		gst_element_set_state(audiorecvbin, GST_STATE_PLAYING);
 	}
 	if (audiosendbin) {
 		gtkmedia->priv->send_progress = gtk_progress_bar_new();
@@ -445,16 +402,43 @@
 		gtk_widget_show(gtkmedia->priv->mute);
 	}
 
+	bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
+
+	if (videorecvbool || videosendbin)
+		gst_bus_set_sync_handler(bus,
+				(GstBusSyncHandler)create_window, gtkmedia);
+
+	if (audiorecvbool || audiosendbin)
+		g_signal_connect(G_OBJECT(bus), "message::element",
+				G_CALLBACK(level_message_cb), gtkmedia);
+
+	gst_object_unref(bus);
+}
+
+static void
+pidgin_media_wait_cb(PurpleMedia *media, PidginMedia *gtkmedia)
+{
+	pidgin_media_set_state(gtkmedia, PIDGIN_MEDIA_WAITING);
+}
+
+/* maybe we should have different callbacks for when we received the accept
+    and we accepted ourselves */
+static void
+pidgin_media_accept_cb(PurpleMedia *media, PidginMedia *gtkmedia)
+{
+	GstElement *audiosendbin = NULL;
+	GstElement *audiorecvbin = NULL;
+	GstElement *videosendbin = NULL;
+	GstElement *videorecvbin = NULL;
+
+	pidgin_media_emit_message(gtkmedia, _("Call in progress."));
+	pidgin_media_set_state(gtkmedia, PIDGIN_MEDIA_ACCEPTED);
+
+	purple_media_get_elements(media, &audiosendbin, &audiorecvbin,
+				  &videosendbin, &videorecvbin);
+
 	if (audiorecvbin || audiosendbin || videorecvbin || videosendbin)
 		gtk_widget_show(gtkmedia->priv->display);
-
-	bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
-	if (audiorecvbin || audiosendbin)
-		g_signal_connect(G_OBJECT(bus), "message::element",
-				G_CALLBACK(level_message_cb), gtkmedia);
-	if (videorecvbin || videosendbin)
-		gst_bus_set_sync_handler(bus, (GstBusSyncHandler)create_window, gtkmedia);
-	gst_object_unref(bus);
 }
 
 static void