basesrc: release the object lock sooner
authorWim Taymans <wim.taymans@collabora.co.uk>
Thu, 7 Jun 2012 13:28:39 +0000 (15:28 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Thu, 7 Jun 2012 13:32:27 +0000 (15:32 +0200)
Release the object lock before we get the time of the clock because that code
might take other locks.
Fix potential clock refcount error because we released the object lock but
didn't ref the clock.

libs/gst/base/gstbasesrc.c

index 8a4fec6..c5fad37 100644 (file)
@@ -2013,7 +2013,7 @@ gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
   GstClockTime base_time;
   GstClock *clock;
   GstClockTime now = GST_CLOCK_TIME_NONE, timestamp;
-  gboolean do_timestamp, first, pseudo_live;
+  gboolean do_timestamp, first, pseudo_live, is_live;
 
   bclass = GST_BASE_SRC_GET_CLASS (basesrc);
 
@@ -2028,8 +2028,9 @@ gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
    * latency. */
   GST_OBJECT_LOCK (basesrc);
 
+  is_live = basesrc->is_live;
   /* if we are asked to sync against the clock we are a pseudo live element */
-  pseudo_live = (start != -1 && basesrc->is_live);
+  pseudo_live = (start != -1 && is_live);
   /* check for the first buffer */
   first = (basesrc->priv->latency == -1);
 
@@ -2057,17 +2058,20 @@ gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
     }
   } else if (first) {
     GST_DEBUG_OBJECT (basesrc, "no latency needed, live %d, sync %d",
-        basesrc->is_live, start != -1);
+        is_live, start != -1);
     basesrc->priv->latency = 0;
   }
 
   /* get clock, if no clock, we can't sync or do timestamps */
   if ((clock = GST_ELEMENT_CLOCK (basesrc)) == NULL)
     goto no_clock;
+  else
+    gst_object_ref (clock);
 
   base_time = GST_ELEMENT_CAST (basesrc)->base_time;
 
   do_timestamp = basesrc->priv->do_timestamp;
+  GST_OBJECT_UNLOCK (basesrc);
 
   /* first buffer, calculate the timestamp offset */
   if (first) {
@@ -2125,7 +2129,7 @@ gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
   if (!GST_CLOCK_TIME_IS_VALID (start))
     goto no_sync;
 
-  if (basesrc->is_live && GST_CLOCK_TIME_IS_VALID (timestamp)) {
+  if (is_live && GST_CLOCK_TIME_IS_VALID (timestamp)) {
     /* for pseudo live sources, add our ts_offset to the timestamp */
     GST_BUFFER_TIMESTAMP (buffer) += basesrc->priv->ts_offset;
     start += basesrc->priv->ts_offset;
@@ -2135,10 +2139,11 @@ gst_base_src_do_sync (GstBaseSrc * basesrc, GstBuffer * buffer)
       "waiting for clock, base time %" GST_TIME_FORMAT
       ", stream_start %" GST_TIME_FORMAT,
       GST_TIME_ARGS (base_time), GST_TIME_ARGS (start));
-  GST_OBJECT_UNLOCK (basesrc);
 
   result = gst_base_src_wait (basesrc, clock, start + base_time);
 
+  gst_object_unref (clock);
+
   GST_LOG_OBJECT (basesrc, "clock entry done: %d", result);
 
   return result;
@@ -2153,7 +2158,7 @@ no_clock:
 no_sync:
   {
     GST_DEBUG_OBJECT (basesrc, "no sync needed");
-    GST_OBJECT_UNLOCK (basesrc);
+    gst_object_unref (clock);
     return GST_CLOCK_OK;
   }
 }