flacenc: implement proper accept-caps
authorThiago Santos <thiagoss@osg.samsung.com>
Sun, 16 Aug 2015 16:21:41 +0000 (13:21 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Sun, 16 Aug 2015 17:30:57 +0000 (14:30 -0300)
Should just compare with what can be immediatelly accepted by
the element. flacenc can't renegotiate so if it has a caps already
it should only accept if it is that caps otherwise just use the
template caps

ext/flac/gstflacenc.c

index f18b1ee..377699d 100644 (file)
@@ -141,6 +141,8 @@ static GstFlowReturn gst_flac_enc_handle_frame (GstAudioEncoder * enc,
 static GstCaps *gst_flac_enc_getcaps (GstAudioEncoder * enc, GstCaps * filter);
 static gboolean gst_flac_enc_sink_event (GstAudioEncoder * enc,
     GstEvent * event);
+static gboolean gst_flac_enc_sink_query (GstAudioEncoder * enc,
+    GstQuery * query);
 
 static void gst_flac_enc_finalize (GObject * object);
 
@@ -359,6 +361,7 @@ gst_flac_enc_class_init (GstFlacEncClass * klass)
   base_class->handle_frame = GST_DEBUG_FUNCPTR (gst_flac_enc_handle_frame);
   base_class->getcaps = GST_DEBUG_FUNCPTR (gst_flac_enc_getcaps);
   base_class->sink_event = GST_DEBUG_FUNCPTR (gst_flac_enc_sink_event);
+  base_class->sink_query = GST_DEBUG_FUNCPTR (gst_flac_enc_sink_query);
 }
 
 static void
@@ -1267,6 +1270,40 @@ gst_flac_enc_sink_event (GstAudioEncoder * enc, GstEvent * event)
   return ret;
 }
 
+static gboolean
+gst_flac_enc_sink_query (GstAudioEncoder * enc, GstQuery * query)
+{
+  GstPad *pad = GST_AUDIO_ENCODER_SINK_PAD (enc);
+  gboolean ret = FALSE;
+
+  GST_DEBUG ("Received %s query on sinkpad, %" GST_PTR_FORMAT,
+      GST_QUERY_TYPE_NAME (query), query);
+
+  switch (GST_QUERY_TYPE (query)) {
+    case GST_QUERY_ACCEPT_CAPS:{
+      GstCaps *acceptable, *caps;
+
+      if (gst_pad_has_current_caps (pad)) {
+        acceptable = gst_pad_get_current_caps (pad);
+      } else {
+        acceptable = gst_pad_get_pad_template_caps (pad);
+      }
+
+      gst_query_parse_accept_caps (query, &caps);
+
+      gst_query_set_accept_caps_result (query,
+          gst_caps_is_subset (caps, acceptable));
+      gst_caps_unref (acceptable);
+    }
+      break;
+    default:
+      ret = GST_AUDIO_ENCODER_CLASS (parent_class)->sink_query (enc, query);
+      break;
+  }
+
+  return ret;
+}
+
 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
 #define READ_INT24 GST_READ_UINT24_LE
 #else