[farsight2/master] Do proper locking in special_sources_remove

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


---
 gst/fsrtpconference/fs-rtp-session.c        |   23 +++++--------------
 gst/fsrtpconference/fs-rtp-session.h        |    2 +
 gst/fsrtpconference/fs-rtp-special-source.c |   33 ++++++++++++++++----------
 gst/fsrtpconference/fs-rtp-special-source.h |    7 +++--
 4 files changed, 32 insertions(+), 33 deletions(-)

diff --git a/gst/fsrtpconference/fs-rtp-session.c b/gst/fsrtpconference/fs-rtp-session.c
index 8f327d5..66e02e2 100644
--- a/gst/fsrtpconference/fs-rtp-session.c
+++ b/gst/fsrtpconference/fs-rtp-session.c
@@ -3135,25 +3135,14 @@ fs_rtp_session_remove_send_codec_bin (FsRtpSession *self,
   }
 
   if (codec_without_config)
-  {
-    GError *error = NULL;
-
-    FS_RTP_SESSION_LOCK (self);
-    self->priv->extra_sources = fs_rtp_special_sources_remove (
-        self->priv->extra_sources,
-        self->priv->codec_associations, codec_without_config,
+    fs_rtp_special_sources_remove (
+        &self->priv->extra_sources,
+        &self->priv->codec_associations,
+        FS_RTP_SESSION_GET_LOCK (self),
+        codec_without_config,
         GST_ELEMENT (self->priv->conference),
         self->priv->rtpmuxer);
-    FS_RTP_SESSION_UNLOCK (self);
-    if (error)
-    {
-      if (error_emit)
-        fs_session_emit_error (FS_SESSION (self), FS_ERROR_INTERNAL,
-            "Could not remove unused special sources",
-            "Could not remove unused special sources");
-      return FALSE;
-    }
-  }
+
   /*
    * Lets reset the clock-rate (because rtpmuxer saves it.. )
    */
diff --git a/gst/fsrtpconference/fs-rtp-session.h b/gst/fsrtpconference/fs-rtp-session.h
index 1b3eddd..0ea4c0e 100644
--- a/gst/fsrtpconference/fs-rtp-session.h
+++ b/gst/fsrtpconference/fs-rtp-session.h
@@ -100,6 +100,8 @@ struct _FsRtpSession
   g_mutex_unlock ((session)->mutex)
 #endif
 
+#define FS_RTP_SESSION_GET_LOCK(session) ((session)->mutex)
+
 GType fs_rtp_session_get_type (void);
 
 FsRtpSession *fs_rtp_session_new (FsMediaType media_type,
diff --git a/gst/fsrtpconference/fs-rtp-special-source.c b/gst/fsrtpconference/fs-rtp-special-source.c
index 28b4053..2fee5fe 100644
--- a/gst/fsrtpconference/fs-rtp-special-source.c
+++ b/gst/fsrtpconference/fs-rtp-special-source.c
@@ -392,21 +392,23 @@ _source_order_compare_func (gconstpointer item1,gconstpointer item2)
 
 /**
  * fs_rtp_special_sources_remove:
- * @current_extra_sources: The #GList returned by previous calls to this function
- * @negotiated_codecs: A #GList of current negotiated #CodecAssociation
- * @send_codec: The currently selected send codec
+ * @extra_sources: A pointer to the #GList returned by previous calls to this
+ *  function
+ * @negotiated_codecs: A pointer to the #GList of current negotiated
+ * #CodecAssociation
+ * @mutex: the mutex protecting the last two things
+ * @send_codec: A pointer to the currently selected send codec
  * @bin: The #GstBin to add the stuff to
  * @rtpmuxer: The rtpmux element
  *
  * This function removes any special source that are not compatible with the
  * currently selected send codec.
- *
- * Returns: A #GList to be passed to other functions in this class
  */
-GList *
+void
 fs_rtp_special_sources_remove (
-    GList *current_extra_sources,
-    GList *negotiated_codecs,
+    GList **extra_sources,
+    GList **negotiated_codecs,
+    GMutex *mutex,
     FsCodec *send_codec,
     GstElement *bin,
     GstElement *rtpmuxer)
@@ -423,8 +425,11 @@ fs_rtp_special_sources_remove (
     GList *obj_item;
     FsRtpSpecialSource *obj = NULL;
 
+  restart:
+    g_mutex_lock (mutex);
+
     /* Check if we already have an object for this type */
-    for (obj_item = g_list_first (current_extra_sources);
+    for (obj_item = g_list_first (*extra_sources);
          obj_item;
          obj_item = g_list_next (obj_item))
     {
@@ -435,16 +440,18 @@ fs_rtp_special_sources_remove (
 
     if (obj_item)
     {
-      if (!fs_rtp_special_source_class_want_source (klass, negotiated_codecs,
+      if (!fs_rtp_special_source_class_want_source (klass, *negotiated_codecs,
               send_codec))
       {
-        current_extra_sources = g_list_remove (current_extra_sources, obj);
+        *extra_sources = g_list_remove (*extra_sources, obj);
+        g_mutex_unlock (mutex);
         g_object_unref (obj);
+        goto restart;
       }
     }
-  }
 
-  return current_extra_sources;
+    g_mutex_unlock (mutex);
+  }
 }
 
 
diff --git a/gst/fsrtpconference/fs-rtp-special-source.h b/gst/fsrtpconference/fs-rtp-special-source.h
index bca2a1e..19848aa 100644
--- a/gst/fsrtpconference/fs-rtp-special-source.h
+++ b/gst/fsrtpconference/fs-rtp-special-source.h
@@ -108,10 +108,11 @@ struct _FsRtpSpecialSource
 
 GType fs_rtp_special_source_get_type (void);
 
-GList *
+void
 fs_rtp_special_sources_remove (
-    GList *current_extra_sources,
-    GList *negotiated_codecs,
+    GList **current_extra_sources,
+    GList **negotiated_codecs,
+    GMutex *mutex,
     FsCodec *send_codec,
     GstElement *bin,
     GstElement *rtpmuxer);
-- 
1.5.6.5




More information about the farsight-commits mailing list