[farsight2/master] Add transmitter sink just in time

Olivier Crête olivier.crete at collabora.co.uk
Mon Apr 6 17:33:54 PDT 2009


---
 gst/fsrtpconference/fs-rtp-session.c |   61 ++++++++++++++++++++++++++++++---
 1 files changed, 55 insertions(+), 6 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 612e679..ee0fd46 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -110,6 +110,8 @@ struct _FsRtpSessionPrivate
 
   GHashTable *transmitters;
 
+  GList *transmitters_add_sink;
+
   /* We keep references to these elements
    */
 
@@ -391,18 +393,21 @@ _remove_transmitter (gpointer key, gpointer value, gpointer user_data)
   FsRtpSession *self = FS_RTP_SESSION (user_data);
   FsTransmitter *transmitter = FS_TRANSMITTER (value);
   GstElement *src, *sink;
+  GstObject *parent;
 
   g_object_get (transmitter, "gst-sink", &sink, "gst-src", &src, NULL);
 
   gst_element_set_locked_state (src, TRUE);
   gst_element_set_state (src, GST_STATE_NULL);
   gst_bin_remove (GST_BIN (self->priv->conference), src);
-  gst_element_set_locked_state (src, FALSE);
 
   gst_element_set_locked_state (sink, TRUE);
   gst_element_set_state (sink, GST_STATE_NULL);
-  gst_bin_remove (GST_BIN (self->priv->conference), sink);
-  gst_element_set_locked_state (sink, FALSE);
+  if ((parent = gst_object_get_parent (GST_OBJECT (sink))))
+  {
+    gst_object_unref (parent);
+    gst_bin_remove (GST_BIN (self->priv->conference), sink);
+  }
 
   gst_object_unref (src);
   gst_object_unref (sink);
@@ -626,6 +631,11 @@ fs_rtp_session_dispose (GObject *object)
     self->priv->transmitters = NULL;
   }
 
+  g_list_foreach (self->priv->transmitters_add_sink, (GFunc) g_object_unref,
+      NULL);
+  g_list_free (self->priv->transmitters_add_sink);
+  self->priv->transmitters_add_sink = NULL;
+
   if (self->priv->free_substreams)
   {
     g_list_foreach (self->priv->free_substreams, (GFunc) g_object_unref, NULL);
@@ -1801,6 +1811,7 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
 {
   FsTransmitter *transmitter;
   GstElement *src;
+  gboolean sink_add_later = FALSE;
 
   FS_RTP_SESSION_LOCK (self);
 
@@ -1829,8 +1840,15 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
   g_signal_connect (transmitter, "get-recvonly-filter",
       G_CALLBACK (_get_recvonly_filter), NULL);
 
-  if (!fs_rtp_session_add_transmitter_gst_sink (self, transmitter, error))
-    goto error;
+  if (self->priv->send_codecbin)
+  {
+    if (!fs_rtp_session_add_transmitter_gst_sink (self, transmitter, error))
+      goto error;
+  }
+  else
+  {
+    sink_add_later = TRUE;
+  }
 
   g_object_get (transmitter, "gst-src", &src, NULL);
 
@@ -1863,8 +1881,11 @@ fs_rtp_session_get_new_stream_transmitter (FsRtpSession *self,
     goto error;
   }
 
+  if (sink_add_later)
+    self->priv->transmitters_add_sink = g_list_prepend (
+        self->priv->transmitters_add_sink, g_object_ref (transmitter));
   g_hash_table_insert (self->priv->transmitters, g_strdup (transmitter_name),
-    transmitter);
+      transmitter);
   FS_RTP_SESSION_UNLOCK (self);
 
   gst_object_unref (src);
@@ -3226,6 +3247,7 @@ fs_rtp_session_add_send_codec_bin_unlock (FsRtpSession *session,
   GstIterator *iter;
   GValue link_rv = {0};
   struct link_data data;
+  GList *item;
 
   GST_DEBUG ("Trying to add send codecbin for " FS_CODEC_FORMAT,
       FS_CODEC_ARGS (codec));
@@ -3331,6 +3353,33 @@ fs_rtp_session_add_send_codec_bin_unlock (FsRtpSession *session,
     goto error;
   }
 
+
+  FS_RTP_SESSION_LOCK (session);
+  while ((item = session->priv->transmitters_add_sink) != NULL)
+  {
+    FsTransmitter *transmitter = item->data;
+
+    session->priv->transmitters_add_sink = g_list_delete_link (
+        session->priv->transmitters_add_sink, item);
+
+    FS_RTP_SESSION_UNLOCK (session);
+
+    if (!fs_rtp_session_add_transmitter_gst_sink (session, transmitter, error))
+    {
+      FS_RTP_SESSION_LOCK (session);
+      g_object_unref (transmitter);
+      g_list_foreach (session->priv->transmitters_add_sink,
+          (GFunc) g_object_unref, NULL);
+      g_list_free (session->priv->transmitters_add_sink);
+      session->priv->transmitters_add_sink = NULL;
+      goto error;
+    }
+
+    g_object_unref (transmitter);
+    FS_RTP_SESSION_LOCK (session);
+  }
+  FS_RTP_SESSION_UNLOCK (session);
+
   g_object_set (session->priv->media_sink_valve, "drop", FALSE, NULL);
 
   session->priv->send_codecbin = codecbin;
-- 
1.5.6.5




More information about the farsight-commits mailing list