Add functions useful default pad_link and fixate functions.
authorDavid Schleef <ds@schleef.org>
Wed, 31 Dec 2003 08:06:49 +0000 (08:06 +0000)
committerDavid Schleef <ds@schleef.org>
Wed, 31 Dec 2003 08:06:49 +0000 (08:06 +0000)
Original commit message from CVS:
Add functions useful default pad_link and fixate functions.

ChangeLog
gst/gstpad.c
gst/gstpad.h

index 556cac7..90fe9c8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2003-12-31  David Schleef  <ds@schleef.org>
+
+       * gst/gstpad.c: (gst_pad_proxy_pad_link), (gst_pad_proxy_fixate):
+       * gst/gstpad.h: Add functions that are useful as default pad
+       link and fixate functions for elements.
+
 2003-12-30  David Schleef  <ds@schleef.org>
 
        * gst/gstpad.c: (gst_pad_link_try):
index 2dedd5d..eb2c57c 100644 (file)
@@ -2014,6 +2014,91 @@ gst_pad_proxy_getcaps (GstPad *pad)
 }
 
 /**
+ * gst_pad_proxy_pad_link:
+ * @pad: a #GstPad to proxy.
+ *
+ * Calls gst_pad_try_set_caps() for every other pad belonging to the
+ * same element as @pad.  If gst_pad_try_set_caps() fails on any pad,
+ * the proxy link fails.
+ *
+ * Returns: GST_PAD_LINK_OK if sucessful
+ */
+GstPadLinkReturn
+gst_pad_proxy_pad_link (GstPad *pad, const GstCaps *caps)
+{
+  GstElement *element;
+  const GList *pads;
+  GstPadLinkReturn ret;
+
+  GST_DEBUG ("proxying pad link for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
+
+  element = gst_pad_get_parent (pad);
+
+  pads = gst_element_get_pad_list (element);
+  
+  while (pads) {
+    GstPad *otherpad = GST_PAD (pads->data);
+
+    if (otherpad != pad) {
+      ret = gst_pad_try_set_caps (otherpad, caps);
+      if (GST_PAD_LINK_FAILED (ret)) {
+        return ret;
+      }
+    }
+    pads = g_list_next (pads);
+  }
+
+  return GST_PAD_LINK_OK;
+}
+
+/**
+ * gst_pad_proxy_fixate:
+ * @pad: a #GstPad to proxy.
+ *
+ * Implements a default fixate function based on the caps set on the other
+ * pads in the element.  This function should only be used if every pad
+ * has the same pad template caps.
+ *
+ * Returns: a fixated caps, or NULL if caps cannot be fixed
+ */
+GstCaps *
+gst_pad_proxy_fixate (GstPad *pad, const GstCaps *caps, gpointer unused)
+{
+  GstElement *element;
+  const GList *pads;
+  const GstCaps *othercaps;
+
+  GST_DEBUG ("proxying fixate for %s:%s\n", GST_DEBUG_PAD_NAME (pad));
+
+  element = gst_pad_get_parent (pad);
+
+  pads = gst_element_get_pad_list (element);
+
+  while (pads) {
+    GstPad *otherpad = GST_PAD (pads->data);
+
+    /* FIXME check that each pad has the same pad template caps */
+
+    if (otherpad != pad) {
+      othercaps = gst_pad_get_negotiated_caps (otherpad);
+
+      if (othercaps) {
+        GstCaps *icaps;
+        icaps = gst_caps_intersect (othercaps, caps);
+        if (!gst_caps_is_empty (icaps)) {
+          return icaps;
+        } else {
+          gst_caps_free (icaps);
+        }
+      }
+    }
+    pads = g_list_next (pads);
+  }
+  
+  return NULL;
+}
+
+/**
  * gst_pad_proxy_link:
  * @pad: a #GstPad to proxy to.
  * @caps: the #GstCaps to use in proxying.
index be89fe8..cf136be 100644 (file)
@@ -411,7 +411,11 @@ gboolean           gst_pad_check_compatibility             (GstPad *srcpad, GstPad *sinkpad);
 void                   gst_pad_set_getcaps_function            (GstPad *pad, GstPadGetCapsFunction getcaps);
 void                   gst_pad_set_fixate_function             (GstPad *pad, GstPadFixateFunction fixate);
 GstCaps *              gst_pad_proxy_getcaps                   (GstPad *pad);
+GstPadLinkReturn        gst_pad_proxy_pad_link                  (GstPad *pad, const GstCaps *caps);
+GstCaps *               gst_pad_proxy_fixate                    (GstPad *pad, const GstCaps *caps, gpointer unused);
+#ifndef GST_DISABLE_DEPRECATED
 GstPadLinkReturn       gst_pad_proxy_link                      (GstPad *pad, const GstCaps *caps);
+#endif
 gboolean               gst_pad_relink_filtered                 (GstPad *srcpad, GstPad *sinkpad, const GstCaps *filtercaps);
 #ifndef GST_DISABLE_DEPRECATED
 gboolean               gst_pad_perform_negotiate               (GstPad *srcpad, GstPad *sinkpad);