soc.2008.vv: 3201a4b0: Set the media pipeline to PLAYING immedi...

maiku at soc.pidgin.im maiku at soc.pidgin.im
Thu Jul 17 19:20:58 EDT 2008


-----------------------------------------------------------------
Revision: 3201a4b09a29001e82ce04bfba2eab788d96e819
Ancestor: b88dd63d0a173529f5d5c05c7713e82b8fe346e5
Author: maiku at soc.pidgin.im
Date: 2008-07-17T21:01:46
Branch: im.pidgin.soc.2008.vv
URL: http://d.pidgin.im/viewmtn/revision/info/3201a4b09a29001e82ce04bfba2eab788d96e819

Modified files:
        libpurple/media.c libpurple/mediamanager.c
        libpurple/protocols/jabber/jingle.c pidgin/gtkmedia.c

ChangeLog: 

Set the media pipeline to PLAYING immediately after initialization
(and a few other changes to make it actually work and not hang).

-------------- next part --------------
============================================================
--- libpurple/media.c	434f12547890caada25bf2b6f77f6c57aed01c8d
+++ libpurple/media.c	daa5fec1874067706400d38b0b9f1c686ce8fe7f
@@ -219,10 +219,22 @@ purple_media_finalize (GObject *media)
 purple_media_finalize (GObject *media)
 {
 	PurpleMediaPrivate *priv = PURPLE_MEDIA_GET_PRIVATE(media);
+	GList *sessions = g_hash_table_get_values(priv->sessions);
 	purple_debug_info("media","purple_media_finalize\n");
 
 	g_free(priv->name);
 
+	for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
+		PurpleMediaSession *session = sessions->data;
+		GList *streams = g_hash_table_get_values(session->streams);
+
+		for (; streams; streams = g_list_delete_link(streams, streams)) {
+			g_object_unref(streams->data);
+		}
+
+		g_object_unref(session->session);
+	}
+
 	if (priv->pipeline) {
 		gst_element_set_state(priv->pipeline, GST_STATE_NULL);
 		gst_object_unref(priv->pipeline);
@@ -928,11 +940,9 @@ purple_media_src_pad_added_cb(FsStream *
 purple_media_src_pad_added_cb(FsStream *stream, GstPad *srcpad,
 			      FsCodec *codec, PurpleMediaSession *session)
 {
-	GstElement *pipeline = purple_media_get_pipeline(session->media);
 	GstPad *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(pipeline, GST_STATE_PLAYING);
 }
 
 static gboolean
============================================================
--- libpurple/mediamanager.c	2abad99e2cc67a6c21a9a320baafae58b79c714c
+++ libpurple/mediamanager.c	7332f1cde467612d789cd7d3a52843469acc83cc
@@ -135,20 +135,24 @@ purple_media_manager_create_media(Purple
 {
 	PurpleMedia *media;
 	FsConference *conference = FS_CONFERENCE(gst_element_factory_make(conference_type, NULL));
-	GstStateChangeReturn ret = gst_element_set_state(GST_ELEMENT(conference), GST_STATE_READY);
+	GstStateChangeReturn ret;
 
+	media = PURPLE_MEDIA(g_object_new(purple_media_get_type(),
+			     "screenname", remote_user,
+			     "connection", gc, 
+			     "farsight-conference", conference,
+			     NULL));
+
+	ret = gst_element_set_state(purple_media_get_pipeline(media), GST_STATE_PLAYING);
+
 	if (ret == GST_STATE_CHANGE_FAILURE) {
 		purple_conv_present_error(remote_user,
 					  purple_connection_get_account(gc),
 					  _("Error creating conference."));
+		g_object_unref(media);
 		return NULL;
 	}
 
-	media = PURPLE_MEDIA(g_object_new(purple_media_get_type(),
-			     "screenname", remote_user,
-			     "connection", gc, 
-			     "farsight-conference", conference,
-			     NULL));
 	manager->priv->medias = g_list_append(manager->priv->medias, media);
 	g_signal_emit(manager, purple_media_manager_signals[INIT_MEDIA], 0, media);
 	return media;
============================================================
--- libpurple/protocols/jabber/jingle.c	72a3eac220c017be03942536f085adb61b42a7b5
+++ libpurple/protocols/jabber/jingle.c	de7750c26538e39f9936bb39f8975cbda878b74c
@@ -819,8 +819,7 @@ jabber_jingle_session_send_session_accep
 	if (purple_media_candidates_prepared(media, remote_jid)) {
 		jabber_iq_send(jabber_jingle_session_create_session_accept(session));
 
-		purple_debug_info("jingle", "Sent session accept, starting stream\n");
-		gst_element_set_state(purple_media_get_pipeline(session->media), GST_STATE_PLAYING);
+		purple_debug_info("jingle", "Sent session accept.\n");
 		jabber_jingle_session_set_state(session, ACTIVE);
 	} else
 		jabber_jingle_session_set_state(session, ACCEPTED);
@@ -922,9 +921,7 @@ jabber_jingle_session_candidate_pair_est
 				jabber_jingle_session_get_remote_jid(session))) {
 		jabber_iq_send(jabber_jingle_session_create_session_accept(session));
 		
-		purple_debug_info("jingle", "Sent session accept, starting stream\n");
-		gst_element_set_state(purple_media_get_pipeline(session->media),
-				      GST_STATE_PLAYING);
+		purple_debug_info("jingle", "Sent session accept.\n");
 		jabber_jingle_session_set_state(session, ACTIVE);
 	}
 }
@@ -1223,9 +1220,7 @@ jabber_jingle_session_handle_session_acc
 
 	if (!strcmp(action, "session-accept")) {
 		purple_media_got_accept(jabber_jingle_session_get_media(session));
-		purple_debug_info("jingle", "Got session-accept, starting stream\n");
-		gst_element_set_state(purple_media_get_pipeline(session->media),
-				      GST_STATE_PLAYING);
+		purple_debug_info("jingle", "Got session-accept");
 	}
 
 	jabber_iq_send(jabber_jingle_session_create_ack(session, jingle));
@@ -1332,8 +1327,6 @@ jabber_jingle_session_handle_session_ter
 
 	/* maybe we should look at the reasoncode to determine if it was
 	   a hangup or a reject, and call different callbacks to purple_media */
-	gst_element_set_state(purple_media_get_pipeline(session->media), GST_STATE_NULL);
-
 	purple_media_got_hangup(jabber_jingle_session_get_media(session));
 	jabber_iq_send(jabber_jingle_session_create_ack(session, jingle));
 	jabber_jingle_session_destroy(session);
============================================================
--- pidgin/gtkmedia.c	ea220f60e5ff37e144b22ca5b43af3783fbe5e25
+++ pidgin/gtkmedia.c	61ab89eebb433e0af06f420c43287f8e33a5d8ba
@@ -288,15 +288,12 @@ pidgin_media_ready_cb(PurpleMedia *media
 static void
 pidgin_media_ready_cb(PurpleMedia *media, PidginMedia *gtkmedia)
 {
-	GstElement *element = purple_media_get_pipeline(media);
-
 	GstElement *audiosendbin = NULL, *audiosendlevel = NULL;
 	GstElement *audiorecvbin = NULL, *audiorecvlevel = NULL;
 	GstElement *videosendbin = NULL;
 	GstElement *videorecvbin = NULL;
 
 	GList *sessions = purple_media_get_session_names(media);
-	GstBus *bus;
 
 	for (; sessions; sessions = g_list_delete_link(sessions, sessions)) {
 		if (purple_media_get_session_type(media, sessions->data) & PURPLE_MEDIA_AUDIO) {
@@ -306,6 +303,9 @@ pidgin_media_ready_cb(PurpleMedia *media
 				purple_media_audio_init_recv(&audiorecvbin, &audiorecvlevel);
 			purple_media_set_src(media, sessions->data, audiosendbin);
 			purple_media_set_sink(media, sessions->data, audiorecvbin);
+
+			gst_element_set_state(audiosendbin, GST_STATE_READY);
+			gst_element_set_state(audiorecvbin, GST_STATE_READY);
 		} else if (purple_media_get_session_type(media, sessions->data) & PURPLE_MEDIA_VIDEO) {
 			if (!videosendbin)
 				purple_media_video_init_src(&videosendbin);
@@ -313,6 +313,9 @@ pidgin_media_ready_cb(PurpleMedia *media
 				purple_media_video_init_recv(&videorecvbin);
 			purple_media_set_src(media, sessions->data, videosendbin);
 			purple_media_set_sink(media, sessions->data, videorecvbin);
+
+			gst_element_set_state(videosendbin, GST_STATE_READY);
+			gst_element_set_state(videorecvbin, GST_STATE_READY);
 		}
 	}
 
@@ -321,14 +324,6 @@ pidgin_media_ready_cb(PurpleMedia *media
 				       "recv-level", audiorecvlevel,
 				       NULL);
 	}
-
-	bus = gst_pipeline_get_bus(GST_PIPELINE(element));
-	gst_bus_add_signal_watch(GST_BUS(bus));
-	g_signal_connect(G_OBJECT(gst_pipeline_get_bus(GST_PIPELINE(element))),
-			 "message", 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
@@ -344,10 +339,12 @@ pidgin_media_accept_cb(PurpleMedia *medi
 {
 	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);
@@ -392,6 +389,9 @@ pidgin_media_accept_cb(PurpleMedia *medi
 
 		gtkmedia->priv->local_video = local_video;
 		gtkmedia->priv->remote_video = remote_video;
+
+		gst_element_set_state(videosendbin, GST_STATE_PLAYING);
+		gst_element_set_state(videorecvbin, GST_STATE_PLAYING);
 	}
 
 	if (audiorecvbin || audiosendbin) {
@@ -415,7 +415,20 @@ pidgin_media_accept_cb(PurpleMedia *medi
 
 		gtk_widget_show(gtkmedia->priv->send_progress);
 		gtk_widget_show(gtkmedia->priv->recv_progress);
+
+		gst_element_set_state(audiosendbin, GST_STATE_PLAYING);
+		gst_element_set_state(audiorecvbin, GST_STATE_PLAYING);
 	}
+
+	bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
+	if (audiorecvbin || audiosendbin) {
+		gst_bus_add_signal_watch(GST_BUS(bus));
+		g_signal_connect(G_OBJECT(bus), "message",
+				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


More information about the Commits mailing list