[farsight2/master] Emit the new-active-candidate-pair signal from FsRawUdpStreamTransmitter

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


---
 transmitters/rawudp/fs-rawudp-stream-transmitter.c |   91 ++++++++++++++++++--
 1 files changed, 84 insertions(+), 7 deletions(-)

diff --git a/transmitters/rawudp/fs-rawudp-stream-transmitter.c b/transmitters/rawudp/fs-rawudp-stream-transmitter.c
index bd0a8d3..402774d 100644
--- a/transmitters/rawudp/fs-rawudp-stream-transmitter.c
+++ b/transmitters/rawudp/fs-rawudp-stream-transmitter.c
@@ -90,6 +90,9 @@ struct _FsRawUdpStreamTransmitterPrivate
   FsCandidate *local_stun_rtp_candidate;
   FsCandidate *local_stun_rtcp_candidate;
 
+  FsCandidate *local_active_rtp_candidate;
+  FsCandidate *local_active_rtcp_candidate;
+
   UdpPort *rtp_udpport;
   UdpPort *rtcp_udpport;
 
@@ -142,6 +145,8 @@ static FsCandidate * fs_rawudp_stream_transmitter_build_forced_candidate (
     guint component_id);
 static gboolean fs_rawudp_stream_transmitter_finish_candidate_generation (
     gpointer user_data);
+static void fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (
+    FsRawUdpStreamTransmitter *self, guint component_id);
 
 
 static GObjectClass *parent_class = NULL;
@@ -329,6 +334,26 @@ fs_rawudp_stream_transmitter_finalize (GObject *object)
     self->priv->local_forced_rtcp_candidate = NULL;
   }
 
+  if (self->priv->local_stun_rtp_candidate) {
+    fs_candidate_destroy (self->priv->local_stun_rtp_candidate);
+    self->priv->local_stun_rtp_candidate = NULL;
+  }
+
+  if (self->priv->local_stun_rtcp_candidate) {
+    fs_candidate_destroy (self->priv->local_stun_rtcp_candidate);
+    self->priv->local_stun_rtcp_candidate = NULL;
+  }
+
+  if (self->priv->local_active_rtp_candidate) {
+    fs_candidate_destroy (self->priv->local_active_rtp_candidate);
+    self->priv->local_active_rtp_candidate = NULL;
+  }
+
+  if (self->priv->local_active_rtcp_candidate) {
+    fs_candidate_destroy (self->priv->local_active_rtcp_candidate);
+    self->priv->local_active_rtcp_candidate = NULL;
+  }
+
   if (self->priv->sources_mutex) {
     g_mutex_free (self->priv->sources_mutex);
     self->priv->sources_mutex = NULL;
@@ -603,6 +628,9 @@ fs_rawudp_stream_transmitter_add_remote_candidate (
       return FALSE;
   }
 
+  fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+    candidate->component_id);
+
   return TRUE;
 }
 
@@ -643,10 +671,15 @@ fs_rawudp_stream_transmitter_emit_stun_candidate (gpointer user_data)
 {
   struct CandidateTransit *data = user_data;
 
-  if (data->component_id == FS_COMPONENT_RTP)
+  if (data->component_id == FS_COMPONENT_RTP) {
     data->self->priv->local_stun_rtp_candidate = data->candidate;
-  else if (data->component_id == FS_COMPONENT_RTCP)
+    data->self->priv->local_active_rtp_candidate =
+      fs_candidate_copy (data->candidate);
+  } else if (data->component_id == FS_COMPONENT_RTCP) {
     data->self->priv->local_stun_rtcp_candidate = data->candidate;
+    data->self->priv->local_active_rtcp_candidate =
+      fs_candidate_copy (data->candidate);
+  }
 
   g_signal_emit_by_name (data->self, "new-local-candidate", data->candidate);
 
@@ -668,6 +701,9 @@ fs_rawudp_stream_transmitter_emit_stun_candidate (gpointer user_data)
     }
   }
 
+  fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (data->self,
+    data->component_id);
+
   g_free (data);
 
   /* We only pass one candidate at a time */
@@ -940,13 +976,20 @@ fs_rawudp_stream_transmitter_emit_local_candidates (
 
     g_signal_emit_by_name (self, "new-local-candidate", candidate);
 
+    if (component_id == FS_COMPONENT_RTP)
+      self->priv->local_active_rtp_candidate = fs_candidate_copy (candidate);
+    else if (component_id == FS_COMPONENT_RTCP)
+      self->priv->local_active_rtcp_candidate = fs_candidate_copy (candidate);
+
     fs_candidate_destroy (candidate);
   }
 
-
   /* free list of ips */
   g_list_foreach (ips, (GFunc) g_free, NULL);
   g_list_free (ips);
+
+  fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+    component_id);
 }
 
 /*
@@ -962,22 +1005,32 @@ fs_rawudp_stream_transmitter_finish_candidate_generation (gpointer user_data)
   /* If we have a STUN'd rtp candidate, dont send the locally generated
    * ones */
   if (!self->priv->local_stun_rtp_candidate) {
-    if (self->priv->local_forced_rtp_candidate)
+    if (self->priv->local_forced_rtp_candidate) {
+      self->priv->local_active_rtp_candidate = fs_candidate_copy (
+          self->priv->local_forced_rtp_candidate);
       g_signal_emit_by_name (self, "new-local-candidate",
         self->priv->local_forced_rtp_candidate);
-    else
+      fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+        FS_COMPONENT_RTP);
+    } else {
       fs_rawudp_stream_transmitter_emit_local_candidates (self,
         FS_COMPONENT_RTP);
+    }
   }
 
   /* Lets do the same for rtcp */
   if (!self->priv->local_stun_rtcp_candidate) {
-    if (self->priv->local_forced_rtcp_candidate)
+    if (self->priv->local_forced_rtcp_candidate) {
+      self->priv->local_active_rtcp_candidate = fs_candidate_copy (
+          self->priv->local_forced_rtcp_candidate);
       g_signal_emit_by_name (self, "new-local-candidate",
         self->priv->local_forced_rtcp_candidate);
-    else
+      fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (self,
+        FS_COMPONENT_RTCP);
+    } else {
       fs_rawudp_stream_transmitter_emit_local_candidates (self,
         FS_COMPONENT_RTCP);
+    }
   }
 
   g_signal_emit_by_name (self, "local-candidates-prepared");
@@ -997,3 +1050,27 @@ fs_rawudp_stream_transmitter_finish_candidate_generation (gpointer user_data)
 
   return FALSE;
 }
+
+static void
+fs_rawudp_stream_transmitter_maybe_new_active_candidate_pair (
+    FsRawUdpStreamTransmitter *self, guint component_id)
+{
+  switch (component_id) {
+    case FS_COMPONENT_RTP:
+      if (self->priv->local_active_rtp_candidate &&
+        self->priv->remote_rtcp_candidate) {
+        g_signal_emit_by_name (self, "new-active-candidate-pair",
+          self->priv->local_active_rtp_candidate,
+          self->priv->remote_rtp_candidate);
+      }
+      break;
+    case FS_COMPONENT_RTCP:
+      if (self->priv->local_active_rtcp_candidate &&
+        self->priv->remote_rtcp_candidate) {
+        g_signal_emit_by_name (self, "new-active-candidate-pair",
+          self->priv->local_active_rtcp_candidate,
+          self->priv->remote_rtcp_candidate);
+      }
+      break;
+  }
+}
-- 
1.5.6.5




More information about the farsight-commits mailing list