agent: Add API to retrieve the selected GSocket
authorBryce Allen <ballen@ci.uchicago.edu>
Wed, 20 Nov 2013 21:46:06 +0000 (16:46 -0500)
committerOlivier CrĂȘte <olivier.crete@collabora.com>
Wed, 20 Nov 2013 21:46:06 +0000 (16:46 -0500)
This should be used only when the protocol has it's own keepalive mechanism

agent/agent.c
agent/agent.h
nice/libnice.sym
win32/vs9/libnice.def

index 034b53c..364dfac 100644 (file)
@@ -2889,6 +2889,33 @@ nice_agent_get_selected_pair (NiceAgent *agent, guint stream_id,
   return ret;
 }
 
+NICEAPI_EXPORT GSocket *
+nice_agent_get_selected_socket (NiceAgent *agent, guint stream_id,
+    guint component_id)
+{
+  Component *component;
+  Stream *stream;
+  NiceSocket *nice_socket;
+  GSocket *g_socket = NULL;
+
+  agent_lock();
+
+  /* step: check that params specify an existing pair */
+  if (!agent_find_component (agent, stream_id, component_id,
+          &stream, &component))
+    goto done;
+
+  if (component->selected_pair.local && component->selected_pair.remote) {
+    nice_socket = (NiceSocket *)component->selected_pair.local->sockptr;
+    g_socket = nice_socket->fileno;
+  }
+
+ done:
+  agent_unlock();
+
+  return g_socket;
+}
+
 GSource* agent_timeout_add_with_context (NiceAgent *agent, guint interval,
     GSourceFunc function, gpointer data)
 {
index d03741f..7b2f45b 100644 (file)
 
 
 #include <glib-object.h>
+#include <gio/gio.h>
 
 /**
  * NiceAgent:
@@ -715,6 +716,30 @@ nice_agent_get_selected_pair (
   NiceCandidate **remote);
 
 /**
+ * nice_agent_get_selected_socket:
+ * @agent: The #NiceAgent Object
+ * @stream_id: The ID of the stream
+ * @component_id: The ID of the component
+ *
+ * Retreive the local socket associated with the selected candidate pair
+ * for media transmission for a given stream's component.
+ *
+ * This is useful for adding ICE support to legacy applications that already
+ * have a protocol that maintains a connection. If the socket is duplicated
+ * before unrefing the agent, the application can take over and continue to use
+ * it. New applications are encouraged to use the built in libnice stream
+ * handling instead and let libnice handle the connection maintenance.
+ *
+ * Returns: pointer to the socket, or NULL if there is no selected candidate
+ * Since: 0.1.5
+ */
+GSocket *
+nice_agent_get_selected_socket (
+  NiceAgent *agent,
+  guint stream_id,
+  guint component_id);
+
+/**
  * nice_agent_set_selected_remote_candidate:
  * @agent: The #NiceAgent Object
  * @stream_id: The ID of the stream
index d1a51ab..195092d 100644 (file)
@@ -26,6 +26,7 @@ nice_agent_get_local_candidates
 nice_agent_get_local_credentials
 nice_agent_get_remote_candidates
 nice_agent_get_selected_pair
+nice_agent_get_selected_socket
 nice_agent_get_stream_name
 nice_agent_get_type
 nice_agent_new
index 53d7cb0..abb7732 100644 (file)
@@ -30,6 +30,7 @@ nice_agent_get_local_candidates
 nice_agent_get_local_credentials
 nice_agent_get_remote_candidates
 nice_agent_get_selected_pair
+nice_agent_get_selected_socket
 nice_agent_get_stream_name
 nice_agent_get_type
 nice_agent_new