+static gboolean
+gst_v4l2sink_sink_query (GstPad * sinkpad, GstQuery * query)
+{
+ GstV4l2Sink *v4l2sink = GST_V4L2SINK (GST_PAD_PARENT (sinkpad));
+ GstV4l2Object *obj = v4l2sink->v4l2object;
+ gboolean res = TRUE;
+
+ switch (GST_QUERY_TYPE (query)) {
+ case GST_QUERY_ALLOCATION:
+ {
+ GstBufferPool *pool;
+ GstStructure *config;
+ GstCaps *caps;
+ guint size = 0;
+ gboolean need_pool;
+
+ gst_query_parse_allocation (query, &caps, &need_pool);
+
+ if (caps == NULL)
+ goto no_caps;
+
+ if ((pool = obj->pool))
+ gst_object_ref (pool);
+
+ if (pool != NULL) {
+ const GstCaps *pcaps;
+
+ /* we had a pool, check caps */
+ config = gst_buffer_pool_get_config (pool);
+ gst_buffer_pool_config_get (config, &pcaps, &size, NULL, NULL, NULL,
+ NULL);
+
+ GST_DEBUG_OBJECT (v4l2sink,
+ "we had a pool with caps %" GST_PTR_FORMAT, pcaps);
+ if (!gst_caps_is_equal (caps, pcaps)) {
+ gst_object_unref (pool);
+ goto different_caps;
+ }
+ }
+ gst_query_set_allocation_params (query, size, 0, 0, 0, 15, pool);
+
+ /* we also support various metadata */
+ gst_query_add_allocation_meta (query, GST_META_API_VIDEO);
+ gst_query_add_allocation_meta (query, GST_META_API_VIDEO_CROP);
+
+ if (pool)
+ gst_object_unref (pool);
+ break;
+ }
+ default:
+ res = FALSE;
+ break;
+ }
+ return res;
+
+ /* ERRORS */
+no_caps:
+ {
+ GST_DEBUG_OBJECT (sinkpad, "no caps specified");
+ return FALSE;
+ }
+different_caps:
+ {
+ /* different caps, we can't use this pool */
+ GST_DEBUG_OBJECT (v4l2sink, "pool has different caps");
+ return FALSE;
+ }
+}
+