pidgin.vv: 502bd1da: Add purple_media_is_initiator.

maiku at soc.pidgin.im maiku at soc.pidgin.im
Mon Mar 30 22:35:50 EDT 2009


-----------------------------------------------------------------
Revision: 502bd1daac7c1a83dd531e938e40c7623c74fd5f
Ancestor: 285d61d81bfd6e17212a4891c12c7ecd61999814
Author: maiku at soc.pidgin.im
Date: 2009-03-31T01:38:50
Branch: im.pidgin.pidgin.vv
URL: http://d.pidgin.im/viewmtn/revision/info/502bd1daac7c1a83dd531e938e40c7623c74fd5f

Modified files:
        finch/gntmedia.c libpurple/media.c libpurple/media.h
        libpurple/protocols/jabber/google.c
        libpurple/protocols/jabber/jingle/rtp.c pidgin/gtkmedia.c

ChangeLog: 

Add purple_media_is_initiator.

-------------- next part --------------
============================================================
--- finch/gntmedia.c	c20f3beb2d7b55f1368040eb018a8cdc6cda2698
+++ finch/gntmedia.c	2ae7195f5a382441f6e0e74920df0424b0c33ac2
@@ -295,7 +295,6 @@ finch_media_set_property (GObject *objec
 	switch (prop_id) {
 		case PROP_MEDIA:
 		{
-			gboolean is_initiator;
 			if (media->priv->media)
 				g_object_unref(media->priv->media);
 			media->priv->media = g_value_get_object(value);
@@ -307,9 +306,8 @@ finch_media_set_property (GObject *objec
 			g_signal_connect_swapped(G_OBJECT(media->priv->hangup), "activate",
 				 G_CALLBACK(finch_media_hangup_cb), media->priv->media);
 
-			g_object_get(G_OBJECT(media->priv->media), "initiator",
-					&is_initiator, NULL);
-			if (is_initiator == TRUE) {
+			if (purple_media_is_initiator(media->priv->media,
+					NULL, NULL) == TRUE) {
 				finch_media_wait_cb(media->priv->media, media);
 			}
 			g_signal_connect(G_OBJECT(media->priv->media), "state-changed",
============================================================
--- libpurple/media.c	2890709a9ba5d2d71ed285de13b0089668cc71e0
+++ libpurple/media.c	70bbfd2d8c7955967ba8f2c68321897629b4a927
@@ -55,6 +55,7 @@ struct _PurpleMediaSession
 	FsSession *session;
 
 	PurpleMediaSessionType type;
+	gboolean initiator;
 
 	gulong window_id;
 };
@@ -70,6 +71,7 @@ struct _PurpleMediaStream
 	GList *local_candidates;
 	GList *remote_candidates;
 
+	gboolean initiator;
 	gboolean accepted;
 	gboolean candidates_prepared;
 
@@ -1659,7 +1661,7 @@ purple_media_add_stream_internal(PurpleM
 purple_media_add_stream_internal(PurpleMedia *media, const gchar *sess_id,
 				 const gchar *who, FsMediaType type,
 				 FsStreamDirection type_direction,
-				 const gchar *transmitter,
+				 gboolean initiator, const gchar *transmitter,
 				 guint num_params, GParameter *params)
 {
 	PurpleMediaSession *session;
@@ -1730,6 +1732,7 @@ purple_media_add_stream_internal(PurpleM
 		session->id = g_strdup(sess_id);
 		session->media = media;
 		session->type = purple_media_from_fs(type, type_direction);
+		session->initiator = initiator;
 
 		purple_media_add_session(media, session);
 		g_signal_emit(media, purple_media_signals[STATE_CHANGED],
@@ -1849,6 +1852,7 @@ purple_media_add_stream_internal(PurpleM
 		}
 
 		stream = purple_media_insert_stream(session, who, fsstream);
+		stream->initiator = initiator;
 
 		/* callback for source pad added (new stream source ready) */
 		g_signal_connect(G_OBJECT(fsstream),
@@ -1868,7 +1872,7 @@ purple_media_add_stream(PurpleMedia *med
 
 gboolean
 purple_media_add_stream(PurpleMedia *media, const gchar *sess_id, const gchar *who,
-			PurpleMediaSessionType type,
+			PurpleMediaSessionType type, gboolean initiator,
 			const gchar *transmitter,
 			guint num_params, GParameter *params)
 {
@@ -1881,7 +1885,7 @@ purple_media_add_stream(PurpleMedia *med
 		type_direction = purple_media_to_fs_stream_direction(type & PURPLE_MEDIA_AUDIO);
 
 		if (!purple_media_add_stream_internal(media, sess_id, who,
-						      FS_MEDIA_TYPE_AUDIO, type_direction,
+						      FS_MEDIA_TYPE_AUDIO, type_direction, initiator,
 						      transmitter, num_params, params)) {
 			return FALSE;
 		}
@@ -1890,7 +1894,7 @@ purple_media_add_stream(PurpleMedia *med
 		type_direction = purple_media_to_fs_stream_direction(type & PURPLE_MEDIA_VIDEO);
 
 		if (!purple_media_add_stream_internal(media, sess_id, who,
-						      FS_MEDIA_TYPE_VIDEO, type_direction,
+						      FS_MEDIA_TYPE_VIDEO, type_direction, initiator,
 						      transmitter, num_params, params)) {
 			return FALSE;
 		}
@@ -2131,6 +2135,28 @@ gboolean
 }
 
 gboolean
+purple_media_is_initiator(PurpleMedia *media,
+		const gchar *sess_id, const gchar *participant)
+{
+#ifdef USE_VV
+	g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE);
+
+	if (sess_id == NULL && participant == NULL)
+		return media->priv->initiator;
+	else if (sess_id != NULL && participant == NULL) {
+		PurpleMediaSession *session =
+				purple_media_get_session(media, sess_id);
+		return session != NULL ? session->initiator : FALSE;
+	} else if (sess_id != NULL && participant != NULL) {
+		PurpleMediaStream *stream = purple_media_get_stream(
+				media, sess_id, participant);
+		return stream != NULL ? stream->initiator : FALSE;
+	}
+#endif
+	return FALSE;
+}
+
+gboolean
 purple_media_accepted(PurpleMedia *media, const gchar *sess_id,
 		const gchar *participant)
 {
============================================================
--- libpurple/media.h	6484c60da3122fdfe1065fd0bd1475583a58abd9
+++ libpurple/media.h	1947abfdcb3d362afd6090de93d397286039a12c
@@ -382,14 +382,16 @@ void purple_media_stream_info(PurpleMedi
  * @param sess_id The session id of the session to add the stream to.
  * @param who The name of the remote user to add the stream for.
  * @param type The type of stream to create.
+ * @param initiator Whether or not the local user initiated the stream.
  * @param transmitter The transmitter to use for the stream.
  * @param num_params The number of parameters to pass to Farsight.
  * @param params The parameters to pass to Farsight.
  *
  * @return @c TRUE The stream was added successfully, @c FALSE otherwise.
  */
-gboolean purple_media_add_stream(PurpleMedia *media, const gchar *sess_id, const gchar *who,
-		PurpleMediaSessionType type, const gchar *transmitter,
+gboolean purple_media_add_stream(PurpleMedia *media, const gchar *sess_id,
+		const gchar *who, PurpleMediaSessionType type,
+		gboolean initiator, const gchar *transmitter,
 		guint num_params, GParameter *params);
 
 /**
@@ -506,6 +508,18 @@ gboolean purple_media_codecs_ready(Purpl
 gboolean purple_media_codecs_ready(PurpleMedia *media, const gchar *sess_id);
 
 /**
+ * Gets whether the local user is the conference/session/stream's initiator.
+ *
+ * @param media The media instance to find the session in.
+ * @param sess_id The session id of the session to check.
+ * @param participant The participant of the stream to check.
+ *
+ * @return TRUE if the local user is the stream's initator, else FALSE.
+ */
+gboolean purple_media_is_initiator(PurpleMedia *media,
+		const gchar *sess_id, const gchar *participant);
+
+/**
  * Gets whether a streams selected have been accepted.
  *
  * @param media The media object to find the session in.
============================================================
--- libpurple/protocols/jabber/google.c	abeba0b990f3bcc606a496d8ae153f5edf07178a
+++ libpurple/protocols/jabber/google.c	be66b0a4d03bd79a60556e737fe0a1c90431825b
@@ -329,7 +329,7 @@ jabber_google_session_initiate(JabberStr
 
 	if (purple_media_add_stream(session->media, "google-voice",
 				session->remote_jid, PURPLE_MEDIA_AUDIO,
-				"nice", num_params, params) == FALSE) {
+				TRUE, "nice", num_params, params) == FALSE) {
 		purple_media_error(session->media, "Error adding stream.");
 		purple_media_stream_info(session->media,
 				PURPLE_MEDIA_INFO_HANGUP, NULL, NULL, TRUE);
@@ -376,8 +376,9 @@ google_session_handle_initiate(JabberStr
 
 	params = jabber_google_session_get_params(js, &num_params);
 
-	if (purple_media_add_stream(session->media, "google-voice", session->remote_jid, 
-				PURPLE_MEDIA_AUDIO, "nice", num_params, params) == FALSE) {
+	if (purple_media_add_stream(session->media, "google-voice",
+			session->remote_jid, PURPLE_MEDIA_AUDIO, FALSE,
+			"nice", num_params, params) == FALSE) {
 		purple_media_error(session->media, "Error adding stream.");
 		purple_media_stream_info(session->media,
 				PURPLE_MEDIA_INFO_HANGUP, NULL, NULL, TRUE);
============================================================
--- libpurple/protocols/jabber/jingle/rtp.c	7e6be996e9ac8ced0864e5b00728f3692f7500d2
+++ libpurple/protocols/jabber/jingle/rtp.c	90042e19c6e5b25ae2f9132dd6e85cbc58f397f1
@@ -535,12 +535,14 @@ jingle_rtp_init_media(JingleContent *con
 {
 	JingleSession *session = jingle_content_get_session(content);
 	PurpleMedia *media = jingle_rtp_get_media(session);
+	gchar *creator;
 	gchar *media_type;
 	gchar *remote_jid;
 	gchar *senders;
 	gchar *name;
 	const gchar *transmitter;
 	gboolean is_audio;
+	gboolean is_creator;
 	PurpleMediaSessionType type;
 	JingleTransport *transport;
 	GParameter *params = NULL;
@@ -582,8 +584,16 @@ jingle_rtp_init_media(JingleContent *con
 
 	params = 
 		jingle_get_params(jingle_session_get_js(session), &num_params);
+
+	creator = jingle_content_get_creator(content);
+	if (!strcmp(creator, "initiator"))
+		is_creator = jingle_session_is_initiator(session);
+	else
+		is_creator = !jingle_session_is_initiator(session);
+	g_free(creator);
+
 	purple_media_add_stream(media, name, remote_jid,
-			type, transmitter, num_params, params);
+			type, is_creator, transmitter, num_params, params);
 
 	g_free(name);
 	g_free(media_type);
============================================================
--- pidgin/gtkmedia.c	ebdee423229b7bd24bf114cd867fca85cebf4ed2
+++ pidgin/gtkmedia.c	1b5e92d56dba2f0dd2a742823001abda295774fa
@@ -586,7 +586,6 @@ pidgin_media_ready_cb(PurpleMedia *media
 {
 	GstElement *pipeline = purple_media_get_pipeline(media);
 	GtkWidget *send_widget = NULL, *recv_widget = NULL;
-	gboolean is_initiator;
 	PurpleMediaSessionType type =
 			purple_media_get_session_type(media, sid);
 
@@ -727,9 +726,7 @@ pidgin_media_ready_cb(PurpleMedia *media
 	if (recv_widget != NULL)
 		gtkmedia->priv->recv_widget = recv_widget;
 
-	g_object_get(G_OBJECT(media), "initiator", &is_initiator, NULL);
-
-	if (is_initiator == FALSE) {
+	if (purple_media_is_initiator(media, sid, NULL) == FALSE) {
 		if (gtkmedia->priv->timeout_id != 0)
 			g_source_remove(gtkmedia->priv->timeout_id);
 		gtkmedia->priv->request_type |= type;
@@ -799,15 +796,13 @@ pidgin_media_set_property (GObject *obje
 	switch (prop_id) {
 		case PROP_MEDIA:
 		{
-			gboolean initiator;
 			if (media->priv->media)
 				g_object_unref(media->priv->media);
 			media->priv->media = g_value_get_object(value);
 			g_object_ref(media->priv->media);
 
-			g_object_get(G_OBJECT(media->priv->media),
-					"initiator", &initiator, NULL);
-			if (initiator == TRUE)
+			if (purple_media_is_initiator(media->priv->media,
+					 NULL, NULL) == TRUE)
 				pidgin_media_set_state(media, PIDGIN_MEDIA_WAITING);
 			else
 				pidgin_media_set_state(media, PIDGIN_MEDIA_REQUESTED);
@@ -893,7 +888,6 @@ pidgin_media_new_cb(PurpleMediaManager *
 {
 	PidginMedia *gtkmedia = PIDGIN_MEDIA(
 			pidgin_media_new(media, screenname));
-	gboolean initiator;
 	PurpleBuddy *buddy = purple_find_buddy(
 			purple_connection_get_account(pc), screenname);
 	const gchar *alias = buddy ? 
@@ -901,8 +895,7 @@ pidgin_media_new_cb(PurpleMediaManager *
 	gtkmedia->priv->pc = pc;
 	gtk_window_set_title(GTK_WINDOW(gtkmedia), alias);
 
-	g_object_get(G_OBJECT(media), "initiator", &initiator, NULL);
-	if (initiator == TRUE)
+	if (purple_media_is_initiator(media, NULL, NULL) == TRUE)
 		gtk_widget_show(GTK_WIDGET(gtkmedia));
 
 	return TRUE;


More information about the Commits mailing list