[farsight2/master] nice: Emit new-candidate and selected-candidate-pair signals from an idle

Olivier Crête olivier.crete at collabora.co.uk
Mon Jul 20 14:53:28 PDT 2009


Emit the signals from an idle because libnice keeps a lock over signal emissions
---
 transmitters/nice/fs-nice-stream-transmitter.c |   64 ++++++++++++++++++++---
 1 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/transmitters/nice/fs-nice-stream-transmitter.c b/transmitters/nice/fs-nice-stream-transmitter.c
index 0951314..0c5a0fa 100644
--- a/transmitters/nice/fs-nice-stream-transmitter.c
+++ b/transmitters/nice/fs-nice-stream-transmitter.c
@@ -1431,6 +1431,36 @@ agent_state_changed (NiceAgent *agent,
 }
 
 
+struct candidate_signal_data
+{
+  FsNiceStreamTransmitter *self;
+  const gchar *signal_name;
+  FsCandidate *candidate1;
+  FsCandidate *candidate2;
+};
+
+static void
+free_candidate_signal_data (gpointer user_data)
+{
+  struct candidate_signal_data *data = user_data;
+  fs_candidate_destroy (data->candidate1);
+  if (data->candidate2)
+    fs_candidate_destroy (data->candidate2);
+  g_object_unref (data->self);
+  g_slice_free (struct candidate_signal_data, data);
+}
+
+static gboolean
+agent_candidate_signal_idle (gpointer userdata)
+{
+  struct candidate_signal_data *data = userdata;
+
+  g_signal_emit_by_name (data->self, data->signal_name, data->candidate1,
+                         data->candidate2);
+  return FALSE;
+}
+
+
 static void
 agent_new_selected_pair (NiceAgent *agent,
     guint stream_id,
@@ -1481,15 +1511,25 @@ agent_new_selected_pair (NiceAgent *agent,
 
 
   if (local && remote)
-    g_signal_emit_by_name (self, "new-active-candidate-pair", local, remote);
-
-  if (local)
-    fs_candidate_destroy (local);
-  if (remote)
-    fs_candidate_destroy (remote);
+  {
+    struct candidate_signal_data *data =
+      g_slice_new (struct candidate_signal_data);
+    data->self = g_object_ref (self);
+    data->signal_name = "new-active-candidate-pair";
+    data->candidate1 = local;
+    data->candidate2 = remote;
+    fs_nice_agent_add_idle (self->priv->agent, agent_candidate_signal_idle,
+        data, free_candidate_signal_data);
+  }
+  else
+  {
+    if (local)
+      fs_candidate_destroy (local);
+    if (remote)
+      fs_candidate_destroy (remote);
+  }
 }
 
-
 static void
 agent_new_candidate (NiceAgent *agent,
     guint stream_id,
@@ -1523,8 +1563,14 @@ agent_new_candidate (NiceAgent *agent,
 
   if (fscandidate)
   {
-    g_signal_emit_by_name (self, "new-local-candidate", fscandidate);
-    fs_candidate_destroy (fscandidate);
+    struct candidate_signal_data *data =
+      g_slice_new (struct candidate_signal_data);
+    data->self = g_object_ref (self);
+    data->signal_name = "new-local-candidate";
+    data->candidate1 = fscandidate;
+    data->candidate2 = NULL;
+    fs_nice_agent_add_idle (self->priv->agent, agent_candidate_signal_idle,
+        data, free_candidate_signal_data);
   }
   else
   {
-- 
1.5.6.5




More information about the farsight-commits mailing list