changeset 26025:1a2d446cb8a0

Fix support for audio and video (at the same time) sessions.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Mon, 03 Nov 2008 03:07:07 +0000
parents 78c3e991782a
children 431c59a6959d
files libpurple/protocols/jabber/jingle/content.c libpurple/protocols/jabber/jingle/content.h libpurple/protocols/jabber/jingle/jingle.c libpurple/protocols/jabber/jingle/rtp.c
diffstat 4 files changed, 43 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jingle/content.c	Sun Nov 02 21:00:46 2008 +0000
+++ b/libpurple/protocols/jabber/jingle/content.c	Mon Nov 03 03:07:07 2008 +0000
@@ -447,9 +447,9 @@
 }
 
 void
-jingle_content_handle_action(JingleContent *content, xmlnode *jingle, JingleActionType action)
+jingle_content_handle_action(JingleContent *content, xmlnode *xmlcontent, JingleActionType action)
 {
 	g_return_if_fail(JINGLE_IS_CONTENT(content));
-	JINGLE_CONTENT_GET_CLASS(content)->handle_action(content, jingle, action);
+	JINGLE_CONTENT_GET_CLASS(content)->handle_action(content, xmlcontent, action);
 }
 
--- a/libpurple/protocols/jabber/jingle/content.h	Sun Nov 02 21:00:46 2008 +0000
+++ b/libpurple/protocols/jabber/jingle/content.h	Mon Nov 03 03:07:07 2008 +0000
@@ -53,7 +53,7 @@
 
 	xmlnode *(*to_xml) (JingleContent *content, xmlnode *jingle, JingleActionType action);
 	JingleContent *(*parse) (xmlnode *content);
-	void (*handle_action) (JingleContent *content, xmlnode *jingle, JingleActionType action);
+	void (*handle_action) (JingleContent *content, xmlnode *xmlcontent, JingleActionType action);
 	const gchar *description_type;
 };
 
@@ -105,7 +105,7 @@
 
 JingleContent *jingle_content_parse(xmlnode *content);
 xmlnode *jingle_content_to_xml(JingleContent *content, xmlnode *jingle, JingleActionType action);
-void jingle_content_handle_action(JingleContent *content, xmlnode *jingle, JingleActionType action);
+void jingle_content_handle_action(JingleContent *content, xmlnode *xmlcontent, JingleActionType action);
 
 #ifdef __cplusplus
 }
--- a/libpurple/protocols/jabber/jingle/jingle.c	Sun Nov 02 21:00:46 2008 +0000
+++ b/libpurple/protocols/jabber/jingle/jingle.c	Mon Nov 03 03:07:07 2008 +0000
@@ -213,12 +213,13 @@
 	for (; content; content = xmlnode_get_next_twin(content)) {
 		const gchar *name = xmlnode_get_attrib(content, "name");
 		const gchar *creator = xmlnode_get_attrib(content, "creator");
-		JingleContent *content = jingle_session_find_content(session, name, creator);
-		if (content == NULL) {
+		JingleContent *parsed_content =
+				jingle_session_find_content(session, name, creator);
+		if (parsed_content == NULL) {
 			purple_debug_error("jingle", "Error parsing content\n");
 			/* XXX: send error */
 		} else {
-			jingle_content_handle_action(content, jingle,
+			jingle_content_handle_action(parsed_content, content,
 					JINGLE_SESSION_ACCEPT);
 		}
 	}
@@ -243,7 +244,7 @@
 			/* XXX: send error */
 		} else {
 			jingle_session_add_content(session, parsed_content);
-			jingle_content_handle_action(parsed_content, jingle,
+			jingle_content_handle_action(parsed_content, content,
 					JINGLE_SESSION_INITIATE);
 		}
 	}
@@ -287,12 +288,13 @@
 	for (; content; content = xmlnode_get_next_twin(content)) {
 		const gchar *name = xmlnode_get_attrib(content, "name");
 		const gchar *creator = xmlnode_get_attrib(content, "creator");
-		JingleContent *content = jingle_session_find_content(session, name, creator);
-		if (content == NULL) {
+		JingleContent *parsed_content = 
+				jingle_session_find_content(session, name, creator);
+		if (parsed_content == NULL) {
 			purple_debug_error("jingle", "Error parsing content\n");
 			/* XXX: send error */
 		} else {
-			jingle_content_handle_action(content, jingle,
+			jingle_content_handle_action(parsed_content, content,
 					JINGLE_TRANSPORT_INFO);
 		}
 	}
--- a/libpurple/protocols/jabber/jingle/rtp.c	Sun Nov 02 21:00:46 2008 +0000
+++ b/libpurple/protocols/jabber/jingle/rtp.c	Mon Nov 03 03:07:07 2008 +0000
@@ -409,9 +409,6 @@
 	g_free(senders);
 	g_object_unref(session);
 
-	/* needs to be after all the streams have been added */
-	purple_media_ready(media);
-
 	return TRUE;
 }
 
@@ -523,25 +520,30 @@
 }
 
 static void
-jingle_rtp_handle_action_internal(JingleContent *content, xmlnode *jingle, JingleActionType action)
+jingle_rtp_handle_action_internal(JingleContent *content, xmlnode *xmlcontent, JingleActionType action)
 {
 	switch (action) {
 		case JINGLE_SESSION_ACCEPT: {
 			JingleSession *session = jingle_content_get_session(content);
-			xmlnode *description = xmlnode_get_child(jingle, "content/description");
+			xmlnode *description = xmlnode_get_child(xmlcontent, "description");
 			GList *codecs = jingle_rtp_parse_codecs(description);
 
 			purple_media_set_remote_codecs(jingle_rtp_get_media(session),
 					jingle_content_get_name(content),
 					jingle_session_get_remote_jid(session), codecs);
 
+			/* This needs to be for the entire session, not a single content */
+			/* very hacky */
+			if (xmlnode_get_next_twin(xmlcontent) == NULL)
+				purple_media_got_accept(jingle_rtp_get_media(session));
+
 			g_object_unref(session);
 			break;
 		}
 		case JINGLE_SESSION_INITIATE: {
 			JingleSession *session = jingle_content_get_session(content);
-			xmlnode *description = xmlnode_get_child(jingle, "content/description");
-			xmlnode *transport = xmlnode_get_child(jingle, "content/transport");
+			xmlnode *description = xmlnode_get_child(xmlcontent, "description");
+			xmlnode *transport = xmlnode_get_child(xmlcontent, "transport");
 			FsCandidate *candidate = jingle_rtp_transport_to_candidate(transport);
 			GList *candidates = g_list_append(NULL, candidate);
 			GList *codecs = jingle_rtp_parse_codecs(description);
@@ -563,6 +565,10 @@
 					jingle_session_get_remote_jid(session),
 					candidates);
 
+			/* very hacky */
+			if (xmlnode_get_next_twin(xmlcontent) == NULL)
+				purple_media_ready(jingle_rtp_get_media(session));
+
 			g_object_unref(session);
 			break;
 		}
@@ -574,7 +580,7 @@
 		}
 		case JINGLE_TRANSPORT_INFO: {
 			JingleSession *session = jingle_content_get_session(content);
-			xmlnode *transport = xmlnode_get_child(jingle, "content/transport");
+			xmlnode *transport = xmlnode_get_child(xmlcontent, "transport");
 			FsCandidate *candidate = jingle_rtp_transport_to_candidate(transport);
 			GList *candidates = g_list_append(NULL, candidate);
 
@@ -588,7 +594,6 @@
 					jingle_content_get_name(content),
 					jingle_session_get_remote_jid(session),
 					candidates);
-			purple_media_got_accept(jingle_rtp_get_media(session));
 			g_object_unref(session);
 			break;
 		}
@@ -634,16 +639,25 @@
 	session = jingle_session_create(js, sid, me, jid, TRUE);
 	g_free(sid);
 
-	transport = jingle_transport_create(JINGLE_TRANSPORT_RAWUDP);
-	content = jingle_content_create(JINGLE_APP_RTP, "initiator", "session", "test-session", "both", transport);
-	jingle_session_add_content(session, content);
-	if (purple_media_to_fs_media_type(type) == FS_MEDIA_TYPE_AUDIO)
+
+	if (type & PURPLE_MEDIA_AUDIO) {
+		transport = jingle_transport_create(JINGLE_TRANSPORT_RAWUDP);
+		content = jingle_content_create(JINGLE_APP_RTP, "initiator",
+				"session", "audio-session", "both", transport);
+		jingle_session_add_content(session, content);
 		JINGLE_RTP(content)->priv->media_type = g_strdup("audio");
-	else
+		jingle_rtp_init_media(content);
+	}
+	if (type & PURPLE_MEDIA_VIDEO) {
+		transport = jingle_transport_create(JINGLE_TRANSPORT_RAWUDP);
+		content = jingle_content_create(JINGLE_APP_RTP, "initiator",
+				"session", "video-session", "both", transport);
+		jingle_session_add_content(session, content);
 		JINGLE_RTP(content)->priv->media_type = g_strdup("video");
+		jingle_rtp_init_media(content);
+	}
 
-	jingle_rtp_init_media(content);
-
+	purple_media_ready(jingle_rtp_get_media(session));
 	purple_media_wait(jingle_rtp_get_media(session));
 
 	g_free(jid);