pad: implement fixed caps with an object flag
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 6 May 2011 15:59:33 +0000 (17:59 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 6 May 2011 15:59:33 +0000 (17:59 +0200)
Implement fixed caps with an object flag instead of a custom getcaps function.

gst/gstpad.c
gst/gstpad.h
gst/gstutils.c
gst/gstutils.h

index 0c83011..f62837d 100644 (file)
@@ -333,9 +333,6 @@ gst_pad_class_init (GstPadClass * klass)
   GST_DEBUG_REGISTER_FUNCPTR (gst_pad_iterate_internal_links_default);
   GST_DEBUG_REGISTER_FUNCPTR (gst_pad_acceptcaps_default);
 
-  /* from gstutils.c */
-  GST_DEBUG_REGISTER_FUNCPTR (gst_pad_get_fixed_caps_func);
-
   klass->have_data = default_have_data;
 }
 
@@ -2180,10 +2177,13 @@ gst_pad_get_caps_unlocked (GstPad * pad)
 {
   GstCaps *result = NULL;
   GstPadTemplate *templ;
+  gboolean fixed_caps;
 
   GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
 
-  if (GST_PAD_GETCAPSFUNC (pad)) {
+  fixed_caps = GST_PAD_IS_FIXED_CAPS (pad);
+
+  if (!fixed_caps && GST_PAD_GETCAPSFUNC (pad)) {
     GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
         "dispatching to pad getcaps function");
 
@@ -2223,6 +2223,12 @@ gst_pad_get_caps_unlocked (GstPad * pad)
       goto done;
     }
   }
+  if (fixed_caps && (result = get_pad_caps (pad))) {
+    GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
+        "using pad caps %p %" GST_PTR_FORMAT, result, result);
+    result = gst_caps_ref (result);
+    goto done;
+  }
   if ((templ = GST_PAD_PAD_TEMPLATE (pad))) {
     result = GST_PAD_TEMPLATE_CAPS (templ);
     GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
@@ -2232,10 +2238,9 @@ gst_pad_get_caps_unlocked (GstPad * pad)
     result = gst_caps_ref (result);
     goto done;
   }
-  if ((result = get_pad_caps (pad))) {
+  if (!fixed_caps && (result = get_pad_caps (pad))) {
     GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad,
         "using pad caps %p %" GST_PTR_FORMAT, result, result);
-
     result = gst_caps_ref (result);
     goto done;
   }
index ba2cf47..681102d 100644 (file)
@@ -514,6 +514,9 @@ typedef enum {
  *                            reconfiguration happened.
  *                            Since: 0.10.34.
  * @GST_PAD_NEED_EVENTS: the pad has pending events
+ * @GST_PAD_FIXED_CAPS: the pad is using fixed caps this means that once the
+ *                      caps are set on the pad, the getcaps function only
+ *                      returns those caps.
  * @GST_PAD_FLAG_LAST: offset to define more flags
  *
  * Pad state flags
@@ -526,6 +529,7 @@ typedef enum {
   GST_PAD_BLOCKING         = (GST_OBJECT_FLAG_LAST << 4),
   GST_PAD_NEED_RECONFIGURE = (GST_OBJECT_FLAG_LAST << 5),
   GST_PAD_NEED_EVENTS      = (GST_OBJECT_FLAG_LAST << 6),
+  GST_PAD_FIXED_CAPS       = (GST_OBJECT_FLAG_LAST << 7),
   /* padding */
   GST_PAD_FLAG_LAST        = (GST_OBJECT_FLAG_LAST << 16)
 } GstPadFlags;
@@ -693,7 +697,11 @@ struct _GstPadClass {
 #define GST_PAD_DO_BUFFER_SIGNALS(pad)         (GST_PAD_CAST(pad)->do_buffer_signals)
 #define GST_PAD_DO_EVENT_SIGNALS(pad)  (GST_PAD_CAST(pad)->do_event_signals)
 
+#define GST_PAD_IS_SRC(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
+#define GST_PAD_IS_SINK(pad)           (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
+
 #define GST_PAD_IS_LINKED(pad)         (GST_PAD_PEER(pad) != NULL)
+
 #define GST_PAD_IS_BLOCKED(pad)                (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKED))
 #define GST_PAD_IS_BLOCKING(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_BLOCKING))
 #define GST_PAD_IS_FLUSHING(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FLUSHING))
@@ -701,8 +709,7 @@ struct _GstPadClass {
 #define GST_PAD_IS_IN_SETCAPS(pad)     (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_IN_SETCAPS))
 #define GST_PAD_NEEDS_RECONFIGURE(pad)  (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_NEED_RECONFIGURE))
 #define GST_PAD_NEEDS_EVENTS(pad)       (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_NEED_EVENTS))
-#define GST_PAD_IS_SRC(pad)            (GST_PAD_DIRECTION(pad) == GST_PAD_SRC)
-#define GST_PAD_IS_SINK(pad)           (GST_PAD_DIRECTION(pad) == GST_PAD_SINK)
+#define GST_PAD_IS_FIXED_CAPS(pad)     (GST_OBJECT_FLAG_IS_SET (pad, GST_PAD_FIXED_CAPS))
 
 #define GST_PAD_SET_FLUSHING(pad)      (GST_OBJECT_FLAG_SET (pad, GST_PAD_FLUSHING))
 #define GST_PAD_UNSET_FLUSHING(pad)    (GST_OBJECT_FLAG_UNSET (pad, GST_PAD_FLUSHING))
index d4552da..5013fdd 100644 (file)
@@ -2377,9 +2377,8 @@ gst_element_seek_simple (GstElement * element, GstFormat format,
  * gst_pad_use_fixed_caps:
  * @pad: the pad to use
  *
- * A helper function you can use that sets the
- * @gst_pad_get_fixed_caps_func as the getcaps function for the
- * pad. This way the function will always return the negotiated caps
+ * A helper function you can use that sets the FIXED_CAPS flag
+ * This way the default getcaps function will always return the negotiated caps
  * or in case the pad is not negotiated, the padtemplate caps.
  *
  * Use this function on a pad that, once gst_pad_set_caps() has been called
@@ -2388,52 +2387,7 @@ gst_element_seek_simple (GstElement * element, GstFormat format,
 void
 gst_pad_use_fixed_caps (GstPad * pad)
 {
-  gst_pad_set_getcaps_function (pad, gst_pad_get_fixed_caps_func);
-}
-
-/**
- * gst_pad_get_fixed_caps_func:
- * @pad: the pad to use
- *
- * A helper function you can use as a GetCaps function that
- * will return the currently negotiated caps or the padtemplate
- * when NULL.
- *
- * Free-function: gst_caps_unref
- *
- * Returns: (transfer full): the currently negotiated caps or the padtemplate.
- */
-GstCaps *
-gst_pad_get_fixed_caps_func (GstPad * pad)
-{
-  GstCaps *result;
-
-  g_return_val_if_fail (GST_IS_PAD (pad), NULL);
-
-  GST_OBJECT_LOCK (pad);
-  if (GST_PAD_CAPS (pad)) {
-    result = GST_PAD_CAPS (pad);
-
-    GST_CAT_DEBUG (GST_CAT_CAPS,
-        "using pad caps %p %" GST_PTR_FORMAT, result, result);
-
-    result = gst_caps_ref (result);
-  } else if (GST_PAD_PAD_TEMPLATE (pad)) {
-    GstPadTemplate *templ = GST_PAD_PAD_TEMPLATE (pad);
-
-    result = GST_PAD_TEMPLATE_CAPS (templ);
-    GST_CAT_DEBUG (GST_CAT_CAPS,
-        "using pad template %p with caps %p %" GST_PTR_FORMAT, templ, result,
-        result);
-
-    result = gst_caps_ref (result);
-  } else {
-    GST_CAT_DEBUG (GST_CAT_CAPS, "pad has no caps");
-    result = gst_caps_new_empty ();
-  }
-  GST_OBJECT_UNLOCK (pad);
-
-  return result;
+  GST_OBJECT_FLAG_SET (pad, GST_PAD_FIXED_CAPS);
 }
 
 /**
index 1bed731..dec9e98 100644 (file)
@@ -907,7 +907,6 @@ void                        gst_element_class_install_std_props (GstElementClass * klass,
 
 /* pad functions */
 void                   gst_pad_use_fixed_caps          (GstPad *pad);
-GstCaps*               gst_pad_get_fixed_caps_func     (GstPad *pad);
 GstCaps*               gst_pad_proxy_getcaps           (GstPad * pad);
 gboolean               gst_pad_proxy_setcaps           (GstPad * pad, GstCaps * caps);