changeset 26466:bea334b214fa

Add purple_media_is_initiator.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Tue, 31 Mar 2009 01:38:50 +0000
parents 5c2d82afe578
children 8bc4b9094913
files finch/gntmedia.c libpurple/media.c libpurple/media.h libpurple/protocols/jabber/google.c libpurple/protocols/jabber/jingle/rtp.c pidgin/gtkmedia.c
diffstat 6 files changed, 67 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntmedia.c	Mon Mar 30 23:50:44 2009 +0000
+++ b/finch/gntmedia.c	Tue Mar 31 01:38:50 2009 +0000
@@ -295,7 +295,6 @@
 	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 @@
 			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",
--- a/libpurple/media.c	Mon Mar 30 23:50:44 2009 +0000
+++ b/libpurple/media.c	Tue Mar 31 01:38:50 2009 +0000
@@ -55,6 +55,7 @@
 	FsSession *session;
 
 	PurpleMediaSessionType type;
+	gboolean initiator;
 
 	gulong window_id;
 };
@@ -70,6 +71,7 @@
 	GList *local_candidates;
 	GList *remote_candidates;
 
+	gboolean initiator;
 	gboolean accepted;
 	gboolean candidates_prepared;
 
@@ -1659,7 +1661,7 @@
 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 @@
 		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 @@
 		}
 
 		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 @@
 
 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 @@
 		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 @@
 		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
+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)
 {
--- a/libpurple/media.h	Mon Mar 30 23:50:44 2009 +0000
+++ b/libpurple/media.h	Tue Mar 31 01:38:50 2009 +0000
@@ -382,14 +382,16 @@
  * @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(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.
--- a/libpurple/protocols/jabber/google.c	Mon Mar 30 23:50:44 2009 +0000
+++ b/libpurple/protocols/jabber/google.c	Tue Mar 31 01:38:50 2009 +0000
@@ -329,7 +329,7 @@
 
 	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 @@
 
 	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);
--- a/libpurple/protocols/jabber/jingle/rtp.c	Mon Mar 30 23:50:44 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Tue Mar 31 01:38:50 2009 +0000
@@ -535,12 +535,14 @@
 {
 	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 @@
 
 	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);
--- a/pidgin/gtkmedia.c	Mon Mar 30 23:50:44 2009 +0000
+++ b/pidgin/gtkmedia.c	Tue Mar 31 01:38:50 2009 +0000
@@ -586,7 +586,6 @@
 {
 	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 @@
 	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 @@
 	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 @@
 {
 	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 @@
 	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;