changeset 29576:a27e41f373db

Handle part of accepting a stream in the Fs2 media backend.
author maiku@pidgin.im
date Tue, 27 Oct 2009 00:13:39 +0000
parents ec5ed142f551
children 3bab2237724d
files libpurple/media/backend-fs2.c libpurple/media/media.c
diffstat 2 files changed, 57 insertions(+), 91 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/media/backend-fs2.c	Mon Oct 26 23:26:59 2009 +0000
+++ b/libpurple/media/backend-fs2.c	Tue Oct 27 00:13:39 2009 +0000
@@ -625,6 +625,33 @@
 	return NULL;
 }
 
+static GList *
+_get_streams(PurpleMediaBackendFs2 *self,
+		const gchar *sess_id, const gchar *name)
+{
+	PurpleMediaBackendFs2Private *priv;
+	GList *streams, *ret = NULL;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_BACKEND_FS2(self), NULL);
+
+	priv = PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
+	streams = priv->streams;
+
+	for (; streams; streams = g_list_next(streams)) {
+		PurpleMediaBackendFs2Stream *stream = streams->data;
+
+		if (sess_id != NULL && strcmp(stream->session->id, sess_id))
+			continue;
+		else if (name != NULL && strcmp(stream->participant, name))
+			continue;
+		else
+			ret = g_list_prepend(ret, stream);
+	}
+
+	ret = g_list_reverse(ret);
+	return ret;
+}
+
 static PurpleMediaBackendFs2Session *
 _get_session_from_fs_stream(PurpleMediaBackendFs2 *self, FsStream *stream)
 {
@@ -964,6 +991,33 @@
 		gchar *sid, gchar *name, gboolean local,
 		PurpleMediaBackendFs2 *self)
 {
+	if (type == PURPLE_MEDIA_INFO_ACCEPT) {
+		GList *streams = _get_streams(self, sid, name);
+		
+		for (; streams; streams =
+				g_list_delete_link(streams, streams)) {
+			PurpleMediaBackendFs2Stream *stream = streams->data;
+			GError *err = NULL;
+
+			g_object_set(G_OBJECT(stream->stream), "direction",
+					_session_type_to_fs_stream_direction(
+					stream->session->type), NULL);
+
+			if (stream->remote_candidates == NULL)
+				continue;
+
+			fs_stream_set_remote_candidates(stream->stream,
+					stream->remote_candidates, &err);
+
+			if (err == NULL)
+				continue;
+
+			purple_debug_error("backend-fs2", "Error adding "
+					"remote candidates: %s\n",
+					err->message);
+			g_error_free(err);
+		}
+	}
 }
 
 static gboolean
--- a/libpurple/media/media.c	Mon Oct 26 23:26:59 2009 +0000
+++ b/libpurple/media/media.c	Tue Oct 27 00:13:39 2009 +0000
@@ -509,72 +509,6 @@
 
 }
 
-static FsCandidate *
-purple_media_candidate_to_fs(PurpleMediaCandidate *candidate)
-{
-	FsCandidate *fscandidate;
-	gchar *foundation;
-	guint component_id;
-	gchar *ip;
-	guint port;
-	gchar *base_ip;
-	guint base_port;
-	PurpleMediaNetworkProtocol proto;
-	guint32 priority;
-	PurpleMediaCandidateType type;
-	gchar *username;
-	gchar *password;
-	guint ttl;
-
-	if (candidate == NULL)
-		return NULL;
-
-	g_object_get(G_OBJECT(candidate),
-			"foundation", &foundation,
-			"component-id", &component_id,
-			"ip", &ip,
-			"port", &port,
-			"base-ip", &base_ip,
-			"base-port", &base_port,
-			"protocol", &proto,
-			"priority", &priority,
-			"type", &type,
-			"username", &username,
-			"password", &password,
-			"ttl", &ttl,
-			NULL);
-
-	fscandidate = fs_candidate_new(foundation,
-			component_id, type,
-			proto, ip, port);
-
-	fscandidate->base_ip = base_ip;
-	fscandidate->base_port = base_port;
-	fscandidate->priority = priority;
-	fscandidate->username = username;
-	fscandidate->password = password;
-	fscandidate->ttl = ttl;
-
-	g_free(foundation);
-	g_free(ip);
-	return fscandidate;
-}
-
-static GList *
-purple_media_candidate_list_to_fs(GList *candidates)
-{
-	GList *new_list = NULL;
-
-	for (; candidates; candidates = g_list_next(candidates)) {
-		new_list = g_list_prepend(new_list,
-				purple_media_candidate_to_fs(
-				candidates->data));
-	}
-
-	new_list = g_list_reverse(new_list);
-	return new_list;
-}
-
 static FsMediaType
 purple_media_to_fs_media_type(PurpleMediaSessionType type)
 {
@@ -974,27 +908,8 @@
 		for (; streams; streams =
 				g_list_delete_link(streams, streams)) {
 			PurpleMediaStream *stream = streams->data;
-			g_object_set(G_OBJECT(stream->stream), "direction",
-					purple_media_to_fs_stream_direction(
-					stream->session->type), NULL);
+
 			stream->accepted = TRUE;
-
-			if (stream->remote_candidates != NULL) {
-				GError *err = NULL;
-				GList *candidates;
-
-				candidates = purple_media_candidate_list_to_fs(
-						stream->remote_candidates);
-				fs_stream_set_remote_candidates(stream->stream,
-						candidates, &err);
-				fs_candidate_list_destroy(candidates);
-
-				if (err) {
-					purple_debug_error("media", "Error adding remote"
-							" candidates: %s\n", err->message);
-					g_error_free(err);
-				}
-			}
 		}
 	} else if (local == TRUE && (type == PURPLE_MEDIA_INFO_MUTE ||
 			type == PURPLE_MEDIA_INFO_UNMUTE)) {
@@ -1444,11 +1359,8 @@
 	stream->remote_candidates = g_list_concat(stream->remote_candidates,
 			purple_media_candidate_list_copy(remote_candidates));
 
-	if (stream->accepted == TRUE) {
-		purple_media_backend_add_remote_candidates(
-				media->priv->backend, sess_id, participant,
-				remote_candidates);
-	}
+	purple_media_backend_add_remote_candidates(media->priv->backend,
+			sess_id, participant, remote_candidates);
 #endif
 }