cpw.maiku.media_refactor: 3cb3c965: Move handling Farsight 2's new-local-can...

maiku at pidgin.im maiku at pidgin.im
Fri Oct 23 22:10:32 EDT 2009


-----------------------------------------------------------------
Revision: 3cb3c9654737630864caac6622dc07f4f985d484
Ancestor: e3b09c466ac702c7759a29f45c64535e1f7265fd
Author: maiku at pidgin.im
Date: 2009-10-23T22:20:45
Branch: im.pidgin.cpw.maiku.media_refactor
URL: http://d.pidgin.im/viewmtn/revision/info/3cb3c9654737630864caac6622dc07f4f985d484

Modified files:
        libpurple/media/backend-fs2.c libpurple/media/media.c

ChangeLog: 

Move handling Farsight 2's new-local-candidate signal in Fs2 media backend.

-------------- next part --------------
============================================================
--- libpurple/media/backend-fs2.c	a2d163ce78c985119476b606e1de65fc8f2c2791
+++ libpurple/media/backend-fs2.c	8da15c615a8f7f42309b607beed6540c88f6d0d8
@@ -49,7 +49,7 @@ static gboolean
 static void purple_media_backend_iface_init(PurpleMediaBackendIface *iface);
 
 static gboolean
-_gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackend *self);
+_gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackendFs2 *self);
 static void
 _state_changed_cb(PurpleMedia *media, PurpleMediaState state,
 		gchar *sid, gchar *name, PurpleMediaBackendFs2 *self);
@@ -347,8 +347,80 @@ _session_type_from_fs(FsMediaType type, 
 	}
 	return result;
 }
+
+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;
+}
 #endif
 
+static PurpleMediaCandidate *
+purple_media_candidate_from_fs(FsCandidate *fscandidate)
+{
+	PurpleMediaCandidate *candidate;
+
+	if (fscandidate == NULL)
+		return NULL;
+
+	candidate = purple_media_candidate_new(fscandidate->foundation,
+		fscandidate->component_id, fscandidate->type,
+		fscandidate->proto, fscandidate->ip, fscandidate->port);
+	g_object_set(candidate,
+			"base-ip", fscandidate->base_ip,
+			"base-port", fscandidate->base_port,
+			"priority", fscandidate->priority,
+			"username", fscandidate->username,
+			"password", fscandidate->password,
+			"ttl", fscandidate->ttl, NULL);
+	return candidate;
+}
+
 static PurpleMediaBackendFs2Session *
 _get_session(PurpleMediaBackendFs2 *self, const gchar *sess_id)
 {
@@ -365,9 +437,38 @@ _get_session(PurpleMediaBackendFs2 *self
 	return session;
 }
 
+static PurpleMediaBackendFs2Session *
+_get_session_from_fs_stream(PurpleMediaBackendFs2 *self, FsStream *stream)
+{
+	PurpleMediaBackendFs2Private *priv =
+			PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
+	FsSession *fssession;
+	GList *values;
+
+	g_return_val_if_fail(PURPLE_IS_MEDIA_BACKEND_FS2(self), NULL);
+	g_return_val_if_fail(FS_IS_STREAM(stream), NULL);
+
+	g_object_get(stream, "session", &fssession, NULL);
+
+	values = g_hash_table_get_values(priv->sessions);
+
+	for (; values; values = g_list_delete_link(values, values)) {
+		PurpleMediaBackendFs2Session *session = values->data;
+
+		if (session->session == fssession) {
+			g_list_free(values);
+			g_object_unref(fssession);
+			return session;
+		}
+	}
+
+	g_object_unref(fssession);
+	return NULL;
+}
+
 static void
 _gst_handle_message_element(GstBus *bus, GstMessage *msg,
-		PurpleMediaBackend *self)
+		PurpleMediaBackendFs2 *self)
 {
 	PurpleMediaBackendFs2Private *priv =
 			PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
@@ -424,18 +525,35 @@ _gst_handle_message_element(GstBus *bus,
 		const GValue *value;
 		FsStream *stream;
 		FsCandidate *local_candidate;
-#if 0
-		PurpleMediaSession *session;
-#endif
+		PurpleMediaCandidate *candidate;
+		FsParticipant *participant;
+		PurpleMediaBackendFs2Session *session;
+		gchar *name;
 
 		value = gst_structure_get_value(msg->structure, "stream");
 		stream = g_value_get_object(value);
 		value = gst_structure_get_value(msg->structure, "candidate");
 		local_candidate = g_value_get_boxed(value);
+
+		session = _get_session_from_fs_stream(self, stream);
+
+		purple_debug_info("backend-fs2",
+				"got new local candidate: %s\n",
+				local_candidate->foundation);
+
+		g_object_get(stream, "participant", &participant, NULL);
+		g_object_get(participant, "cname", &name, NULL);
+		g_object_unref(participant);
+
 #if 0
-		session = purple_media_session_from_fs_stream(media, stream);
-		_new_local_candidate_cb(stream,	local_candidate, session);
+		purple_media_insert_local_candidate(session, name,
+				fs_candidate_copy(local_candidate));
 #endif
+
+		candidate = purple_media_candidate_from_fs(local_candidate);
+		g_signal_emit_by_name(self, "new-candidate",
+				session->id, name, candidate);
+		g_object_unref(candidate);
 	} else if (gst_structure_has_name(msg->structure,
 			"farsight-local-candidates-prepared")) {
 		const GValue *value;
@@ -576,7 +694,7 @@ _gst_handle_message_error(GstBus *bus, G
 
 static void
 _gst_handle_message_error(GstBus *bus, GstMessage *msg,
-		PurpleMediaBackend *self)
+		PurpleMediaBackendFs2 *self)
 {
 	PurpleMediaBackendFs2Private *priv =
 			PURPLE_MEDIA_BACKEND_FS2_GET_PRIVATE(self);
@@ -620,7 +738,7 @@ static gboolean
 }
 
 static gboolean
-_gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackend *self)
+_gst_bus_cb(GstBus *bus, GstMessage *msg, PurpleMediaBackendFs2 *self)
 {
 	switch(GST_MESSAGE_TYPE(msg)) {
 		case GST_MESSAGE_ELEMENT:
============================================================
--- libpurple/media/media.c	607c0a87ca7fe8dfc0e59256c9bc46f489e57789
+++ libpurple/media/media.c	d4b27fa190500afc7a95b19e998047f4eb7516a9
@@ -138,8 +138,9 @@ static void purple_media_set_property (G
 static void purple_media_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
 static void purple_media_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 
-static void purple_media_new_local_candidate_cb(FsStream *stream,
-		FsCandidate *local_candidate, PurpleMediaSession *session);
+static void purple_media_new_local_candidate_cb(PurpleMediaBackend *backend,
+		const gchar *sess_id, const gchar *participant,
+		PurpleMediaCandidate *candidate, PurpleMedia *media);
 static void purple_media_candidates_prepared_cb(FsStream *stream,
 		PurpleMediaSession *session);
 static void purple_media_candidate_pair_established_cb(FsStream *stream,
@@ -438,6 +439,11 @@ purple_media_set_property (GObject *obje
 					media->priv->conference_type,
 					"media", media,
 					NULL);
+			g_signal_connect(media->priv->backend,
+					"new-candidate",
+					G_CALLBACK(
+					purple_media_new_local_candidate_cb),
+					media);
 			break;
 		case PROP_INITIATOR:
 			media->priv->initiator = g_value_get_boolean(value);
@@ -1055,12 +1061,6 @@ media_bus_call(GstBus *bus, GstMessage *
 				break;
 
 			if (gst_structure_has_name(msg->structure,
-					"farsight-new-local-candidate")) {
-				FsStream *stream = g_value_get_object(gst_structure_get_value(msg->structure, "stream"));
-				FsCandidate *local_candidate = g_value_get_boxed(gst_structure_get_value(msg->structure, "candidate"));
-				PurpleMediaSession *session = purple_media_session_from_fs_stream(media, stream);
-				purple_media_new_local_candidate_cb(stream, local_candidate, session);
-			} else if (gst_structure_has_name(msg->structure,
 					"farsight-local-candidates-prepared")) {
 				FsStream *stream = g_value_get_object(gst_structure_get_value(msg->structure, "stream"));
 				PurpleMediaSession *session = purple_media_session_from_fs_stream(media, stream);
@@ -1263,30 +1263,18 @@ static void
 
 #ifdef USE_VV
 static void
-purple_media_new_local_candidate_cb(FsStream *stream,
-				    FsCandidate *local_candidate,
-				    PurpleMediaSession *session)
+purple_media_new_local_candidate_cb(PurpleMediaBackend *backend,
+		const gchar *sess_id, const gchar *participant,
+		PurpleMediaCandidate *candidate, PurpleMedia *media)
 {
-	gchar *name;
-	FsParticipant *participant;
-	PurpleMediaCandidate *candidate;
+	PurpleMediaSession *session =
+			purple_media_get_session(media, sess_id);
 
-	g_return_if_fail(FS_IS_STREAM(stream));
-	g_return_if_fail(session != NULL);
+	purple_media_insert_local_candidate(session, participant,
+			purple_media_candidate_to_fs(candidate));
 
-	purple_debug_info("media", "got new local candidate: %s\n", local_candidate->foundation);
-	g_object_get(stream, "participant", &participant, NULL);
-	g_object_get(participant, "cname", &name, NULL);
-	g_object_unref(participant);
-
-	purple_media_insert_local_candidate(session, name, fs_candidate_copy(local_candidate));
-
-	candidate = purple_media_candidate_from_fs(local_candidate);
 	g_signal_emit(session->media, purple_media_signals[NEW_CANDIDATE],
-		      0, session->id, name, candidate);
-	g_object_unref(candidate);
-
-	g_free(name);
+		      0, session->id, participant, candidate);
 }
 
 static void


More information about the Commits mailing list