[gst-cvs] gst-plugins-base: cddabasesrc: safely handle the indexes

Wim Taymans wtay at kemper.freedesktop.org
Fri Aug 28 10:07:22 PDT 2009


Module: gst-plugins-base
Branch: master
Commit: 008c760b6b8432b4f92fcbc1680490372e5a8d9d
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=008c760b6b8432b4f92fcbc1680490372e5a8d9d

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Fri Aug 28 19:06:57 2009 +0200

cddabasesrc: safely handle the indexes

---

 gst-libs/gst/cdda/gstcddabasesrc.c |   33 ++++++++++++++++++++++++++++-----
 1 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/gst-libs/gst/cdda/gstcddabasesrc.c b/gst-libs/gst/cdda/gstcddabasesrc.c
index 216e750..182aadf 100644
--- a/gst-libs/gst/cdda/gstcddabasesrc.c
+++ b/gst-libs/gst/cdda/gstcddabasesrc.c
@@ -284,6 +284,9 @@ gst_cdda_base_src_finalize (GObject * obj)
   g_free (cddasrc->uri);
   g_free (cddasrc->device);
 
+  if (cddasrc->index)
+    gst_object_unref (cddasrc->index);
+
   G_OBJECT_CLASS (parent_class)->finalize (obj);
 }
 
@@ -1362,12 +1365,26 @@ static void
 gst_cdda_base_src_set_index (GstElement * element, GstIndex * index)
 {
   GstCddaBaseSrc *src = GST_CDDA_BASE_SRC (element);
+  GstIndex *old;
 
+  GST_OBJECT_LOCK (element);
+  old = src->index;
+  if (old == index) {
+    GST_OBJECT_UNLOCK (element);
+    return;
+  }
+  if (index)
+    gst_object_ref (index);
   src->index = index;
-
-  gst_index_get_writer_id (index, GST_OBJECT (src), &src->index_id);
-  gst_index_add_format (index, src->index_id, track_format);
-  gst_index_add_format (index, src->index_id, sector_format);
+  GST_OBJECT_UNLOCK (element);
+  if (old)
+    gst_object_unref (old);
+
+  if (index) {
+    gst_index_get_writer_id (index, GST_OBJECT (src), &src->index_id);
+    gst_index_add_format (index, src->index_id, track_format);
+    gst_index_add_format (index, src->index_id, sector_format);
+  }
 }
 
 
@@ -1375,8 +1392,14 @@ static GstIndex *
 gst_cdda_base_src_get_index (GstElement * element)
 {
   GstCddaBaseSrc *src = GST_CDDA_BASE_SRC (element);
+  GstIndex *index;
+
+  GST_OBJECT_LOCK (element);
+  if ((index = src->index))
+    gst_object_ref (index);
+  GST_OBJECT_UNLOCK (element);
 
-  return src->index;
+  return index;
 }
 
 static gint





More information about the Gstreamer-commits mailing list