gst/gstpad.c: Don't pound the cpu to pieces by checking get_caps when accept_caps...
authorJan Schmidt <thaytan@mad.scientist.com>
Thu, 16 Mar 2006 10:18:27 +0000 (10:18 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Thu, 16 Mar 2006 10:18:27 +0000 (10:18 +0000)
Original commit message from CVS:
* gst/gstpad.c: (gst_pad_accept_caps), (gst_pad_alloc_buffer_full),
(gst_pad_push):
Don't pound the cpu to pieces by checking get_caps when accept_caps
is called with the same caps as the pad already has.
Use GST_DEBUG_OBJECT when outputting caps change information.

ChangeLog
gst/gstpad.c

index f60badd..7adcc87 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-03-16  Jan Schmidt  <thaytan@mad.scientist.com>
+
+       * gst/gstpad.c: (gst_pad_accept_caps), (gst_pad_alloc_buffer_full),
+       (gst_pad_push):
+       Don't pound the cpu to pieces by checking get_caps when accept_caps
+       is called with the same caps as the pad already has.
+       Use GST_DEBUG_OBJECT when outputting caps change information.
+
 2006-03-15  Wim Taymans  <wim@fluendo.com>
 
        * gst/gstclock.c: (gst_clock_class_init):
index e2cac8b..b6bdba3 100644 (file)
@@ -2095,6 +2095,7 @@ gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
 {
   gboolean result;
   GstPadAcceptCapsFunction acceptfunc;
+  GstCaps *existing = NULL;
 
   g_return_val_if_fail (GST_IS_PAD (pad), FALSE);
 
@@ -2104,11 +2105,17 @@ gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
 
   GST_OBJECT_LOCK (pad);
   acceptfunc = GST_PAD_ACCEPTCAPSFUNC (pad);
+  if (GST_PAD_CAPS (pad) != NULL)
+    existing = gst_caps_ref (GST_PAD_CAPS (pad));
 
   GST_CAT_DEBUG (GST_CAT_CAPS, "pad accept caps of %s:%s (%p)",
       GST_DEBUG_PAD_NAME (pad), pad);
   GST_OBJECT_UNLOCK (pad);
 
+  /* The current caps on a pad are trivially acceptable */
+  if (existing && (caps == existing || gst_caps_is_equal (caps, existing)))
+    goto is_same_caps;
+
   if (G_LIKELY (acceptfunc)) {
     /* we can call the function */
     result = acceptfunc (pad, caps);
@@ -2117,6 +2124,10 @@ gst_pad_accept_caps (GstPad * pad, GstCaps * caps)
     result = gst_pad_acceptcaps_default (pad, caps);
   }
   return result;
+
+is_same_caps:
+  gst_caps_unref (existing);
+  return TRUE;
 }
 
 /**
@@ -2524,7 +2535,7 @@ do_caps:
   caps_changed = caps && caps != GST_PAD_CAPS (pad);
   /* we got a new datatype on the pad, see if it can handle it */
   if (G_UNLIKELY (caps_changed)) {
-    GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
+    GST_DEBUG_OBJECT (pad, "caps changed to %" GST_PTR_FORMAT, caps);
     if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, setcaps)))
       goto not_negotiated;
   }
@@ -3305,7 +3316,7 @@ gst_pad_push (GstPad * pad, GstBuffer * buffer)
 
   /* we got a new datatype from the pad, it had better handle it */
   if (G_UNLIKELY (caps_changed)) {
-    GST_DEBUG ("caps changed to %" GST_PTR_FORMAT, caps);
+    GST_DEBUG_OBJECT (pad, "caps changed to %" GST_PTR_FORMAT, caps);
     if (G_UNLIKELY (!gst_pad_configure_src (pad, caps, TRUE)))
       goto not_negotiated;
   }