pwg: fix more negotiation for 1.0
authorWim Taymans <wim.taymans@collabora.co.uk>
Fri, 28 Sep 2012 08:04:51 +0000 (10:04 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Fri, 28 Sep 2012 08:07:28 +0000 (10:07 +0200)
docs/pwg/advanced-negotiation.xml

index f26e9be..6264ec2 100644 (file)
@@ -423,26 +423,58 @@ gst_my_filter_chain (GstPad    *pad,
 #include "init.func"
 --><!-- example-end getcaps.c a -->
 <!-- example-begin getcaps.c b -->
-static GstCaps *
-gst_my_filter_getcaps (GstPad *pad)
+static gboolean
+gst_my_filter_query (GstPad *pad, GstObject * parent, GstQuery * query)
 {
-  GstMyFilter *filter = GST_MY_FILTER (GST_OBJECT_PARENT (pad));
-  GstPad *otherpad = (pad == filter-&gt;srcpad) ? filter-&gt;sinkpad :
-                                                 filter-&gt;srcpad;
-  GstCaps *othercaps = gst_pad_get_allowed_caps (otherpad), *caps;
-  gint i;
+  gboolean ret;
+  GstMyFilter *filter = GST_MY_FILTER (parent);
 
-  /* We support *any* samplerate, indifferent from the samplerate
-   * supported by the linked elements on both sides. */
-  for (i = 0; i &lt; gst_caps_get_size (othercaps); i++) {
-    GstStructure *structure = gst_caps_get_structure (othercaps, i);
+  switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_CAPS
+    {
+      GstPad *otherpad;
+      GstCaps *temp, *caps, *filter, *tcaps;
+      gint i;
 
-    gst_structure_remove_field (structure, "rate");
-  }
-  caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad));
-  gst_caps_unref (othercaps);
+      otherpad = (pad == filter-&gt;srcpad) ? filter-&gt;sinkpad :
+                                              filter-&gt;srcpad;
+      caps = gst_pad_get_allowed_caps (otherpad);
+
+      gst_query_parse_caps (query, &amp;filter);
+
+      /* We support *any* samplerate, indifferent from the samplerate
+       * supported by the linked elements on both sides. */
+      for (i = 0; i &lt; gst_caps_get_size (caps); i++) {
+        GstStructure *structure = gst_caps_get_structure (caps, i);
 
-  return caps;
+        gst_structure_remove_field (structure, "rate");
+      }
+
+      /* make sure we only return results that intersect our
+       * padtemplate */
+      tcaps = gst_pad_get_pad_template_caps (pad);
+      if (tcaps) {
+        temp = gst_caps_intersect (caps, tcaps);
+        gst_caps_unref (caps);
+        gst_caps_unref (tcaps);
+        caps = temp;
+      }
+      /* filter against the query filter when needed */
+      if (filter) {
+        temp = gst_caps_intersect (caps, filter);
+        gst_caps_unref (caps);
+        caps = temp;
+      }
+      gst_query_set_caps_result (query, caps);
+      gst_caps_unref (caps);
+      ret = TRUE;
+      break;
+    }
+    default:
+      ret = gst_pad_query_default (pad, parent, query);
+      break;
+  }
+  return ret;
 }
 <!-- example-end getcaps.c b -->
 <!-- example-begin getcaps.c c --><!--