pad: remove get_caps_reffed variants
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 7 Dec 2010 17:14:38 +0000 (18:14 +0100)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 7 Dec 2010 17:14:38 +0000 (18:14 +0100)
Make the _get_caps functions behave like the _get_caps_reffed variants and
remove the _reffed variants. This means that _get_caps doesn't return a writable
caps anymore and an explicit _make_writable() is needed before modifying the
caps.

gst/gstcompat.h
gst/gstghostpad.c
gst/gstpad.c
gst/gstpad.h
gst/gstutils.c
libs/gst/base/gstbasesrc.c
libs/gst/base/gstbasetransform.c
tests/check/gst/gstpad.c

index d1877d5..07f5cc2 100644 (file)
@@ -44,6 +44,8 @@ G_BEGIN_DECLS
 #define gst_element_factory_get_documentation_uri(f)  gst_element_factory_get_metadata(f, GST_ELEMENT_METADATA_DOC_URI)
 #define gst_element_factory_get_icon_name(f)   gst_element_factory_get_metadata(f, GST_ELEMENT_METADATA_ICON_NAME)
 
+#define gst_pad_get_caps_reffed(p)             gst_pad_get_caps(p)
+#define gst_pad_peer_get_caps_reffed(p)        gst_pad_peer_get_caps(p)
 
 #ifndef GST_DISABLE_DEPRECATED
 
index 83d468c..ba38570 100644 (file)
@@ -200,7 +200,7 @@ gst_proxy_pad_do_getcaps (GstPad * pad)
 
   if (target) {
     /* if we have a real target, proxy the call */
-    res = gst_pad_get_caps_reffed (target);
+    res = gst_pad_get_caps (target);
 
     GST_DEBUG_OBJECT (pad, "get caps of target %s:%s : %" GST_PTR_FORMAT,
         GST_DEBUG_PAD_NAME (target), res);
index 61f4f1d..cbf4e48 100644 (file)
@@ -2210,38 +2210,6 @@ done:
   return result;
 }
 
-/* FIXME-0.11: what about making this the default and using
- * gst_caps_make_writable() explicitely where needed
- */
-/**
- * gst_pad_get_caps_reffed:
- * @pad: a  #GstPad to get the capabilities of.
- *
- * Gets the capabilities this pad can produce or consume. Preferred function if
- * one only wants to read or intersect the caps.
- *
- * Returns: the caps of the pad with incremented ref-count.
- *
- * Since: 0.10.26
- */
-GstCaps *
-gst_pad_get_caps_reffed (GstPad * pad)
-{
-  GstCaps *result = NULL;
-
-  g_return_val_if_fail (GST_IS_PAD (pad), NULL);
-
-  GST_OBJECT_LOCK (pad);
-
-  GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
-
-  result = gst_pad_get_caps_unlocked (pad);
-
-  GST_OBJECT_UNLOCK (pad);
-
-  return result;
-}
-
 /**
  * gst_pad_get_caps:
  * @pad: a  #GstPad to get the capabilities of.
@@ -2253,78 +2221,38 @@ gst_pad_get_caps_reffed (GstPad * pad)
  * the pad's get_caps function;
  * this returns the pad template caps if not explicitly set.
  *
- * Returns: a newly allocated copy of the #GstCaps of this pad.
- *
- * MT safe.
- */
-GstCaps *
-gst_pad_get_caps (GstPad * pad)
-{
-  GstCaps *result = gst_pad_get_caps_reffed (pad);
-
-  /* be sure that we have a copy */
-  if (G_LIKELY (result))
-    result = gst_caps_make_writable (result);
-
-  return result;
-}
-
-/* FIXME-0.11: what about making this the default and using
- * gst_caps_make_writable() explicitely where needed
- */
-/**
- * gst_pad_peer_get_caps_reffed:
- * @pad: a  #GstPad to get the capabilities of.
- *
- * Gets the capabilities of the peer connected to this pad. Preferred function
- * if one only wants to read or intersect the caps.
+ * Note that this function does not return writable #GstCaps, use
+ * gst_caps_make_writable() before modifying the caps.
  *
  * Returns: the caps of the pad with incremented ref-count.
- *
- * Since: 0.10.26
  */
 GstCaps *
-gst_pad_peer_get_caps_reffed (GstPad * pad)
+gst_pad_get_caps (GstPad * pad)
 {
-  GstPad *peerpad;
   GstCaps *result = NULL;
 
   g_return_val_if_fail (GST_IS_PAD (pad), NULL);
 
   GST_OBJECT_LOCK (pad);
 
-  GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get peer caps");
+  GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
 
-  peerpad = GST_PAD_PEER (pad);
-  if (G_UNLIKELY (peerpad == NULL))
-    goto no_peer;
+  result = gst_pad_get_caps_unlocked (pad);
 
-  gst_object_ref (peerpad);
   GST_OBJECT_UNLOCK (pad);
 
-  result = gst_pad_get_caps_reffed (peerpad);
-
-  gst_object_unref (peerpad);
-
   return result;
-
-no_peer:
-  {
-    GST_OBJECT_UNLOCK (pad);
-    return NULL;
-  }
 }
 
 /**
  * gst_pad_peer_get_caps:
- * @pad: a  #GstPad to get the peer capabilities of.
+ * @pad: a  #GstPad to get the capabilities of.
  *
  * Gets the capabilities of the peer connected to this pad. Similar to
  * gst_pad_get_caps().
  *
- * Returns: a newly allocated copy of the #GstCaps of the peer pad. Use
- * gst_caps_unref() to get rid of it. This function returns %NULL if there is
- * no peer pad.
+ * Returns: the caps of the peer pad with incremented ref-count. This function
+ * returns %NULL when there is no peer pad.
  */
 GstCaps *
 gst_pad_peer_get_caps (GstPad * pad)
@@ -2470,7 +2398,7 @@ gst_pad_acceptcaps_default (GstPad * pad, GstCaps * caps)
 
   GST_DEBUG_OBJECT (pad, "caps %" GST_PTR_FORMAT, caps);
 
-  allowed = gst_pad_get_caps_reffed (pad);
+  allowed = gst_pad_get_caps (pad);
   if (!allowed)
     goto nothing_allowed;
 
@@ -2810,9 +2738,9 @@ gst_pad_get_allowed_caps (GstPad * pad)
 
   gst_object_ref (peer);
   GST_OBJECT_UNLOCK (pad);
-  mycaps = gst_pad_get_caps_reffed (pad);
+  mycaps = gst_pad_get_caps (pad);
 
-  peercaps = gst_pad_get_caps_reffed (peer);
+  peercaps = gst_pad_get_caps (peer);
   gst_object_unref (peer);
 
   caps = gst_caps_intersect (mycaps, peercaps);
index 3e6e233..e9e67b9 100644 (file)
@@ -900,13 +900,11 @@ void                      gst_pad_set_setcaps_function            (GstPad *pad, GstPadSetCapsFunction setcaps
 G_CONST_RETURN GstCaps*        gst_pad_get_pad_template_caps           (GstPad *pad);
 
 /* capsnego function for linked/unlinked pads */
-GstCaps *              gst_pad_get_caps_reffed                 (GstPad * pad);
 GstCaps *              gst_pad_get_caps                        (GstPad * pad);
 void                   gst_pad_fixate_caps                     (GstPad * pad, GstCaps *caps);
 gboolean               gst_pad_accept_caps                     (GstPad * pad, GstCaps *caps);
 gboolean               gst_pad_set_caps                        (GstPad * pad, GstCaps *caps);
 
-GstCaps *              gst_pad_peer_get_caps_reffed            (GstPad * pad);
 GstCaps *              gst_pad_peer_get_caps                   (GstPad * pad);
 gboolean               gst_pad_peer_accept_caps                (GstPad * pad, GstCaps *caps);
 
index 7d75e93..f8895d2 100644 (file)
@@ -1148,7 +1148,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
           gboolean compatible;
 
           /* Now check if the two pads' caps are compatible */
-          temp = gst_pad_get_caps_reffed (pad);
+          temp = gst_pad_get_caps (pad);
           if (caps) {
             intersection = gst_caps_intersect (temp, caps);
             gst_caps_unref (temp);
@@ -1156,7 +1156,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
             intersection = temp;
           }
 
-          temp = gst_pad_get_caps_reffed (current);
+          temp = gst_pad_get_caps (current);
           compatible = gst_caps_can_intersect (temp, intersection);
           gst_caps_unref (temp);
           gst_caps_unref (intersection);
@@ -1202,7 +1202,7 @@ gst_element_get_compatible_pad (GstElement * element, GstPad * pad,
   /* try to create a new one */
   /* requesting is a little crazy, we need a template. Let's create one */
   /* FIXME: why not gst_pad_get_pad_template (pad); */
-  templcaps = gst_pad_get_caps_reffed (pad);
+  templcaps = gst_pad_get_caps (pad);
 
   templ = gst_pad_template_new ((gchar *) GST_PAD_NAME (pad),
       GST_PAD_DIRECTION (pad), GST_PAD_ALWAYS, templcaps);
@@ -2680,7 +2680,7 @@ getcaps_fold_func (GstPad * pad, GValue * ret, GstPad * orig)
   GstCaps *peercaps, *existing;
 
   existing = g_value_get_pointer (ret);
-  peercaps = gst_pad_peer_get_caps_reffed (pad);
+  peercaps = gst_pad_peer_get_caps (pad);
   if (G_LIKELY (peercaps)) {
     GstCaps *intersection = gst_caps_intersect (existing, peercaps);
 
index 649a07c..9768f56 100644 (file)
@@ -2589,7 +2589,7 @@ gst_base_src_default_negotiate (GstBaseSrc * basesrc)
   gboolean result = FALSE;
 
   /* first see what is possible on our source pad */
-  thiscaps = gst_pad_get_caps_reffed (GST_BASE_SRC_PAD (basesrc));
+  thiscaps = gst_pad_get_caps (GST_BASE_SRC_PAD (basesrc));
   GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
   /* nothing or anything is allowed, we're done */
   if (thiscaps == NULL || gst_caps_is_any (thiscaps))
@@ -2599,7 +2599,7 @@ gst_base_src_default_negotiate (GstBaseSrc * basesrc)
     goto no_caps;
 
   /* get the peer caps */
-  peercaps = gst_pad_peer_get_caps_reffed (GST_BASE_SRC_PAD (basesrc));
+  peercaps = gst_pad_peer_get_caps (GST_BASE_SRC_PAD (basesrc));
   GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
   if (peercaps) {
     /* get intersection */
index 62731c5..ba02627 100644 (file)
@@ -639,7 +639,7 @@ gst_base_transform_getcaps (GstPad * pad)
   otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
 
   /* we can do what the peer can */
-  caps = gst_pad_peer_get_caps_reffed (otherpad);
+  caps = gst_pad_peer_get_caps (otherpad);
   if (caps) {
     GstCaps *temp;
     const GstCaps *templ;
@@ -888,7 +888,7 @@ gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
 
     GST_DEBUG_OBJECT (trans, "othercaps now %" GST_PTR_FORMAT, othercaps);
 
-    peercaps = gst_pad_get_caps_reffed (otherpeer);
+    peercaps = gst_pad_get_caps (otherpeer);
     intersect = gst_caps_intersect (peercaps, othercaps);
     gst_caps_unref (peercaps);
     gst_caps_unref (othercaps);
@@ -1029,9 +1029,9 @@ gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
 
     /* get all the formats we can handle on this pad */
     if (direction == GST_PAD_SRC)
-      allowed = gst_pad_get_caps_reffed (trans->srcpad);
+      allowed = gst_pad_get_caps (trans->srcpad);
     else
-      allowed = gst_pad_get_caps_reffed (trans->sinkpad);
+      allowed = gst_pad_get_caps (trans->sinkpad);
 
     if (!allowed) {
       GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
@@ -1736,8 +1736,7 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
         GST_DEBUG_OBJECT (trans, "Suggested caps is not fixed: %"
             GST_PTR_FORMAT, sink_suggest);
 
-        peercaps =
-            gst_pad_peer_get_caps_reffed (GST_BASE_TRANSFORM_SINK_PAD (trans));
+        peercaps = gst_pad_peer_get_caps (GST_BASE_TRANSFORM_SINK_PAD (trans));
         /* try fixating by intersecting with peer caps */
         if (peercaps) {
           GstCaps *intersect;
index 74bfd59..e07c18e 100644 (file)
@@ -651,33 +651,6 @@ GST_START_TEST (test_sink_unref_unlink)
 
 GST_END_TEST;
 
-/* gst_pad_get_caps should return a copy of the caps */
-GST_START_TEST (test_get_caps_must_be_copy)
-{
-  GstPad *pad;
-  GstCaps *caps;
-  GstPadTemplate *templ;
-
-  caps = gst_caps_new_any ();
-  templ =
-      gst_pad_template_new ("test_templ", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
-
-  pad = gst_pad_new_from_template (templ, NULL);
-  fail_unless (GST_PAD_CAPS (pad) == NULL, "caps present on pad");
-  /* This is a writable copy ! */
-  caps = gst_pad_get_caps (pad);
-
-  /* we must own the caps */
-  ASSERT_OBJECT_REFCOUNT (caps, "caps", 1);
-
-  /* cleanup */
-  gst_object_unref (templ);
-  gst_caps_unref (caps);
-  gst_object_unref (pad);
-}
-
-GST_END_TEST;
-
 static void
 unblock_async_cb (GstPad * pad, gboolean blocked, gpointer user_data)
 {
@@ -989,7 +962,6 @@ gst_pad_suite (void)
   tcase_add_test (tc_chain, test_push_negotiation);
   tcase_add_test (tc_chain, test_src_unref_unlink);
   tcase_add_test (tc_chain, test_sink_unref_unlink);
-  tcase_add_test (tc_chain, test_get_caps_must_be_copy);
   tcase_add_test (tc_chain, test_block_async);
 #if 0
   tcase_add_test (tc_chain, test_block_async_replace_callback);