[farsight2/master] Use FsNiceAgent to provide agent in FsNiceTransmitter

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 23 15:26:28 PST 2008


---
 transmitters/nice/fs-nice-stream-transmitter.c |  183 ++++++------------------
 1 files changed, 45 insertions(+), 138 deletions(-)

diff --git a/transmitters/nice/fs-nice-stream-transmitter.c b/transmitters/nice/fs-nice-stream-transmitter.c
index afb5845..8327891 100644
--- a/transmitters/nice/fs-nice-stream-transmitter.c
+++ b/transmitters/nice/fs-nice-stream-transmitter.c
@@ -76,7 +76,7 @@ struct _FsNiceStreamTransmitterPrivate
 {
   FsNiceTransmitter *transmitter;
 
-  NiceAgent *agent;
+  FsNiceAgent *agent;
 
   guint stream_id;
 
@@ -327,27 +327,27 @@ fs_nice_stream_transmitter_dispose (GObject *object)
   self->priv->gststream = NULL;
 
   if (self->priv->stream_id)
-    nice_agent_remove_stream (self->priv->agent,
+    nice_agent_remove_stream (self->priv->agent->agent,
         self->priv->stream_id);
   self->priv->stream_id = 0;
 
   if (self->priv->state_changed_handler_id)
-    g_signal_handler_disconnect (self->priv->agent,
+    g_signal_handler_disconnect (self->priv->agent->agent,
         self->priv->state_changed_handler_id);
   self->priv->state_changed_handler_id = 0;
 
   if (self->priv->gathering_done_handler_id)
-    g_signal_handler_disconnect (self->priv->agent,
+    g_signal_handler_disconnect (self->priv->agent->agent,
         self->priv->gathering_done_handler_id);
   self->priv->gathering_done_handler_id = 0;
 
   if (self->priv->new_selected_pair_handler_id)
-    g_signal_handler_disconnect (self->priv->agent,
+    g_signal_handler_disconnect (self->priv->agent->agent,
         self->priv->new_selected_pair_handler_id);
   self->priv->new_selected_pair_handler_id = 0;
 
   if (self->priv->new_candidate_handler_id)
-    g_signal_handler_disconnect (self->priv->agent,
+    g_signal_handler_disconnect (self->priv->agent->agent,
         self->priv->new_candidate_handler_id);
   self->priv->new_candidate_handler_id = 0;
 
@@ -407,28 +407,28 @@ fs_nice_stream_transmitter_get_property (GObject *object,
       break;
     case PROP_STUN_IP:
       if (self->priv->agent)
-        g_object_get_property (G_OBJECT (self->priv->agent),
+        g_object_get_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       else
         g_value_set_string (value, self->priv->stun_ip);
       break;
     case PROP_STUN_PORT:
       if (self->priv->agent)
-        g_object_get_property (G_OBJECT (self->priv->agent),
+        g_object_get_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       else
         g_value_set_uint (value, self->priv->stun_port);
       break;
     case PROP_TURN_IP:
       if (self->priv->agent)
-        g_object_get_property (G_OBJECT (self->priv->agent),
+        g_object_get_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       else
         g_value_set_string (value, self->priv->turn_ip);
       break;
     case PROP_TURN_PORT:
       if (self->priv->agent)
-        g_object_get_property (G_OBJECT (self->priv->agent),
+        g_object_get_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       else
         g_value_set_uint (value, self->priv->turn_port);
@@ -436,7 +436,7 @@ fs_nice_stream_transmitter_get_property (GObject *object,
       break;
     case PROP_CONTROLLING_MODE:
       if (self->priv->agent)
-        g_object_get_property (G_OBJECT (self->priv->agent),
+        g_object_get_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       else
         g_value_set_boolean (value, self->priv->controlling_mode);
@@ -485,7 +485,7 @@ fs_nice_stream_transmitter_set_property (GObject *object,
     case PROP_CONTROLLING_MODE:
       self->priv->controlling_mode = g_value_get_boolean (value);
       if (self->priv->transmitter && self->priv->agent)
-        g_object_set_property (G_OBJECT (self->priv->agent),
+        g_object_set_property (G_OBJECT (self->priv->agent->agent),
             g_param_spec_get_name (pspec), value);
       break;
     case PROP_COMPATIBILITY_MODE:
@@ -615,7 +615,7 @@ fs_nice_stream_transmitter_add_remote_candidate (
 
   list = g_slist_prepend (NULL, cand);
 
-  nice_agent_set_remote_candidates (self->priv->agent,
+  nice_agent_set_remote_candidates (self->priv->agent->agent,
       self->priv->stream_id, candidate->component_id, list);
 
   g_slist_foreach (list, (GFunc)nice_candidate_free, NULL);
@@ -657,7 +657,7 @@ fs_nice_stream_transmitter_remote_candidates_added (
   if (candidates)
   {
     FsCandidate *cand = candidates->data;
-    nice_agent_set_remote_credentials (self->priv->agent,
+    nice_agent_set_remote_credentials (self->priv->agent->agent,
         self->priv->stream_id, cand->username, cand->password);
   }
   else
@@ -687,7 +687,7 @@ fs_nice_stream_transmitter_remote_candidates_added (
       }
     }
 
-    nice_agent_set_remote_candidates (self->priv->agent,
+    nice_agent_set_remote_candidates (self->priv->agent->agent,
         self->priv->stream_id, c, nice_candidates);
 
     g_slist_foreach (nice_candidates, (GFunc)nice_candidate_free, NULL);
@@ -728,7 +728,7 @@ fs_nice_stream_transmitter_select_candidate_pair (
   }
 
   for (c = 1; c <= self->priv->transmitter->components; c++)
-    if (!nice_agent_set_selected_pair (self->priv->agent,
+    if (!nice_agent_set_selected_pair (self->priv->agent->agent,
             self->priv->stream_id, c, local_foundation, remote_foundation))
       res = FALSE;
 
@@ -860,10 +860,8 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
     GError **error)
 {
   GList *item;
-  gboolean set = FALSE;
   GList *agents  = NULL;
-  FsNiceAgent *thread = NULL;
-  NiceAgent *agent = NULL;
+  FsNiceAgent *agent = NULL;
 
   /* Before going any further, check that the list of candidates are ok */
 
@@ -918,7 +916,7 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
 
     agent = item->data;
 
-    g_object_get (agent,
+    g_object_get (agent->agent,
         "stun-server", &stun_server,
         "stun-server-port", &stun_port,
         "turn-server", &turn_server,
@@ -926,9 +924,6 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
         "compatibility", &compatibility,
         NULL);
 
-    if (!thread)
-      thread = g_object_get_data (G_OBJECT (agent), "nice-thread");
-
     /*
      * Check if the agent matches our requested criteria
      */
@@ -942,12 +937,19 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
             (turn_server && self->priv->turn_ip &&
                 !strcmp (turn_server, self->priv->turn_ip))))
     {
-      GList *prefs = g_object_get_data (G_OBJECT (agent),
-          "preferred-local-candidates");
+      GList *prefs = NULL;
+
+      g_object_get (G_OBJECT (agent),
+          "preferred-local-candidates", &prefs,
+          NULL);
 
       if (candidate_list_are_equal (prefs,
               self->priv->preferred_local_candidates))
+      {
+        fs_candidate_list_destroy (prefs);
         break;
+      }
+      fs_candidate_list_destroy (prefs);
     }
   }
 
@@ -955,130 +957,35 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
   /* In this case we need to build a new agent */
   if (item == NULL)
   {
-    GMainContext *ctx = NULL;
-    GList *local_prefs_copy;
-
-    /* If we don't have a thread, build one */
-    if (thread == NULL)
-    {
-      thread = fs_nice_agent_new (self->priv->compatibility_mode,
-          self->priv->preferred_local_candidates,
-          error);
-      if (!thread)
-        return FALSE;
-    }
-
-    ctx = fs_nice_agent_get_context (thread);
-
-    agent = nice_agent_new (&udpfactory, ctx, self->priv->compatibility_mode);
+    agent = fs_nice_agent_new (self->priv->compatibility_mode,
+        self->priv->preferred_local_candidates,
+        error);
 
     if (!agent)
-    {
-      g_object_unref (thread);
-      g_object_unref (thread);
-      g_set_error (error, FS_ERROR, FS_ERROR_INTERNAL,
-          "Could not make nice agent");
-      return FALSE;
-    }
-
-    fs_nice_agent_add_weak_object (thread, G_OBJECT (agent));
-
-    g_object_set_data (G_OBJECT (thread), "nice-thread", thread);
-
-    g_object_unref (thread);
+        return FALSE;
 
     if (self->priv->stun_ip && self->priv->stun_port)
-      g_object_set (agent,
+      g_object_set (agent->agent,
           "stun-server", self->priv->stun_ip,
           "stun-server-port", self->priv->stun_port,
           NULL);
 
     if (self->priv->turn_ip && self->priv->turn_port)
-      g_object_set (agent,
+      g_object_set (agent->agent,
           "turn-server", self->priv->turn_ip,
           "turn-server-port", self->priv->turn_port,
           NULL);
 
-    g_object_set (agent,
+    g_object_set (agent->agent,
         "controlling-mode", self->priv->controlling_mode,
         NULL);
 
-    local_prefs_copy = fs_candidate_list_copy (
-        self->priv->preferred_local_candidates);
-    g_object_set_data (G_OBJECT (agent), "preferred-local-candidates",
-        local_prefs_copy);
-    g_object_weak_ref (G_OBJECT (agent),
-        (GWeakNotify) fs_candidate_list_destroy,
-        local_prefs_copy);
-
     agents = g_list_prepend (agents, agent);
     g_object_set_data (G_OBJECT (participant), "nice-agents", agents);
     g_object_weak_ref (G_OBJECT (agent), weak_agent_removed, participant);
     g_object_ref (participant);
 
     self->priv->agent = agent;
-
-    for (item = self->priv->preferred_local_candidates;
-         item;
-         item = g_list_next (item))
-    {
-      FsCandidate *cand = item->data;
-      NiceAddress *addr = nice_address_new ();
-
-      if (nice_address_set_from_string (addr, cand->ip))
-      {
-        if (!nice_agent_add_local_address (self->priv->agent, addr))
-        {
-          g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
-              "Unable to set preferred local candidate");
-          return FALSE;
-        }
-        set = TRUE;
-      }
-      else
-      {
-        g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
-            "Invalid local address passed");
-        nice_address_free (addr);
-        return FALSE;
-      }
-      nice_address_free (addr);
-    }
-
-    if (!set)
-    {      GList *addresses = fs_interfaces_get_local_ips (FALSE);
-
-      for (item = addresses;
-           item;
-           item = g_list_next (item))
-      {
-        NiceAddress *addr = nice_address_new ();;
-
-        if (nice_address_set_from_string (addr, item->data))
-        {
-          if (!nice_agent_add_local_address (self->priv->agent,
-                  addr))
-          {
-            g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
-                "Unable to set preferred local candidate");
-            return FALSE;
-          }
-        }
-        else
-        {
-          g_set_error (error, FS_ERROR, FS_ERROR_INVALID_ARGUMENTS,
-              "Invalid local address passed");
-          nice_address_free (addr);
-          return FALSE;
-        }
-        nice_address_free (addr);
-      }
-
-      g_list_foreach (addresses, (GFunc) g_free, NULL);
-      g_list_free (addresses);
-    }
-
-
   } else {
     self->priv->agent = g_object_ref (agent);
   }
@@ -1088,7 +995,7 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
 
 
   self->priv->stream_id = nice_agent_add_stream (
-      self->priv->agent,
+      self->priv->agent->agent,
       self->priv->transmitter->components);
 
   if (self->priv->stream_id == 0)
@@ -1110,7 +1017,7 @@ fs_nice_stream_transmitter_build (FsNiceStreamTransmitter *self,
 
   self->priv->gststream = fs_nice_transmitter_add_gst_stream (
       self->priv->transmitter,
-      self->priv->agent,
+      self->priv->agent->agent,
       self->priv->stream_id,
       error);
   if (self->priv->gststream == NULL)
@@ -1132,7 +1039,7 @@ fs_nice_stream_transmitter_gather_local_candidates (
 
   GST_DEBUG ("Stream %u started", self->priv->stream_id);
 
-  nice_agent_gather_candidates (self->priv->agent,
+  nice_agent_gather_candidates (self->priv->agent->agent,
       self->priv->stream_id);
 
   return TRUE;
@@ -1216,7 +1123,7 @@ agent_new_selected_pair (NiceAgent *agent,
     return;
 
   candidates = nice_agent_get_local_candidates (
-      self->priv->agent,
+      self->priv->agent->agent,
       self->priv->stream_id, component_id);
 
   for (item = candidates; item; item = g_slist_next (item))
@@ -1225,7 +1132,7 @@ agent_new_selected_pair (NiceAgent *agent,
 
     if (!strcmp (candidate->foundation, lfoundation))
     {
-      local = nice_candidate_to_fs_candidate (self->priv->agent,
+      local = nice_candidate_to_fs_candidate (self->priv->agent->agent,
           candidate, TRUE);
       break;
     }
@@ -1234,7 +1141,7 @@ agent_new_selected_pair (NiceAgent *agent,
   g_slist_free (candidates);
 
   candidates = nice_agent_get_remote_candidates (
-      self->priv->agent,
+      self->priv->agent->agent,
       self->priv->stream_id, component_id);
 
   for (item = candidates; item; item = g_slist_next (item))
@@ -1243,7 +1150,7 @@ agent_new_selected_pair (NiceAgent *agent,
 
     if (!strcmp (candidate->foundation, rfoundation))
     {
-      remote = nice_candidate_to_fs_candidate (self->priv->agent,
+      remote = nice_candidate_to_fs_candidate (self->priv->agent->agent,
           candidate, FALSE);
       break;
     }
@@ -1288,7 +1195,7 @@ agent_new_candidate (NiceAgent *agent,
       stream_id, component_id);
 
   candidates = nice_agent_get_local_candidates (
-      self->priv->agent,
+      self->priv->agent->agent,
       self->priv->stream_id, component_id);
 
   for (item = candidates; item; item = g_slist_next (item))
@@ -1298,7 +1205,7 @@ agent_new_candidate (NiceAgent *agent,
     if (!strcmp (item->data, foundation))
     {
       fscandidate = nice_candidate_to_fs_candidate (
-          self->priv->agent, candidate, TRUE);
+          self->priv->agent->agent, candidate, TRUE);
       break;
     }
   }
@@ -1332,7 +1239,7 @@ agent_gathering_done (NiceAgent *agent, gpointer user_data)
   for (c = 1; c <= self->priv->transmitter->components; c++)
   {
     candidates = nice_agent_get_local_candidates (
-        self->priv->agent,
+        self->priv->agent->agent,
         self->priv->stream_id, c);
 
     for (item = candidates; item; item = g_slist_next (item))
@@ -1341,7 +1248,7 @@ agent_gathering_done (NiceAgent *agent, gpointer user_data)
       FsCandidate *fscandidate;
 
       fscandidate = nice_candidate_to_fs_candidate (
-          self->priv->agent, candidate, TRUE);
+          self->priv->agent->agent, candidate, TRUE);
       g_signal_emit_by_name (self, "new-local-candidate", fscandidate);
       fs_candidate_destroy (fscandidate);
     }
-- 
1.5.6.5




More information about the farsight-commits mailing list