audio{enc,dec}oder: Check if srcpad caps are a subset of the template caps
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 1 Feb 2012 15:32:53 +0000 (16:32 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Wed, 1 Feb 2012 15:32:53 +0000 (16:32 +0100)
gst-libs/gst/audio/gstaudiodecoder.c
gst-libs/gst/audio/gstaudioencoder.c

index c28af8b..1056e50 100644 (file)
@@ -503,6 +503,7 @@ gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
   gboolean res = TRUE;
   guint old_rate;
   GstCaps *caps;
+  GstCaps *templ_caps;
 
   GST_DEBUG_OBJECT (dec, "Setting output format");
 
@@ -514,6 +515,15 @@ gst_audio_decoder_set_output_format (GstAudioDecoder * dec,
   if (!caps)
     goto refuse_caps;
 
+  /* Only allow caps that are a subset of the template caps */
+  templ_caps = gst_pad_get_pad_template_caps (dec->srcpad);
+  if (!gst_caps_is_subset (caps, templ_caps)) {
+    gst_caps_unref (caps);
+    gst_caps_unref (templ_caps);
+    goto refuse_caps;
+  }
+  gst_caps_unref (templ_caps);
+
   /* adjust ts tracking to new sample rate */
   old_rate = GST_AUDIO_INFO_RATE (&dec->priv->ctx.info);
   if (GST_CLOCK_TIME_IS_VALID (dec->priv->base_ts) && old_rate) {
index dc5d79e..689df06 100644 (file)
@@ -2183,12 +2183,21 @@ gboolean
 gst_audio_encoder_set_output_format (GstAudioEncoder * enc, GstCaps * caps)
 {
   gboolean res = FALSE;
+  GstCaps *templ_caps;
 
   GST_DEBUG_OBJECT (enc, "Setting srcpad caps %" GST_PTR_FORMAT, caps);
 
   if (!gst_caps_is_fixed (caps))
     goto refuse_caps;
 
+  /* Only allow caps that are a subset of the template caps */
+  templ_caps = gst_pad_get_pad_template_caps (enc->srcpad);
+  if (!gst_caps_is_subset (caps, templ_caps)) {
+    gst_caps_unref (templ_caps);
+    goto refuse_caps;
+  }
+  gst_caps_unref (templ_caps);
+
   res = gst_pad_set_caps (enc->srcpad, caps);
 
 done: