audiodecoder: implement caps and accept-caps queries
authorThiago Santos <thiagoss@osg.samsung.com>
Tue, 16 Dec 2014 21:36:57 +0000 (18:36 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Wed, 17 Dec 2014 22:15:23 +0000 (19:15 -0300)
Allows decoders to proxy downstream restrictions on caps.

Also implements accept-caps query to prevent regressions caused by the
new fields on the return of a caps query that would cause the accept-caps
to fail as it uses subset caps comparisons

gst-libs/gst/audio/gstaudiodecoder.c

index a5d10ad..efd979b 100644 (file)
 #endif
 
 #include "gstaudiodecoder.h"
+#include "gstaudioutilsprivate.h"
 #include <gst/pbutils/descriptions.h>
 
 #include <string.h>
@@ -2460,6 +2461,44 @@ gst_audio_decoder_sink_query (GstPad * pad, GstObject * parent,
         res = klass->propose_allocation (dec, query);
       break;
     }
+    case GST_QUERY_CAPS:{
+      GstCaps *filter;
+      GstCaps *result;
+
+      gst_query_parse_caps (query, &filter);
+      result = __gst_audio_element_proxy_getcaps (GST_ELEMENT_CAST (dec),
+          GST_AUDIO_DECODER_SINK_PAD (dec),
+          GST_AUDIO_DECODER_SRC_PAD (dec), NULL, filter);
+      gst_query_set_caps_result (query, result);
+      gst_caps_unref (result);
+      res = TRUE;
+      break;
+    }
+    case GST_QUERY_ACCEPT_CAPS:{
+      GstCaps *caps;
+      GstCaps *allowed_caps;
+      GstCaps *template_caps;
+      gboolean accept;
+
+      gst_query_parse_accept_caps (query, &caps);
+
+      template_caps = gst_pad_get_pad_template_caps (pad);
+      accept = gst_caps_is_subset (caps, template_caps);
+      gst_caps_unref (template_caps);
+
+      if (accept) {
+        allowed_caps = gst_pad_query_caps (GST_AUDIO_DECODER_SINK_PAD (dec),
+            caps);
+
+        accept = gst_caps_can_intersect (caps, allowed_caps);
+
+        gst_caps_unref (allowed_caps);
+      }
+
+      gst_query_set_accept_caps_result (query, accept);
+      res = TRUE;
+      break;
+    }
     case GST_QUERY_SEEKING:
     {
       GstFormat format;