cpw.malu.xmpp.google_relay: 1a4d83bf: Actually handle candidates we receive fr...

malu at pidgin.im malu at pidgin.im
Thu Sep 2 17:05:49 EDT 2010


----------------------------------------------------------------------
Revision: 1a4d83bf629ef1561c5587cdd4487d9db012979b
Parent:   67a9105587ae5686beed39fca65c15a5fc8bcad1
Author:   malu at pidgin.im
Date:     09/02/10 17:00:25
Branch:   im.pidgin.cpw.malu.xmpp.google_relay
URL: http://d.pidgin.im/viewmtn/revision/info/1a4d83bf629ef1561c5587cdd4487d9db012979b

Changelog: 

Actually handle candidates we receive from the initiator before setting up our own streams (after getting a relay response from the HTTP server). This seems to somewhat work now, though for some reason it seems to use relays also locally...

Changes against parent 67a9105587ae5686beed39fca65c15a5fc8bcad1

  patched  libpurple/protocols/jabber/google/google_session.c

-------------- next part --------------
============================================================
--- libpurple/protocols/jabber/google/google_session.c	b604b0975fdcd4d14b1d54748f03016d1324de9b
+++ libpurple/protocols/jabber/google/google_session.c	d901867c0d16291af782dd40d4d4434913f957b3
@@ -29,6 +29,10 @@ typedef struct {
 typedef struct {
 	PurpleMedia *media;
 	gboolean video;
+	GList *remote_audio_candidates; /* list of PurpleMediaCandidate */
+	GList *remote_video_candidates; /* list of PurpleMediaCandidate */
+	gboolean added_streams;		/* this indicates if the streams have been
+	 							   to media (ie. after getting relay credentials */
 } GoogleAVSessionData;
 
 static gboolean
@@ -43,9 +47,18 @@ google_session_destroy(GoogleSession *se
 static void
 google_session_destroy(GoogleSession *session)
 {
+	GoogleAVSessionData *session_data =
+		(GoogleAVSessionData *) session->session_data;
 	g_free(session->id.id);
 	g_free(session->id.initiator);
 	g_free(session->remote_jid);
+
+	if (session_data->remote_audio_candidates)
+		purple_media_candidate_list_free(session_data->remote_audio_candidates);
+
+	if (session_data->remote_video_candidates)
+		purple_media_candidate_list_free(session_data->remote_video_candidates);
+
 	g_free(session->session_data);
 	g_free(session);
 }
@@ -436,6 +449,8 @@ jabber_google_relay_response_session_ini
 		purple_media_error(session_data->media, "Error adding stream.");
 		purple_media_end(session_data->media, NULL, NULL);
 		g_free(params);
+	} else {
+		session_data->added_streams = TRUE;
 	}
 
 	g_free(params);	
@@ -576,9 +591,26 @@ jabber_google_relay_response_session_han
 		purple_media_error(session_data->media, "Error adding stream.");
 		purple_media_stream_info(session_data->media,
 				PURPLE_MEDIA_INFO_REJECT, NULL, NULL, TRUE);
-		g_free(params);
+	} else {
+		/* successfully added stream(s) */
+		session_data->added_streams = TRUE;
+
+		if (session_data->remote_audio_candidates) {
+			purple_media_add_remote_candidates(session_data->media,
+				"google-voice", session->remote_jid, 
+			    session_data->remote_audio_candidates);
+			purple_media_candidate_list_free(session_data->remote_audio_candidates);
+			session_data->remote_audio_candidates = NULL;
+		}
+		if (session_data->remote_video_candidates) {
+			purple_media_add_remote_candidates(session_data->media,
+				"google-video", session->remote_jid, 
+			    session_data->remote_video_candidates);
+			purple_media_candidate_list_free(session_data->remote_video_candidates);
+			session_data->remote_video_candidates = NULL;
+		}
 	}
-
+		
 	g_free(params);
 
 	for (codec_element = xmlnode_get_child(desc_element, "payload-type");
@@ -744,23 +776,36 @@ google_session_handle_candidates(JabberS
 					atoi(port));
 			g_object_set(info, "username", xmlnode_get_attrib(cand, "username"),
 					"password", xmlnode_get_attrib(cand, "password"), NULL);
-			if (!strncmp(cname, "video_", 6))
-				video_list = g_list_append(video_list, info);
-			else
-				list = g_list_append(list, info);
+			if (!strncmp(cname, "video_", 6)) {
+				if (session_data->added_streams) {
+					video_list = g_list_append(video_list, info);
+				} else {
+					session_data->remote_video_candidates =
+						g_list_append(session_data->remote_video_candidates,
+							info);
+				}
+			} else {
+				if (session_data->added_streams) {
+					list = g_list_append(list, info);
+				} else {
+					session_data->remote_audio_candidates =
+						g_list_append(session_data->remote_audio_candidates,
+							info);
+				}
+			}
 		}
 	}
 
-	if (list)
-		purple_media_add_remote_candidates(
-				session_data->media, "google-voice",
-				session->remote_jid, list);
-	if (video_list)
-		purple_media_add_remote_candidates(
-				session_data->media, "google-video",
-				session->remote_jid, video_list);
-	purple_media_candidate_list_free(list);
-	purple_media_candidate_list_free(video_list);
+	if (list) {
+		purple_media_add_remote_candidates(session_data->media, "google-voice",
+			session->remote_jid, list);
+		purple_media_candidate_list_free(list);
+	}
+	if (video_list) {
+		purple_media_add_remote_candidates(session_data->media, "google-video",
+			session->remote_jid, video_list);
+		purple_media_candidate_list_free(video_list);
+	}
 
 	result = jabber_iq_new(js, JABBER_IQ_RESULT);
 	jabber_iq_set_id(result, iq_id);


More information about the Commits mailing list