# HG changeset patch # User maiku@pidgin.im # Date 1256336445 0 # Node ID 2460e6774e08d534518e05751fcb9c680d90fbbd # Parent efeb21092ed26be140fad3d2fbe5e1c4395fcf01 Move handling Farsight 2's new-local-candidate signal in Fs2 media backend. diff -r efeb21092ed2 -r 2460e6774e08 libpurple/media/backend-fs2.c --- a/libpurple/media/backend-fs2.c Fri Oct 23 21:40:38 2009 +0000 +++ b/libpurple/media/backend-fs2.c Fri Oct 23 22:20:45 2009 +0000 @@ -49,7 +49,7 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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 -_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: diff -r efeb21092ed2 -r 2460e6774e08 libpurple/media/media.c --- a/libpurple/media/media.c Fri Oct 23 21:40:38 2009 +0000 +++ b/libpurple/media/media.c Fri Oct 23 22:20:45 2009 +0000 @@ -138,8 +138,9 @@ 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 @@ 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 @@ 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 @@ #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; - - g_return_if_fail(FS_IS_STREAM(stream)); - g_return_if_fail(session != NULL); + PurpleMediaSession *session = + purple_media_get_session(media, sess_id); - 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)); + purple_media_insert_local_candidate(session, participant, + purple_media_candidate_to_fs(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