[farsight2/master] Emit negotiated-codecs notify after letting the locks go safely

Olivier Crête olivier.crete at collabora.co.uk
Tue Dec 16 14:32:29 PST 2008


---
 gst/fsrtpconference/fs-rtp-session.c |   16 ++++++++++++++++
 gst/fsrtpconference/fs-rtp-stream.c  |    8 ++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index bd8b870..eba17eb 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -163,6 +163,7 @@ struct _FsRtpSessionPrivate
 
   /* These lists are protected by the session mutex */
   GList *streams;
+  guint streams_cookie;
   GList *free_substreams;
 
   /* The static list of all the blueprints */
@@ -641,6 +642,7 @@ fs_rtp_session_dispose (GObject *object)
     g_object_weak_unref (G_OBJECT (item->data), _remove_stream, self);
   g_list_free (self->priv->streams);
   self->priv->streams = NULL;
+  self->priv->streams_cookie++;
 
   /* MAKE sure dispose does not run twice. */
   self->priv->disposed = TRUE;
@@ -1412,6 +1414,7 @@ _remove_stream (gpointer user_data,
   FS_RTP_SESSION_LOCK (self);
   self->priv->streams =
     g_list_remove_all (self->priv->streams, where_the_object_was);
+  self->priv->streams_cookie++;
 
   g_hash_table_foreach_remove (self->priv->ssrc_streams, _remove_stream_from_ht,
       where_the_object_was);
@@ -1466,6 +1469,7 @@ fs_rtp_session_new_stream (FsSession *session,
 
   FS_RTP_SESSION_LOCK (self);
   self->priv->streams = g_list_append (self->priv->streams, new_stream);
+  self->priv->streams_cookie++;
   FS_RTP_SESSION_UNLOCK (self);
 
   g_object_weak_ref (G_OBJECT (new_stream), _remove_stream, self);
@@ -1888,6 +1892,11 @@ fs_rtp_session_distribute_recv_codecs_locked (FsRtpSession *session,
     GList *forced_remote_codecs)
 {
   GList *item = NULL;
+  guint cookie;
+
+ restart:
+
+  cookie = session->priv->streams_cookie;
 
   for (item = session->priv->streams;
        item;
@@ -1951,7 +1960,14 @@ fs_rtp_session_distribute_recv_codecs_locked (FsRtpSession *session,
         }
       }
 
+      /* This function unlocks the lock, so we have to check the cookie
+       * when we come back */
+      g_object_ref (stream);
       fs_rtp_stream_set_negotiated_codecs_locked (stream, new_codecs);
+      g_object_unref (stream);
+
+      if (cookie != session->priv->streams_cookie)
+        goto restart;
     }
   }
 }
diff --git a/gst/fsrtpconference/fs-rtp-stream.c b/gst/fsrtpconference/fs-rtp-stream.c
index 94e33eb..a3f0e68 100644
--- a/gst/fsrtpconference/fs-rtp-stream.c
+++ b/gst/fsrtpconference/fs-rtp-stream.c
@@ -870,9 +870,9 @@ fs_rtp_stream_set_negotiated_codecs_locked (FsRtpStream *stream,
 
   stream->negotiated_codecs = codecs;
 
-  /*
-    TODO: I have no idea how to make this thread safe
+  FS_RTP_SESSION_UNLOCK (stream->priv->session);
+
+  g_object_notify (G_OBJECT (stream), "negotiated-codecs");
 
-    g_object_notify (G_OBJECT (stream), "negotiated-codecs");
-  */
+  FS_RTP_SESSION_LOCK (stream->priv->session);
 }
-- 
1.5.6.5




More information about the farsight-commits mailing list